Leaflet - 点击标记上的不需要的移动

时间:2013-07-09 10:56:53

标签: javascript jquery-plugins leaflet


我正在尝试使用点击标记弹出窗口制作地图和标记。我正在使用传单插件。一切都很好,除了当我点击任何标记时,地图将移动到某个点,而不是专注于标记的弹出。但是,如果我改变浏览器的大小(如恢复或打开控制台),那么它将继续正常工作。我有一个函数来获取弹出窗口的HTML。这是我的代码

      var cloudmadeUrl = 'https://server/tiles/test_format5_set4/tiles_{z}_{y}x{x}.png',marker,
        cloudmadeAttribution = '', latlng,
        cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 4, attribution: cloudmadeAttribution});
        latlng = new L.LatLng(0, 0);
        var LeafIcon = L.Icon.extend({
            options: {
                iconSize:     [25, 41],   // size of the icon
                shadowSize: [50, 64],   // size of the shadow 
                iconAnchor: [22, 94],   // / point of the icon which will correspond to marker's location
                shadowAnchor: [4, 62],    // the same for the shadow
                popupAnchor: [-3, -76]   // point from which the popup should open relative to the iconAnchor
            }
        });
        var completedIcon = new LeafIcon({iconUrl: '../styles/images/marker-icon green.png'});
        var startedIcon = new LeafIcon({iconUrl: '../styles/images/marker-icon red.png'});
        var createdIcon = new LeafIcon({iconUrl: '../styles/images/marker-icon yellow.png'});
    map = new L.Map('table_map', {center : latlng, zoom : 1, layers : [cloudmade]});
    ticket_layer.clearLayers();
    map.removeLayer(ticket_layer);
   for (var m in  SOURCE_ARRAY) {
                (function (n) {
                    if (SOURCE_ARRAY.hasOwnProperty(n)) {
                        createHtmlForPopUp(n, function (data) {

                            if (SOURCE_ARRAY[n].state.state === "created") {
                                marker = new L.Marker(new L.LatLng(SOURCE_ARRAY[n].location.x, SOURCE_ARRAY[n].location.y), {icon: createdIcon});       
                            }
                            else if (SOURCE_ARRAY[n].state.state === "started") {
                                marker = new L.Marker([SOURCE_ARRAY[n].location.x, SOURCE_ARRAY[n].location.y], {icon: startedIcon});
                            }
                            else {
                                marker = new L.Marker([SOURCE_ARRAY[n].location.x, SOURCE_ARRAY[n].location.y], {icon: completedIcon});
                            }
                            marker.bindPopup(data); // calling a function with callback
                            ticket_layer.addLayer(marker);
                        });
                    }
                })(m);  
            } // for loop ends here

        map.addLayer(ticket_layer);

1 个答案:

答案 0 :(得分:0)

您是否尝试将autoPan选项设为false?

Docs.