UNPKG

@tuoyuan/map-adapter-lib

Version:

地图适配器库

2 lines (1 loc) 2.98 kB
"use strict";var S=Object.defineProperty;var f=(l,s,t)=>s in l?S(l,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[s]=t;var i=(l,s,t)=>f(l,typeof s!="symbol"?s+"":s,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../utils/deep-assign.js"),A=require("../utils/is-pointIn-polygon.js"),B=require("./MapEvent.js"),L=require("./Position.js"),x=require("./Label.js");class g extends B.EventBus{constructor(t,e,a){var n,h,b,_,r,d,c,p,m,u,y,w,P;super();i(this,"_top");i(this,"_id");i(this,"_name");i(this,"_path");i(this,"_style");i(this,"_icon");i(this,"_label");i(this,"_data");i(this,"_visible");i(this,"_labelBasePlacement","center");this._top=t,this._labelBasePlacement=a.labelBasePlacement??"center",this._id=e.id,this._name=e.name,this._path=e.path.map(v=>new L.Position(...v)),this._visible=e.visible??!0,this._data=e.data,this._style=o.deepAssign({},t.options.style.polygon,{line:{style:(h=(n=e.style)==null?void 0:n.line)==null?void 0:h.style,color:(_=(b=e.style)==null?void 0:b.line)==null?void 0:_.color,width:(d=(r=e.style)==null?void 0:r.line)==null?void 0:d.width,opacity:(p=(c=e.style)==null?void 0:c.line)==null?void 0:p.opacity},fill:{color:(u=(m=e.style)==null?void 0:m.fill)==null?void 0:u.color,opacity:(w=(y=e.style)==null?void 0:y.fill)==null?void 0:w.opacity}}),this._label=this.genLabel(this._top,o.deepAssign({},this._top.options.label,this._top.options.style.polygon.label,e.label,(P=e.style)==null?void 0:P.label)),this._label.listenAndUpdateVisible({showLabel:this.showLabel.bind(this),hiddenLabel:this.hiddenLabel.bind(this)})}genLabel(t,e){return new x.Label(t,{canShow:e.visible!==!1,minShowZoom:e.minShowZoom,color:e.color,backgroundColor:e.backgroundColor,fontSize:e.fontSize,placement:e.placement,visible:e.visible,text:e.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(t){this._name=t}setPath(t){this._path=t.map(e=>new L.Position(...e))}setStyle(t){var e,a,n,h;this._style=o.deepAssign({},this._style,t),this._label=this.genLabel(this._top,o.deepAssign({},this._top.options.label,this._top.options.style.polygon.label,{text:(e=this._label)==null?void 0:e.text,minShowZoom:(a=this._label)==null?void 0:a.minShowZoom,visible:(n=this._label)==null?void 0:n.visible},(h=this._style)==null?void 0:h.label)),this._label.listenAndUpdateVisible({showLabel:this.showLabel.bind(this),hiddenLabel:this.hiddenLabel.bind(this)})}setData(t){this._data=t}show(){var t;this._visible=!0,(t=this._label)!=null&&t.canShow&&this.showLabel()}hidden(){this._visible=!1,this.hiddenLabel()}showLabel(){var t,e;(e=(t=this._label)==null?void 0:t.setVisible)==null||e.call(t,!0)}hiddenLabel(){var t,e;(e=(t=this._label)==null?void 0:t.setVisible)==null||e.call(t,!1)}contains(t){return A.isPointInPolygon(t,this._path)}}class q extends g{}exports.AbstractPolygon=q;exports.BasePolygon=g;