@vuemap-5ebdc63e.js 9.0 KB

1
  1. import{A as d}from"./@amap-aca98dec.js";import{m as f}from"./lodash-es-91418b19.js";import{d as C,o as $,c as y,r as g,a as b}from"./@vue-cb50a1c4.js";function v(e){if(!e||e.length<4)return e;const t=e.substring(3,e.length);return e[2].toLowerCase()+t}const E=/^on[A-Z]+/,_=e=>typeof e=="function",w=e=>typeof e=="symbol";new Set(Object.getOwnPropertyNames(Symbol).filter(e=>e!=="arguments"&&e!=="caller").map(e=>Symbol[e]).filter(w));function A(e){return _(e)?{setup:e,name:e.name}:e}var M=function(){var e=[].map.call(arguments,function(t){return t.trim()}).filter(function(t){return t.length}).join("-");return e.length?e.length===1||!/[_.\- ]+/.test(e)?e[0]===e[0].toLowerCase()&&e.slice(1)!==e.slice(1).toLowerCase()?e:e.toLowerCase():e.replace(/^[_.\- ]+/,"").toLowerCase().replace(/[_.\- ]+(\w|$)/g,function(t,n){return n.toUpperCase()}):""},h=M,I=function(){var e=h.apply(h,arguments);return e.charAt(0).toUpperCase()+e.slice(1)};let p;class B{constructor(){this._listener=new Map}addListener(t,n,o,a){if(!AMap)throw new Error("please wait for Map API load");if(!t.on)return;t.on(n,o,a),this._listener.get(t)||this._listener.set(t,{});const s=this._listener.get(t);s[n]||(s[n]=[]),s[n].push(o)}removeListener(t,n,o){if(!AMap)throw new Error("please wait for Map API load");if(!t.off||!this._listener.get(t)||!this._listener.get(t)[n])return;const a=this._listener.get(t)[n];if(o){const s=a.indexOf(o);t.off(n,a[s]),a.splice(s,1)}else a.forEach(s=>{t.off(n,s)}),this._listener.get(t)[n]=[]}addListenerOnce(t,n,o,a){return t.on(n,o,a,!0)}trigger(t,n,o){return t.emit(n,o)}clearListeners(t){const n=this._listener.get(t);n&&Object.keys(n).map(o=>{t.clearEvents(o)})}}p=p||new B;var m=p,S=A({inject:{parentInstance:{default:null}},inheritAttrs:!1,props:{visible:{type:Boolean,default:!0},zIndex:{type:Number},reEventWhenUpdate:{type:Boolean,default:!1},extraOptions:{type:Object}},emits:["init"],data(){return{needInitComponents:[],unwatchFns:[],propsRedirect:{},converters:{},isDestroy:!1,cacheEvents:{},isMounted:!1}},created(){this.$amapComponent=null,this.$parentComponent=null},mounted(){this.parentInstance&&(this.parentInstance.$amapComponent?this.register():this.parentInstance.addChildComponent(this))},beforeUnmount(){this.$amapComponent&&(this.unregisterEvents(),this.unwatchFns.forEach(e=>e()),this.unwatchFns=[],this.destroyComponent(),this.isDestroy=!0)},beforeUpdate(){this.reEventWhenUpdate&&this.isMounted&&this.$amapComponent&&this.unregisterEvents()},updated(){this.reEventWhenUpdate&&this.isMounted&&this.$amapComponent&&this.registerEvents()},methods:{getHandlerFun(e){return this[`__${e}`]?this[`__${e}`]:this.$amapComponent?this.$amapComponent[`set${I(e)}`]:null},convertProps(){const e={},{$props:t,propsRedirect:n}=this;return this.extraOptions&&Object.assign(e,this.extraOptions),Object.keys(t).reduce((o,a)=>{let s=a;const i=this.convertSignalProp(s,t[s]);return i===void 0||(n&&n[a]&&(s=n[s]),e[s]=i),o},e)},convertSignalProp(e,t){return this.converters&&this.converters[e]?this.converters[e].call(this,t):t},registerEvents(){const e=this.$attrs;Object.keys(e).forEach(t=>{if(E.test(t)){const n=v(t);m.addListener(this.$amapComponent,n,e[t]),this.cacheEvents[n]=e[t]}})},unregisterEvents(){Object.keys(this.cacheEvents).forEach(e=>{m.removeListener(this.$amapComponent,e,this.cacheEvents[e]),delete this.cacheEvents[e]})},setPropWatchers(){const{propsRedirect:e,$props:t}=this;Object.keys(t).forEach(n=>{let o=n;e&&e[n]&&(o=e[n]);const a=this.getHandlerFun(o);if(!a)return;const s={deep:!1},i=Object.prototype.toString.call(t[n]);(i==="[object Object]"||i==="[object Array]")&&(s.deep=!0);const c=this.$watch(n,u=>{a.call(this.$amapComponent,this.convertSignalProp(n,u))},s);this.unwatchFns.push(c)})},initProps(){["editable","visible","zooms"].forEach(t=>{if(this[t]!==void 0){const n=this.getHandlerFun(t);n&&n.call(this.$amapComponent,this.convertSignalProp(t,this[t]))}})},lazyRegister(){const e=this.parentInstance;e&&e.addChildComponent&&e.addChildComponent(this)},addChildComponent(e){this.needInitComponents.push(e)},createChildren(){for(;this.needInitComponents.length>0;)this.needInitComponents[0].register(),this.needInitComponents.splice(0,1)},register(){this.parentInstance&&!this.$parentComponent&&(this.$parentComponent=this.parentInstance.$amapComponent);const e=this.__initComponent&&this.__initComponent(this.convertProps());e&&e.then?e.then(t=>this.registerRest(t)):this.registerRest(e)},registerRest(e){!this.$amapComponent&&e&&(this.$amapComponent=e),this.registerEvents(),this.initProps(),this.setPropWatchers(),this.$emit("init",this.$amapComponent,this),this.$nextTick(()=>{this.createChildren()}),this.isMounted=!0},$$getInstance(){return this.$amapComponent},destroyComponent(){this.$amapComponent.setMap&&this.$amapComponent.setMap(null),this.$amapComponent.close&&this.$amapComponent.close(),this.$amapComponent.editor&&this.$amapComponent.editor.close()},__visible(e){this.$amapComponent&&this.$amapComponent.show&&this.$amapComponent.hide&&(e===!1?this.$amapComponent.hide():this.$amapComponent.show())},__zIndex(e){this.$amapComponent&&this.$amapComponent.setzIndex&&this.$amapComponent.setzIndex(e)}}});function j(){const e=[],t="0123456789abcdef";for(let n=0;n<36;n++)e[n]=t.substr(Math.floor(Math.random()*16),1);return e[14]="4",e[19]=t.substr(e[19]&3|8,1),e[8]=e[13]=e[18]=e[23]="-",e.join("")}const L=(e,t)=>{if(e.install=n=>{for(const o of[e,...Object.values(t??{})])n.component(o.name,o)},t)for(const[n,o]of Object.entries(t))e[n]=o;return e},O={key:"",version:"2.0",plugins:[],serviceHost:"",securityJsCode:""};function P(e={}){return e=f({},O,e),e.serviceHost?window._AMapSecurityConfig={serviceHost:e.serviceHost}:e.securityJsCode&&(window._AMapSecurityConfig={securityJsCode:e.securityJsCode}),d.load(e)}let r=null;const U=e=>{r||(r||(e.offline?r=new Promise(t=>{console.log("@vuemap/vue-amap离线部署"),t(window.AMap)}):r=P(e)),r.then())};var l=C({name:"ElAmap",mixins:[S],provide(){return{parentInstance:this}},props:{vid:{type:String},center:{type:Array},zoom:{type:Number},rotation:{type:Number},pitch:{type:Number},viewMode:{type:String},features:{type:Array},layers:{type:Array},zooms:{type:Array},resizeEnable:{type:Boolean,default:!0},dragEnable:{type:Boolean,default:!0},zoomEnable:{type:Boolean,default:!0},jogEnable:{type:Boolean,default:!0},pitchEnable:{type:Boolean,default:!0},rotateEnable:{type:Boolean,default:!0},animateEnable:{type:Boolean,default:!0},keyboardEnable:{type:Boolean,default:!0},doubleClickZoom:{type:Boolean,default:!0},scrollWheel:{type:Boolean,default:!0},touchZoom:{type:Boolean,default:!0},touchZoomCenter:{type:Number},showLabel:{type:Boolean,default:!0},defaultCursor:{type:String},isHotspot:{type:Boolean},mapStyle:{type:String},wallColor:{type:[String,Array]},roofColor:{type:[String,Array]},showBuildingBlock:{type:Boolean,default:!0},showIndoorMap:{type:Boolean,default:!1},skyColor:{type:[String,Array]},labelRejectMask:{type:Boolean,default:!1},mask:{type:Array},WebGLParams:{type:Object},terrain:{type:Boolean,default:!1}},emits:["update:zoom","update:center","update:rotation","update:pitch"],data(){return{}},computed:{},mounted(){this.createMap()},beforeUnmount(){this.$amapComponent&&(this.$amapComponent.destroy(),this.$amapComponent=null,this.$parentComponent=null)},methods:{createMap(){r.then(()=>{const e=this.$el.querySelector(".el-vue-amap"),t=this.vid||j();e.id=t,this.$nextTick(()=>{this.$amapComponent=new AMap.Map(t,this.convertProps()),this.register(),this.bindModelEvents()})}).catch(e=>{console.warn("init map error: ",e)})},bindModelEvents(){this.$amapComponent.on("zoomchange",()=>{this.$emit("update:zoom",this.$amapComponent.getZoom())}),this.$amapComponent.on("rotatechange",()=>{this.$emit("update:rotation",this.$amapComponent.getRotation()),this.$emit("update:pitch",this.$amapComponent.getPitch())}),this.$amapComponent.on("dragging",()=>{this.$emit("update:center",this.getCenter()),this.$emit("update:pitch",this.$amapComponent.getPitch())}),this.$amapComponent.on("touchmove",()=>{this.$emit("update:center",this.getCenter())})},getCenter(){const e=this.$amapComponent.getCenter();return[e.lng,e.lat]},__dragEnable(e){this.$amapComponent&&this.$amapComponent.setStatus({dragEnable:e})},__zoomEnable(e){this.$amapComponent&&this.$amapComponent.setStatus({zoomEnable:e})},__jogEnable(e){this.$amapComponent&&this.$amapComponent.setStatus({jogEnable:e})},__keyboardEnable(e){this.$amapComponent&&this.$amapComponent.setStatus({keyboardEnable:e})},__doubleClickZoom(e){this.$amapComponent&&this.$amapComponent.setStatus({doubleClickZoom:e})},__scrollWheel(e){this.$amapComponent&&this.$amapComponent.setStatus({scrollWheel:e})},__rotateEnable(e){this.$amapComponent&&this.$amapComponent.setStatus({rotateEnable:e})},__resizeEnable(e){this.$amapComponent&&this.$amapComponent.setStatus({resizeEnable:e})},__showIndoorMap(e){this.$amapComponent&&this.$amapComponent.setStatus({showIndoorMap:e})}}});const z={class:"el-vue-amap-container"},k=b("div",{class:"el-vue-amap"},null,-1);function F(e,t,n,o,a,s){return $(),y("div",z,[k,g(e.$slots,"default")])}l.render=F;l.__file="src/vue-amap/packages/amap/amap.vue";const W=L(l);export{W as E,U as i};