@tuoyuan/map-adapter-tmap
Version:
天地图适配器
15 lines (14 loc) • 4.57 kB
JavaScript
"use strict";var u=Object.defineProperty;var _=(o,i,t)=>i in o?u(o,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[i]=t;var a=(o,i,t)=>_(o,typeof i!="symbol"?i+"":i,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("@tuoyuan/map-adapter-lib");class f extends h.BaseMarker{constructor(t,e){super(t._top,e,{basePlacement:"right-bottom",labelBasePlacement:"right-bottom"});a(this,"_ctx");a(this,"currentLngLat");a(this,"iconInstance");a(this,"labelInstance");a(this,"busInstance");a(this,"app");a(this,"container");this._ctx=t,this.currentLngLat=new t.TMap.LngLat(e==null?void 0:e.position[0],e==null?void 0:e.position[1]),this.iconInstance=new this._ctx.TMap.Marker(this.currentLngLat),this.renderIcon(),this.renderLabel(),this.addListener((n,s)=>{this._ctx._top.options.dev&&(console.groupCollapsed("[Marker.event]",n),console.log("payload: ",s),console.groupEnd())})}initEvent(){["click","dblclick","rightclick"].forEach(e=>{this.iconInstance.on(e,n=>{this.emit(e,{e:n.originalEvent,position:new h.Position(n.lnglat.lng,n.lnglat.lat),pixel:new h.Pixel(n.containerPoint.x,n.containerPoint.y),data:this.data})})})}renderIcon(){var n,s,c,l;this.iconInstance&&this._ctx._map.removeOverLay(this.iconInstance);const t=(n=this._icon)==null?void 0:n.getRealOffset(),e=new this._ctx.TMap.Icon({iconUrl:(s=this._icon)==null?void 0:s.image,iconSize:new this._ctx.TMap.Point((c=this._icon)==null?void 0:c.size.width,(l=this._icon)==null?void 0:l.size.height),iconAnchor:new this._ctx.TMap.Point(-((t==null?void 0:t.x)??0),-((t==null?void 0:t.y)??0))});this.iconInstance=new this._ctx.TMap.Marker(this.currentLngLat,{icon:e}),this._ctx._map.addOverLay(this.iconInstance),this.initEvent()}renderLabel(){var s,c,l,r,d,p,I,L,b,g;if(this.labelInstance&&this._ctx._map.removeOverLay(this.labelInstance),!((s=this._label)!=null&&s.text))return;const t=(d=(r=(l=(c=this._label).getRealOffset)==null?void 0:l.call(c,{padding:[2,10,2,10]}))==null?void 0:r.toArray)==null?void 0:d.call(r),e=new this._ctx.TMap.Point(t[0]-12,t[1]+12),n={text:`<div style="line-height: 1.2; padding: 2px 0; font-size: ${(p=this._label)==null?void 0:p.fontSize}px">${((I=this._label)==null?void 0:I.text)||""}</div>`,position:this.currentLngLat,offset:e};this.labelInstance=new this._ctx.TMap.Label(n),this.labelInstance.setBorderLine(0),this.labelInstance.setFontColor((L=this._label)==null?void 0:L.color),this.labelInstance.setBackgroundColor((b=this._label)==null?void 0:b.backgroundColor),((g=this._label)==null?void 0:g.visible)===!1&&this.labelInstance.hide(),this._ctx._map.addOverLay(this.labelInstance)}setName(t){super.setName(t)}setIcon(t){super.setIcon(t),this.iconInstance.getIcon().setIconUrl(t)}setPosition(t){super.setPosition(t),this.currentLngLat=this._ctx.TMap.LngLat(t[0],t[1]),this.iconInstance.setLngLat(this.currentLngLat),this.setLabelPosition(t)}setLabelPosition(t){this.currentLngLat=this._ctx.TMap.LngLat(t[0],t[1]),this.labelInstance.setLngLat(this.currentLngLat)}setLabel(t){var e;super.setLabel(t),(e=this.labelInstance)==null||e.setLabel(t)}setFontSize(t){var e;(e=this.labelInstance)==null||e.setFontSize(h.pxToPt(t,h.getDPI()))}setBackgroundColor(t){var e;(e=this.labelInstance)==null||e.setBackgroundColor(t)}openInfoWindow(t){if(t.url){const e=`
<div style="width:${t.size.width}px; height:${t.size.height}px; padding:10px;">
<iframe src=${t.url}
width="100%"
height="100%"
frameborder="0"
scrolling="auto">
</iframe>
</div>
`,n=new this._ctx.TMap.InfoWindow({});n.setContent(e),this.iconInstance.openInfoWindow(n)}else{const e=`
<div :closeButton="false" style="width:${t.size.width}px; height:${t.size.height}px; overflow: hidden; pointer-events: none;">
${t.html}
</div>
`,n=new this._ctx.TMap.InfoWindow;n.setContent(e);const s=new this._ctx.TMap.Point(10,0);n.setOffset(s),this.iconInstance.openInfoWindow(n)}}closeInfoWindow(){this.iconInstance.closeInfoWindow()}setStyle(t){super.setStyle(t),this.renderIcon(),this.renderLabel()}hidden(){super.hidden(),this.iconInstance.setOpacity(0)}show(){super.show(),this.iconInstance.setOpacity(1)}showLabel(){var t,e;super.showLabel(),(e=(t=this.labelInstance)==null?void 0:t.show)==null||e.call(t)}hiddenLabel(){var t,e;super.hiddenLabel(),(e=(t=this.labelInstance)==null?void 0:t.hide)==null||e.call(t)}getInstances(){return[this.iconInstance,this.labelInstance].filter(e=>!!e)}remove(){this.closeInfoWindow(),this.getInstances().forEach(t=>this._ctx._map.removeOverLay(t))}panTo(){this._ctx._map.panTo(this.currentLngLat)}}exports.TMapMarker=f;