Javascript 传单禁用缩放标记以及如何始终保持弹出窗口处于活动状态

Javascript 传单禁用缩放标记以及如何始终保持弹出窗口处于活动状态,javascript,leaflet,Javascript,Leaflet,您好,我有一个应用程序,它在传单地图上绘制一个人的位置和他的朋友的位置。我使用了两个不同的函数,因为有多个朋友等 当它打印用户登录时,它将缩放到他的位置,然后当它打印朋友时,它将缩放到他的位置。我需要它,以便所有标记的弹出窗口始终处于活动状态,并且不会缩放到任何一个标记 var markers = new L.FeatureGroup(); function addMarkerGroup(lat_ret,lon_ret,map,user){ map.removeLayer(mar

您好,我有一个应用程序,它在传单地图上绘制一个人的位置和他的朋友的位置。我使用了两个不同的函数,因为有多个朋友等

当它打印用户登录时,它将缩放到他的位置,然后当它打印朋友时,它将缩放到他的位置。我需要它,以便所有标记的弹出窗口始终处于活动状态,并且不会缩放到任何一个标记

  var markers = new L.FeatureGroup();
  function addMarkerGroup(lat_ret,lon_ret,map,user){
    map.removeLayer(markers);
    markers = new L.FeatureGroup();
    var marker = L.marker([lat_ret, lon_ret]).addTo(map).bindPopup("User:" + user).openPopup();
    markers.addLayer(marker);
    map.addLayer(markers);
  }

  var friend_markers = new L.FeatureGroup();
  function addFriendMarkerGroup(lat_ret,lon_ret,map,user){
    map.removeLayer(friend_markers);
    friend_markers = new L.FeatureGroup();
    var friend_marker = L.marker([lat_ret, lon_ret]).addTo(map).bindPopup("User:" + user).openPopup();
    friend_markers.addLayer(friend_marker);
    map.addLayer(friend_markers);
  }

您确定打开弹出窗口时地图会缩放吗?据我所知,地图只能平移,以便弹出窗口可见。我在你的代码中也没有看到实现zoom的东西,所以我认为你错了。如果要禁用对刚打开的弹出窗口的平移,可以禁用
autoPan
选项:

new L.Marker([0, 0]).bindPopup('Foo', {
    autoPan: false
}).addTo(map).openPopup();

如果在注释/省略当前打开的弹出窗口关闭的行中使用自己的函数覆盖
L.Map
openPopup
功能,则无法同时打开两个弹出窗口:

L.Map.include({
    openPopup: function (popup, latlng, options) { // (Popup) or (String || HTMLElement, LatLng[, Object])

        // Commented out, previous popup(s) will remain open 
        // this.closePopup();

        if (!(popup instanceof L.Popup)) {
            var content = popup;

            popup = new L.Popup(options)
                .setLatLng(latlng)
                .setContent(content);
        }
        popup._isOpen = true;

        this._popup = popup;
        return this.addLayer(popup);
    }
});
例如:

在传单1.0(目前为beta版)中,有一个新的弹出选项,名为
autoClose
,它将解决此问题:

new L.Marker([0, 0]).bindPopup('Foo', {
    autoClose: false
}).addTo(map).openPopup();

您确定打开弹出窗口时地图会缩放吗?据我所知,地图只能平移,以便弹出窗口可见。我在你的代码中也没有看到实现zoom的东西,所以我认为你错了。如果要禁用对刚打开的弹出窗口的平移,可以禁用
autoPan
选项:

new L.Marker([0, 0]).bindPopup('Foo', {
    autoPan: false
}).addTo(map).openPopup();

如果在注释/省略当前打开的弹出窗口关闭的行中使用自己的函数覆盖
L.Map
openPopup
功能,则无法同时打开两个弹出窗口:

L.Map.include({
    openPopup: function (popup, latlng, options) { // (Popup) or (String || HTMLElement, LatLng[, Object])

        // Commented out, previous popup(s) will remain open 
        // this.closePopup();

        if (!(popup instanceof L.Popup)) {
            var content = popup;

            popup = new L.Popup(options)
                .setLatLng(latlng)
                .setContent(content);
        }
        popup._isOpen = true;

        this._popup = popup;
        return this.addLayer(popup);
    }
});
例如:

在传单1.0(目前为beta版)中,有一个新的弹出选项,名为
autoClose
,它将解决此问题:

new L.Marker([0, 0]).bindPopup('Foo', {
    autoClose: false
}).addTo(map).openPopup();

您必须在bindPopup()中提供autoPan:false和autoClose:false


您必须在bindPopup()中提供autoPan:false和autoClose:false

您必须在bindPopup()中提供autoPan:false和autoClose:false


您必须在bindPopup()中提供autoPan:false和autoClose:false