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 }');
}
}