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