0
所以我一直在使用谷歌地圖反應example for converting GeoJSON data to polygons。我遇到的問題是該示例不支持轉換'MultiPolygon'類型的GeoJSON功能。 (多個多邊形組合在一起)。反應谷歌地圖模塊 - 如何處理GeoJSON MultiPolygons
有什麼我可以改變的例子來支持?想着也許我可以只的情況下,增加了如下功能:
function geometryToComponentWithLatLng(geometry) {
const typeFromThis = Array.isArray(geometry);
const type = typeFromThis ? this.type : geometry.type;
let coordinates = typeFromThis ? geometry : geometry.coordinates;
switch (type) {
case 'Polygon':
return {
ElementClass: Polygon,
paths: coordinates.map(
geometryToComponentWithLatLng, {
type: 'LineString'
}
)[0],
};
case 'LineString':
coordinates = coordinates.map(
geometryToComponentWithLatLng, {
type: 'Point'
}
);
return typeFromThis ? coordinates : {
ElementClass: Polyline,
path: coordinates,
};
case 'Point':
coordinates = {
lat: coordinates[1],
lng: coordinates[0]
}
return typeFromThis ? coordinates : {
ElementClass: Marker,
ChildElementClass: InfoWindow,
position: coordinates,
};
default:
throw new TypeError('Unknown geometry type: ${ type }');
}
}