draw.js
2.28 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
69
70
71
72
73
74
import {maps} from '@/libs/map/mapUtils'
import {loadModules} from 'esri-loader'
export default {
data() {
return {
drawAction:null,
graphicLayer:null,
creatEvent:null,
}
},
methods: {
/**
* @description: initDraw
* @param {*} type
* @param {*} viewId
* @param {*} creationMode
* @param {*} callBackFunction
* @author: renchao
*/
initDraw(type,viewId,creationMode,callBackFunction){
var self = this;
loadModules([
"esri/widgets/Sketch",
"esri/layers/GraphicsLayer"
]).then(([
Sketch,
GraphicsLayer
]) => {
var view = maps[viewId];
if(!self.drawAction){
self.graphicLayer = new GraphicsLayer({
id:"_drawLayer"
})
self.drawAction = new Sketch({
view: view,
layer:self.graphicLayer,
creationMode: "single"
});
}else {
// this.drawAction.cancel();
if(creationMode){
self.drawAction.creationMode = creationMode;
}
// graphicLayer = view.map.findLayerById("_drawLayer");
}
self.drawAction.create(type);
if(self.creatEvent){
self.creatEvent.remove();
}
self.creatEvent = self.drawAction.on("create", function(event) {
if (event.state === "complete") {
self.graphicLayer.remove(event.graphic);
if(callBackFunction && typeof callBackFunction == 'function'){
callBackFunction(event.graphic.geometry);
}
}
})
}).catch(err=>{
throw(err);
});
},
/**
* @description: destroyeDraw
* @author: renchao
*/
destroyeDraw() {
if(this.drawAction){
this.drawAction.cancel();
}
}
}
}