|
@@ -1,6 +1,6 @@
|
|
|
import GraphicsLayer from "@arcgis/core/layers/GraphicsLayer.js";
|
|
|
import SketchViewModel from "@arcgis/core/widgets/Sketch/SketchViewModel.js";
|
|
|
-
|
|
|
+import Graphic from "@arcgis/core/Graphic.js";
|
|
|
|
|
|
class AddDrawEvent {
|
|
|
constructor(options) {
|
|
@@ -8,12 +8,14 @@ class AddDrawEvent {
|
|
|
this.type = options.type;
|
|
|
this.hasZ = options.hasZ || false;
|
|
|
this.graphicLayer = null;
|
|
|
+ this.path = options.path || null;
|
|
|
+ this.graphic = null;
|
|
|
this.sketchViewModel = null;
|
|
|
this.createListenerEventHander = null;
|
|
|
this.updateListenerEventHander = null;
|
|
|
this.symbol = options.symbol;
|
|
|
}
|
|
|
- start(){
|
|
|
+ ready(){
|
|
|
this.graphicLayer = new GraphicsLayer();
|
|
|
this.view.map.add(this.graphicLayer);
|
|
|
this.sketchViewModel = new SketchViewModel({
|
|
@@ -34,8 +36,27 @@ class AddDrawEvent {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ if(this.path){
|
|
|
+ const predefinedPath = {
|
|
|
+ type: "polyline",
|
|
|
+ paths: this.path, // 示例路径坐标
|
|
|
+ spatialReference: this.view.spatialReference,
|
|
|
+ };
|
|
|
+ this.graphic = new Graphic({
|
|
|
+ geometry: predefinedPath,
|
|
|
+ symbol: this.symbol,
|
|
|
+ });
|
|
|
+ this.graphicLayer.add(this.graphic);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ start(){
|
|
|
+ this.ready();
|
|
|
this.sketchViewModel.create(this.type);
|
|
|
}
|
|
|
+ update(){
|
|
|
+ this.ready();
|
|
|
+ this.sketchViewModel.update([this.graphic]);
|
|
|
+ }
|
|
|
createListenerEvent(callback){
|
|
|
this.clearCreateListenerEvent()
|
|
|
this.createListenerEventHander = this.sketchViewModel.on("create", (event) => {
|