【发布时间】:2016-06-12 08:24:08
【问题描述】:
所以我一直在使用 google-maps-react example for converting GeoJSON data to polygons。我遇到的问题是该示例不支持转换“MultiPolygon”类型的 GeoJSON 功能。 (多个多边形组合在一起)。
我可以在示例中更改什么来支持它吗?想我也许可以在以下函数中添加一个案例:
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 }');
}
}
【问题讨论】:
标签: google-maps reactjs geojson