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.

2 lines
8.1 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.

import{d as t,r as e,a as n,b as o,w as i,j as r,e as l,i as a,x as u,f as c,aa as s,m as f,v as d,B as m,k as v,l as p,_ as g}from"./index-BIkOonBg.js";import{g as w,w as h}from"./coordChina.DSiWE9WA.js";const y=new Map,T="#05c9ac";function E(t){const e=function(t){if(!t||"string"!=typeof t)return T;let e=t.trim();if(e.startsWith("#")||(e=`#${e}`),/^#[0-9A-Fa-f]{6}$/.test(e))return e;if(/^#[0-9A-Fa-f]{3}$/.test(e)){const t=e[1],n=e[2],o=e[3];return`#${t}${t}${n}${n}${o}${o}`}return T}(t||"");if(y.has(e))return y.get(e);if("undefined"==typeof document)return y.set(e,""),"";const n=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 56" width="48" height="56">\n<path fill="${e}" stroke="#ffffff" stroke-width="2" stroke-linejoin="round" d="M24 4C14.6 4 7 11.4 7 20.5C7 32 24 50 24 50S41 32 41 20.5C41 11.4 33.4 4 24 4Z"/>\n<circle cx="24" cy="21" r="7" fill="#ffffff"/>\n<circle cx="24" cy="21" r="3.5" fill="${e}"/>\n</svg>`)}`;return y.set(e,n),n}const b=120;function L(t,e){const n=t.venue_type_color;return n&&"string"==typeof n&&function(t){if(!t||"string"!=typeof t)return null;let e=t.trim();e.startsWith("#")||(e=`#${e}`);const n=e.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);if(!n)return null;let o=n[1];return 3===o.length&&(o=`${o[0]}${o[0]}${o[1]}${o[1]}${o[2]}${o[2]}`),o.toLowerCase()}(n.trim())?n.trim():e()}let k=null;function I(t){k=t}let N=null;function F(){return String("ebd6693edf7730d8f8f9a7ba1719f5c1").trim()}function $(t){const e=window.T,n=new e.TileLayer(function(t){return`https://t0.tianditu.gov.cn/vec_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${t}`}(t),{minZoom:1,maxZoom:18}),o=new e.TileLayer(function(t){return`https://t0.tianditu.gov.cn/cva_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${t}`}(t),{minZoom:1,maxZoom:18});return[n,o]}function C(t,e){const n=w(t,e);return new window.T.LngLat(n.lng,n.lat)}function R(t){const{lng:e,lat:n}=function(t){if(!t)throw new Error("missing lnglat");const e="function"==typeof t.getLng?t.getLng():"number"==typeof t.lng?t.lng:NaN,n="function"==typeof t.getLat?t.getLat():"number"==typeof t.lat?t.lat:NaN;if(!Number.isFinite(e)||!Number.isFinite(n))throw new Error("invalid lnglat");return{lng:e,lat:n}}(t.lnglat),o=h(e,n);return{lat:Number(o.lat.toFixed(6)),lng:Number(o.lng.toFixed(6))}}function S(t){const e=(t||"").trim();if(!e.startsWith("#"))return{color:"#05C9AC",opacity:.9};if(9===e.length){const t=e.slice(0,7),n=parseInt(e.slice(7,9),16)/255;return{color:t,opacity:Number.isFinite(n)?n:.9}}return{color:e.slice(0,7),opacity:.9}}const x=g(t({__name:"TiandituMap",props:{latitude:{},longitude:{},zoom:{},markers:{default:()=>[]},polygons:{default:()=>[]},fitPoints:{default:()=>[]},fitKey:{default:""},useFitPoints:{type:Boolean,default:!0},markerTapFn:{}},emits:["venue-marker-tap","markertap","tap","zoomchange"],setup(t,{emit:g}){const w=t,h=g,y=e(null),T=e(""),E=e(!1),b=e(!F());let L=null,I=[];const x=new WeakMap;let A=[],P=!1,_="",z=!1,M=0;function O(t){var e;const n=Number(t);Number.isFinite(n)&&(M=Date.now()+500,null==(e=w.markerTapFn)||e.call(w,n),function(t){const e=Number(t);Number.isFinite(e)&&(null==k||k(e))}(n),h("venue-marker-tap",n),h("markertap",{detail:{markerId:n}}))}function Z(t){var e,n;if(!t||"object"!=typeof t)return null;const o=x.get(t);if("number"==typeof o&&Number.isFinite(o))return o;for(const r of I)if(r.overlay===t)return r.id;const i=t.options;return null!=(null==(e=null==i?void 0:i.extData)?void 0:e.venueId)?Number(i.extData.venueId):null!=(null==(n=null==i?void 0:i.item)?void 0:n.id)?Number(i.item.id):null}function D(t){t.stopPropagation()}function W(t,e){const n=e;"function"==typeof n.addEventListener&&n.addEventListener("click",e=>{O(Z(null==e?void 0:e.target)??t)})}function K(){var t,e;if(!L||!E.value)return;null==(t=L.checkResize)||t.call(L);const n=w.fitKey??"";w.useFitPoints&&((null==(e=w.fitPoints)?void 0:e.length)??0)>0?n!==_&&(_=n,function(){var t;if(L){if(w.useFitPoints&&(null==(t=w.fitPoints)?void 0:t.length)){const t=w.fitPoints.map(t=>C(t.longitude,t.latitude));return L.setViewport(t),void h("zoomchange",L.getZoom())}L.centerAndZoom(C(w.longitude,w.latitude),w.zoom)}}()):(_="",L.setZoom(w.zoom),L.centerAndZoom(C(w.longitude,w.latitude),w.zoom)),function(){if(!L||!window.T)return;const t=window.T;for(const e of A)L.removeOverLay(e);A=[];for(const e of w.polygons){const n=(e.points||[]).filter(t=>Number.isFinite(t.latitude)&&Number.isFinite(t.longitude));if(n.length<3)continue;const o=S(e.strokeColor||"#05C9ACE6"),i=S(e.fillColor||"#05C9AC14"),r=n.map(t=>C(t.longitude,t.latitude)),l=new t.Polygon(r,{color:o.color,weight:e.strokeWidth??2,opacity:o.opacity,fillColor:i.color,fillOpacity:.35*i.opacity});L.addOverLay(l),A.push(l)}}(),function(){var t,e;if(!L||!window.T)return;const n=window.T;for(const o of I)L.removeOverLay(o.overlay);I=[];for(const o of w.markers){const i=Number(o.latitude),r=Number(o.longitude);if(!Number.isFinite(i)||!Number.isFinite(r))continue;const l={};if(o.iconPath){const i=o.width||28,r=o.height||32,a=((null==(t=o.anchor)?void 0:t.x)??.5)*i,u=((null==(e=o.anchor)?void 0:e.y)??1)*r;l.icon=new n.Icon({iconUrl:o.iconPath,iconSize:new n.Point(i,r),iconAnchor:new n.Point(a,u)})}const a=new n.Marker(C(r,i),{...l,extData:{venueId:o.id},item:{id:o.id}});x.set(a,o.id),W(o.id,a),L.addOverLay(a),I.push({id:o.id,overlay:a})}}()}function U(t){const e=Z(t.target);if(null==e){try{const{lat:e,lng:n}=R(t),o=function(t,e){const n=(null==L?void 0:L.getZoom())??w.zoom??12,o=.006/Math.pow(2,.5*Math.max(0,n-11)),i=o*o;let r=null,l=1/0;for(const a of w.markers){const n=Number(a.latitude),o=Number(a.longitude);if(!Number.isFinite(n)||!Number.isFinite(o))continue;const u=1.15*(n-t),c=o-e,s=u*u+c*c;s<=i&&s<l&&(l=s,r=a)}return r}(e,n);if(o)return void O(o.id)}catch{}Date.now()<M||h("tap")}else O(e)}async function V(){if(y.value){T.value="";try{if(await async function(){if("undefined"==typeof window)throw new Error("天地图仅支持 H5 浏览器");if(window.T)return;const t=F();if(!t)throw new Error("请先配置 VITE_TIANDITU_TK");if(N||(N=new Promise((e,n)=>{const o=document.createElement("script");o.src=`https://api.tianditu.gov.cn/api?v=4.0&tk=${encodeURIComponent(t)}`,o.async=!0,o.onload=()=>e(),o.onerror=()=>n(new Error("天地图 SDK 加载失败")),document.head.appendChild(o)})),await N,!window.T)throw new Error("天地图 SDK 未就绪")}(),L)return;L=function(t,e,n,o){var i,r,l,a;const u=F(),c=new window.T.Map(t,{projection:"EPSG:4326",layers:$(u)});return c.centerAndZoom(C(e,n),o),null==(i=c.enableScrollWheelZoom)||i.call(c),null==(r=c.enableDrag)||r.call(c),null==(l=c.enableDoubleClickZoom)||l.call(c),null==(a=c.enablePinchToZoom)||a.call(c),c}(y.value,w.longitude,w.latitude,w.zoom),function(t){if(z)return;z=!0;const e=["touchstart","touchmove","touchend","wheel"];for(const n of e)t.addEventListener(n,D,!1);t.addEventListener("click",D,!1)}(y.value),L&&!P&&(L.addEventListener("click",t=>U(t)),L.addEventListener("zoomend",()=>{L&&h("zoomchange",L.getZoom())}),P=!0),E.value=!0,_="",K(),setTimeout(()=>{var t;null==(t=null==L?void 0:L.checkResize)||t.call(L)},200)}catch(t){T.value=(null==t?void 0:t.message)||"地图加载失败"}}}return n(()=>{V()}),o(()=>{!function(){if(L){for(const t of I)L.removeOverLay(t.overlay);I=[];for(const t of A)L.removeOverLay(t);A=[]}}(),L=null,E.value=!1,_="",P=!1,z=!1}),i(()=>[w.latitude,w.longitude,w.zoom,w.fitKey,w.useFitPoints,w.markers,w.polygons,w.fitPoints],()=>K(),{deep:!0}),(t,e)=>{const n=a,o=p;return r(),l(n,{class:"tdt-wrap",onTouchmove:e[0]||(e[0]=u(()=>{},["stop"]))},{default:c(()=>[s("div",{ref_key:"rootRef",ref:y,class:"tdt-map"},null,512),T.value?(r(),l(n,{key:0,class:"tdt-err"},{default:c(()=>[f(d(T.value),1)]),_:1})):b.value?(r(),l(n,{key:1,class:"tdt-err"},{default:c(()=>[f("未配置 VITE_TIANDITU_TK")]),_:1})):m("",!0),v(o,{class:"tdt-copy"},{default:c(()=>[f("审图号GS20240568号 · 数据来源:天地图")]),_:1})]),_:1})}}}),[["__scopeId","data-v-b885381f"]]);export{b as S,x as T,E as g,I as s,L as t};