openPopup won't show when called from sidebar

253 views
Skip to first unread message

F.Xavier Echapp

unread,
Oct 6, 2015, 12:35:37 PM10/6/15
to Leaflet

Hello,

i've been reading around for a while and still haven't found a solution to my issue.


I have a GeoJson that i load in a map. I use markers clusters to group all the features. I bind popups to those markers and that works fine: popups show on click, no problem.

I build a custom control area in which i have two inputs, to filter my geojson datas regarding their price (min and max); then i load a result list below -> that works fine also, and when i mouseover a marker, i can highlight the result-list's item.


My problem: i want to open the marker's popup in the map when i click on the result-list's item that correspond to it. But popup doesn't show. Map paning seems ok, as the map is recentring toward the marker. Even the popup datas are loaded (which i can see with a console.log(layer.getPopup())). But still no popup popping.


The issue is the same if i get rid of the MarkerCluster lib and directly use the geojson layer (cf) , so it comes from something i'm doing wrong but i don't know what.


Here is a jsfiddle http://jsfiddle.net/n3pkzcm7/4/. The openPopup() call is at line 88 in _getHtmlList function.

F.Xavier Echapp

unread,
Oct 6, 2015, 12:50:36 PM10/6/15
to Leaflet
I'll add that if i bind a popupopen event to the map itself like:

map.on('popupopen', function(){
console.log('open!!');
})

the event is fired, whether i click on a marker or on the sidebar's result list item.

ghybs

unread,
Oct 7, 2015, 7:19:12 AM10/7/15
to Leaflet
Bonjour,

It looks like a timeout solves the issue: http://jsfiddle.net/n3pkzcm7/6/

I do not know how you implemented the map panning, but this may be related to panning closing the popup just after you request it to open.

Also notice that when clicking on a link in your control, your marker could actually be clustered.
Worse, it could even be removed from map, since MCG by default removes anything that is too far away from the view port to free up memory.
Make sure to use `myMCG.zoomToShowLayer(myMarker)` (see https://github.com/Leaflet/Leaflet.markercluster/tree/master#other-methods) to request MCG to reveal the marker.
This could even replace your panning function.

Finally, this method gives you the possibility to pass a callback, in which you could place your `openPopup()` instruction.
It would then be called after any panning / zooming, so it could solve the issue if the problem comes from panning simultaneously with opening the popup.

Edit: well, unfortunately this is still not enough (http://jsfiddle.net/n3pkzcm7/7/). When there is only a map panning, only a timeout solves the problem. Try to disable your panning function and see if it works.

Good luck!

F.Xavier Echapp

unread,
Oct 9, 2015, 7:22:21 AM10/9/15
to Leaflet
Thanks ghybs this helped me a lot. Actually i didn't use a  settimeout  but, as i was adviced here i used the disableClickPropagation method on the creation of the side panel, to prevent propagation of click event that would close all the required popup instantly.
I also used the zoomToShowLayer as you told me, to uncluster the desired markers, and things look perfect now. http://jsfiddle.net/n3pkzcm7/8/

ghybs 1

unread,
Oct 9, 2015, 7:35:43 AM10/9/15
to leafl...@googlegroups.com
Hi,

I am glad you could pin out the issue and make it work!

Cheers.
Reply all
Reply to author
Forward
0 new messages