Cmen
3 years ago
3 changed files with 54 additions and 2 deletions
@ -0,0 +1,50 @@
|
||||
import { IMapOptions, IOverlay } from "@map"; |
||||
import { OverlayTypes } from "@types"; |
||||
import { getUID } from "@utils"; |
||||
|
||||
export function getMapOptions(geojson: GeoJSON.FeatureCollection) { |
||||
const { features } = geojson; |
||||
const mapOptions: IMapOptions = { |
||||
overlays: [], |
||||
}; |
||||
|
||||
const addPolygon = (feature: GeoJSON.Feature) => { |
||||
const { geometry, properties } = feature; |
||||
const { name, fineType, lngLat, radius } = properties as any; |
||||
const { coordinates } = geometry as GeoJSON.Polygon; |
||||
const [path] = coordinates; |
||||
const overlay: IOverlay = { |
||||
id: getUID(), |
||||
name, |
||||
type: OverlayTypes.Polygon, |
||||
}; |
||||
if (fineType === "rect") { |
||||
overlay.path = path; |
||||
overlay.type = OverlayTypes.Rectangle; |
||||
} else if (fineType === "circle") { |
||||
overlay.lngLat = lngLat; |
||||
overlay.radius = radius; |
||||
overlay.type = OverlayTypes.Circle; |
||||
} else { |
||||
overlay.type = OverlayTypes.Polygon; |
||||
overlay.path = path; |
||||
} |
||||
mapOptions.overlays.push(overlay); |
||||
}; |
||||
|
||||
const addPolyline = (feature: GeoJSON.Feature) => { |
||||
//
|
||||
}; |
||||
|
||||
features.forEach((feature) => { |
||||
const { geometry } = feature; |
||||
const { type } = geometry; |
||||
if (type === "Polygon") { |
||||
addPolygon(feature); |
||||
} else { |
||||
addPolyline(feature); |
||||
} |
||||
}); |
||||
|
||||
return mapOptions; |
||||
} |
Loading…
Reference in new issue