Skip to content

Commit 5e28cbb

Browse files
committed
修改测量数据源策略
1 parent ff3bff7 commit 5e28cbb

File tree

4 files changed

+38
-41
lines changed

4 files changed

+38
-41
lines changed

geojson-editor/src/App.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,21 @@ function handleMapLoaded(map: maplibregl.Map) {
4545
glManager.on('all', () => {
4646
fc.value = glManager.fc;
4747
});
48-
const drawManager = new DrawManager(glManager, {});
48+
const drawManager = new DrawManager(glManager);
4949
5050
map.loadImage(img_marker).then((img) => {
5151
map.addImage("marker", img.data);
5252
5353
map.getLayerProxy<maplibregl.CircleLayerSpecification>(drawManager.id_layer_point).value.layout!['visibility'] = 'none';
5454
const layout = map.getLayerProxy<maplibregl.SymbolLayerSpecification>(drawManager.id_layer_point_symbol).value.layout!;
5555
layout['icon-image'] = 'marker'
56-
layout['icon-size'] = 0.5;
56+
layout['icon-size'] = 0.3;
57+
layout['icon-anchor'] = 'bottom';
5758
});
5859
5960
createMapControl(map, ShowEditorButton);
6061
createMapControl(map, Drawer, { drawManager }, 'top-left');
61-
createMapControl(map, Measurer, { measureManager: new MeasureManager(glManager, {}) }, 'top-left');
62+
createMapControl(map, Measurer, { measureManager: new MeasureManager(glManager) }, 'top-left');
6263
}
6364
6465
function createMapControl(map: maplibregl.Map, component: Component, data?: Record<string, unknown>, position: maplibregl.ControlPosition = 'top-right') {
-311 Bytes
Loading

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class DrawManager {
2929
/**
3030
*
3131
*/
32-
constructor(protected glManager: GeoJSONLayerManagerBase, private options: DrawOptions) {
32+
constructor(public glManager: GeoJSONLayerManagerBase, private options: DrawOptions = {}) {
3333
//#region add layers
3434

3535
glManager.addLayer({
@@ -114,6 +114,13 @@ export class DrawManager {
114114
}
115115
});
116116

117+
glManager.on('clear', () => {
118+
((glManager.map as any).getSource(this.id_layer_polygon_subline)).setData({
119+
type: 'FeatureCollection',
120+
features: []
121+
});
122+
});
123+
117124
//#endregion
118125

119126
this.escOnce = (e: KeyboardEvent) => {
@@ -169,11 +176,6 @@ export class DrawManager {
169176

170177
clear(): void {
171178
this.glManager.clear();
172-
173-
((this.glManager.map as any).getSource(this.id_layer_polygon_subline)).setData({
174-
type: 'FeatureCollection',
175-
features: []
176-
});
177179
}
178180

179181
private drawPoint() {

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

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import booleanClockwise from '@turf/boolean-clockwise';
2-
import { DrawManager, DrawOptions } from './geojson-draw-manager';
2+
import { DrawManager } from './geojson-draw-manager';
33
import { GeoJSONLayerManagerBase } from './geojson-layer-manager';
44
import { Units, Measurement, Tools } from '../utils';
55
import { TIdentityGeoJSONFeature } from '../types';
@@ -9,24 +9,12 @@ type TMeasureUnits = {
99
length: Units.TUnitsLength | "MKM",
1010
}
1111

12-
interface MeasureOptions extends DrawOptions {
12+
interface MeasureOptions {
1313
}
1414

15-
export class MeasureManager extends DrawManager {
16-
/**
17-
* 测量id
18-
*
19-
* 用于创建标注文字id
20-
*/
21-
readonly id_layer_measure_symbol = Tools.uuid();
22-
23-
/**
24-
* 面方向图层id
25-
*
26-
* 用于创建面方向layer和source
27-
*/
28-
readonly id_layer_polygon_clockwise = Tools.uuid();
15+
export class MeasureManager {
2916

17+
private glManager: GeoJSONLayerManagerBase;
3018

3119
private customFeatures: TIdentityGeoJSONFeature[] = [];
3220

@@ -45,6 +33,20 @@ export class MeasureManager extends DrawManager {
4533
*/
4634
private polygonDistance: boolean = true;
4735

36+
/**
37+
* 测量id
38+
*
39+
* 用于创建标注文字id
40+
*/
41+
readonly id_layer_measure_symbol = Tools.uuid();
42+
43+
/**
44+
* 面方向图层id
45+
*
46+
* 用于创建面方向layer和source
47+
*/
48+
readonly id_layer_polygon_clockwise = Tools.uuid();
49+
4850
/**
4951
* 长度单位
5052
*/
@@ -59,17 +61,18 @@ export class MeasureManager extends DrawManager {
5961
return this.units.area;
6062
}
6163

62-
constructor(glManager: GeoJSONLayerManagerBase, options: MeasureOptions) {
63-
super(glManager, options);
64-
glManager.on('all', () => this.renderMeasure());
64+
constructor(dataSource: DrawManager | GeoJSONLayerManagerBase, options: MeasureOptions = {}) {
65+
this.glManager = dataSource instanceof DrawManager ? dataSource.glManager : dataSource;
6566

66-
glManager.addLayer(this.id_layer_measure_symbol);
67-
glManager.addLayer(this.id_layer_polygon_clockwise);
67+
this.glManager.on('all', () => this.renderMeasure());
68+
69+
this.glManager.addLayer(this.id_layer_measure_symbol);
70+
this.glManager.addLayer(this.id_layer_polygon_clockwise);
6871

6972
/**
7073
* 添加测量数值图层
7174
*/
72-
glManager.map.addLayer({
75+
this.glManager.map.addLayer({
7376
id: this.id_layer_measure_symbol,
7477
type: 'symbol',
7578
source: {
@@ -94,7 +97,7 @@ export class MeasureManager extends DrawManager {
9497
/**
9598
* 添加面方向图层
9699
*/
97-
glManager.map.addLayer({
100+
this.glManager.map.addLayer({
98101
id: this.id_layer_polygon_clockwise,
99102
type: 'symbol',
100103
source: {
@@ -236,15 +239,6 @@ export class MeasureManager extends DrawManager {
236239
val ? undefined : ['!', ['boolean', ['get', 'center'], false]]);
237240
}
238241

239-
/**
240-
* 清除测量数据
241-
*/
242-
clear() {
243-
super.clear();
244-
this.customFeatures = [];
245-
this.renderMeasure();
246-
}
247-
248242
/**
249243
* 重绘
250244
*/

0 commit comments

Comments
 (0)