Skip to content

Commit 9be660c

Browse files
committed
展示解决maplibre顶点编辑器delete键删除不成功的问题
1 parent d801b2e commit 9be660c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/maplugin-core/utils/units.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ref, watch } from "vue";
2+
import { IMap } from '../types';
23

34
export namespace Units {
45
export type TUnitsLength = "M" | "KM";
@@ -216,5 +217,13 @@ export namespace Units {
216217
const vu = createUseUnits(Units.convertLength, value, units, valueUnits);
217218
return { ...vu, unitsDescriptions: Units.unitsLengthDescriptions };
218219
}
220+
221+
export function isMaplibregl(map: IMap) {
222+
return map.getCanvas()!.classList.contains("maplibregl-canvas");
223+
}
224+
225+
export function isMapboxgl(map: IMap) {
226+
return map.getCanvas()!.classList.contains("mapboxgl-canvas");
227+
}
219228
}
220229

packages/maplugin-core/utils/vertex-editor.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import MapboxDraw from "@mapbox/mapbox-gl-draw";
22
import { IMap, TIdentityGeoJSONFeature } from '../types';
3+
import { Units } from '../utils';
34

45
export class VertexEditor {
56
private editor: MapboxDraw;
@@ -24,7 +25,7 @@ export class VertexEditor {
2425
if (state.selectedCoordPaths.length > 0)
2526
onDrag?.call(this, state, e);
2627
};
27-
28+
2829
// 禁止删除图形
2930
const directSelectOnTrash = MapboxDraw.modes.direct_select.onTrash;
3031
MapboxDraw.modes.direct_select.onTrash = function (this, state) {
@@ -38,6 +39,15 @@ export class VertexEditor {
3839
}
3940
MapboxDraw.modes.simple_select.onTrash = function (this, _) { }
4041

42+
// TODO : mapbox-gl-draw 之后会更新调整contracts.classes.CANVASE 数值
43+
if (Units.isMaplibregl(map)) {
44+
window.addEventListener("keydown", e => {
45+
if (e.code === "Delete") {
46+
this.editor.trash();
47+
}
48+
});
49+
}
50+
4151
const time = setInterval(() => {
4252
["gl-draw-line-inactive.cold", "gl-draw-polygon-stroke-inactive.cold", "gl-draw-polygon-fill-inactive.cold"].forEach(x => {
4353
if (map.getLayer(x)) {

0 commit comments

Comments
 (0)