|
|
var e=new Set([`mapPane`,`tilePane`,`floatPane`]),t=/tdt-overlay-pane|tdt-marker-pane|tdt-tooltip-pane|tdt-popup-pane|tdt-shadow-pane/i;function n(e,t){let n=e[t];typeof n==`function`&&n.call(e)}function r(e){e.checkResize?.()}function i(e,t){if(typeof ResizeObserver>`u`)return()=>{};let n=new ResizeObserver(()=>{let e=t();e&&r(e)});return n.observe(e),()=>n.disconnect()}function a(e,t=[0,80,240,480,800]){for(let n of t)window.setTimeout(()=>r(e),n)}function o(n){let r=n.getPanes?.();if(r)for(let[t,n]of Object.entries(r))!n||e.has(t)||(n.style.pointerEvents=`none`);let i=n.getContainer?.();i&&(i.querySelectorAll(`[class*="tdt-"][class*="pane"]`).forEach(e=>{t.test(e.className)&&(e.style.pointerEvents=`none`)}),i.querySelectorAll(`.slake-map-school-marker`).forEach(e=>{e.style.pointerEvents=`auto`}))}function s(e){n(e,`enableScrollWheelZoom`),n(e,`enableDrag`),n(e,`enableInertia`),n(e,`enableAutoResize`);let t=e.setOptions;t?.({drag:!0}),o(e)}function c(e,t,r={}){let i=e.getContainer?.();if(!i||!e.panBy)return()=>{};let a=i;n(e,`disableDrag`);let o=r.ignoreSelector??`.slake-map-school-marker, .slake-map-school-marker *`,s=!1,c=0,l=0;function u(e){return e instanceof Element&&!!e.closest(o)}function d(e,t){s=!0,c=e,l=t,a.style.cursor=`grabbing`}function f(n,r){if(!s)return;let i=n-c,a=r-l;!i&&!a||(c=n,l=r,e.panBy?.(new t.Point(-i,-a)))}function p(){s&&(s=!1,a.style.cursor=`grab`)}let m=e=>{e.button!==0||u(e.target)||(d(e.clientX,e.clientY),e.preventDefault())},h=e=>{f(e.clientX,e.clientY)},g=()=>p(),_=e=>{u(e.target)||e.touches.length!==1||d(e.touches[0].clientX,e.touches[0].clientY)},v=e=>{!s||e.touches.length!==1||(f(e.touches[0].clientX,e.touches[0].clientY),e.preventDefault())},y=()=>p();return a.style.cursor=`grab`,a.addEventListener(`mousedown`,m),window.addEventListener(`mousemove`,h),window.addEventListener(`mouseup`,g),a.addEventListener(`touchstart`,_,{passive:!1}),a.addEventListener(`touchmove`,v,{passive:!1}),a.addEventListener(`touchend`,y),a.addEventListener(`touchcancel`,y),()=>{a.removeEventListener(`mousedown`,m),window.removeEventListener(`mousemove`,h),window.removeEventListener(`mouseup`,g),a.removeEventListener(`touchstart`,_),a.removeEventListener(`touchmove`,v),a.removeEventListener(`touchend`,y),a.removeEventListener(`touchcancel`,y),a.style.cursor=``}}var l=null,u=null,d=`cc3f61fa6cafe2f0ad440018d0f07b13`;function f(){return`cc3f61fa6cafe2f0ad440018d0f07b13`?.trim()||d}function p(){return window.T?Promise.resolve(window.T):(l||=new Promise((e,t)=>{let n=f();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)}),l)}var m={lng:120.585316,lat:31.298886};function h(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}function g(e){return u||(u=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.style.pointerEvents=`auto`,t.innerHTML=`<span class="slake-map-school-dot" aria-hidden="true"></span><span class="slake-map-school-label">${h(this.options.name.trim()||`—`)}</span>`,this._div=t;let n=e.getPanes?.(),r=n?.overlayPane??n?.markerPane;r&&r.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})}}),u)}function _(e,t,n=!1){return new(g(e))(new e.LngLat(t.longitude,t.latitude),{name:t.name,active:n})}function v(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 y(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:v(n[0],n[1])}let t=e,n=e.lonlat??t.LonLat??t.lonLat;if(typeof n==`string`&&n.trim()){let e=y(n);if(e)return e}let r=e.lng??e.lon??t.Lon,i=e.lat??t.Lat;return r!=null&&i!=null?v(r,i):null}function b(e){return e?Array.isArray(e)?e:typeof e==`object`?Object.values(e):[]:[]}function x(e,t,n=11){e.centerAndZoom(new t.LngLat(m.lng,m.lat),n)}export{x as a,f as c,b as d,y as f,i,r as l,o as n,s as o,a as p,c as r,_ as s,m as t,p as u}; |