我有以下代码:
$.getJSON("rodents.geojson",function(data){
var rodents = L.geoJson(data,{
pointToLayer : function(feature,latlng){
var marker = L.marker(latlng);
//turf.centroid(feature).geometry.coordinates
// marker.bindPopup(feature.properties.Location + '<br/>' + feature.properties.OPEN_DT);
return marker;
}
});
});
实际上,我想通过这样的方法来通过计算质心来传递LatLng变量:turf.centroid(feature).geometry.coordinates
PointToLayer以特性和最近状态作为参数,那么我如何实现这一点?我尝试了很多东西,但都没成功。
发布于 2017-06-23 04:50:45
首先,让我引用 option的API文档,强调我的:
pointToLayer
一种函数,定义GeoJSON 如何指向产卵传单层。当数据被添加时,内部调用它..。style
定义GeoJSON 线条和多边形样式的路径选项的函数,在添加数据时在内部调用。..。
如果GeoJSON不包含点数,则不使用L.GeoJSON
的pointToLayer
选项。
相反,我建议从您的GeoJSON中创建一个质心GeoJSON,例如:
$.getJSON("rodents.geojson", function(data){
centroids = {
type: 'FeatureCollection',
features: data.features.map(function(feat) {
return {
type: 'Feature',
properties: feat.properties,
geometry: turf.centroid(feat).geometry
}
})
};
//console.log(data);
//console.log(centroids);
var rodents = L.geoJson( centroids , { ... });
});
https://stackoverflow.com/questions/44703600
复制相似问题