Leaflet Mouseout called on MouseOver event

后端 未结 3 819
挽巷
挽巷 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 05:57

    I also recently came across this problem again too. In case this helps anyone: As of Leaflet 1.0, you can use L.Tooltip instead of popups with mouseover or other mouse-related events. I've found that it works much more smoothly than making a Popup, and uses less code, especially if you're just opening the popup on hover. In your case it might look like:

    function makeMarker(){
      var Marker = L.marker...
      Marker.bindTooltip('HI').openPopup();
    }
    

    And you can use the permanent boolean flag if you want to keep it open.

    In my case I didn't need the popup to open on click (in addition to hover), so that might be a little more complicated. However L.Tooltip has become very widely used and there are other SO questions that deal with this issue.

提交回复
热议问题