|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import { OverlayTypes } from "../../types/enum"; |
|
|
|
|
import { IMapOptions } from "@map"; |
|
|
|
|
import { IMapOptions, IOverlay, OverlayCategory } from "@map"; |
|
|
|
|
|
|
|
|
|
const EarthRadius = 6378137; |
|
|
|
|
|
|
|
|
@ -8,52 +8,59 @@ export function getGeoJSON(state: IMapOptions): GeoJSON.FeatureCollection {
|
|
|
|
|
const features: GeoJSON.Feature[] = []; |
|
|
|
|
const { overlays } = state; |
|
|
|
|
|
|
|
|
|
overlays |
|
|
|
|
.filter((overlay) => overlay.type === OverlayTypes.Rectangle) |
|
|
|
|
.forEach((rect) => { |
|
|
|
|
const path = rect.path!; |
|
|
|
|
|
|
|
|
|
features.push({ |
|
|
|
|
type: "Feature", |
|
|
|
|
geometry: { |
|
|
|
|
type: "Polygon", |
|
|
|
|
coordinates: [path], |
|
|
|
|
}, |
|
|
|
|
properties: { |
|
|
|
|
fineType: OverlayTypes.Rectangle, |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
const addPolygonFeature = ( |
|
|
|
|
coordinates: GeoJSON.Position[][], |
|
|
|
|
overlay: IOverlay, |
|
|
|
|
restProperties: GeoJSON.GeoJsonProperties = {} |
|
|
|
|
) => { |
|
|
|
|
const properties: GeoJSON.GeoJsonProperties = { |
|
|
|
|
...restProperties, |
|
|
|
|
fineType: overlay.type, |
|
|
|
|
}; |
|
|
|
|
const { category } = overlay; |
|
|
|
|
if (category === OverlayCategory.Building) { |
|
|
|
|
properties.building = true; |
|
|
|
|
properties.height = overlay.height; |
|
|
|
|
} else if (category === OverlayCategory.Grass) { |
|
|
|
|
properties.grass = true; |
|
|
|
|
} else if (category === OverlayCategory.Water) { |
|
|
|
|
properties.water = true; |
|
|
|
|
} |
|
|
|
|
features.push({ |
|
|
|
|
type: "Feature", |
|
|
|
|
geometry: { |
|
|
|
|
type: "Polygon", |
|
|
|
|
coordinates, |
|
|
|
|
}, |
|
|
|
|
properties, |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
overlays |
|
|
|
|
.filter((overlay) => overlay.type === OverlayTypes.Polygon) |
|
|
|
|
.forEach((polygon) => { |
|
|
|
|
const path = polygon.path!; |
|
|
|
|
features.push({ |
|
|
|
|
type: "Feature", |
|
|
|
|
geometry: { |
|
|
|
|
type: "Polygon", |
|
|
|
|
coordinates: [path], |
|
|
|
|
}, |
|
|
|
|
properties: { |
|
|
|
|
fineType: OverlayTypes.Polygon, |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
.filter( |
|
|
|
|
(overlay) => |
|
|
|
|
overlay.type === OverlayTypes.Rectangle || |
|
|
|
|
overlay.type === OverlayTypes.Polygon |
|
|
|
|
) |
|
|
|
|
.forEach((rect) => addPolygonFeature([rect.path!], rect)); |
|
|
|
|
|
|
|
|
|
overlays |
|
|
|
|
.filter((overlay) => overlay.type === OverlayTypes.Polyline) |
|
|
|
|
.forEach((polyline) => { |
|
|
|
|
const path = polyline.path!; |
|
|
|
|
const properties: GeoJSON.GeoJsonProperties = { |
|
|
|
|
fineType: OverlayTypes.Polyline, |
|
|
|
|
}; |
|
|
|
|
if (polyline.category === OverlayCategory.Road) { |
|
|
|
|
properties.road = true; |
|
|
|
|
} |
|
|
|
|
features.push({ |
|
|
|
|
type: "Feature", |
|
|
|
|
geometry: { |
|
|
|
|
type: "LineString", |
|
|
|
|
coordinates: path, |
|
|
|
|
}, |
|
|
|
|
properties: { |
|
|
|
|
fineType: OverlayTypes.Polyline, |
|
|
|
|
}, |
|
|
|
|
properties, |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -64,19 +71,7 @@ export function getGeoJSON(state: IMapOptions): GeoJSON.FeatureCollection {
|
|
|
|
|
const radius = circle.radius!; |
|
|
|
|
|
|
|
|
|
const path = getCirclePath(center, radius); |
|
|
|
|
|
|
|
|
|
features.push({ |
|
|
|
|
type: "Feature", |
|
|
|
|
geometry: { |
|
|
|
|
type: "Polygon", |
|
|
|
|
coordinates: [path], |
|
|
|
|
}, |
|
|
|
|
properties: { |
|
|
|
|
fineType: OverlayTypes.Circle, |
|
|
|
|
center, |
|
|
|
|
radius, |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
addPolygonFeature([path], circle, { center, radius }); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|