You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
5.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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,t){return new e.Map(t)}function i(e){e.checkResize?.()}async function a(e,t=5e3){let n=Date.now()+t;for(;Date.now()<n;){let t=e.getBoundingClientRect();if(t.width>0&&t.height>0)return!0;await new Promise(e=>requestAnimationFrame(()=>e()))}return!1}function o(e,t,n,r){i(e),e.centerAndZoom(new t.LngLat(n.lng,n.lat),r),c(e,[50,200,500])}function s(e,t){if(typeof ResizeObserver>`u`)return()=>{};let n=new ResizeObserver(()=>{let e=t();e&&i(e)});return n.observe(e),()=>n.disconnect()}function c(e,t=[0,80,240,480,800]){for(let n of t)window.setTimeout(()=>i(e),n)}function l(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 u(e){n(e,`enableScrollWheelZoom`),n(e,`enableDrag`),n(e,`enableInertia`),n(e,`enableAutoResize`);let t=e.setOptions;t?.({drag:!0})}function d(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,u=0,d=0,f=0;function p(e){return e instanceof Element&&!!e.closest(o)}function m(e,t){s=!0,c=e,l=t,a.style.cursor=`grabbing`}function h(n,r){if(!s)return;let i=n-c,a=r-l;!i&&!a||(c=n,l=r,u+=i,d+=a,!f&&(f=requestAnimationFrame(()=>{f=0,!(!u&&!d)&&(e.panBy?.(new t.Point(-u,-d)),u=0,d=0)})))}function g(){s&&(s=!1,a.style.cursor=`grab`)}let _=e=>{e.button!==0||p(e.target)||(m(e.clientX,e.clientY),e.preventDefault())},v=e=>{h(e.clientX,e.clientY)},y=()=>g(),b=e=>{p(e.target)||e.touches.length!==1||m(e.touches[0].clientX,e.touches[0].clientY)},x=e=>{!s||e.touches.length!==1||(h(e.touches[0].clientX,e.touches[0].clientY),e.preventDefault())},S=()=>g();return a.style.cursor=`grab`,a.addEventListener(`mousedown`,_),window.addEventListener(`mousemove`,v),window.addEventListener(`mouseup`,y),a.addEventListener(`touchstart`,b,{passive:!1}),a.addEventListener(`touchmove`,x,{passive:!1}),a.addEventListener(`touchend`,S),a.addEventListener(`touchcancel`,S),()=>{f&&=(cancelAnimationFrame(f),0),a.removeEventListener(`mousedown`,_),window.removeEventListener(`mousemove`,v),window.removeEventListener(`mouseup`,y),a.removeEventListener(`touchstart`,b),a.removeEventListener(`touchmove`,x),a.removeEventListener(`touchend`,S),a.removeEventListener(`touchcancel`,S),a.style.cursor=``}}var f=null,p=null,m=`cc3f61fa6cafe2f0ad440018d0f07b13`;function h(){return`cc3f61fa6cafe2f0ad440018d0f07b13`?.trim()||m}function g(){return window.T?Promise.resolve(window.T):(f||=new Promise((e,t)=>{let n=h();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)}),f)}var _={lng:120.585316,lat:31.298886};function v(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}function y(e){return p||(p=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">${v(this.options.name.trim()||``)}</span>`,this._div=t;let n=e.getPanes?.(),r=n?.overlayPane??n?.markerPane;r&&r.appendChild(t);let i=0;this._onMapChange=()=>{i||=requestAnimationFrame(()=>{i=0,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})}}),p)}function b(e,t,n=!1){return new(y(e))(new e.LngLat(t.longitude,t.latitude),{name:t.name,active:n})}function x(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 S(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:x(n[0],n[1])}let t=e,n=e.lonlat??t.LonLat??t.lonLat;if(typeof n==`string`&&n.trim()){let e=S(n);if(e)return e}let r=e.lng??e.lon??t.Lon,i=e.lat??t.Lat;return r!=null&&i!=null?x(r,i):null}function C(e){return e?Array.isArray(e)?e:typeof e==`object`?Object.values(e):[]:[]}function w(e,t,n=11){e.centerAndZoom(new t.LngLat(_.lng,_.lat),n)}export{w as a,r as c,C as d,S as f,a as h,s as i,h as l,c as m,l as n,u as o,o as p,d as r,b as s,_ as t,g as u};