Blame view

src/utils/map/draw.js 2.28 KB
yuanbo committed
1
import {maps} from '@/libs/map/mapUtils'
任超 committed
2 3 4 5 6 7 8 9 10 11 12
import {loadModules} from 'esri-loader'

export default {
    data() {
        return {
            drawAction:null,
            graphicLayer:null,
            creatEvent:null,
        }
    },
    methods: {
yuanbo committed
13 14 15 16 17 18 19 20
      /**
       * @description: initDraw
       * @param {*} type
       * @param {*} viewId
       * @param {*} creationMode
       * @param {*} callBackFunction
       * @author: renchao
       */
任超 committed
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
        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);
                       }
yuanbo committed
57

任超 committed
58 59 60 61 62 63
                    }
                   })
             }).catch(err=>{
                 throw(err);
             });
        },
yuanbo committed
64 65 66 67
      /**
       * @description: destroyeDraw
       * @author: renchao
       */
任超 committed
68 69 70 71 72 73
        destroyeDraw() {
         if(this.drawAction){
            this.drawAction.cancel();
         }
        }
     }
yuanbo committed
74
}