|
|
function e(e){e.checkResize?.()}var t=null,n=null,r=`cc3f61fa6cafe2f0ad440018d0f07b13`;function i(){return`cc3f61fa6cafe2f0ad440018d0f07b13`?.trim()||r}function a(){return window.T?Promise.resolve(window.T):(t||=new Promise((e,t)=>{let n=i();if(!n){t(Error(`未配置 VITE_TIANDITU_TK`));return}let r=document.createElement(`script`);r.src=`https://api.tianditu.gov.cn/api?v=4.0&tk=${encodeURIComponent(n)}`,r.async=!0,r.onload=()=>{window.T?e(window.T):t(Error(`天地图 SDK 加载失败`))},r.onerror=()=>t(Error(`天地图脚本加载失败`)),document.head.appendChild(r)}),t)}var o={lng:120.585316,lat:31.298886};function s(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}function c(e){return n||(n=e.Overlay.extend({lnglat:{lng:0,lat:0},options:{name:``},map:null,_div:null,_onMapChange:null,_listeners:[],initialize(e,t){this.lnglat=e,this.options=t||{name:``},this._listeners=[]},onAdd(e){this.map=e;let t=document.createElement(`div`);t.className=`slake-map-school-marker`,this.options.active&&t.classList.add(`is-active`),t.setAttribute(`role`,`button`),t.setAttribute(`tabindex`,`0`),t.innerHTML=`<span class="slake-map-school-dot" aria-hidden="true"></span><span class="slake-map-school-label">${s(this.options.name.trim()||`—`)}</span>`,this._div=t,e.getPanes?.().overlayPane.appendChild(t),this._onMapChange=()=>this.update(),e.addEventListener?.(`move`,this._onMapChange),e.addEventListener?.(`zoomend`,this._onMapChange),this.update();for(let{type:e,handler:t}of this._listeners)this._div?.addEventListener(e,t)},onRemove(){let e=this.map;e&&this._onMapChange&&(e.removeEventListener?.(`move`,this._onMapChange),e.removeEventListener?.(`zoomend`,this._onMapChange)),this._div?.parentNode&&this._div.parentNode.removeChild(this._div),this.map=null,this._div=null},update(){let e=this.map;if(!e?.lngLatToLayerPoint||!this._div)return;let t=e.lngLatToLayerPoint(this.lnglat);this._div.style.left=`${t.x}px`,this._div.style.top=`${t.y}px`},setActive(e){this.options.active=e,this._div?.classList.toggle(`is-active`,e)},addEventListener(e,t){if(this._div){this._div.addEventListener(e,t);return}this._listeners.push({type:e,handler:t})}}),n)}function l(e,t,n=!1){return new(c(e))(new e.LngLat(t.longitude,t.latitude),{name:t.name,active:n})}function u(e,t){let n=Number(e),r=Number(t);return!Number.isFinite(n)||!Number.isFinite(r)?null:(n<=60&&r>=70&&([n,r]=[r,n]),{lng:n,lat:r})}function d(e){if(typeof e==`string`){let t=e.trim();if(!t)return null;let n=t.split(/[\s,;,]+/).filter(Boolean);return n.length<2?null:u(n[0],n[1])}let t=e,n=e.lonlat??t.LonLat??t.lonLat;if(typeof n==`string`&&n.trim()){let e=d(n);if(e)return e}let r=e.lng??e.lon??t.Lon,i=e.lat??t.Lat;return r!=null&&i!=null?u(r,i):null}function f(e){return e?Array.isArray(e)?e:typeof e==`object`?Object.values(e):[]:[]}function p(e,t,n=11){e.centerAndZoom(new t.LngLat(o.lng,o.lat),n)}export{e as a,d as c,i,p as n,a as o,l as r,f as s,o as t}; |