Skip to content

Commit 6caac24

Browse files
committed
增加编辑器
1 parent 5690421 commit 6caac24

File tree

2 files changed

+39
-21
lines changed

2 files changed

+39
-21
lines changed

geojson-editor/src/App.vue

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,25 @@ function handleMapLoaded(map: maplibregl.Map) {
6161
layout['icon-anchor'] = 'bottom';
6262
});
6363
64-
map.on('click', drawManager.id_layer_polygon, ({ features }) => {
65-
if (drawManager.drawing || !features || features.length === 0) return;
66-
const f = glManager.query((features[0].properties as any)['id']);
67-
if (f) {
68-
glManager.setFeatureHidden(f.properties.id);
69-
vertexEditor.setFeature(f, feature => {
70-
71-
glManager.clearFeatureHidden();
72-
glManager.update(feature);
73-
});
74-
}
75-
});
64+
map.on('click', [
65+
drawManager.id_layer_polygon,
66+
drawManager.id_layer_polygon_circle,
67+
drawManager.id_layer_polygon_outline,
68+
drawManager.id_layer_line,
69+
drawManager.id_layer_line_circle,
70+
drawManager.id_layer_point,
71+
drawManager.id_layer_point_symbol], ({ features }) => {
72+
if (drawManager.drawing || !features || features.length === 0) return;
73+
const f = glManager.query((features[0].properties as any)['id']);
74+
if (f) {
75+
glManager.setFeatureHidden(f.properties.id);
76+
vertexEditor.setFeature(f, g => {
77+
glManager.clearFeatureHidden();
78+
f.geometry = g;
79+
glManager.update(f);
80+
});
81+
}
82+
});
7683
7784
createMapControl(map, ShowEditorButton);
7885
createMapControl(map, Drawer, { drawManager }, 'top-left');

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,30 @@ export class VertexEditor {
3434
}
3535
}
3636
MapboxDraw.modes.simple_select.onTrash = function (this, _) { }
37+
38+
const time = setInterval(() => {
39+
["gl-draw-line-inactive.cold", "gl-draw-polygon-stroke-inactive.cold", "gl-draw-polygon-fill-inactive.cold"].forEach(x => {
40+
if (map.getLayer(x)) {
41+
map.setLayoutProperty(x, "visibility", "none");
42+
clearInterval(time);
43+
}
44+
});
45+
}, 400);
3746
}
3847

39-
setFeature(feature: TIdentityGeoJSONFeature, onChange: (feature: TIdentityGeoJSONFeature) => void) {
40-
const fId = feature.properties.id;
41-
feature.id = fId;
42-
const geometryCopy = JSON.stringify(feature.geometry);
48+
setFeature<TF extends TIdentityGeoJSONFeature>(feature: TF, onDone: (geometry: TF['geometry']) => void) {
49+
const fId = '1';
4350

4451
// 编辑器重置数据
4552
const editor = this.editor;
46-
editor.set({ type: 'FeatureCollection', "features": [feature] });
53+
editor.set({
54+
type: 'FeatureCollection', "features": [{
55+
type: 'Feature',
56+
id: fId,
57+
geometry: feature.geometry,
58+
properties: {}
59+
}]
60+
});
4761

4862
if (feature.geometry.type === 'Point')
4963
editor.changeMode('simple_select', { featureIds: [fId] })
@@ -55,10 +69,7 @@ export class VertexEditor {
5569

5670
// 当前选择图形失去选择状态 完成修改
5771
if (e.features.length === 0 && cFeature) {
58-
// 若发生改变
59-
if (geometryCopy === JSON.stringify(cFeature.geometry)) {
60-
onChange(cFeature as TIdentityGeoJSONFeature);
61-
}
72+
onDone(cFeature.geometry);
6273

6374
// 删除编辑数据
6475
this.map.off('draw.selectionchange', handleSelectChange);

0 commit comments

Comments
 (0)