Browse Source

默认三维城市地理类型&导出

master
Cmen 3 years ago
parent
commit
816968d7e7
  1. 12
      src/map/MapEditor.ts
  2. 9
      src/store/reducers/map/index.ts
  3. 87
      src/store/utils/getGeoJSON.ts

12
src/map/MapEditor.ts

@ -11,7 +11,7 @@ import {
CircleEditor, CircleEditor,
} from "./editors"; } from "./editors";
import { IMapOptions, IMapEditor, IOverlay } from "./type"; import { IMapOptions, IMapEditor } from "./type";
import { PolygonOptions, PolylineOptions, SelectedOptions } from "./constants"; import { PolygonOptions, PolylineOptions, SelectedOptions } from "./constants";
@ -143,7 +143,11 @@ export class MapEditor extends Emitter implements IMapEditor {
for (let id in this.overlayMap) { for (let id in this.overlayMap) {
this.map.remove(this.overlayMap[id].target); this.map.remove(this.overlayMap[id].target);
} }
for (let id in this.imageLayerMap) {
this.map.remove(this.imageLayerMap[id]);
}
this.overlayMap = {}; this.overlayMap = {};
this.imageLayerMap = {};
this.selectedIds = []; this.selectedIds = [];
} }
@ -211,13 +215,13 @@ export class MapEditor extends Emitter implements IMapEditor {
let id = getUID(); let id = getUID();
if (isCreatingOverlay) { if (isCreatingOverlay) {
this._addOverlay(id, { type, target }); this._addOverlay(id, { type, target });
target.setOptions(
type === OverlayTypes.Polyline ? PolylineOptions : PolygonOptions
);
} else { } else {
id = this.selectedIds[0]; id = this.selectedIds[0];
} }
this._updateOverlay(id); this._updateOverlay(id);
target.setOptions(
type === OverlayTypes.Polyline ? PolylineOptions : PolygonOptions
);
this.editorStatus = null; this.editorStatus = null;
} }

9
src/store/reducers/map/index.ts

@ -2,7 +2,7 @@ import produce from "immer";
import { initState } from "../../initState"; import { initState } from "../../initState";
import { OverlayNamePrefixs } from "@store"; import { OverlayNamePrefixs } from "@store";
import { OverlayTypes, Status } from "@types"; import { OverlayTypes, Status } from "@types";
import { IOverlay } from "@map"; import { IOverlay, OverlayCategory } from "@map";
export function createOverlay(state = initState, payload: OverlayTypes) { export function createOverlay(state = initState, payload: OverlayTypes) {
return produce(state, (draft) => { return produce(state, (draft) => {
@ -40,6 +40,13 @@ export function finishEditOverlay(state = initState, payload: any) {
...overlay, ...overlay,
}; };
} else { } else {
const isRoad = type === OverlayTypes.Polyline;
if (isRoad) {
overlay.category = OverlayCategory.Road;
} else {
overlay.category = OverlayCategory.Building;
overlay.height = 100;
}
overlays.push(overlay); overlays.push(overlay);
} }
draft.overlayType = null; draft.overlayType = null;

87
src/store/utils/getGeoJSON.ts

@ -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 = {}
) => {
features.push({ const properties: GeoJSON.GeoJsonProperties = {
type: "Feature", ...restProperties,
geometry: { fineType: overlay.type,
type: "Polygon", };
coordinates: [path], const { category } = overlay;
}, if (category === OverlayCategory.Building) {
properties: { properties.building = true;
fineType: OverlayTypes.Rectangle, 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 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 {

Loading…
Cancel
Save