Skip to content

Commit 7a16f0a

Browse files
author
潘卓然Y7000P
committed
【站点】【新增】【实现响应式的测量组件】
1 parent ed63f95 commit 7a16f0a

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

  • website/public/static/demo/mapboxgl/example/vue/control

website/public/static/demo/mapboxgl/example/vue/control/measure.htm

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050
:map-style="mapStyle"
5151
:zoom="mapZoom"
5252
:center="outerCenter"
53-
:crs="mapCrs">
53+
:crs="mapCrs"
54+
v-on:load="handleMapLoad"
55+
>
5456
<mapbox-igs-tdt-layer
5557
:layer="layer"
5658
:layer-id="layerId"
@@ -124,16 +126,37 @@
124126
component.enableMeasure();
125127
}
126128
},
129+
handleMapLoad(payload) {
130+
this.map = payload.map;
131+
},
127132
handleAdded(e, data) {
133+
const vm = this;
128134
let { measure, map } = e;
129135
this.measure = measure;
136+
vm.map.on('draw.selectionchange', (e) => {
137+
const { features, points } = e;
138+
const hasLine = (features && (features.length > 0));
139+
const hasPoints = (points && (points.length > 0));
140+
if (hasLine && ! hasPoints) {
141+
// line clicked
142+
if (vm.measure.getMode() !== 'direct_select') {
143+
vm.measure.changeMode('direct_select', { featureId: features[0].id });
144+
}
145+
} else if (hasLine && hasPoints) {
146+
// line vertex clicked
147+
} else if (! hasLine && ! hasPoints) {
148+
// deselected
149+
}
150+
});
130151
},
131152
handleCreate(e) {
132153
// this.measure && this.measure.deleteAll();
133154
console.log('绘制结果', e);
155+
this.disableDrag();
134156
},
135157
handleMeasure(e) {
136158
console.log('测量结果', e);
159+
this.disableDrag();
137160
const {center, perimeter, area} = e;
138161
const coords = center.geometry.coordinates;
139162
this.coordinates = coords;
@@ -151,6 +174,25 @@
151174
this.coordinates = [];
152175
this.measureMode = "measure-area";
153176
this.measure && this.measure.changeMode('draw_polygon');
177+
},
178+
disableDrag() {
179+
const vm = this;
180+
vm.map.on('draw.selectionchange', (e) => {
181+
const { features, points } = e;
182+
const hasLine = (features && (features.length > 0));
183+
const hasPoints = (points && (points.length > 0));
184+
if (hasLine && ! hasPoints) {
185+
// line clicked
186+
if (vm.measure.getMode() !== 'direct_select') {
187+
vm.measure.changeMode('simple_select', { featureIds: [] })
188+
// vm.measure.changeMode('direct_select', { featureId: features[0].id });
189+
}
190+
} else if (hasLine && hasPoints) {
191+
// line vertex clicked
192+
} else if (! hasLine && ! hasPoints) {
193+
// deselected
194+
}
195+
});
154196
}
155197
}
156198
});

0 commit comments

Comments
 (0)