2a10e568 by 刘远

jikai commit

1 parent d3efcda7
......@@ -2,50 +2,88 @@ import { loadModules } from "esri-loader";
import mapManage from './towMapObjects';
export default class DrawTool {
static getInstance() {
mapManage.drawTool || (mapManage.drawTool = new this());
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.polygon = null;
this.guids = [];
loadModules(["esri/symbols/PictureMarkerSymbol", "esri/layers/GraphicsLayer", "esri/views/draw/Draw"]).then(([w, z, d]) => {
this.options1 || (this.options1 = {}, this.options1.pm = new w({
url: "", width: "", height: "", xoffset: 0, yoffset: 0
}));
this.map.add(this.graphicsLayer = new z({ id: "drawtool" }));
this.draw = new Draw({ view: this.view });
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.guids = [];
this.downCount = 0;
this.map.reorder(this.graphicsLayer, this.map.allLayers.length - 1);
// this.map.reorder(this.graphicsLayer, this.map.allLayers.length - 1);
switch (this.drawType) {
case "POINT1":
loadModules(["esri/Graphic"]).then(([h, f]) => {
loadModules(["esri/Graphic", "esri/geometry/Point"]).then(([h, f]) => {
this.downCount = 0;
this.view.container.addEventListener('mousedown', b => {
var a = new h(b.offsetX, b.offsetY), a = this.view.toMap(a);
console.log(a);
// this.graphic = new f(a, this.options1.pm, null);
// this.graphicsLayer.add(this.graphic);
// console.log('OKOKOK');
// b.stopPropagation()
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);
}
}
\ No newline at end of file
......