Skip to content

Commit d0f9d30

Browse files
committed
增加顶点编辑器
1 parent 17e3570 commit d0f9d30

File tree

6 files changed

+735
-19
lines changed

6 files changed

+735
-19
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",
6+
"private": true,
67
"scripts": {
78
"build": "pnpm -r --filter=./packages/* run build",
89
"release": "bumpp package.json packages/**/package.json",
@@ -15,12 +16,14 @@
1516
"author": "",
1617
"license": "ISC",
1718
"dependencies": {
19+
"@mapbox/mapbox-gl-draw": "^1.4.3",
1820
"@turf/boolean-clockwise": "^7.1.0",
1921
"@turf/center": "^7.1.0",
2022
"proj4": "^2.12.1"
2123
},
2224
"devDependencies": {
2325
"@types/geojson": "^7946.0.14",
26+
"@types/mapbox__mapbox-gl-draw": "^1.4.8",
2427
"@types/proj4": "^2.5.5",
2528
"@vitejs/plugin-vue": "^5.1.4",
2629
"bumpp": "^9.7.1",
@@ -30,4 +33,4 @@
3033
"vitepress": "^1.4.1",
3134
"vue": "^3.5.12"
3235
}
33-
}
36+
}

packages/maplugin-core/managers/geojson-layer-manager.ts

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { IMap } from "../types";
1+
import { IMap, TIdentityGeoJSONFeature } from "../types";
22
import { Tools } from "../utils/tools";
33

44
export type TFeatureEvent = "all" | "add" | "update" | "delete" | "clear" | "destory";
5-
export type TIdentityGeoJSONFeature = GeoJSON.Feature<GeoJSON.Geometry, { id: string }>;
65

76
export interface GeoJSONLayerManagerOptions<TFeature extends TIdentityGeoJSONFeature = TIdentityGeoJSONFeature> {
87
map: IMap;
@@ -13,6 +12,7 @@ export abstract class GeoJSONLayerManagerBase<TFeature extends TIdentityGeoJSONF
1312
private events = new Map<string, Array<(e: { features?: TFeature[] }) => void>>();
1413
protected readonly layers = new Array<string>();
1514
protected data = new Map<string, TFeature>();
15+
protected hiddenData = new Map<string, TFeature>();
1616

1717
readonly map: IMap;
1818
readonly source: string = Tools.uuid();
@@ -42,6 +42,15 @@ export abstract class GeoJSONLayerManagerBase<TFeature extends TIdentityGeoJSONF
4242

4343
protected abstract onChange(mode: TFeatureEvent, features?: TFeature[]): void;
4444

45+
/**
46+
* 获取数据
47+
* @param id
48+
* @returns
49+
*/
50+
query(id: string): TFeature | undefined {
51+
return this.data.get(id);
52+
}
53+
4554
/**
4655
* 添加图层
4756
* @param layer
@@ -55,15 +64,6 @@ export abstract class GeoJSONLayerManagerBase<TFeature extends TIdentityGeoJSONF
5564
}
5665
}
5766

58-
/**
59-
* 获取数据
60-
* @param id
61-
* @returns
62-
*/
63-
query(id: string): TFeature | undefined {
64-
return this.data.get(id);
65-
}
66-
6767
/**
6868
* 创建数据
6969
* @param features
@@ -133,6 +133,65 @@ export abstract class GeoJSONLayerManagerBase<TFeature extends TIdentityGeoJSONF
133133
this.map.removeSource(this.source);
134134
}
135135

136+
/**
137+
* 设置Feature隐藏
138+
* @param id
139+
* @returns
140+
*/
141+
setFeatureHidden(...id: string[]) {
142+
const fs = new Array<TFeature>();
143+
id.forEach(i => {
144+
const f = this.data.get(i);
145+
if (!f) return;
146+
147+
// 如果已经隐藏,则不处理
148+
if (this.hiddenData.has(i)) return;
149+
150+
// 处理隐藏
151+
this.data.delete(i)
152+
this.hiddenData.set(i, f);
153+
fs.push(f);
154+
});
155+
156+
this.onChange("delete", fs);
157+
}
158+
159+
/**
160+
*
161+
* @param id 当id为空时清除所有隐藏
162+
*/
163+
clearFeatureHidden(...id: string[]) {
164+
const fs = new Array<TFeature>();
165+
if (id.length === 0)
166+
id.forEach(i => {
167+
const f = this.hiddenData.get(i);
168+
if (!f) return;
169+
170+
this.hiddenData.delete(i);
171+
this.data.set(i, f);
172+
fs.push(f);
173+
});
174+
else {
175+
this.hiddenData.forEach((v, k) => {
176+
this.data.set(k, v);
177+
fs.push(v);
178+
});
179+
this.hiddenData.clear();
180+
}
181+
182+
this.onChange('add', fs);
183+
}
184+
185+
/**
186+
* 设置是否显示
187+
* @param visible
188+
*/
189+
setVisible(visible: boolean) {
190+
this.layers.forEach(l => {
191+
this.map.setLayoutProperty(l, 'visibility', visible ? 'visible' : 'none');
192+
});
193+
}
194+
136195
/**
137196
* 挂在事件
138197
* @param mode

packages/maplugin-core/managers/measure-manager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import booleanClockwise from '@turf/boolean-clockwise';
22
import { DrawManager, DrawOptions } from './geojson-draw-manager';
3-
import { GeoJSONLayerManagerBase, TIdentityGeoJSONFeature } from './geojson-layer-manager';
3+
import { GeoJSONLayerManagerBase } from './geojson-layer-manager';
44
import { Units, Measurement, Tools } from '../utils';
5+
import { TIdentityGeoJSONFeature } from '../types';
56

67
type TMeasureUnits = {
78
area: Units.TUnitsArea | "M2KM2",

packages/maplugin-core/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type TMapEvent = 'click' | 'dblclick' | 'mousemove' | 'contextmenu' | 'zoom' | 'style.load';
1+
export type TMapEvent = 'click' | 'dblclick' | 'mousemove' | 'contextmenu' | 'zoom' | 'style.load' | 'draw.selectionchange';
22

33
export interface IMap {
44
dragRotate: number,
@@ -33,4 +33,6 @@ export interface IMap {
3333
setLayoutProperty(layerId: string, property: string, value: any): void,
3434

3535
setFilter(id: string, filter?: any, options?: any): void
36-
}
36+
}
37+
38+
export type TIdentityGeoJSONFeature = GeoJSON.Feature<GeoJSON.Geometry, { id: string }>;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './measurement';
22
export * from './tools';
33
export * from './units';
4-
export * from './middle-button-roate';
4+
export * from './middle-button-roate';
5+
export * from './vertex-editor';

0 commit comments

Comments
 (0)