UNPKG

@tuoyuan/map-adapter-lib

Version:

地图适配器库

2 lines (1 loc) 3.37 kB
"use strict";var w=Object.defineProperty;var L=(b,o,e)=>o in b?w(b,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[o]=e;var n=(b,o,e)=>L(b,typeof o!="symbol"?o+"":o,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../utils/deep-assign.js"),P=require("../utils/get-distance.js"),f=require("./MapEvent.js"),_=require("./Position.js"),v=require("./Bounds.js"),S=require("./Label.js");class p extends f.EventBus{constructor(e,t,i){var l,h,s,r,d,a,c,g,m;super();n(this,"_top");n(this,"_id");n(this,"_name");n(this,"_path");n(this,"_style");n(this,"_icon");n(this,"_label");n(this,"_data");n(this,"_visible");n(this,"_labelBasePlacement","center");this._top=e,this._labelBasePlacement=i.labelBasePlacement??"center",this._id=t.id,this._name=t.name,this._path=t.path.map(y=>new _.Position(...y)),this._visible=t.visible??!0,this._data=t.data,this._style=u.deepAssign({},e.options.style.polyline,{line:{style:(h=(l=t.style)==null?void 0:l.line)==null?void 0:h.style,color:(r=(s=t.style)==null?void 0:s.line)==null?void 0:r.color,width:(a=(d=t.style)==null?void 0:d.line)==null?void 0:a.width,opacity:(g=(c=t.style)==null?void 0:c.line)==null?void 0:g.opacity}}),this._label=this.genLabel(e,u.deepAssign({},e.options.label,e.options.style.polyline.label,t.label,(m=t.style)==null?void 0:m.label)),this._label.listenAndUpdateVisible({showLabel:this.showLabel.bind(this),hiddenLabel:this.hiddenLabel.bind(this)})}genLabel(e,t){return new S.Label(e,{canShow:t.visible!==!1,minShowZoom:t.minShowZoom,color:t.color,backgroundColor:t.backgroundColor,fontSize:t.fontSize,placement:t.placement,visible:t.visible,text:t.text,basePlacement:this._labelBasePlacement})}get id(){return this._id}get name(){return this._name}get path(){return this._path}get icon(){return this._icon}get data(){return this._data}setName(e){this._name=e}setPath(e){this._path=e.map(t=>new _.Position(...t))}setStyle(e){var t,i,l,h;this._style=u.deepAssign({},this._style,e),this._label=this.genLabel(this._top,u.deepAssign({},this._top.options.label,this._top.options.style.polyline.label,{text:(t=this._label)==null?void 0:t.text,minShowZoom:(i=this._label)==null?void 0:i.minShowZoom,visible:(l=this._label)==null?void 0:l.visible},(h=this._style)==null?void 0:h.label)),this._label.listenAndUpdateVisible({showLabel:this.showLabel.bind(this),hiddenLabel:this.hiddenLabel.bind(this)})}setData(e){this._data=e}show(){var e;this._visible=!0,(e=this._label)!=null&&e.canShow&&this.showLabel()}hidden(){this._visible=!1,this.hiddenLabel()}showLabel(){var e,t;(t=(e=this._label)==null?void 0:e.setVisible)==null||t.call(e,!0)}hiddenLabel(){var e,t;(t=(e=this._label)==null?void 0:e.setVisible)==null||t.call(e,!1)}getLength(){return this._path.reduce((t,i,l)=>(l<this._path.length-1&&(t+=P.getDistance(i,this._path[l+1])),t),0)}contains(e){for(let t=0;t<this._path.length;t++)if(this._path[t].equals(e))return!0;return!1}getBounds(){return v.Bounds.getBounds(this._path)}findClosestPointToCentroid(e){function t(s){let r=0,d=0;const a=s.length;for(let c=0;c<a;c++)r+=s[c].longitude,d+=s[c].latitude;return new _.Position(r/a,d/a)}const i=t(e);let l=null,h=1/0;for(let s=0;s<e.length;s++){const r=e[s].longitude-i.longitude,d=e[s].longitude-i.longitude,a=Math.sqrt(r*r+d*d);a<h&&(h=a,l=e[s])}return l}}class B extends p{}exports.AbstractPolyline=B;exports.BasePolyline=p;