【发布时间】:2019-04-17 23:29:53
【问题描述】:
我正在尝试将 JSON 映射到从 Foursquare 提取的传单上,但我很难让它显示出来。
这是一个使用 JSON 的工作脚本,我从 NYC Open Data 获取。
fetch('complaintdata.json')
.then(function (response) {
// Read data as JSON
return response.json();
})
.then(function (data) {
// Create the Leaflet layer for the data
var complaintData = L.geoJson(data, {
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {icon: myIcon});
},
onEachFeature: function (feature, layer) {
layer.on('click', function () {
// This function is called whenever a feature on the layer is clicked
console.log(layer.feature.properties);
// Render the template with all of the properties. Mustache ignores properties
// that aren't used in the template, so this is fine.
var sidebarContentArea = document.querySelector('.sidebar-content');
console.log(sidebarContentArea);
sidebarContentArea.innerHTML = Mustache.render(popupTemplate, layer.feature.properties);
});
}
});
// Add data to the map
complaintData.addTo(map);
});
这是使用 Google 地图的working example,但我很难将其转移到 Leaflet。
这是JSON 我想复制这个过程:
【问题讨论】:
标签: javascript json parsing leaflet foursquare