ui-leaflet icon indicating copy to clipboard operation
ui-leaflet copied to clipboard

Doesn't work with CSS percentages or Javascript styles

Open davidrhoderick opened this issue 8 years ago • 4 comments

I am building an app where I want the map full width and full height of its parent element. Width is achieved through CSS using width: 100% and height is achieved through an angular directive that watches for changes in window height and applies a calculated 100% height of the parent. These are applied to the <leaflet> directive.

When I render in browser, these full width and height measures throw off the coordinates for center and for bounds. Is there any work around? Do I just have to set a fixed width using media queries? What is going wrong?

P.S. Removing my CSS width setting makes the map full width but I have the same problem.

davidrhoderick avatar Feb 15 '16 18:02 davidrhoderick

height is achieved through an angular directive that watches for changes in window height and applies a calculated 100% height of the parent.

Why are you using JavaScript to calculate the height? Can't you use pure CSS for this instead? (e.g. position: relative; height: 100%;) This may alleviate your center coordinates issue.

MattSidor avatar Feb 19 '16 00:02 MattSidor

Tried that, didn't work; I need to use my directive. I don't know if it is because at the highest level, my app has to be full-screen and I use a directive to do that to adjust for screen/browser window size changes. I tried to remove all directives and use CSS and it didn't even show the map. I apparently need to use a pixel-based height for it to show up correctly.

davidrhoderick avatar Mar 01 '16 12:03 davidrhoderick

This is what I use in stylus

.angular-leaflet-map
  height 100%
  width 100%
  position absolute
  background #e3e1de

nmccready avatar Mar 01 '16 14:03 nmccready

Might be an old thread, but could be worth to others. I assume the reason your CSS only solution didn't work was because you didn't have a parent height for the percentage to be base upon. It's a typical mistake people do, I think mostly because the width of an (block) element is by default 100% (expressed as auto), so it works most of the time. However the height is a different beast. It's always 0, so you're setting 100% of nothing When setting the height of an element you have to put a value other than 0 to its parents tags.

Example: https://gist.github.com/hefler/f6d6c6ad87d2b7702d5122fb274c9f81

hefler avatar May 03 '16 08:05 hefler