measure.js
2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import {loadModules} from 'esri-loader'
import {maps} from '@/libs/map/mapUtils'
export default{
data(){
return{
//activeWidget:null,
areaActive:null,
distanceActive:null
}
},
methods: {
/**
* @description: measure
* @param {*} viewId
* @param {*} type
* @author: renchao
*/
measure(viewId,type){
var view = maps[viewId];
var self = this;
loadModules([
"esri/widgets/DistanceMeasurement2D",
"esri/widgets/AreaMeasurement2D"
]).then(([
DistanceMeasurement2D,
AreaMeasurement2D
]) => {
switch (type) {
case "distance":
if(!self.distanceActive){
self.distanceActive = new DistanceMeasurement2D({
view: view
});
}
// skip the initial 'new measurement' button
self.distanceActive.viewModel.start();
break;
case "area":
if(!self.areaActive){
self.areaActive = new AreaMeasurement2D({
view: view
});
}
// skip the initial 'new measurement' button
self.areaActive.viewModel.start();
break;
case null:
if (self.distanceActive) {
self.distanceActive.viewModel.clear();
// self.distanceActive = null;
}
if (self.areaActive) {
self.areaActive.viewModel.clear();
// self.areaActive = null;
}
break;
}
}).catch(err => {
throw(err);
});
}
}
}