[英]Parent polygon in Leaflet js
Short answer: no. 简短的回答:不。
If you want to create an envelope for your polygones, then it is an algorithm problem that goes beyond the scope of leafletjs. 如果要为多边形创建一个包络,那么这是一个算法问题,已经超出了leafletjs的范围。
You can look at the answers of this question to start solving your problem. 您可以查看此问题的答案以开始解决您的问题。
EDIT: here is an example using Turfjs library (thanks to @IvanSanchez for the heads up and to @HudsonPH for the polygons). 编辑:这是一个使用Turfjs库的示例 (感谢@IvanSanchez抬头,感谢@HudsonPH多边形)。
// draw envelope
var points = {
"type": "FeatureCollection",
"features":
[
// collect the points of your polygons
turf.point([-104.05, 48.99]),
// ...
]
};
var hull = turf.convex(points);
L.geoJson(hull).addTo(map);
You can have a group, but you need define all the coordinates more info: http://leafletjs.com/examples/geojson.html 您可以有一个组,但是需要定义所有坐标的更多信息: http : //leafletjs.com/examples/geojson.html
var states = [{
"type": "Feature",
"properties": {"party": "Republican"},
"geometry": {
"type": "Polygon",
"coordinates": [[
[-104.05, 48.99],
[-97.22, 48.98],
[-96.58, 45.94],
[-104.03, 45.94],
[-104.05, 48.99]
]]
}
}, {
"type": "Feature",
"properties": {"party": "Democrat"},
"geometry": {
"type": "Polygon",
"coordinates": [[
[-109.05, 41.00],
[-102.06, 40.99],
[-102.03, 36.99],
[-109.04, 36.99],
[-109.05, 41.00]
]]
}
}];
L.geoJson(states, {
style: function(feature) {
switch (feature.properties.party) {
case 'Republican': return {color: "#ff0000"};
case 'Democrat': return {color: "#0000ff"};
}
}
}).addTo(map);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.