Saya baru bekerja dengan Leaflet API dan saya mengalami masalah dengan membuat sembulan untuk lapisan GeoJSON. Saya telah melihat posting berikut sebagai referensi dan saya masih mengalami kesulitan: mengikat array bersarang sebagai geojson popup di leaflet
Data GeoJson saya terlihat seperti:
{
"type": "FeatureCollection",
"features": [
{
"geometry": {
"type": "Point",
"coordinates": [
-73.97364044189453,
40.66893768310547
]
},
"type": "Feature",
"properties": {
"lon": -73.97364044189453,
"lat": 40.66893768310547,
"version": "1.1",
"t": 1381167616,
"device": "iPhone3,3",
"alt": 67,
"os": "6.1.3"
}
},
{
"geometry": {
"type": "Point",
"coordinates": [
-73.96121215820312,
40.66240692138672
]
},
"type": "Feature",
"properties": {
"lon": -73.96121215820312,
"lat": 40.66240692138672,
"version": "1.1",
"t": 1381171200,
"device": "iPhone3,3",
"alt": 45,
"os": "6.1.3"
}
}
]
}
Leaflet js saya adalah sebagai berikut:
// create a variable to load Stamen 'toner' tiles
var layer = new L.StamenTileLayer("toner");
// initialize and set map center and zoom
var map = L.map('map', {
center: new L.LatLng(40.67, -73.94),
zoom: 12
});
// create the map
map.addLayer(layer);
// on each feature use feature data to create a pop-up
function onEachFeature(feature, layer) {
if (feature.properties) {
var popupContent;
popupContent = feature.properties.t;
console.log(popupContent);
}
layer.bindPopup(popupContent);
}
// grab the processed GeoJSON through ajax call
var geojsonFeature = (function() {
var json = null;
$.ajax({
'async': false,
'global': false,
'url': "/data/test_random.json",
'dataType': "json",
'success': function (data) {
json = data;
}
});
return json;
})();
// create an object to store marker style properties
var geojsonMarkerOptions = {
radius: 10,
fillColor: "rgb(255,0,195)",
color: "#000",
weight: 0,
opacity: 1,
fillOpacity: 1
};
// load the geojson to the map with marker styling
L.geoJson(geojsonFeature, {
style: function (feature) {
return feature.properties && feature.properties.style;
},
onEachFeature: onEachFeature,
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, geojsonMarkerOptions)
}
}).addTo(map);
The console.log(popupContent);
panggilan dalam onEachFeature
fungsi mengembalikan data, namun ketika saya klik pada poin GeoJSON di peta saya mendapatkan error berikut:
Uncaught NotFoundError: An attempt was made to reference a Node in a context where it does not exist.
Saya sudah mencoba melihat ke dalam ini tanpa hasil sejauh ini.
sumber