Browse Source

支持导入geojson

master
Cmen 3 years ago
parent
commit
29dcb0ea66
  1. 5
      src/store/actions/index.ts
  2. 50
      src/store/utils/getMapOptions.ts
  3. 1
      src/store/utils/index.ts

5
src/store/actions/index.ts

@ -9,7 +9,7 @@ import {
setItem, setItem,
} from "@utils"; } from "@utils";
import { getGeoJSON } from "../utils"; import { getGeoJSON, getMapOptions } from "../utils";
import { OverlayTypes, EventTypes } from "@types"; import { OverlayTypes, EventTypes } from "@types";
import { IOverlay, IMapOptions } from "@map"; import { IOverlay, IMapOptions } from "@map";
import { StoreAction } from "./StoreAction"; import { StoreAction } from "./StoreAction";
@ -184,7 +184,8 @@ export class EditorAction {
} }
private _openGeoJSON(geojson: GeoJSON.FeatureCollection) { private _openGeoJSON(geojson: GeoJSON.FeatureCollection) {
console.log(geojson); const options = getMapOptions(geojson);
this._openProject(options);
} }
private _openProject(options: IMapOptions) { private _openProject(options: IMapOptions) {

50
src/store/utils/getMapOptions.ts

@ -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;
}

1
src/store/utils/index.ts

@ -1 +1,2 @@
export * from "./getGeoJSON"; export * from "./getGeoJSON";
export * from "./getMapOptions";

Loading…
Cancel
Save