javascript - Hide Markers - Mapbox -
i have added markers given in example below.
for (let x = 0; x < mapmarkers.length; x++) { //mapobject.totalmarkers.push(createmarker(mapmarkers[x].wherelat, mapmarkers[x].wherelng, mapmarkers[x].id, detailcontid)); markerclusters.addlayer(createmarker(mapmarkers[x].wherelat, mapmarkers[x].wherelng, mapmarkers[x].id, detailcontid)); } markerclusters.on('clusterclick', function(a) { zoomlevel = mapobject.getzoom(); if (zoomlevel < appconfig.usersetting.maxzoom) { mapobject.zoomin(); } else { a.layer.spiderfy(); } }); mapobject.addlayer(markerclusters);
now want hide markers. have done rnd given below not able succeed. great me.
objmap.removelayer(mapmarkers[0]);
objmap.removelayer(mapmarkers[0]);
this make sense if adding mapmarkers map, code shows, isn't case: mapmarkers data transform marker objects using createmarker
method before adding map.
conceptually, have mapobject
, contains markerclusters
, contains markers (which aren't assigning variable names to). so, if want remove specific marker markerclusters, need call removelayer
cluster's perspective, not map's.
so can use markercluster.eachlayer
, like
markerclusters.eachlayer(function (layer, i) { if (i == 0) markerclusters.removelayer(layer); });
that remove first layer. if have other criteria which cluster want remove, you'll need either store markers in array before adding them cluster, or change simple if
statement tests whether marker should removed.
Comments
Post a Comment