区别两个多边形js

时间:2018-10-29 08:24:55

标签: javascript google-maps gis polygon turfjs

我有一个多边形和一张莫斯科地图。该多边形不能完全覆盖地图。我正在尝试获得一个完全位于莫斯科的多边形(即从四边形多边形中切出一个超出莫斯科边界的多边形)。我找到了2个解决方案(http://turfjs.org/docs/#differencehttps://github.com/w8r/martinez,例如:https://codepen.io/w8r/pen/rrBkER),但是最后我得到了一个垃圾填埋场,它位于一个完全不同的国家。告诉我我的代码有什么问题,我在哪里可以了解到更多信息?

/tmp/ccGVkdZ4.o: In function `main':
furian_main.c:(.text.startup+0x256): undefined reference to `vbprintf'
/mnt/c/.../furian-1.0/libfurian.a(furian.o): In function `furian':
furian.c:(.text+0x111c): undefined reference to `vbprintf'
furian.c:(.text+0x3223): undefined reference to `vbprintf'
furian.c:(.text+0x3a62): undefined reference to `vbprintf'
furian.c:(.text+0x3aca): undefined reference to `vbprintf'
/mnt/c/Users/matth/Desktop/cesure_1/cesure_fourier/furian-1.0/libfurian.a(furian.o):furian.c:(.text+0x3bcd): more undefined references to `vbprintf' follow
collect2: error: ld returned 1 exit status
Makefile:39: recipe for target 'furian_main' failed
make: *** [furian_main] Error 1

CSS:

let prefix =  'https://cors-anywhere.herokuapp.com/'
// The origin of the catchment.
let lng = 37.4306983;
  lat = 55.6347171;



// Center map on the origin.
let map = L.map('map', {
  center: [lat, lng],
  zoom: 20
});




map.createPane('labels');
map.getPane('labels').style.zIndex = 550;
map.getPane('labels').style.pointerEvents = 'none';

L.tileLayer(`https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png`).addTo(map);



var mapit = {};

    mapit.area_loaded = function(data) {
        var area = new L.GeoJSON(data,{
    // symbolize features
    style: function(feature) {
      return {
        color: '#210499',

      }
    }});
        mapit.areas.addLayer(area);

        map.fitBounds(mapit.areas.getBounds());
    };


    let xhr = new XMLHttpRequest();
mapit.areas = L.featureGroup();
    xhr.open('GET', prefix + `https://raw.githubusercontent.com/alphavector/json/master/959173.json`,false);
    xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
    xhr.setRequestHeader('Access-Control-Headers', 'X-Requested-With');
    xhr.onload = () => {
      let polygone = JSON.parse(xhr.responseText);
      mapit.dater = polygone;
      mapit.area_loaded( polygone );}

      xhr.send();



let multiPoly = mapit.dater;
mapit.areas.addTo(map);


console.log('mapit', mapit);
console.log('mapit.dater', mapit.dater);

var keys = [];
for(var k in mapit) keys.push(k);
let polcord = [[[55.68623,37.45507], [55.6584,37.53927], [55.60622,37.41147], [55.64954,37.3459],[55.68623,37.45507] ]];
var mypolygon = turf.polygon(polcord);
L.polygon(polcord).addTo(map);
console.log('mypolygon',mypolygon);
console.log("total " + keys.length + " keys: " + keys);
console.log('multipolygon', multiPoly);
//var result = martinez.diff(mypolygon.geometry.coordinates,mapit.dater.coordinates);
//console.log('result',result);

    //new L.GeoJSON(mp).addTo(map);
//var diff = turf.difference(mapit.dater, mypolygon);
//L.geoJSON(diff).addTo(map);
//console.log('diff',diff);
for (var i=0;i<multiPoly.coordinates.length;i++){ 

console.log('multiPoly.coordinates[i]',multiPoly.coordinates[i]);
var mp = {
  "type": "Feature",
  "geometry": {
    "type": "Polygon",
    "coordinates": multiPoly.coordinates[i]}};

var result = martinez.diff(polcord,mp.geometry.coordinates);
var mpr = {
  "type": "Feature",
  "geometry": {
    "type": "MultiPolygon",
    "coordinates": result}};

   new L.geoJson(mpr).addTo(map);

};

HTML

html,
body {
  height: 100%;
  width: 100%;
  position: fixed;
  padding: 0;
  margin: 0;
  border: 0;
}

.map {
  height: 70%;
  width: 100%;
}

0 个答案:

没有答案