Leaflet Mouseout called on MouseOver event

后端 未结 3 839
挽巷
挽巷 2021-02-19 05:26

I have a leaflet map where I\'m dynamically adding markers.

I want to call the popup for a marker when I hover over it in addition to when I click the marker.

My

3条回答
  •  清歌不尽
    2021-02-19 06:04

    The popup is actually loading underneath the cursor and 'stealing' the mouse from the Marker, triggering the Marker.mouseout() event, which causes the popup to close and re-triggers the Marker.mouseover() event... and the cycle continues which is why you see the 'flicker'.

    I have seen this happen depending on the zoom level (usually when zoomed right out).

    Try adding an offset into your popup options to get it out of the way:

    function makeMarker(){
       var Marker = L.marker...
       Marker.on('mouseover', function(){Marker.bindPopup('HI', {'offset': L.point(0,-50)}).openPopup();});
    
       Marker.on('mouseout', function(){Marker.closePopup();});
    }
    

提交回复
热议问题