jikai commit
Showing
1 changed file
with
59 additions
and
21 deletions
| ... | @@ -2,50 +2,88 @@ import { loadModules } from "esri-loader"; | ... | @@ -2,50 +2,88 @@ import { loadModules } from "esri-loader"; |
| 2 | import mapManage from './towMapObjects'; | 2 | import mapManage from './towMapObjects'; |
| 3 | export default class DrawTool { | 3 | export default class DrawTool { |
| 4 | static getInstance() { | 4 | static getInstance() { |
| 5 | mapManage.drawTool || (mapManage.drawTool = new this()); | 5 | loadModules(["esri/symbols/PictureMarkerSymbol", "esri/layers/GraphicsLayer", "esri/views/draw/Draw"]).then((a) => { |
| 6 | mapManage.drawTool || (mapManage.drawTool = new this(a)); | ||
| 7 | }); | ||
| 6 | } | 8 | } |
| 7 | constructor() { | 9 | constructor() { |
| 10 | let arg = arguments[0]; | ||
| 8 | this.view = mapManage.mapView; | 11 | this.view = mapManage.mapView; |
| 9 | this.map = mapManage.mapView.map; | 12 | this.map = mapManage.mapView.map; |
| 10 | this.active = !1; | 13 | this.active = !1; |
| 11 | this.polygon = null; | 14 | this.paths = []; |
| 12 | this.guids = []; | 15 | this.options1 || (this.options1 = {}, this.options1.pm = { |
| 13 | loadModules(["esri/symbols/PictureMarkerSymbol", "esri/layers/GraphicsLayer", "esri/views/draw/Draw"]).then(([w, z, d]) => { | 16 | type: 'simple-marker', color: [165, 42, 42, 0.7], width: "5px", height: "5px" |
| 14 | this.options1 || (this.options1 = {}, this.options1.pm = new w({ | ||
| 15 | url: "", width: "", height: "", xoffset: 0, yoffset: 0 | ||
| 16 | })); | ||
| 17 | this.map.add(this.graphicsLayer = new z({ id: "drawtool" })); | ||
| 18 | this.draw = new Draw({ view: this.view }); | ||
| 19 | }); | 17 | }); |
| 18 | this.map.add(this.graphicsLayer = new arg[1]({ | ||
| 19 | id: "drawtool", | ||
| 20 | graphics: [] | ||
| 21 | })); | ||
| 22 | this.draw = new arg[2]({ view: this.view }); | ||
| 20 | } | 23 | } |
| 21 | activate(c, b) { | 24 | activate(c, b) { |
| 22 | this.active = !0; | 25 | this.active = !0; |
| 23 | this.drawType = c.toUpperCase(); | 26 | this.drawType = c.toUpperCase(); |
| 24 | this.callback = b; | 27 | this.callback = b; |
| 25 | this.guids = []; | ||
| 26 | this.downCount = 0; | 28 | this.downCount = 0; |
| 27 | this.map.reorder(this.graphicsLayer, this.map.allLayers.length - 1); | 29 | // this.map.reorder(this.graphicsLayer, this.map.allLayers.length - 1); |
| 28 | switch (this.drawType) { | 30 | switch (this.drawType) { |
| 29 | |||
| 30 | case "POINT1": | 31 | case "POINT1": |
| 31 | loadModules(["esri/Graphic"]).then(([h, f]) => { | 32 | loadModules(["esri/Graphic", "esri/geometry/Point"]).then(([h, f]) => { |
| 32 | this.downCount = 0; | 33 | this.downCount = 0; |
| 33 | this.view.container.addEventListener('mousedown', b => { | 34 | let action = this.draw.create("point", { |
| 34 | var a = new h(b.offsetX, b.offsetY), a = this.view.toMap(a); | 35 | mode: "click" |
| 35 | console.log(a); | 36 | }); |
| 36 | // this.graphic = new f(a, this.options1.pm, null); | 37 | action.on("draw-complete", event => { |
| 37 | // this.graphicsLayer.add(this.graphic); | 38 | !this.paths.length && this.graphicsLayer.graphics.add(this.graphic = new h({ |
| 38 | // console.log('OKOKOK'); | 39 | geometry: this.construc({ |
| 39 | // b.stopPropagation() | 40 | type: f, |
| 41 | vertices: event.vertices | ||
| 42 | }), | ||
| 43 | symbol: this.options1.pm | ||
| 44 | })); | ||
| 45 | this.paths.push(event.vertices[0]); | ||
| 46 | this.callback(event.vertices); | ||
| 40 | }); | 47 | }); |
| 41 | }); | 48 | }); |
| 42 | |||
| 43 | break; | 49 | break; |
| 44 | } | 50 | } |
| 45 | } | 51 | } |
| 52 | createPolyline() { | ||
| 53 | this.graphicsLayer.graphics.remove(this.graphic); | ||
| 54 | loadModules(["esri/Graphic", "esri/geometry/Polygon"]).then(([h, f]) => { | ||
| 55 | this.graphic = new h({ | ||
| 56 | geometry: this.construc({ | ||
| 57 | type: f, | ||
| 58 | rings: this.paths | ||
| 59 | }), | ||
| 60 | symbol: { | ||
| 61 | type: "simple-line", | ||
| 62 | color: [238, 44, 44, 0.8], | ||
| 63 | width: 2, | ||
| 64 | style: 'solid' | ||
| 65 | } | ||
| 66 | }); | ||
| 67 | this.graphicsLayer.graphics.add(this.graphic); | ||
| 68 | }); | ||
| 69 | } | ||
| 46 | deactivate() { | 70 | deactivate() { |
| 47 | this.active = !1; | 71 | this.active = !1; |
| 48 | this.drawType = ""; | 72 | this.drawType = ""; |
| 49 | this.downCount = 0; | 73 | this.downCount = 0; |
| 50 | } | 74 | } |
| 75 | construc(arg) { | ||
| 76 | let settings = { | ||
| 77 | hasZ: false, | ||
| 78 | hasM: false, | ||
| 79 | spatialReference: this.view.spatialReference, | ||
| 80 | paths: arg.paths, | ||
| 81 | rings: arg.rings | ||
| 82 | }; | ||
| 83 | arg.vertices && Object.assign(settings, { | ||
| 84 | x: arg.vertices[0][0], | ||
| 85 | y: arg.vertices[0][1] | ||
| 86 | }); | ||
| 87 | return new arg.type(settings); | ||
| 88 | } | ||
| 51 | } | 89 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment