【问题标题】:Mapbox simplestyle blocks popupContent? Using pointToLayer and onEachFeatureMapbox simplestyle阻止popupContent?使用 pointToLayer 和 onEachFeature
【发布时间】:2014-06-03 03:01:46
【问题描述】:

我在 Mapbox 中使用这个函数和 geoJson 来使用来自simplestyle 的样式标记

var groupThree = new L.LayerGroup();
L.geoJson(layerThree, {
    pointToLayer: L.mapbox.marker.style,
    style: function (feature) {
        return feature.properties;
    }
}, {
    onEachFeature: onEachFeature
}).addTo(groupThree);

但是当我运行它时,当我单击标记时无法出现弹出窗口。这是 popupContent 的函数:

var popupContent = "";
function onEachFeature(feature, layer) {
        if (feature.properties && feature.properties.popupContent) {
            popupContent = feature.properties.popupContent;
        }
        layer.bindPopup(popupContent);
    }

Here's my fiddle 显示没有 simplestyle 且弹出窗口有效的标记,以及带有 simplestyle 但弹出窗口无效的标记。

pointToLayer 和 onEachFeature 是否会以某种方式干扰?我怎样才能让它发挥作用?

【问题讨论】:

    标签: javascript geocoding leaflet geojson mapbox


    【解决方案1】:

    除了一个语法错误,一切正常:

    var groupTwo = new L.LayerGroup();
    L.geoJson(layerTwo, {
      pointToLayer: L.mapbox.marker.style,
      style: function(feature) { return feature.properties; }
    }, {onEachFeature: onEachFeature}).addTo(groupTwo);
     ^
     ^
    

    在这里,您将onEachFeature 作为L.geoJson 的单独参数传递,但L.geoJson 中没有第三个参数。所以基本上你创建了两个对象而不是一个。

    固定:

    var groupTwo = new L.LayerGroup();
    L.geoJson(layerTwo, {
      pointToLayer: L.mapbox.marker.style,
      style: function(feature) { return feature.properties; },
      onEachFeature: onEachFeature
    }).addTo(groupTwo);
    

    groupThree 的情况相同。

    Working JSFiddle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-23
      • 1970-01-01
      • 2012-02-05
      • 1970-01-01
      • 2011-10-29
      • 1970-01-01
      • 2013-10-30
      • 2018-10-25
      相关资源
      最近更新 更多