Trigger openPopup() on clustered markers
See original GitHub issueHi, I have every marker added to the markerclusterer markers
also added to an object markersList = {}
Each marker added also creates a row in a sidebar, such that when a user clicks on a row, the marker corresponding to that row will openPopup()
.
Problem: Without adding the markers to markercluster, the markers will openPopup()
when its row in the Sidebar is clicked. However if these markers were to be added to markerclusterer, openPopup()
does nothing. this.model.id
is an id unique to each marker, retrieved from a backbone.js model this.model
.
Is there currently a way to achieve this with the markers added to markerclusterer? Thank you so much!! 😃
A loop creates all the markers required
// Create marker
var marker = new L.marker(
new L.LatLng( this.model.get('lat'), this.model.get('lng') ));
var content = this.templatePopup( this.model.toJSON() );
marker.bindPopup(content);
// Popup does not open if added to marker clusterer
//markers.addLayer(marker);
// Popup works when added to map
marker.addTo(map);
// Add to list of markers
markersList[this.model.id] = marker;
When a row in the sidebar is clicked…
// Opens the marker's popup when row in Sidebar is clicked
$('row').click(function() {
markersList[this.model.id].openPopup();
})
Issue Analytics
- State:
- Created 11 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
How to open popup for a specific marker inside a leaflet ...
You can iterate through all visible cluster markers, then leverage getAllChildMarkers ; but that will get messy soon, as you will have to...
Read more >Open the popups of all markers that are visible on the map ...
And the next question: do you want to open popups only for unclustered markers at given zoom or for all markers, regardless of...
Read more >Creating Popup Box For Markerclusterer
Map Layer. markercluster Trigger openPopup() on clustered markers #72. Leaflet marker cluster and popups. js click on marker open popup and show div ......
Read more >Marker Clustering | Maps SDK for iOS
When the user taps a marker, an individual cluster item, or a cluster, the API triggers mapView:didTapMarker: and attaches the extra cluster data...
Read more >Work with markers in Mapbox.js | Help
Add custom, interactive markers to your map with Mapbox.js. ... Cluster markers. More examples. Toggle layers ... Click the markers to trigger the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the suggestion, I tried your second suggestion:
If I click on the first
.row
, then click on map, then on the second.row
, then on map, the markers and popup appears correctly, and closes correctly.Problem 1: If I click on the first
.row
, (first popup opens) then on the second.row
, the first marker and its popup disappears (as expected) and popup for the second marker shows up, but not the second marker.Problem 2: For the above scenarios, the markers whose rows are clicked on are within clusters. If a marker not in any cluster has its
.row
clicked, and then the map is clicked to close the popup, the marker vanishes as well.Problem 3: In all cases, the number of
popupclose
even listeners starts increasing with each opening of popups, which can be observed by the increasing number ofconsole.log
lines.map.removeListener('popupclose')
results in an errorUncaught TypeError: Object [object Object] has no method 'removeListener'
I guess the first suggestion could be better? I’l need to figure out how to transfer the popup content from the first marker to the new popup.