"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../loadPlugins.js"),t=require("../mixins/mixins.js"),s=require("../../utils/amap-helpers.js"),o=require("../mixins/props.js"),r=require("../mixins/base.js"),a=require("../overlay/Circle.js"),i=require("../overlay/Marker.js"),n=require("../overlay/Polygon.js"),p=require("../overlay/Polyline.js"),l=require("../overlay/Rectangle.js");const d=i.default.sealedOptions,c=p.default.sealedOptions,h=n.default.sealedOptions,m=l.default.sealedOptions,u=a.default.sealedOptions;var g=t.default(r.default).extend({amapMeta:{prepare:()=>e.default("AMap.MouseTool"),async initComponent(e){return new e.MouseTool(this.map)},add(){},remove(){}},props:{mode:o.defineProp({type:String,default:"none"}),clearWhenClose:{type:Boolean,default:!0},options:{type:Object}},data:()=>({drawingMode:void 0}),methods:{close(e){this.component.close(e)},draw(){if(this.mode===this.drawingMode)return;const{mode:e}=this,t=this.component;switch(e){case"none":this.close(this.clearWhenClose);break;case"marker":t.marker(s.getInitialOptionsFromProps(this,d.props,this.options||{}));break;case"polyline":t.polyline(s.getInitialOptionsFromProps(this,c.props,this.options||{}));break;case"polygon":t.polygon(s.getInitialOptionsFromProps(this,h.props,this.options||{}));break;case"rectangle":t.rectangle(s.getInitialOptionsFromProps(this,m.props,this.options||{}));break;case"circle":t.circle(s.getInitialOptionsFromProps(this,u.props,this.options||{}));break;case"rule":t.rule(s.getInitialOptionsFromProps(this,h.props,this.options||{}));break;case"measureArea":t.measureArea(s.getInitialOptionsFromProps(this,h.props,this.options||{}));break;case"rectZoomIn":t.rectZoomIn(s.getInitialOptionsFromProps(this,h.props,this.options||{}));break;case"rectZoomOut":t.rectZoomOut(s.getInitialOptionsFromProps(this,h.props,this.options||{}))}this.drawingMode=e},_onDraw(e){if(this.mode!==this.drawingMode)return this.close(!0),void this.draw();const t=e.obj,o=this.drawingMode;let r=t;switch(o){case"marker":r=s.lngLat2Array(t.getPosition());break;case"polyline":case"polygon":r=t.getPath().map(e=>s.lngLat2Array(e));break;case"rectangle":r=s.bounds2Array(t.getBounds());break;case"circle":r={center:s.lngLat2Array(t.getCenter()),radius:t.getRadius()};break;case"rule":r={path:t.getPath().map(e=>s.lngLat2Array(e)),length:t.getLength()};break;case"measureArea":r={path:t.getPath().map(e=>s.lngLat2Array(e)),area:t.getArea()}}this.$emit("draw",o,r),this.$emit("update:mode","none")}},async mounted(){if(await this.context.ready,this.context.destroyed)return;this.component.on("draw",this._onDraw),this.$watch("mode",async e=>{"none"!==e&&"none"!==this.drawingMode&&this.close(!0),this.draw()},{immediate:!0})}});exports.default=g;
