measure.js 2.31 KB
    import {loadModules} from 'esri-loader'
    import {maps} from '@/libs/map/mapUtils'
    export default{
        data(){
            return{
                //activeWidget:null,
                areaActive:null,
                distanceActive:null
            }
        },
        methods: {
          /**
           * @description: measure
           * @param {*} viewId
           * @param {*} type
           * @author: renchao
           */
            measure(viewId,type){
                var view = maps[viewId];
                var self = this;
                loadModules([
                    "esri/widgets/DistanceMeasurement2D",
                     "esri/widgets/AreaMeasurement2D"
                ]).then(([
                    DistanceMeasurement2D,
                    AreaMeasurement2D
                ]) => {
                    switch (type) {
                        case "distance":
                            if(!self.distanceActive){
                                self.distanceActive = new DistanceMeasurement2D({
                                    view: view
                                  });
                            }
                          // skip the initial 'new measurement' button
                          self.distanceActive.viewModel.start();
                          break;
                        case "area":
                            if(!self.areaActive){
                                self.areaActive = new AreaMeasurement2D({
                                    view: view
                                  });
                            }


                          // skip the initial 'new measurement' button
                          self.areaActive.viewModel.start();
                          break;
                        case null:
                          if (self.distanceActive) {
                            self.distanceActive.viewModel.clear();
                           // self.distanceActive = null;
                          }
                          if (self.areaActive) {
                            self.areaActive.viewModel.clear();
                           // self.areaActive = null;
                          }
                          break;
                      }

                }).catch(err => {
                    throw(err);
                });

        }

    }
}