html5 - How to draw markers of different sizes -


the following html script draws specified map tiles , markers planned. but, size of markers same. how can draw markers size specified in items 3 , 4 in list 'planes'? way can differentiate different markers per properties.

<!doctype html> <html> <head> <title>simple leaflet map</title> <meta charset="utf-8" /> <link      rel="stylesheet"      href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css" /> </head> <body>  <div id="map" style="width: 600px; height: 400px"></div>  <script     src="http://cdn.leafletjs.com/leaflet-0.7/leaflet.js"> </script>  <script>  var planes = [     ["7c6b07",-40.99497,174.50808, 5, 5],     ["7c6b38",-41.30269,173.63696, 10, 10],     ["7c6ca1",-41.49413,173.5421, 15, 5],     ["7c6ca2",-40.98585,174.50659, 15, 15],     ["c81d9d",-40.93163,173.81726, 20, 5],     ["c82009",-41.5183,174.78081, 20, 10],     ["c82081",-41.42079,173.5783, 5, 15],     ["c820ab",-42.08414,173.96632, 5, 9],     ["c820b6",-41.51285,173.53274, 7, 12]     ];      var map = l.map('map').setview([-41.3058, 174.82082], 8);     maplink =          '<a href="http://openstreetmap.org">openstreetmap</a>';     l.tilelayer(         'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {         attribution: '&copy; ' + maplink + ' contributors',         maxzoom: 18,         }).addto(map);      (var = 0; < planes.length; i++) {         marker = new l.marker([planes[i][1],planes[i][2]], {iconsize: [planes[i][3], planes[i][4]]})             .bindpopup(planes[i][0])             .addto(map);     }  </script> </body> </html> 

you're assigning iconsize option marker object. not appropriate way.

actually, need create icon object, set iconsize value there, use icon object in options of map object.

here code snippet

for (var = 0; < planes.length; i++) {      //create icon object each marker     var myicon = l.icon({         iconurl: 'http://leafletjs.com/dist/images/marker-icon.png',         iconsize: [planes[i][3], planes[i][4]] //set icon size here     });      marker = new l.marker([planes[i][1],planes[i][2]], {icon: myicon})// use above icon object here         .bindpopup(planes[i][0])         .addto(map); } 

even though icons not looking good. here working fiddle


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -