tdt-overlay-factory
Version:
天地图覆盖物工厂,通过vue组件直接生成天地图覆盖物类,支持vue2/vue3
2 lines (1 loc) • 4.72 kB
JavaScript
(function(p,l){typeof exports=="object"&&typeof module<"u"?module.exports=l():typeof define=="function"&&define.amd?define(l):(p=typeof globalThis<"u"?globalThis:p||self,p.tdtOverlayFactory=l())})(this,function(){"use strict";const p="",l=o=>{const{defineComponent:e,createApp:a}=o;return{pointOverlayFactory:i=>{const s=e(i);return T.Marker.extend({initialize:function(t,n,r){this.lnglat=t,this.props=n||{},this._APP_=null,this._MAP_=null,this._DIV_=null,this.setOptions(r),this.or=T.fq(t)},onAdd:function(t){this._APP_=a(s,this.props),this._MAP_=t,this._DIV_=document.createElement("div"),this._DIV_.classList.add("extend-point-overlay-wrap"),this._APP_.mount(this._DIV_),this._MAP_.on("zoomend",this.update,this),this._MAP_.getPanes().overlayPane.appendChild(this._DIV_),this.update(this.lnglat)},onRemove:function(){var t=this._DIV_.parentNode;this._MAP_.off("zoomend",this.update,this),t&&(this._APP_.unmount(),t.removeChild(this._DIV_),this._MAP_=null,this._DIV_=null)},setLngLat:function(t){this.lnglat=t,this.update()},getLngLat:function(){return this.lnglat},setPos:function(t){this.lnglat=this._MAP_.layerPointToLngLat(t),this.update()},update:function(){var t=this._MAP_.lngLatToLayerPoint(this.lnglat);this._DIV_.style.top=t.y+"px",this._DIV_.style.left=t.x+"px"}})},blockOverlayFactory:i=>{const s=e(i);return T.Overlay.extend({initialize:function(t,n,r){this._bounds=t,this.props=n||{},this._APP_=null,this._MAP_=null,this._DIV_=null,this.setOptions(r)},onAdd:function(t){this._APP_=a(s,this.props),this._MAP_=t,this._DIV_=document.createElement("div"),this._DIV_.classList.add("extend-block-overlay-wrap"),this._APP_.mount(this._DIV_),this._MAP_.on("zoomend",this.update,this),this._MAP_.getPanes().overlayPane.appendChild(this._DIV_),this.update(this.lnglat)},onRemove:function(){var t=this._DIV_.parentNode;this._MAP_.off("zoomend",this.update,this),t&&(this._APP_.unmount(),t.removeChild(this._DIV_),this._MAP_=null,this._DIV_=null)},update:function(){var t=this._MAP_.lngLatToLayerPoint(this._bounds.getNorthEast()),n=this._MAP_.lngLatToLayerPoint(this._bounds.getSouthWest()),r=Math.abs(t.x-n.x),u=Math.abs(t.y-n.y);this._DIV_.style.left=n.x+"px",this._DIV_.style.top=t.y+"px",this._DIV_.style.width=r+"px",this._DIV_.style.height=u+"px"}})}}},d=o=>({pointOverlayFactory:_=>{const h=o.extend(_);return T.Marker.extend({initialize:function(i,s,t){this.lnglat=i,this.props=s||{},this._APP_=null,this._MAP_=null,this._DIV_=null,this.setOptions(t),this.or=T.fq(i)},onAdd:function(i){this._APP_=new h({propsData:this.props}).$mount().$el,this._MAP_=i,this._DIV_=document.createElement("div"),this._DIV_.classList.add("extend-point-overlay-wrap"),this._DIV_.appendChild(this._APP_),this._MAP_.on("zoomend",this.update,this),this._MAP_.getPanes().overlayPane.appendChild(this._DIV_),this.update(this.lnglat)},onRemove:function(){var i=this._DIV_.parentNode;this._MAP_.off("zoomend",this.update,this),i&&(i.removeChild(this._DIV_),this._DIV_=null,this._MAP_=null)},setLngLat:function(i){this.lnglat=i,this.update()},getLngLat:function(){return this.lnglat},setPos:function(i){this.lnglat=this._MAP_.layerPointToLngLat(i),this.update()},update:function(){var i=this._MAP_.lngLatToLayerPoint(this.lnglat);this._DIV_.style.top=i.y+"px",this._DIV_.style.left=i.x+"px"}})},blockOverlayFactory:_=>{const h=o.extend(_);return T.Overlay.extend({initialize:function(i,s,t){this._bounds=i,this.props=s||{},this._APP_=null,this._MAP_=null,this._DIV_=null,this.setOptions(t)},onAdd:function(i){this._APP_=new h({propsData:this.props}).$mount().$el,this._MAP_=i,this._DIV_=document.createElement("div"),this._DIV_.classList.add("extend-block-overlay-wrap"),this._DIV_.appendChild(this._APP_),this._MAP_.on("zoomend",this.update,this),this._MAP_.getPanes().overlayPane.appendChild(this._DIV_),this.update(this.lnglat)},onRemove:function(){var i=this._DIV_.parentNode;this._MAP_.off("zoomend",this.update,this),i&&(i.removeChild(this._DIV_),this._DIV_=null,this._MAP_=null)},update:function(){var i=this._MAP_.lngLatToLayerPoint(this._bounds.getNorthEast()),s=this._MAP_.lngLatToLayerPoint(this._bounds.getSouthWest()),t=Math.abs(i.x-s.x),n=Math.abs(i.y-s.y);this._DIV_.style.left=s.x+"px",this._DIV_.style.top=i.y+"px",this._DIV_.style.width=t+"px",this._DIV_.style.height=n+"px"}})}});return{install(o,e){e=e||o;let a=Number(e.version.split(".")[0]);if(a===2){console.log("\u5F53\u524D\u73AF\u5883Vue2");const{pointOverlayFactory:_,blockOverlayFactory:h}=d(e);e.prototype.$pointOverlayFactory=_,e.prototype.$blockOverlayFactory=h}else if(a===3){console.log("\u5F53\u524D\u73AF\u5883Vue3");const{pointOverlayFactory:_,blockOverlayFactory:h}=l(e);o.provide("pointOverlayFactory",_),o.provide("blockOverlayFactory",h)}}}});