"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("../../loadPlugins.js"),r=(e=require("vue"))&&"object"==typeof e&&"default"in e?e.default:e,n=require("../../utils/common.js"),i=require("../mixins/mixins.js"),s=require("../../utils/amap-helpers.js"),o=require("../mixins/props.js"),a=require("../mixins/base.js"),u=require("../../utils/safe-get.js"),p=require("../overlay/Marker.js"),c=require("../../utils/debounce.js");const l=p.default.sealedOptions,d=r.extend({props:l.props});let m=void 0;function f(e,t){m||(m=document.createElement("div"));const r=e;return r._props=t,r._vnode=null,r.$mount(m),r._vnode.elm}function h(e,t,r){const n=e[t];Array.isArray(n)&&(e[t]=new r(n[0],n[1]))}function k(e){return e&&0!==e.length?e.map(e=>{const t={...e};return h(t,"size",window.AMap.Size),h(t,"offset",window.AMap.Pixel),h(t,"imageOffset",window.AMap.Pixel),t}):e}var y=i.default(a.default).extend({name:"AmapMarkerCluster",amapMeta:{prepare:()=>t.default("AMap.MarkerClusterer"),async initComponent(e,t){return this.$scopedSlots.cluster&&(t.renderClusterMarker=this._renderCluster),new e.MarkerClusterer(this.map,[],t)},events:["click"]},data:()=>({_mcc:null}),props:{data:o.defineProp({type:Array,required:!0,initialize:!1}),keyProp:o.defineProp({type:[String,Function],default:"key",initialize:!1}),positionProp:o.defineProp({type:[String,Function],default:"position",initialize:!1}),gridSize:o.defineProp("setGridSize",Number),minClusterSize:o.defineProp("setMinClusterSize",Number),maxZoom:o.defineProp("setMaxZoom",Number),averageCenter:o.defineProp({type:Boolean,default:void 0,setter:"setAverageCenter"}),styles:o.defineProp({type:Array,setter(e,t){e.setStyles(k(t))},transform:k}),zoomOnClick:o.defineProp({type:Boolean,default:void 0}),markerOptions:o.defineProp({type:Function,initialize:!1}),clusterOptions:o.defineProp({type:Function,initialize:!1})},mounted(){const e=c.default(this._onDataChange,100),t=this.$scopedSlots.marker,n=this.$scopedSlots.cluster;this.context.ready.then(()=>{this._onDataChange()}),this._mcc={markers:new Map,clusters:new Map,MarkerRenderer:r.extend({name:"AmapMarkerClusterMarkerRenderer",props:{point:{type:Object}},render(){if(!t)return null;const e=t(this.point);return u.default(e,"0",null)}}),ClusterRenderer:r.extend({name:"AmapMarkerClusterClusterRenderer",props:{context:{type:Object}},render(){if(!n)return null;const e=n(this.context);return u.default(e,"0",null)}}),dummy:new d},this._mcc.marker=new this._mcc.MarkerRenderer,this._mcc.cluster=new this._mcc.ClusterRenderer,this.$watch("data",{handler:e})},beforeDestroy(){this._mcc.markers.clear()},methods:{_getKey(e,t){const{keyProp:r}=this;return r&&("$index"!==r||"$index"in e)?"function"==typeof r?r(e):e[r]:t},_getPosition(e){const{positionProp:t}=this;return"function"==typeof t?t(e):e[t]},async _onDataChange(){const{data:e}=this;if(await this.context.ready,this.context.destroyed)return;n.timeBegin("Render Markers");const t=e.map((e,t)=>this._getMarker(e,t));n.timeEnd("Render Markers"),n.timeBegin("Set Markers"),this.component.setMarkers(t),n.timeEnd("Set Markers")},_renderMarkerContent(e){if(this.$scopedSlots.marker)return f(this._mcc.marker,{point:e})},_getMarker(e,t){const r=this._getKey(e,t),n=this._mcc.markers;if(n.has(r))return n.get(r);const i={};this.positionProp&&(i.position=this._getPosition(e)),"function"==typeof this.markerOptions&&Object.assign(i,this.markerOptions(e));const o=s.getInitialOptionsFromProps(this,l.props,i,!0),a=this._renderMarkerContent(e);a&&(o.content=a);const u=new window.AMap.Marker(o);return n.set(r,u),u},_renderCluster(e){const t=f(this._mcc.cluster,{context:e});e.marker.setContent(t);const r={};"function"==typeof this.clusterOptions&&Object.assign(r,this.clusterOptions(e));const n=Object.keys(r);if(n.length>0){const{dummy:t}=this._mcc;for(let i=0;i<n.length;++i){const s=n[i],a=r[s],u=l.props[s];void 0!==u&&o.setPropValue(t,e.marker,u,a)}}}},render:e=>null});exports.default=y;
