首页 > 解决方案 > 传单:如何将多边形与 GeoJson 合并?使用 Javascript

问题描述

这是我的地图 地图

这是我的代码

var y_centerFrance = 46.52863469527167
var x_centerFrance = 2.43896484375
var map = L.map('map', {
    center: [y_centerFrance, x_centerFrance],
    zoom: 6,
    maxZoom: 18,
    minZoom: 7
});
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png?access_token=', {
    attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
    subdomains: ['a', 'b', 'c']
}).addTo(map);
$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);
    });
    
});

我想将它们分组,所以只有一个大块而不是多个块你知道一个可以删除多边形组内线的算法吗?

我的json

{"type":"FeatureCollection", "features": [

    {"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-60.935950399999996,14.588120099858655],[-60.932182799999985,14.585930999858398],[-60.93046809999999,14.584483999858223],[-60.93011379999999,14.580125099857703],[-60.921989799999984,14.579337299857624],[-60.92072629999999,14.580330599857728],[-60.915745499999986,14.579306499857612],[-60.91270789999997,14.57694879985734],[-60.90939919999999,14.575148999857127],[-60.909540899999996,14.573746399856965],[-60.906925399999984,14.573847599856977],[-60.90621449999998,14.571602999856706],[-60.90455959999998,14.5697631998565],[-60.90291429999999,14.57036729985657],[-60.90131869999998,14.569685799856483],[-60.899223299999974,14.565686799856014],[-60.89648729999998,14.563088899855702],[-60.895870399999986,14.561893699855561],[-60.89692899999998,14.560517999855406],[-60.893382799999976,14.558153899855132],[-60.891401799999976,14.551875599854386],[-60.89107789999998,14.547721499853903],[-60.89167909999998,14.546520899853764],[-60.895182399999975,14.54593829985369],[-60.895476299999984,14.541778199853196],[-60.89494099999998,14.537850499852734],[-60.89803149999999,14.537434899852697],[-60.89955539999999,14.53793859985275],[-60.90331159999999,14.537499599852694],[-60.90341639999999,14.536720599852616],[-60.90762809999998,14.536320999852565],[-60.90826679999997,14.534340499852329],[-60.91004009999999,14.534516899852342],[-60.910658199999986,14.536336899852554],[-60.91209469999998,14.535333699852448],[-60.92339079999999,14.53875089985285],[-60.925225899999994,14.537886199852744],[-60.92498589999998,14.539796499852974],[-60.92703539999997,14.541713899853193],[-60.93246319999999,14.548356999853974],[-60.945118599999965,14.549944899854161],[-60.94658039999999,14.554450899854688],[-60.948887999999975,14.553958199854641],[-60.95202749999997,14.553969699854635],[-60.95261589999999,14.556057799854887],[-60.95390119999998,14.555348699854807],[-60.955612699999975,14.55761989985507],[-60.954296899999996,14.558257299855136],[-60.95088209999997,14.557943399855102],[-60.95073749999999,14.559368999855277],[-60.94895439999999,14.56238519985562],[-60.95103859999998,14.563046199855703],[-60.954047999999986,14.562206399855608],[-60.953532999999986,14.565625299856013],[-60.95272419999999,14.566261099856089],[-60.947791099999975,14.565986199856043],[-60.94921029999998,14.56805139985629],[-60.947331999999996,14.571283699856671],[-60.94268199999997,14.571801599856737],[-60.942200899999975,14.578372799857512],[-60.94018659999998,14.581935699857913],[-60.939195599999984,14.581987399857935],[-60.935950399999996,14.588120099858655]]]},"properties":{"insee":"97223","nom":"Saint-Esprit","wikipedia":"fr:Saint-Esprit (Martinique)","surf_ha":2318}},
    {"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-61.12164679999998,14.719282999874112],[-61.118520099999984,14.716243299873753],[-61.118533599999985,14.714449199873544],[-61.11560209999999,14.707324599872702],[-61.114850899999986,14.7064851998726],[-61.11324869999999,14.702683499872153],[-61.11345009999997,14.698760199871698],[-61.11533549999999,14.696649699871445],[-61.11624509999997,14.692965299871007],[-61.11621679999998,14.690845599870748],[-61.11986609999999,14.68999179987065],[-61.12306309999998,14.690357399870694],[-61.12441609999996,14.690013999870656],[-61.12809369999997,14.689801299870622],[-61.13247369999996,14.690191999870686],[-61.13464879999999,14.689540999870605],[-61.138730599999974,14.689939299870646],[-61.141242599999984,14.688848099870523],[-61.142479399999985,14.690421899870707],[-61.145638399999996,14.689443199870583],[-61.14803509999997,14.690422299870711],[-61.14888629999999,14.691853299870873],[-61.15150159999998,14.691337299870817],[-61.15423579999998,14.693721399871094],[-61.15542679999999,14.695230199871265],[-61.155833699999995,14.697952299871593],[-61.15880649999998,14.701841399872057],[-61.15830539999999,14.704165699872322],[-61.15885469999997,14.707112499872668],[-61.15811579999998,14.707497499872714],[-61.15770799999998,14.713293699873402],[-61.150605299999995,14.713043599873382],[-61.14696559999998,14.715907599873715],[-61.14383019999999,14.71597429987372],[-61.142535699999996,14.717774899873941],[-61.14093769999999,14.718257099873984],[-61.13791339999998,14.717131299873854],[-61.135850699999985,14.717888699873951],[-61.13320559999999,14.719708999874156],[-61.128336099999984,14.720843599874287],[-61.12375529999998,14.719032499874077],[-61.12209809999999,14.718675499874038],[-61.12164679999998,14.719282999874112]]]},"properties":{"insee":"97233","nom":"Le Morne-Vert","wikipedia":"fr:Le Morne-Vert","surf_ha":1325}}

]}

标签: javascriptleafletgeojson

解决方案


推荐阅读