Leaflet + MarkerCluster + custom Icons + Popups -


i'd use custom icons markers, while using leaflet markercluster.

i managed implement custom icons, now marker popups aren't working more.

my code looks this:

var markers1 = new l.markerclustergroup();  // add markers popup info var geojsonlayer1 = l.geojson(myplaces, {    oneachfeature: function(feature, layer) {       layer.bindpopup(feature.properties.name);    } })  // add markers custom icons var geojsonlayer1 = l.geojson(myplaces, {    oneachfeature: oneachfeature,    pointtolayer: function(feature, latlng) {       var iconurl = feature.properties.img;       return new l.marker(new l.latlng(feature.geometry.coordinates[1], feature.geometry.coordinates[0]), {          icon: l.icon({             iconanchor: [0, 0],             popupanchor: [0, 0],             iconurl: iconurl          })       });    } })  // add markers map markers1.addlayer(geojsonlayer1); map.addlayer(markers1); 

when remove part custom icons (the section below "// add markers custom icons"), marker popups work fine again…

any suggestions? thanks in advance help!!

(i tried think of & i'm going crazy here…) ; )

edit: oops! misunderstood question. yeah issue doing l.geojson twice , doing different things them. function returns new l.geojson object, things add popups not things making custom markers. yeah should combine them.

var geojson = l.geojson(geojsondata, {     pointtolayer: function(obj) {         var mark = l.circlemarker(obj.geometry.coordinates, obj.properties);         mark.bindpopup('<div>' + marks.length + '</div>');         return mark;     } }); 

this piece of code , updated example did here.

i'll leave in bit below custom cluster icons.

as side note, it's typically bad practice attempt create 2 vars same name, , linters complain that.

...

i created little demo uses clustering, popups , custom icons here.

when create markerclustergroup can give arbitrary function creates icons clusters:

iconcreatefunction: function(cluster) {     var count = cluster.getchildcount();     return l.divicon({         html: '<span class="custom">' + (count + 100) + '</span>'     }) } 

where can put logic custom cluster icons. single markers, can pass icon the constructor directly. you'll notice popups work markers , clusters.

edit: previous jsfiddles have incompatibility leaflet , markercluster versions. here working version

hope helps!


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -