In my Application I was making div of map as
<div id="map" style="height: 610px; width:100%"></div>
but to make my map responsive I want to make height also 100%, if I make height: 100%
then it is not working.
How can I make height also variable like width so that map can be seen properly on any device.
Demo : http://jsfiddle.net/CcYp6/
If you change height & width of map then you will not get map.
We recommend Sublime Text . If you want to follow along on your own computer, your maps will need be on a local web server. Easy ways of doing this include running Python's SimpleHTTPServer in your map directory, installing MAMP (for Mac), or installing WampServer (for Windows). This is a simple Leaflet map. A few lines of code. Let's make a map!
GeoJSON is the de facto standard data type for web maps, and Leaflet has built-in methods to make it easy to map GeoJSON data. For more about GeoJSON, start with its Wikipedia article.
There's a whole slew of plugins people have written to extend the Leaflet core, most of them very easy to drop right into your project. We'll use a popular one, Leaflet.markercluster. A map cluttered with rat symbols isn't great, and this plugin will help make it more readable and usable. Poke around on the map below.
If you change height & width of map then you will not get map. Show activity on this post. Explanation: Why do you need to do that? So when you specify an element's height in % then the 1st question that arises is: 100% of what?
You need to set the parent elements to height: 100%;
first
html, body { height: 100%; }
Demo
Demo (This won't work as no parent height is defined)
Explanation: Why do you need to do that? So when you specify an element's height in %
then the 1st question that arises is: 100%
of what? By default, a div has height of 0px
, so 100%
for a div simply won't work, but setting the parent elements height
to 100%;
will work.
You have to set the div size with JavaScript.
$("#map").height($(window).height()).width($(window).width()); map.invalidateSize();
You can find a complete example here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With