Как построить мультиполигон turf.js? - PullRequest
0 голосов
/ 19 сентября 2019

Я нахожусь в процессе использования GEOJson для рисования полигонов на Google Maps.Я использую angular / typcript и имею функцию, которая возвращает кратные структуры данных GEOJson, которыми я хотел бы манипулировать для извлечения координат и динамического определения multiPolygon.Моя функция: this.customerApi.getLocations (this.currentUser.id)

.subscribe((response) => {
  this.locations = response;
  this.locations.forEach(element => {
  this.polygonsArray.coordinates.push(element.geoDefinition.features.geometry.coodinates);
    this.map.data.addGeoJson(element.geoDefinition);
  });
  });
  }

PolygonArray определяется как:

polygonsArray: turf.Polygon;

ответом является массив.Первый элемент массива, например:

0:Object {geoDefinition: Object, id: "5d7a5cc3a08d3a167d0b4805", customerId: "5cd430c65304a21b9464a21a", …}
customerId:"5cd430c65304a21b9464a21a"
geoDefinition:Object {type: "FeatureCollection", features: Array(1)}
features:Array(1) [Object]
length:1
__proto__:Array(0) [, …]
0:Object {type: "Feature", properties: Object, geometry: Object}
geometry:Object {type: "Polygon", coordinates: Array(1)}
coordinates:Array(1) [Array(6)]
length:1
__proto__:Array(0) [, …]
0:Array(6) [Array(2), Array(2), Array(2), …]
length:6
__proto__:Array(0) [, …]
0:Array(2) [5.379856, 43.252967]
1:Array(2) [5.422988, 43.249466]
2:Array(2) [5.425048, 43.245153]
3:Array(2) [5.383804, 43.239838]
4:Array(2) [5.379856, 43.252967]
5:Array(2) [5.379856, 43.252967]
type:"Polygon"
__proto__:Object {constructor: , __defineGetter__: , __defineSetter__: , …}
properties:Object {}
type:"Feature"
__proto__:Object {constructor: , __defineGetter__: , __defineSetter__: , …}

Итак, для каждого элемента я хочу извлечь координаты и вставить их в структуру multiPolygon для рендеринга GEOJson.Полигон не принимает метод push.Он определяется как:

turf.multipolygon(coordinates, properties)

У кого-нибудь есть способ достичь этого?Было бы очень признателен.

С наилучшими пожеланиями,

...