【发布时间】:2021-09-01 11:15:47
【问题描述】:
所以我想在 javascript 中合并相邻的多边形,这就是我的代码实际拥有的:
我想删除内部笔划但保留边框笔划。
所以我想从这里开始:
到这里:
我想为巴黎保留这个洞 - 我可以定义必须对哪些多边形进行分组,但我无法将它们与此代码合并:
var map = L.map('map', {
center: [46.52863469527167, 2.43896484375],
zoom: 6,
maxZoom: 18,
minZoom: 7
});
$http.get("france.json").then(function (response) {
$scope.communeFr = response.data.features
$http.get(apiult).then(function (response) {
$scope.showCommune = response.data.Liste
$scope.communeFr.map(x => {
x.show = false
for (let i = 0; i < $scope.showCommune .length; i++) {
if (x.properties.insee == $scope.showCommune[i].insee) {
x.show = true
return
}
}
})
L.geoJson($scope.communeFr, {
filter: function (feature, latlng) {
return feature.show
}
}).addTo(map);
});
});
更新 - 我尝试使用 turf.union 但输出不正确:
这是我的代码
var GroupPolygons = [];
$scope.communeFr.map(x => {
x.show = false
for (let i = 0; i < $scope.showCommune .length; i++) {
if (x.properties.insee == $scope.showCommune[i].insee) {
GroupPolygons.push(x)
}
}
})
var union = turf.union(...GroupPolygons)
L.geoJson(union).addTo(map)
【问题讨论】:
-
第二张和第三张图片好像和第一张没有关系?
-
如果你想合并多边形使用@turf/union
-
@RobinMackenzie 这不是同一张图片,它只是向你展示我想要的东西
-
@GrzegorzT。我已经尝试使用 turf.union,我想我做错了什么我会告诉你我的代码和我得到什么
标签: leaflet polygon geojson turfjs