Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Leaflet 单张及;映射框:OpenPopup不工作_Leaflet_Mapbox - Fatal编程技术网

Leaflet 单张及;映射框:OpenPopup不工作

Leaflet 单张及;映射框:OpenPopup不工作,leaflet,mapbox,Leaflet,Mapbox,我对传单openPopup方法有异议 showMap = function(elements) { var jsonp = 'http://a.tiles.mapbox.com/v3/blahblahblah.jsonp'; var m = new L.Map("my_map").setView(new L.LatLng(51.5, -0.09), 15); var geojsonLayer = new L.GeoJSON(); var PlaceIcon =

我对传单openPopup方法有异议

showMap = function(elements) {
    var jsonp = 'http://a.tiles.mapbox.com/v3/blahblahblah.jsonp';
    var m = new L.Map("my_map").setView(new L.LatLng(51.5, -0.09), 15);

    var geojsonLayer = new L.GeoJSON();

    var PlaceIcon = L.Icon.extend({
        iconSize: new L.Point(25, 41),
        shadowSize: new L.Point(40, 35),
        popupAnchor: new L.Point(0, -30)
    });

    var icon = new PlaceIcon(__HOME__ + '/images/leaflet/marker.png');
    var marker;


    for (var i = 0; i < elements.length; i++) {
        var address = $("<div/>").html(elements[i].address).text();
        var latlng = new L.LatLng(elements[i].latitude, elements[i].longitude);
        marker = new L.Marker(latlng, {icon: icon}).bindPopup(address);

        if (i == 0) {
            marker.openPopup();
        }
        m.addLayer(geojsonLayer).addLayer(marker);
    }
    // Get metadata about the map from MapBox
    wax.tilejson(jsonp, function(tilejson) {
        m.addLayer(new wax.leaf.connector(tilejson));
    });
}
showMap=函数(元素){
var jsonp=http://a.tiles.mapbox.com/v3/blahblahblah.jsonp';
var m=新的L.Map(“我的地图”).setView(新的L.LatLng(51.5,-0.09),15);
var geojsonLayer=new L.GeoJSON();
var PlaceIcon=L.Icon.extend({
iconSize:新的L点(25,41),
阴影大小:新的L点(40,35),
popupAnchor:新的L点(0,-30)
});
var icon=new PlaceIcon(uuu HOME_uuuu+'/images/传单/marker.png');
var标记;
对于(var i=0;i
当我点击一个标记时,我打开了弹出窗口。但是我想在地图加载时打开第一个弹出窗口。(并在单击时打开其他弹出窗口)


AnNy ideas?

我假设当你点击一个标记时,你会看到弹出窗口,但是当地图加载时,你不会看到第一个标记的弹出窗口自动显示

首先,看起来您并没有实际使用GeoJSON,因此不需要GeoJSON层(您可以只使用FeatureLayer),但这不会导致任何问题。无论使用什么图层组,都只应将其添加到地图中一次,然后将所有子图层添加到图层组中。您当前在“for”循环中多次添加geojsonLayer,这是您不想做的。 其次,在将标记添加到地图后,必须调用
marker.openPopup()
。 尝试更改代码,使其看起来像这样:

var layerGroup = new L.FeatureGroup();
layerGroup.addTo( m );

for (var i = 0; i < elements.length; i++) {
    var address = $("<div/>").html(elements[i].address).text();
    var latlng = new L.LatLng(elements[i].latitude, elements[i].longitude);
    marker = new L.Marker(latlng, {icon: icon}).bindPopup(address);

    //You don't add the marker directly to the map.  The layerGroup has already
    //been added to the map so it will take care of adding the marker to the map
    layerGroup.addLayer( marker );

    if (i == 0) {
        marker.openPopup();
    }
}
var layerGroup=新的L.FeatureGroup();
图层组添加到(m);
对于(var i=0;i
我假设,当你点击一个标记时,你会看到弹出窗口,但当地图加载时,第一个标记的弹出窗口不会自动显示出来

首先,看起来您并没有实际使用GeoJSON,因此不需要GeoJSON层(您可以只使用FeatureLayer),但这不会导致任何问题。无论使用什么图层组,都只应将其添加到地图中一次,然后将所有子图层添加到图层组中。您当前在“for”循环中多次添加geojsonLayer,这是您不想做的。 其次,在将标记添加到地图后,必须调用
marker.openPopup()
。 尝试更改代码,使其看起来像这样:

var layerGroup = new L.FeatureGroup();
layerGroup.addTo( m );

for (var i = 0; i < elements.length; i++) {
    var address = $("<div/>").html(elements[i].address).text();
    var latlng = new L.LatLng(elements[i].latitude, elements[i].longitude);
    marker = new L.Marker(latlng, {icon: icon}).bindPopup(address);

    //You don't add the marker directly to the map.  The layerGroup has already
    //been added to the map so it will take care of adding the marker to the map
    layerGroup.addLayer( marker );

    if (i == 0) {
        marker.openPopup();
    }
}
var layerGroup=新的L.FeatureGroup();
图层组添加到(m);
对于(var i=0;i
将openPopup调用放在之后,将标记添加到地图中,您应该会没事。

将openPopup调用放在之后,将标记添加到地图中,您应该会没事。

首先添加地图,然后放置
openPopup()


首先添加地图,然后放入
openPopup()