我正在使用Omnivore extension将我的GeoJSON文件加载到Mapbox / Leaflet地图中。后来,我在这些数据上使用Turf.js。
我正在将外部GeoJSON文件作为customLayer加载到地图中,但无法在变量pts
中提供GeoJSON数据以供日后使用。
var polyLayer = L.geoJson(null, {
style: function(feature) {
return { color: '#f00', weight: 1, opacity: 0.9
};
}
}).addTo(map);
var polys = omnivore.geojson('polys.geojson', null, polyLayer);
var ptsLayer = L.geoJson(null, {
onEachFeature: labelEachFeature,
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, style(feature))
;}
});
var pts = omnivore.geojson('pts.geojson', null, ptsLayer);
polyLayer.on('mouseover', function(e) {
var matchingPoints = turf.featurecollection([])
matchingPoints.features = pts.features.filter(function(pt) {
if(pt.properties.servesbldg === e.layer.feature.properties.bldg_no) return true
})
ptsLayer.setGeoJSON(matchingPoints);
});
function getPoints(building, pts) {
var matchingPoints = turf.featurecollection([])
matchingPoints.features = pts.features.filter(function(pt) {
if(pt.properties.servesbldg === building.properties.bldg_no) return true
})
return matchingPoints
}
Here's a GIST of what I've got包括GeoJSON文件。