drawTool.js
3.04 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { loadModules } from "esri-loader";
import mapManage from './towMapObjects';
export default class DrawTool {
static getInstance() {
loadModules(["esri/symbols/PictureMarkerSymbol", "esri/layers/GraphicsLayer", "esri/views/draw/Draw"]).then((a) => {
mapManage.drawTool || (mapManage.drawTool = new this(a));
});
}
constructor() {
let arg = arguments[0];
this.view = mapManage.mapView;
this.map = mapManage.mapView.map;
this.active = !1;
this.paths = [];
this.options1 || (this.options1 = {}, this.options1.pm = {
type: 'simple-marker', color: [165, 42, 42, 0.7], width: "5px", height: "5px"
});
this.map.add(this.graphicsLayer = new arg[1]({
id: "drawtool",
graphics: []
}));
this.draw = new arg[2]({ view: this.view });
}
activate(c, b) {
this.active = !0;
this.drawType = c.toUpperCase();
this.callback = b;
this.downCount = 0;
// this.map.reorder(this.graphicsLayer, this.map.allLayers.length - 1);
switch (this.drawType) {
case "POINT1":
loadModules(["esri/Graphic", "esri/geometry/Point"]).then(([h, f]) => {
this.downCount = 0;
let action = this.draw.create("point", {
mode: "click"
});
action.on("draw-complete", event => {
!this.paths.length && this.graphicsLayer.graphics.add(this.graphic = new h({
geometry: this.construc({
type: f,
vertices: event.vertices
}),
symbol: this.options1.pm
}));
this.paths.push(event.vertices[0]);
this.callback(event.vertices);
});
});
break;
}
}
createPolyline() {
this.graphicsLayer.graphics.remove(this.graphic);
loadModules(["esri/Graphic", "esri/geometry/Polygon"]).then(([h, f]) => {
this.graphic = new h({
geometry: this.construc({
type: f,
rings: this.paths
}),
symbol: {
type: "simple-line",
color: [238, 44, 44, 0.8],
width: 2,
style: 'solid'
}
});
this.graphicsLayer.graphics.add(this.graphic);
});
}
deactivate() {
this.active = !1;
this.drawType = "";
this.downCount = 0;
}
construc(arg) {
let settings = {
hasZ: false,
hasM: false,
spatialReference: this.view.spatialReference,
paths: arg.paths,
rings: arg.rings
};
arg.vertices && Object.assign(settings, {
x: arg.vertices[0][0],
y: arg.vertices[0][1]
});
return new arg.type(settings);
}
}