Browse Source

清楚所有覆盖物功能

master
Cmen 3 years ago
parent
commit
2d561fa990
  1. 2
      index.html
  2. 21
      src/editor/Menu/Edit.tsx
  3. 2
      src/editor/Menu/index.tsx
  4. 1
      src/editor/Menu/style.less
  5. 6
      src/editor/Plot/index.less
  6. 2
      src/editor/Plot/index.tsx
  7. 1
      src/map/MapEditor.ts
  8. 1
      src/map/type.ts
  9. 13
      src/store/actions/StoreAction.ts
  10. 17
      src/store/actions/index.ts
  11. 8
      src/store/reducers/index.ts
  12. 4
      src/store/reducers/map/index.ts

2
index.html

@ -4,7 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title> <title>Fine-GeoJSONEditor, 好用的在线GeoJSON编辑工具</title>
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>

21
src/editor/Menu/Edit.tsx

@ -0,0 +1,21 @@
import { editorAction } from "@store";
import MenuGroup from "./MenuGroup";
const EditMenu = () => {
return (
<MenuGroup
{...{
name: "编辑",
items: [
{
name: "清空覆盖物",
onClick: editorAction.clearOverlays,
hotkey: "Ctrl+Alt+C",
},
],
}}
/>
);
};
export default EditMenu;

2
src/editor/Menu/index.tsx

@ -1,4 +1,5 @@
import FileMenu from "./File"; import FileMenu from "./File";
import EditMenu from "./Edit";
import "./style.less"; import "./style.less";
@ -6,6 +7,7 @@ const Menu = () => {
return ( return (
<> <>
<FileMenu /> <FileMenu />
<EditMenu />
</> </>
); );
}; };

1
src/editor/Menu/style.less

