弹出窗口中的geoJSON属性“未定义”

时间:2019-12-03 16:50:05

标签: javascript leaflet geojson

我正在制作传单地图。到目前为止,一切进展顺利。但是,我在将一条信息放入弹出窗口时遇到问题。

弹出窗口应显示与标记关联的峡谷的名称,以及峡谷所在州的名称。状态缩写正在显示,但峡谷名称未显示。我得到“未定义”,我应该在每个弹出窗口中看到一个峡谷的名称。

这是特征创建功能。弹出窗口位于第一部分:

function createFeatures2(canyonsURL, stylecallback, layer) {
    // Define a function we want to run once for each feature in the features array
    // Give each feature a popup with name and state of canyon
    function onEachFeature2(feature, layer) {
        layer.bindPopup(feature.properties.Canyon +
            "<hr><p>" + feature.properties.State);
    }

    // Create a GeoJSON layer containing the features array on the data objects
    // Run the onEachFeature function once for each piece of data in the array
    var canyon = d3.json(canyonsURL, {
        pointToLayer: function(_geometry, coordinates) {
            return L.circleMarker(coordinates);
        },
        onEachFeature2: onEachFeature2,
        style2: style2
    }).addTo(layer);

}

同样,标记正好显示在右边。

这是来自geoJSON数据的样本。请原谅空格:

{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-103.4423,
37.132
]
},
"properties": {
"Canyon": "Aguaje Canyon",
"State": "Colorado"
}
},

关于为什么这将成功获得“州”而不是“峡谷”的任何想法?我使用在线转换器将csv转换为geoJSON,但我不认为这是问题所在-它与其他csv文件一起使用。

0 个答案:

没有答案