首页  >  问答  >  正文

如何使Leaflet中的标记有两个弹出窗口?鼠标悬停时一种,单击时另一种?

我希望将标题悬停在地图上的标记上,然后单击它们时会打开一个包含不同内容的完整弹出窗口。

我尝试制作一个图例,其中包含所有标记的列表,这些标记将用作相应弹出窗口的链接,但我似乎不知道如何做到这一点。

P粉254077747P粉254077747183 天前328

全部回复(1)我来回复

  • P粉495955986

    P粉4959559862024-04-02 00:17:09

    您可以为不同事件的标记设置不同的弹出窗口。以下是如何在指向图层功能中设置它的示例:

    var ptl = function(f, latlng){              
            
            var icon = L.icon({
                iconUrl: 'img/icon.png',
                iconSize:     [30, 50], // size of the icon
                iconAnchor:   [0, 25]
            });
        
                
            return L.marker(latlng, {icon: icon4}).on('click', function(e) {
                    
                this.bindPopup(e.sourceTarget.feature.properties['content']);
            }).on('mouseover', function(e){
                var popup = L.popup({
                    offset: [0, -30]
                })
                    .setLatLng(e.latlng) 
                    .setContent(e.sourceTarget.feature.properties['title'])
                    .openOn(map);
                    
            }).on('mouseleave', function(e){
                this.closePopup();
            });
                
    
        }

    回复
    0
  • 取消回复