@ -1,5 +1,6 @@
.menu-title { .menu-title {
cursor: pointer; cursor: pointer;
margin-right: 12px;
} }
.menu-item { .menu-item {
width: 240px; width: 240px;

6
src/editor/Plot/index.less

@ -1,8 +1,8 @@
.map-stage { .map-stage {
position: absolute; position: absolute;
width: 100%; width: 100%;
height: calc(100% - 40px); height: 100%; //calc(100% - 40px);
top: 40px; // top: 40px;
left: 0; left: 0;
z-index: 0; z-index: 0;
} }
@ -14,7 +14,7 @@
border-bottom: 1px solid #ccc; border-bottom: 1px solid #ccc;
} }
.tools-area { .tools-area {
margin-top: 40px; // margin-top: 40px;
padding: 20px; padding: 20px;
position: relative; position: relative;
z-index: 10; z-index: 10;

2
src/editor/Plot/index.tsx

@ -23,7 +23,7 @@ const Plot = () => {
return ( return (
<> <>
<div className="map-stage" ref={mapStageRef}></div> <div className="map-stage" ref={mapStageRef}></div>
<div className="tools-properties"></div> {/* <div className="tools-properties"></div> */}
<div className="tools-area"> <div className="tools-area">
<Tools /> <Tools />
</div> </div>

1
src/map/MapEditor.ts

@ -143,6 +143,7 @@ export class MapEditor extends Emitter implements IMapEditor {
this.map.remove(this.overlayMap[id].target); this.map.remove(this.overlayMap[id].target);
} }
this.overlayMap = {}; this.overlayMap = {};
this.selectedIds = [];
} }
createOverlay(type: OverlayTypes) { createOverlay(type: OverlayTypes) {

1
src/map/type.ts

@ -8,6 +8,7 @@ export interface IMapEditor {
importGeoJSON(geojson: GeoJSON.FeatureCollection): void; importGeoJSON(geojson: GeoJSON.FeatureCollection): void;
selectOverlays(ids?: string[]): void; selectOverlays(ids?: string[]): void;
deleteOverlays(): void; deleteOverlays(): void;
clearOverlays(): void;
} }
export interface IOverlay { export interface IOverlay {

13
src/store/actions/StoreAction.ts

@ -7,9 +7,15 @@ export enum ActionTypes {
SelectOverlay = "selectOverlay", SelectOverlay = "selectOverlay",
DeleteOverlays = "deleteOverlays", DeleteOverlays = "deleteOverlays",
ReplaceState = "replaceState", ReplaceState = "replaceState",
ClearOverlays = "clearOverlays",
} }
export const StoreAction = { type ActionCreator = (payload?: any) => {
type: ActionTypes;
payload?: any;
};
export const StoreAction: Record<ActionTypes, ActionCreator> = {
createOverlay(type: OverlayTypes) { createOverlay(type: OverlayTypes) {
return { return {
type: ActionTypes.CreateOverlay, type: ActionTypes.CreateOverlay,
@ -40,4 +46,9 @@ export const StoreAction = {
payload: state, payload: state,
}; };
}, },
clearOverlays() {
return {
type: ActionTypes.ClearOverlays,
};
},
}; };

17
src/store/actions/index.ts

@ -106,8 +106,14 @@ export class EditorAction {
saveTemp() { saveTemp() {
// //
} }
clearEditor() { clearOverlays() {
// Modal.confirm({
title: "确定移除所有覆盖物吗?",
onOk: () => {
this.mapEditor?.clearOverlays();
this.dispatch(StoreAction.clearOverlays());
},
});
} }
openGeoJSON() { openGeoJSON() {
// //
@ -137,6 +143,7 @@ export class EditorAction {
this.createPolyline = this.createPolyline.bind(this); this.createPolyline = this.createPolyline.bind(this);
this.createCircle = this.createCircle.bind(this); this.createCircle = this.createCircle.bind(this);
this.deleteOverlays = this.deleteOverlays.bind(this); this.deleteOverlays = this.deleteOverlays.bind(this);
this.clearOverlays = this.clearOverlays.bind(this);
} }
private _registerHotkeys() { private _registerHotkeys() {
@ -149,7 +156,11 @@ export class EditorAction {
}); });
registerHotkey("s", { callback: this.saveTemp, alt: true }); registerHotkey("s", { callback: this.saveTemp, alt: true });
// 清空 // 清空
registerHotkey("c", { callback: this.clearEditor, alt: true }); registerHotkey("c", {
callback: this.clearOverlays,
alt: true,
ctrl: true,
});
// //
registerHotkey("o", { callback: this.openGeoJSON, alt: true }); registerHotkey("o", { callback: this.openGeoJSON, alt: true });
registerHotkey("o", { registerHotkey("o", {

8
src/store/reducers/index.ts

@ -2,7 +2,12 @@ import produce from "immer";
import { IEditorState } from "../type"; import { IEditorState } from "../type";
import { initState } from "../initState"; import { initState } from "../initState";
import { ActionTypes } from "../actions"; import { ActionTypes } from "../actions";
import { createOverlay, finishEditOverlay, deleteOverlays } from "./map"; import {
createOverlay,
finishEditOverlay,
deleteOverlays,
clearOverlays,
} from "./map";
export type Action = { export type Action = {
type: ActionTypes; type: ActionTypes;
@ -17,6 +22,7 @@ const actionReducers: Record<ActionTypes, ActionReducer> = {
[ActionTypes.SelectOverlay]: selectOverlay, [ActionTypes.SelectOverlay]: selectOverlay,
[ActionTypes.DeleteOverlays]: deleteOverlays, [ActionTypes.DeleteOverlays]: deleteOverlays,
[ActionTypes.ReplaceState]: replaceState, [ActionTypes.ReplaceState]: replaceState,
[ActionTypes.ClearOverlays]: clearOverlays,
}; };
function replaceState(state = initState, payload: IEditorState) { function replaceState(state = initState, payload: IEditorState) {

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

@ -11,6 +11,10 @@ export function createOverlay(state = initState, payload: OverlayTypes) {
}); });
} }
export function clearOverlays(state = initState) {
return initState;
}
export function deleteOverlays(state = initState, payload: any) { export function deleteOverlays(state = initState, payload: any) {
const { selectedIds } = state; const { selectedIds } = state;
const [id] = selectedIds!; const [id] = selectedIds!;

Loading…
Cancel
Save