UNPKG

@tuoyuan/map-adapter-tmap

Version:

天地图适配器

11 lines (10 loc) 3.98 kB
"use strict";var x=Object.defineProperty;var w=(s,i,e)=>i in s?x(s,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[i]=e;var r=(s,i,e)=>w(s,typeof i!="symbol"?i+"":i,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@tuoyuan/map-adapter-lib");class L extends a.BasePolyline{constructor(e,t){super(e._top,t,{labelBasePlacement:"right-bottom"});r(this,"_ctx");r(this,"polylineInstance");r(this,"labelInstance");this._ctx=e,this.renderPolyline(),this.renderLabel(),this.addListener((n,l)=>{this._ctx._top.options.dev&&(console.groupCollapsed("[Polyline.event]",n),console.log("payload: ",l),console.groupEnd())})}initEvent(){["click","dblclick","rightclick"].forEach(t=>{this.polylineInstance.on(t,n=>{this.emit(t,{e:n.originEvent,position:new a.Position(n.lnglat.lng,n.lnglat.lat),pixel:new a.Pixel(n.containerPoint.x,n.containerPoint.y),data:this.data})})})}renderLabel(){var o,d,p,c,y,b,_,g,u,I,f;if(this.labelInstance&&this._ctx._map.removeOverLay(this.labelInstance),!((o=this._label)!=null&&o.text))return;const e=a.getDPI(),t=super.findClosestPointToCentroid(this._path),n=(y=(c=(p=(d=this._label).getRealOffset)==null?void 0:p.call(d,{padding:[2,10,2,10]}))==null?void 0:c.toArray)==null?void 0:y.call(c),l=new this._ctx.TMap.Point(n[0]-12,n[1]+15),h={text:`<div style="line-height: 1.2; padding: 2px 0; font-size: ${(b=this._label)==null?void 0:b.fontSize}px">${((_=this._label)==null?void 0:_.text)||""}</div>`,position:new this._ctx.TMap.LngLat(t==null?void 0:t.longitude,t==null?void 0:t.latitude),offset:l};this.labelInstance=new this._ctx.TMap.Label(h),this.labelInstance.setBorderLine(0),this.labelInstance.setFontColor((g=this._style.label)==null?void 0:g.color),this.labelInstance.setFontSize(a.pxToPt((u=this._style.label)==null?void 0:u.fontSize,e)),this.labelInstance.setBackgroundColor((I=this._style.label)==null?void 0:I.backgroundColor),((f=this._label)==null?void 0:f.visible)===!1&&this.labelInstance.hide(),this._ctx._map.addOverLay(this.labelInstance),this.initEvent()}renderPolyline(){var t,n,l,h;this.polylineInstance&&this._ctx._map.removeOverLay(this.polylineInstance);const e=this._path.map(o=>this._ctx.TMap.LngLat(o.longitude,o.latitude));this.polylineInstance=new this._ctx.TMap.Polyline(e,{color:(t=this._style.line)==null?void 0:t.color,weight:(n=this._style.line)==null?void 0:n.width,opacity:(l=this._style.line)==null?void 0:l.opacity,lineStyle:(h=this._style.line)==null?void 0:h.style}),this._ctx._map.addOverLay(this.polylineInstance)}remove(){this.closeInfoWindow(),this.getInstances().forEach(e=>this._ctx._map.removeOverLay(e))}panTo(){const e=this.getBounds(),t=a.Bounds.getCenter(e);this._ctx._map.panTo(this._ctx.TMap.LngLat(t.longitude,t.latitude))}getInstances(){return[this.polylineInstance,this.labelInstance].filter(t=>!!t)}setName(e){super.setName(e)}setPath(e){super.setPath(e);const t=e.map(n=>this._ctx.TMap.LngLat(n[0],n[1]));this.polylineInstance.setLngLats(t)}setStyle(e){super.setStyle(e),this.renderPolyline(),this.renderLabel()}show(){var e;super.show(),this.polylineInstance.setOpacity(((e=this._style.line)==null?void 0:e.opacity)??1)}hidden(){super.hidden(),this.polylineInstance.setOpacity(0)}showLabel(){var e,t;super.showLabel(),(t=(e=this.labelInstance)==null?void 0:e.show)==null||t.call(e)}hiddenLabel(){var e,t;super.hiddenLabel(),(t=(e=this.labelInstance)==null?void 0:e.hide)==null||t.call(e)}openInfoWindow(e){let t="";e.url?t=`<div style="width:${e.size.width}px; height:${e.size.height}px; padding:10px;"> <iframe src=${e.url} width="100%" height="100%" frameborder="0" scrolling="auto"> </iframe> </div>`:t=`<div style="width:${e.size.width}px; height:${e.size.height}px;"> ${e.html} </div>`;const n=new this._ctx.TMap.InfoWindow;n.setContent(t),this.polylineInstance.openInfoWindow(n)}closeInfoWindow(){this.polylineInstance.closeInfoWindow()}}exports.TMapPolyline=L;