@teeechina/teee-map 0.0.28 → 0.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/teee-map.mjs +1 -0
- package/dist/teee-map.umd.js +1 -1
- package/index.d.ts +17 -0
- package/package.json +1 -1
package/dist/teee-map.mjs
CHANGED
|
@@ -52301,6 +52301,7 @@ var ic = class e {
|
|
|
52301
52301
|
this.map.getLayer(e.id) ? console.debug(`图层已存在: ${e.id}`) : this.map.addLayer(e);
|
|
52302
52302
|
});
|
|
52303
52303
|
}
|
|
52304
|
+
this.measureTool = new ic(this.map);
|
|
52304
52305
|
let n = this.map.getStyle()?.sources ?? {}, r = Object.keys(n);
|
|
52305
52306
|
console.log(`源列表 (${r.length}):`, r, n);
|
|
52306
52307
|
let i = this.map.getStyle().layers ?? [], a = i.map((e) => e.id);
|
package/dist/teee-map.umd.js
CHANGED
|
@@ -1281,4 +1281,4 @@ Alt. `,[`to-string`,[`floor`,[`get`,`elevation`]]],` `,[`get`,`elevationUnit`]],
|
|
|
1281
1281
|
.measure-close:hover {
|
|
1282
1282
|
color: #fff;
|
|
1283
1283
|
}
|
|
1284
|
-
`,document.head.appendChild(t)}getSource(e){return this.map.getSource(e)}startDistance(){this.reset(),this.active=!0,this.map.getCanvas().style.cursor=`default`,this.map.doubleClickZoom.enable(),this.tooltipEle=document.createElement(`div`),this.tooltipEle.setAttribute(`class`,`measure-result`),this.tooltip=new l.default.Marker({element:this.tooltipEle,anchor:`left`,offset:[8,0]}).setLngLat([0,0]).addTo(this.map),this.map.getSource(`points`)||(this.map.addSource(`points`,{type:`geojson`,data:this.jsonPoint}),this.map.addSource(`line`,{type:`geojson`,data:this.jsonLine}),this.map.addSource(`line-move`,{type:`geojson`,data:this.jsonLine}),this.map.addLayer({id:`line-move`,type:`line`,source:`line-move`,paint:{"line-color":`#ff0000`,"line-width":3,"line-dasharray":[2,2]}}),this.map.addLayer({id:`line`,type:`line`,source:`line`,paint:{"line-color":`#ff0000`,"line-width":3,"line-dasharray":[2,2]}}),this.map.addLayer({id:`points`,type:`circle`,source:`points`,paint:{"circle-color":`#ff0000`,"circle-radius":4,"circle-stroke-width":2,"circle-stroke-color":`#1677ff`}})),this.bindDistanceEvents()}bindDistanceEvents(){this.map.__isPlacingLoco=!0,this._onClick=e=>{if(!this.active)return;let t=[e.lngLat.lng,e.lngLat.lat];this.addMeasureRes(t),this.addDistancePoint(t),this.points.push(t)},this._onMousemove=e=>{if(!this.active)return;let t=[e.lngLat.lng,e.lngLat.lat];if(this.jsonPoint.features.length>0){let e=this.jsonPoint.features[this.jsonPoint.features.length-1].geometry.coordinates;this.getSource(`line-move`).setData({type:`Feature`,properties:{},geometry:{type:`LineString`,coordinates:[e,t]}}),this.tooltipEle.innerHTML=this.getLength(t)}else this.tooltipEle.innerHTML=`点击地图开始测量,右键结束测量`;this.tooltip.setLngLat(t)},this._onContextmenu=e=>{if(this.map.__isPlacingLoco=!1,!this.active)return;let t=[e.lngLat.lng,e.lngLat.lat];this.addDistancePoint(t),this.active=!1,this.map.getCanvas().style.cursor=``;let n=this.getLength(t);this.tooltipEle.innerHTML=`<span>${n}</span><span class="measure-close">×</span>`,this.tooltip.setLngLat(t);let r=this.tooltipEle.querySelector(`.measure-close`);r.onclick=e=>{e.stopPropagation(),this.map.doubleClickZoom.enable(),this.clear()}},this.map.on(`click`,this._onClick),this.map.on(`mousemove`,this._onMousemove),this.map.on(`contextmenu`,this._onContextmenu)}addDistancePoint(e){if(this.jsonPoint.features.length>0){let t=this.jsonPoint.features[this.jsonPoint.features.length-1].geometry.coordinates;this.jsonLine.features.push({type:`Feature`,properties:{},geometry:{type:`LineString`,coordinates:[t,e]}}),this.getSource(`line`).setData(this.jsonLine)}this.jsonPoint.features.push({type:`Feature`,properties:{},geometry:{type:`Point`,coordinates:e}}),this.getSource(`points`).setData(this.jsonPoint)}addMeasureRes(e){let t=document.createElement(`div`);t.setAttribute(`class`,`measure-result`),t.innerHTML=String(this.points.length===0?`起点`:this.getLength(e));let n=new l.default.Marker({element:t,anchor:`left`,offset:[8,0]}).setLngLat(e).addTo(this.map);this.markers.push(n)}getLength(e){let t=ic(h(this.points.concat([e])));return t<1?(t=Number((t*1e3).toFixed(4)),t+`m`):(t=Number(t.toFixed(4)),t+`km`)}startArea(){this.reset(),this.active=!0,this.map.doubleClickZoom.disable(),this.map.getCanvas().style.cursor=`default`,this.tooltipEle=document.createElement(`div`),this.tooltipEle.setAttribute(`class`,`measure-result`),this.tooltip=new l.default.Marker({element:this.tooltipEle,anchor:`left`,offset:[8,0]}).setLngLat([0,0]).addTo(this.map),this.map.getSource(`points-area`)||(this.map.addSource(`points-area`,{type:`geojson`,data:this.jsonPoint}),this.map.addSource(`line-area`,{type:`geojson`,data:this.jsonLine}),this.map.addLayer({id:`line-area`,type:`fill`,source:`line-area`,paint:{"fill-color":`#ff0000`,"fill-opacity":.1}}),this.map.addLayer({id:`line-area-stroke`,type:`line`,source:`line-area`,paint:{"line-color":`#ff0000`,"line-width":3,"line-dasharray":[2,2]}}),this.map.addLayer({id:`points-area`,type:`circle`,source:`points-area`,paint:{"circle-color":`#ff0000`,"circle-radius":4,"circle-stroke-width":2,"circle-stroke-color":`#1677ff`}})),this.bindAreaEvents()}bindAreaEvents(){this.map.__isPlacingLoco=!0,this._onClick=e=>{if(!this.active)return;let t=[e.lngLat.lng,e.lngLat.lat];this.points.push(t),this.addAreaPoint(t)},this._onContextmenu=e=>{if(this.map.__isPlacingLoco=!1,!this.active)return;let t=[e.lngLat.lng,e.lngLat.lat];this.points.push(t),this.active=!1,this.tooltipEle.innerHTML=`<span>${this.getArea(t)}</span><span class="measure-close">×</span>`,this.tooltip.setLngLat(t);let n=this.tooltipEle.querySelector(`.measure-close`);n.onclick=e=>{e.stopPropagation(),this.map.doubleClickZoom.enable(),this.clear()}},this._onMousemove=e=>{if(!this.active)return;let t=[e.lngLat.lng,e.lngLat.lat],n=this.jsonPoint.features.length;if(n===0)this.tooltipEle.innerHTML=`点击地图开始测量,右键结束测量`;else if(n===1)this.tooltipEle.innerHTML=`点击地图继续测量,右键结束测量`;else{let e=this.points.concat([t]).concat([this.points[0]]);this.getSource(`line-area`).setData({type:`Feature`,properties:{},geometry:{type:`Polygon`,coordinates:[e]}}),this.tooltipEle.innerHTML=this.getArea(t)}this.tooltip.setLngLat(t)},this.map.on(`click`,this._onClick),this.map.on(`contextmenu`,this._onContextmenu),this.map.on(`mousemove`,this._onMousemove)}addAreaPoint(e){this.jsonPoint.features.push({type:`Feature`,properties:{},geometry:{type:`Point`,coordinates:e}}),this.getSource(`points-area`).setData(this.jsonPoint)}getArea(e){let t=Qs(m([this.points.concat([e]).concat([this.points[0]])]));return t<1e3?(t=Number(t.toFixed(4)),t+`m²`):(t=Number((t/1e6).toFixed(4)),t+`km²`)}reset(){this.clear(),this.active=!1,this.jsonPoint={type:`FeatureCollection`,features:[]},this.jsonLine={type:`FeatureCollection`,features:[]},this.points=[],this.markers=[],this.tooltip&&=(this.tooltip.remove(),null)}clear(){this._onClick&&this.map.off(`click`,this._onClick),this._onMousemove&&this.map.off(`mousemove`,this._onMousemove),this._onContextmenu&&this.map.off(`contextmenu`,this._onContextmenu),this._onClick=null,this._onMousemove=null,this._onContextmenu=null,document.querySelectorAll(`.measure-result`).forEach(e=>e.remove()),this.markers.forEach(e=>e.remove()),this.markers=[],[`points`,`line`,`line-move`].forEach(e=>{this.map.getLayer(e)&&this.map.removeLayer(e),this.map.getSource(e)&&this.map.removeSource(e)}),[`points-area`,`line-area-stroke`,`line-area`].forEach(e=>{this.map.getLayer(e)&&this.map.removeLayer(e),this.map.getSource(e)&&this.map.removeSource(e)})}},oc=class{map;mapDir=`left`;mapConfigs;mixingMapConfigs=new Map;stashFeatures=new Map;layerFeaturesCache=new Map;_activeBlinkCleanup=null;constructor(e){let t={version:8,sources:{},layers:[]};this.map=new l.default.Map({container:e,style:t,center:[0,0],zoom:14,attributionControl:!1,maxZoom:24}),Vs.base(this),this.map.on(`load`,()=>{this.cursorTool=new Vs.cursor(this.map),this.drawTool=new Vs.draw(this),this.injectTeeeGeoJson=Vs.injectTeeeGeoJson,this.snaps=new Vs.snaps(this),this.drawRoute=new Vs.drawRoute(this)})}initMap(e,t=!1){let n=async()=>{try{if(console.log(`开始构建业务地图: ${e.id}`),Array.isArray(e.source))if(t){let{sourceLayers:t}=this.mixingMapConfigs.get(e.id.split(`_`)[1]);if(!t)return;e.source.forEach((e,n)=>{this.map.addSource(t[n],e)})}else{let{sourceLayers:t}=this.mapConfigs;if(!t)return;e.source.forEach((e,n)=>{this.map.addSource(t[n],e)})}else this.map.getSource(e.id)?console.warn(`地图源已存在,跳过添加: ${e.id}`):this.map.addSource(e.id,e.source);e.subSourceId&&e.subSource&&(this.map.getSource(e.subSourceId)?console.warn(`地图源已存在,跳过添加: ${e.subSourceId}`):this.map.addSource(e.subSourceId,e.subSource));let n=await R();console.log(`图标列表 (${n.length}):`,n),n.forEach(e=>{this.map.hasImage(e.id)?console.warn(`图标已存在,跳过添加: ${e.id}`):this.map.addImage(e.id,e.image)}),e.layers&&e.layers.forEach(e=>{this.map.getLayer(e.id)?console.debug(`图层已存在: ${e.id}`):this.map.addLayer(e)}),this.layerTree=new Bs(this.map,e.id),this.measureTool=new ac(this.map);let r=this.map.getStyle()?.sources??{},i=Object.keys(r);console.log(`源列表 (${i.length}):`,i,r);let a=this.map.getStyle().layers??[],o=a.map(e=>e.id);console.log(`图层列表 (${o.length}):`,a),this.map.listImages();let s=this.layerFeaturesCache.get(`track`)?.[0]??null;if(s){let e=s.geometry;this.mapDir=e.coordinates[0][0]-e.coordinates[1][0]>0?`left`:`right`}console.groupEnd(),console.log(`地图构建全部完成: ${e.id}`)}catch(t){console.error(`地图初始化失败: ${e.id}`,t),t instanceof Error&&console.error(`错误详情: ${t.message}`)}},r=()=>{this.map.once(`idle`,()=>{t?this.stashMixMapAllFeature():this.stashAllFeature()})};this.map.loaded()?n().then(r):this.map.on(`load`,()=>{n().then(r)})}async initMixMap(e){let t=async()=>{let t=await R();console.log(`图标列表 (${t.length}):`,t),t.forEach(e=>{this.map.hasImage(e.id)?console.warn(`图标已存在,跳过添加: ${e.id}`):this.map.addImage(e.id,e.image)});for(let t of e){if(Array.isArray(t.source)){let{sourceLayers:e}=this.mixingMapConfigs.get(t.id.split(`_`)[1]);if(!e)continue;t.source.forEach((t,n)=>{this.map.addSource(e[n],t)})}else this.map.getSource(t.id)?console.warn(`地图源已存在,跳过添加: ${t.id}`):this.map.addSource(t.id,t.source);t.layers&&t.layers.forEach(e=>{this.map.getLayer(e.id)?console.debug(`图层已存在: ${e.id}`):this.map.addLayer(e)})}let n=this.map.getStyle()?.sources??{},r=Object.keys(n);console.log(`源列表 (${r.length}):`,r,n);let i=this.map.getStyle().layers??[],a=i.map(e=>e.id);console.log(`图层列表 (${a.length}):`,i);let o=r.filter(e=>e.endsWith(`_background`));a.filter(e=>e.endsWith(`_background`)).slice(1).forEach(e=>{this.map.getLayer(e)&&this.map.removeLayer(e)}),o.slice(1).forEach(e=>{this.map.getSource(e)&&this.map.removeSource(e)});let s=e[0],c=this.layerFeaturesCache.get(s.id.split(`_`)[1]+`_track`)?.[0]??null;if(c){let e=c.geometry;this.mapDir=e.coordinates[0][0]-e.coordinates[1][0]>0?`left`:`right`}this.stashMixMapAllFeature(),Vs.geojson(this)};this.map.loaded()?t():this.map.on(`load`,()=>{t()})}createCTCMap(e,t,n){let r=Hs.ctc(e,t,n);this.mapConfigs=r;let i=rt.graph(r.sourceUrl),a=qt.ctc(r),o={id:this.mapConfigs.id,source:i,layers:a};this.initMap(o),this.ctcTool=new Vs.ctc(this),this.ctcMenu=new Vs.ctcMenu(this),this.ctcClick=new Vs.ctcClick(this),this.ctcHoverTool=new Vs.ctcHover(this),this.sgfhqyTool=new Vs.sgfhqy(this),this.doorTool=new Vs.door(this)}createCTCEncryptedMap(e,t,n){Ws(this),this.mapConfigs=Hs.ctc(e,t,n);let r=rt.graph(this.mapConfigs.sourceUrl),i=qt.ctc(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a),this.ctcTool=new Vs.ctc(this),this.ctcMenu=new Vs.ctcMenu(this),this.ctcClick=new Vs.ctcClick(this),this.ctcHoverTool=new Vs.ctcHover(this),this.sgfhqyTool=new Vs.sgfhqy(this),this.doorTool=new Vs.door(this)}createRSWPMap(e){let t=Hs.rswp(e),n=rt.raster(t.sourceUrl),r=qt.raster(t.id),i=Hs.geojson(`rswp-geojson`),a=rt.geojson(),o={id:t.id,source:n,subSourceId:i.id,subSource:a,layers:r};this.mapConfigs=t,this.mapConfigs.subSourceId=i.id,this.initMap(o)}createGraphMap(e,t,n){this.mapConfigs=Hs.graph(e,t,n);let r=rt.graph(this.mapConfigs.sourceUrl),i=qt.graph(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a),Vs.graph(this)}createGraphEncryptedMap(e,t,n){Ws(this),this.mapConfigs=Hs.graph(e,t,n);let r=rt.graph(this.mapConfigs.sourceUrl),i=qt.ctc(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a),this.ctcTool=new Vs.ctc(this),this.ctcMenu=new Vs.ctcMenu(this),this.ctcClick=new Vs.ctcClick(this)}createGeomMap(e,t,n){this.mapConfigs=Hs.geom(e,t,n);let r=rt.geom(this.mapConfigs.sourceUrl),i=qt.geom(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a)}createGeomEncryptedMap(e,t,n){Ws(this),this.mapConfigs=Hs.geom(e,t,n);let r=rt.geom(this.mapConfigs.sourceUrl),i=qt.geom(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a)}async createGeoJsonGeomStationMap(e,t=!0){let n=e.map(e=>e.name),r=n.map(e=>`geojson_${e}`);this.mapConfigs=Hs.geojson(`geojson`),this.mapConfigs.layers=n,this.mapConfigs.sourceLayers=r;let i=await Promise.all(e.map(async(e,t)=>{let n=r[t],i=e.name;if(this.map.getSource(n))return;let a=e.data,o;return typeof a==`string`?(o=await(await fetch(a)).json(),Xs(i,o)):(o=a,Xs(i,o)),this.layerFeaturesCache.set(i,o.features),rt.geojson(o)})),a={id:this.mapConfigs.id,source:i,layers:qt.geojsonGeom(n,r)};if(this.initMap(a),t){let e=`gaode-satellite`;this.map.on(`load`,()=>{this.map.addSource(e,{type:`raster`,tiles:[`https://wprd03.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=6&x={x}&y={y}&z={z}`],tileSize:256,maxzoom:18}),this.map.addLayer({id:`gaode-satellite-layer`,type:`raster`,source:e})})}let o=e.find(e=>e.name===`track`)?.data;if(o){let e=D(o);this.map.fitBounds([[e[0],e[1]],[e[2],e[3]]],{padding:100,maxZoom:15,duration:0})}Vs.geojson(this)}async createMixGeoJsonGeomMap(e,t=!0){if(e.length===0)return;let n=await Promise.all(e.map(async e=>{if(e.type===`region`){let t=e.geojsonData.map(e=>e.name),n=t.map(t=>`geojson_region_${e.code}_${t}`);this.mixingMapConfigs.set(e.code,{id:`geojson_${e.code}`,layers:t,sourceLayers:n,type:`region`});let r=await Promise.all(e.geojsonData.map(async(t,r)=>{let i=n[r],a=t.name;if(this.map.getSource(i))return;let o=t.data,s;return typeof o==`string`?(s=await(await fetch(o)).json(),Xs(a,s)):(s=o,Xs(a,s)),this.layerFeaturesCache.set(`${e.code}_${a}`,s.features),rt.geojson(s)}));return{id:`geojson_${e.code}`,source:r,layers:qt.geojsonGeom(t,n)}}else{let t=e.geojsonData.map(e=>e.name),n=t.map(t=>`geojson_station_${e.code}_${t}`);this.mixingMapConfigs.set(e.code,{id:`geojson_${e.code}`,layers:t,sourceLayers:n,type:`station`});let r=await Promise.all(e.geojsonData.map(async(t,r)=>{let i=n[r],a=t.name;if(this.map.getSource(i))return;let o=t.data,s;return typeof o==`string`?(s=await(await fetch(o)).json(),Xs(a,s)):(s=o,Xs(a,s)),this.layerFeaturesCache.set(`${e.code}_${a}`,s.features),rt.geojson(s)}));return{id:`geojson_${e.code}`,source:r,layers:qt.geojsonGeom(t,n)}}}));if(this.initMixMap(n),t){let e=`gaode-satellite`;this.map.on(`load`,()=>{this.map.addSource(e,{type:`raster`,tiles:[`https://wprd03.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=6&x={x}&y={y}&z={z}`],tileSize:256,maxzoom:18}),this.map.addLayer({id:`gaode-satellite-layer`,type:`raster`,source:e})})}let r=e[1].geojsonData.find(e=>e.name===`track`)?.data;if(r){let e=D(r);this.map.fitBounds([[e[0],e[1]],[e[2],e[3]]],{padding:100,maxZoom:15,duration:0})}Vs.geojson(this)}async createGeoJsonStationMap(e){let t=e.map(e=>e.name),n=t.map(e=>`geojson_${e}`);this.mapConfigs=Hs.geojson(`geojson`),this.mapConfigs.layers=t,this.mapConfigs.sourceLayers=n;let r=await Promise.all(e.map(async(e,t)=>{let r=n[t],i=e.name;if(this.map.getSource(r))return;let a=e.data,o;return typeof a==`string`?(o=Ys(await(await fetch(a)).json()),Xs(i,o)):(o=Ys(a),Xs(i,o)),this.layerFeaturesCache.set(i,o.features),rt.geojson(o)})),i={id:this.mapConfigs.id,source:r,layers:qt.geojson(t,n)};this.initMap(i);let a=e.find(e=>e.name===`track`)?.data;if(a){let e=D(Ys(a));this.map.fitBounds([[e[0],e[1]],[e[2],e[3]]],{padding:100,maxZoom:15,duration:0})}Vs.geojson(this)}async createGeoJsonRegionMap(e,t){let n=t.map(e=>e.name),r=n.map(t=>`geojson_region_${e}_${t}`);this.mixingMapConfigs.set(e,{id:`geojson_${e}`,layers:n,sourceLayers:r,type:`region`});let i=await Promise.all(t.map(async(e,t)=>{let n=r[t],i=e.name;if(this.map.getSource(n))return;let a=e.data,o;return typeof a==`string`?(o=Ys(await(await fetch(a)).json()),Xs(i,o)):(o=Ys(a),Xs(i,o)),this.layerFeaturesCache.set(i,o.features),rt.geojson(o)})),a={id:`geojson_${e}`,source:i,layers:qt.geojson(n,r)};this.initMap(a,!0);let o=t.find(e=>e.name===`track`)?.data;if(o){let e=D(Ys(o));this.map.fitBounds([[e[0],e[1]],[e[2],e[3]]],{padding:100,maxZoom:15,duration:0})}Vs.geojson(this)}async createMixGeoJsonMap(e){if(e.length===0)return;let t=await Promise.all(e.map(async e=>{if(e.type===`region`){let t=e.geojsonData.map(e=>e.name),n=t.map(t=>`geojson_region_${e.code}_${t}`);this.mixingMapConfigs.set(e.code,{id:`geojson_${e.code}`,layers:t,sourceLayers:n,type:`region`});let r=await Promise.all(e.geojsonData.map(async(t,r)=>{let i=n[r],a=t.name;if(this.map.getSource(i))return;let o=t.data,s;return typeof o==`string`?(s=Ys(await(await fetch(o)).json()),Xs(a,s)):(s=Ys(o),Xs(a,s)),this.layerFeaturesCache.set(`${e.code}_${a}`,s.features),rt.geojson(s)}));return{id:`geojson_${e.code}`,source:r,layers:qt.geojson(t,n)}}else{let t=e.geojsonData.map(e=>e.name),n=t.map(t=>`geojson_station_${e.code}_${t}`);this.mixingMapConfigs.set(e.code,{id:`geojson_${e.code}`,layers:t,sourceLayers:n,type:`station`});let r=await Promise.all(e.geojsonData.map(async(t,r)=>{let i=n[r],a=t.name;if(this.map.getSource(i))return;let o=t.data,s;return typeof o==`string`?(s=Ys(Zs(await(await fetch(o)).json(),e.deltaInfo?.deltax||0,e.deltaInfo?.deltay||0)),Xs(a,s)):(s=Ys(Zs(o,e.deltaInfo?.deltax||0,e.deltaInfo?.deltay||0)),Xs(a,s)),this.layerFeaturesCache.set(`${e.code}_${a}`,s.features),rt.geojson(s)}));return{id:`geojson_${e.code}`,source:r,layers:qt.geojson(t,n)}}}));this.initMixMap(t);let n=e[1].geojsonData.find(e=>e.name===`track`)?.data;if(n){let e=D(Ys(n));this.map.fitBounds([[e[0],e[1]],[e[2],e[3]]],{padding:100,maxZoom:15,duration:0})}}createRasterMap(e){this.mapConfigs=Hs.raster(e);let t=rt.raster(this.mapConfigs.sourceUrl),n=qt.raster(this.mapConfigs.id),r={id:this.mapConfigs.id,source:t,layers:n};this.initMap(r)}createEncryptedRasterMap(e){Ws(this),this.mapConfigs=Hs.raster(e);let t=rt.raster(this.mapConfigs.sourceUrl),n=qt.raster(this.mapConfigs.id),r={id:this.mapConfigs.id,source:t,layers:n};this.initMap(r)}createRAGEMap(e,t,n){let r=[`track`,`signal`,`bumper`,`prevention`];Ws(this);let i=Hs.rage(e,t,n,r);this.mapConfigs=i;let a=rt.geom(i.sourceUrl),o=rt.raster(i.subSourceUrl),s=qt.geom(i),c=[...qt.raster(i.subSourceId),...s],l={id:i.id,source:a,subSourceId:i.subSourceId,subSource:o,layers:c};this.initMap(l)}getMap(){return this.map}getMapConfigs(){return this.mapConfigs}destroy(){this._activeBlinkCleanup?.(),this._activeBlinkCleanup=null,this.stashFeatures.clear(),this.layerFeaturesCache.clear(),this.mixingMapConfigs.clear(),this.map.remove()}async stashMixMapAllFeature(){if(this.mixingMapConfigs.size!==0)for(let[e,t]of this.mixingMapConfigs){let n=t.type,r=t.layers??[];await Promise.all(r.map(async t=>{let r=`geojson_${n}_${e}_${t}`,i=this.map.getSource(r);i&&(await i.getData()).features?.forEach(e=>{let t=e.properties?.code;t&&!this.stashFeatures.get(t)&&this.stashFeatures.set(t,{sourceLayer:r,properties:e.properties})})}))}}async stashAllFeature(){if(!this.mapConfigs)return;let e=this.mapConfigs.sourceLayers,t=this.mapConfigs.layers??[],n=this.mapConfigs.id;this.stashFeatures.clear(),e?.forEach((e,r)=>{if(e.includes(`prevention`))return;let i=this.map.querySourceFeatures(n,{sourceLayer:e}),a=new Map;i.forEach(t=>{let n=t.properties?.code;n&&(this.stashFeatures.set(n,{sourceLayer:e}),a.set(String(n),t))});let o=t[r];o&&this.layerFeaturesCache.set(o,Array.from(a.values()))}),await Promise.all(t.map(async e=>{let t=`geojson_${e}`,n=this.map.getSource(t);if(!n)return;let r=await n.getData(),i=r.features??[];r.features?.forEach(e=>{let n=e.properties?.code;n&&!this.stashFeatures.get(n)&&this.stashFeatures.set(n,{sourceLayer:t,properties:e.properties})}),i.length&&this.layerFeaturesCache.set(e,i)}))}updateFeatureState(e,t){let n=this.stashFeatures.get(e);if(n)if(Object.assign(n,t),n.sourceLayer?.startsWith(`geojson_`))this.map.setFeatureState({source:n.sourceLayer,id:e},n);else{if(!this.mapConfigs)return;this.map.setFeatureState({source:this.mapConfigs.id,sourceLayer:n.sourceLayer,id:e},n)}}getFeatureState(e){let t=this.stashFeatures.get(e);if(t)return t}locateGeojsonFeature(e,t=!0){let n=D(t?Ys(e):e);this.map.fitBounds([[n[0],n[1]],[n[2],n[3]]],{padding:50,maxZoom:18})}queryGeojsonFeatures(e){let t=Array.from(this.layerFeaturesCache.keys()).filter(t=>t.endsWith(e));return t.length?t.flatMap(e=>this.layerFeaturesCache.get(e)??[]):[]}getTrackCircuitFeaturesByCodes(e){let t=Array.from(this.layerFeaturesCache.keys()).filter(e=>e.endsWith(`track_circuit`));return t.length?t.flatMap(e=>this.layerFeaturesCache.get(e)??[]).filter(t=>e.includes(t.properties.code))??[]:[]}getGeojsonLayerFeaturesByCode(e,t){let n=Array.from(this.layerFeaturesCache.keys()).filter(e=>e.endsWith(t));if(n.length)return n.flatMap(e=>this.layerFeaturesCache.get(e)??[]).find(t=>t.properties.code===e)}locateFeatureByCode(e,t){let n=this.getGeojsonLayerFeaturesByCode(e,t);if(!n){console.warn(`未找到要素,无法定位: code=${e}, layerType=${t}`);return}let r={type:`FeatureCollection`,features:[n]};this.locateGeojsonFeature(r,!1)}smoothBlinkFeature(e,t,n={}){let r=this.getGeojsonLayerFeaturesByCode(e,t);if(!r)return console.warn(`未找到要素,无法高亮: code=${e}, layerType=${t}`),()=>{};let i={type:`FeatureCollection`,features:[r]},a=[`signal`,`switch`,`bumper`].includes(t)?`point`:`line`,o=`blink-temp-${e}-${t}`;this._activeBlinkCleanup?.(),this._activeBlinkCleanup=null,this.map.getSource(o)&&this.map.removeSource(o),this.map.addSource(o,{type:`geojson`,data:i});let s=`${o}-blink-highlight`,{duration:c=3e3,blinkSpeed:l=500,baseColor:u=[0,255,0],minAlpha:d=.3,maxAlpha:f=.7,strokeWidthBase:p=3,strokeWidthRange:m=2}=n,h=null,g=null;if(a===`point`){let e=`blink-point-icon-${o}`;if(!this.map.hasImage(e)){let t=document.createElement(`canvas`);t.width=36,t.height=36;let n=t.getContext(`2d`);n.beginPath(),n.arc(36/2,36/2,36/2-2,0,Math.PI*2),n.fillStyle=`rgba(${u.join(`,`)}, 0.3)`,n.fill(),n.beginPath(),n.arc(36/2,36/2,36/3,0,Math.PI*2),n.fillStyle=`rgb(${u.join(`,`)})`,n.fill(),n.strokeStyle=`#fff`,n.lineWidth=2,n.stroke();let r=n.getImageData(0,0,36,36);this.map.addImage(e,{width:36,height:36,data:r.data})}this.map.getLayer(s)&&this.map.removeLayer(s),this.map.addLayer({id:s,type:`symbol`,source:o,layout:{"icon-image":e,"icon-allow-overlap":!0,"icon-ignore-placement":!0},paint:{"icon-opacity":f}});let t=e=>{h||=e;let n=e-h;if(n<c){let e=Math.sin(n/l*Math.PI*2)*.5+.5,r=d+(f-d)*e;this.map.setPaintProperty(s,`icon-opacity`,r),g=requestAnimationFrame(t)}else this.map.getLayer(s)&&this.map.removeLayer(s),this.map.getSource(o)&&this.map.removeSource(o),g=null,this._activeBlinkCleanup=null};g=requestAnimationFrame(t);let n=()=>{g&&cancelAnimationFrame(g),this.map.getLayer(s)&&this.map.removeLayer(s),this.map.getSource(o)&&this.map.removeSource(o)};return this._activeBlinkCleanup=n,n}let _=`${s}-outline`;this.map.getLayer(_)&&this.map.removeLayer(_),this.map.addLayer({id:_,type:`line`,source:o,paint:{"line-color":`rgb(${u.join(`,`)})`,"line-width":p}});let v=e=>{h||=e;let t=e-h;if(t<c){let e=Math.sin(t/l*Math.PI*2)*.5+.5;d+(f-d)*e;let n=p+m*e;this.map.setPaintProperty(_,`line-width`,n),g=requestAnimationFrame(v)}else this.map.getLayer(_)&&this.map.removeLayer(_),this.map.getSource(o)&&this.map.removeSource(o),g=null,this._activeBlinkCleanup=null};g=requestAnimationFrame(v);let y=()=>{g&&cancelAnimationFrame(g),this.map.getLayer(_)&&this.map.removeLayer(_),this.map.getSource(o)&&this.map.removeSource(o)};return this._activeBlinkCleanup=y,y}};e.TeeeMap=oc,e.default=oc,e.transformGeoJsonFrom3857=Ys});
|
|
1284
|
+
`,document.head.appendChild(t)}getSource(e){return this.map.getSource(e)}startDistance(){this.reset(),this.active=!0,this.map.getCanvas().style.cursor=`default`,this.map.doubleClickZoom.enable(),this.tooltipEle=document.createElement(`div`),this.tooltipEle.setAttribute(`class`,`measure-result`),this.tooltip=new l.default.Marker({element:this.tooltipEle,anchor:`left`,offset:[8,0]}).setLngLat([0,0]).addTo(this.map),this.map.getSource(`points`)||(this.map.addSource(`points`,{type:`geojson`,data:this.jsonPoint}),this.map.addSource(`line`,{type:`geojson`,data:this.jsonLine}),this.map.addSource(`line-move`,{type:`geojson`,data:this.jsonLine}),this.map.addLayer({id:`line-move`,type:`line`,source:`line-move`,paint:{"line-color":`#ff0000`,"line-width":3,"line-dasharray":[2,2]}}),this.map.addLayer({id:`line`,type:`line`,source:`line`,paint:{"line-color":`#ff0000`,"line-width":3,"line-dasharray":[2,2]}}),this.map.addLayer({id:`points`,type:`circle`,source:`points`,paint:{"circle-color":`#ff0000`,"circle-radius":4,"circle-stroke-width":2,"circle-stroke-color":`#1677ff`}})),this.bindDistanceEvents()}bindDistanceEvents(){this.map.__isPlacingLoco=!0,this._onClick=e=>{if(!this.active)return;let t=[e.lngLat.lng,e.lngLat.lat];this.addMeasureRes(t),this.addDistancePoint(t),this.points.push(t)},this._onMousemove=e=>{if(!this.active)return;let t=[e.lngLat.lng,e.lngLat.lat];if(this.jsonPoint.features.length>0){let e=this.jsonPoint.features[this.jsonPoint.features.length-1].geometry.coordinates;this.getSource(`line-move`).setData({type:`Feature`,properties:{},geometry:{type:`LineString`,coordinates:[e,t]}}),this.tooltipEle.innerHTML=this.getLength(t)}else this.tooltipEle.innerHTML=`点击地图开始测量,右键结束测量`;this.tooltip.setLngLat(t)},this._onContextmenu=e=>{if(this.map.__isPlacingLoco=!1,!this.active)return;let t=[e.lngLat.lng,e.lngLat.lat];this.addDistancePoint(t),this.active=!1,this.map.getCanvas().style.cursor=``;let n=this.getLength(t);this.tooltipEle.innerHTML=`<span>${n}</span><span class="measure-close">×</span>`,this.tooltip.setLngLat(t);let r=this.tooltipEle.querySelector(`.measure-close`);r.onclick=e=>{e.stopPropagation(),this.map.doubleClickZoom.enable(),this.clear()}},this.map.on(`click`,this._onClick),this.map.on(`mousemove`,this._onMousemove),this.map.on(`contextmenu`,this._onContextmenu)}addDistancePoint(e){if(this.jsonPoint.features.length>0){let t=this.jsonPoint.features[this.jsonPoint.features.length-1].geometry.coordinates;this.jsonLine.features.push({type:`Feature`,properties:{},geometry:{type:`LineString`,coordinates:[t,e]}}),this.getSource(`line`).setData(this.jsonLine)}this.jsonPoint.features.push({type:`Feature`,properties:{},geometry:{type:`Point`,coordinates:e}}),this.getSource(`points`).setData(this.jsonPoint)}addMeasureRes(e){let t=document.createElement(`div`);t.setAttribute(`class`,`measure-result`),t.innerHTML=String(this.points.length===0?`起点`:this.getLength(e));let n=new l.default.Marker({element:t,anchor:`left`,offset:[8,0]}).setLngLat(e).addTo(this.map);this.markers.push(n)}getLength(e){let t=ic(h(this.points.concat([e])));return t<1?(t=Number((t*1e3).toFixed(4)),t+`m`):(t=Number(t.toFixed(4)),t+`km`)}startArea(){this.reset(),this.active=!0,this.map.doubleClickZoom.disable(),this.map.getCanvas().style.cursor=`default`,this.tooltipEle=document.createElement(`div`),this.tooltipEle.setAttribute(`class`,`measure-result`),this.tooltip=new l.default.Marker({element:this.tooltipEle,anchor:`left`,offset:[8,0]}).setLngLat([0,0]).addTo(this.map),this.map.getSource(`points-area`)||(this.map.addSource(`points-area`,{type:`geojson`,data:this.jsonPoint}),this.map.addSource(`line-area`,{type:`geojson`,data:this.jsonLine}),this.map.addLayer({id:`line-area`,type:`fill`,source:`line-area`,paint:{"fill-color":`#ff0000`,"fill-opacity":.1}}),this.map.addLayer({id:`line-area-stroke`,type:`line`,source:`line-area`,paint:{"line-color":`#ff0000`,"line-width":3,"line-dasharray":[2,2]}}),this.map.addLayer({id:`points-area`,type:`circle`,source:`points-area`,paint:{"circle-color":`#ff0000`,"circle-radius":4,"circle-stroke-width":2,"circle-stroke-color":`#1677ff`}})),this.bindAreaEvents()}bindAreaEvents(){this.map.__isPlacingLoco=!0,this._onClick=e=>{if(!this.active)return;let t=[e.lngLat.lng,e.lngLat.lat];this.points.push(t),this.addAreaPoint(t)},this._onContextmenu=e=>{if(this.map.__isPlacingLoco=!1,!this.active)return;let t=[e.lngLat.lng,e.lngLat.lat];this.points.push(t),this.active=!1,this.tooltipEle.innerHTML=`<span>${this.getArea(t)}</span><span class="measure-close">×</span>`,this.tooltip.setLngLat(t);let n=this.tooltipEle.querySelector(`.measure-close`);n.onclick=e=>{e.stopPropagation(),this.map.doubleClickZoom.enable(),this.clear()}},this._onMousemove=e=>{if(!this.active)return;let t=[e.lngLat.lng,e.lngLat.lat],n=this.jsonPoint.features.length;if(n===0)this.tooltipEle.innerHTML=`点击地图开始测量,右键结束测量`;else if(n===1)this.tooltipEle.innerHTML=`点击地图继续测量,右键结束测量`;else{let e=this.points.concat([t]).concat([this.points[0]]);this.getSource(`line-area`).setData({type:`Feature`,properties:{},geometry:{type:`Polygon`,coordinates:[e]}}),this.tooltipEle.innerHTML=this.getArea(t)}this.tooltip.setLngLat(t)},this.map.on(`click`,this._onClick),this.map.on(`contextmenu`,this._onContextmenu),this.map.on(`mousemove`,this._onMousemove)}addAreaPoint(e){this.jsonPoint.features.push({type:`Feature`,properties:{},geometry:{type:`Point`,coordinates:e}}),this.getSource(`points-area`).setData(this.jsonPoint)}getArea(e){let t=Qs(m([this.points.concat([e]).concat([this.points[0]])]));return t<1e3?(t=Number(t.toFixed(4)),t+`m²`):(t=Number((t/1e6).toFixed(4)),t+`km²`)}reset(){this.clear(),this.active=!1,this.jsonPoint={type:`FeatureCollection`,features:[]},this.jsonLine={type:`FeatureCollection`,features:[]},this.points=[],this.markers=[],this.tooltip&&=(this.tooltip.remove(),null)}clear(){this._onClick&&this.map.off(`click`,this._onClick),this._onMousemove&&this.map.off(`mousemove`,this._onMousemove),this._onContextmenu&&this.map.off(`contextmenu`,this._onContextmenu),this._onClick=null,this._onMousemove=null,this._onContextmenu=null,document.querySelectorAll(`.measure-result`).forEach(e=>e.remove()),this.markers.forEach(e=>e.remove()),this.markers=[],[`points`,`line`,`line-move`].forEach(e=>{this.map.getLayer(e)&&this.map.removeLayer(e),this.map.getSource(e)&&this.map.removeSource(e)}),[`points-area`,`line-area-stroke`,`line-area`].forEach(e=>{this.map.getLayer(e)&&this.map.removeLayer(e),this.map.getSource(e)&&this.map.removeSource(e)})}},oc=class{map;mapDir=`left`;mapConfigs;mixingMapConfigs=new Map;stashFeatures=new Map;layerFeaturesCache=new Map;_activeBlinkCleanup=null;constructor(e){let t={version:8,sources:{},layers:[]};this.map=new l.default.Map({container:e,style:t,center:[0,0],zoom:14,attributionControl:!1,maxZoom:24}),Vs.base(this),this.map.on(`load`,()=>{this.cursorTool=new Vs.cursor(this.map),this.drawTool=new Vs.draw(this),this.injectTeeeGeoJson=Vs.injectTeeeGeoJson,this.snaps=new Vs.snaps(this),this.drawRoute=new Vs.drawRoute(this)})}initMap(e,t=!1){let n=async()=>{try{if(console.log(`开始构建业务地图: ${e.id}`),Array.isArray(e.source))if(t){let{sourceLayers:t}=this.mixingMapConfigs.get(e.id.split(`_`)[1]);if(!t)return;e.source.forEach((e,n)=>{this.map.addSource(t[n],e)})}else{let{sourceLayers:t}=this.mapConfigs;if(!t)return;e.source.forEach((e,n)=>{this.map.addSource(t[n],e)})}else this.map.getSource(e.id)?console.warn(`地图源已存在,跳过添加: ${e.id}`):this.map.addSource(e.id,e.source);e.subSourceId&&e.subSource&&(this.map.getSource(e.subSourceId)?console.warn(`地图源已存在,跳过添加: ${e.subSourceId}`):this.map.addSource(e.subSourceId,e.subSource));let n=await R();console.log(`图标列表 (${n.length}):`,n),n.forEach(e=>{this.map.hasImage(e.id)?console.warn(`图标已存在,跳过添加: ${e.id}`):this.map.addImage(e.id,e.image)}),e.layers&&e.layers.forEach(e=>{this.map.getLayer(e.id)?console.debug(`图层已存在: ${e.id}`):this.map.addLayer(e)}),this.layerTree=new Bs(this.map,e.id),this.measureTool=new ac(this.map);let r=this.map.getStyle()?.sources??{},i=Object.keys(r);console.log(`源列表 (${i.length}):`,i,r);let a=this.map.getStyle().layers??[],o=a.map(e=>e.id);console.log(`图层列表 (${o.length}):`,a),this.map.listImages();let s=this.layerFeaturesCache.get(`track`)?.[0]??null;if(s){let e=s.geometry;this.mapDir=e.coordinates[0][0]-e.coordinates[1][0]>0?`left`:`right`}console.groupEnd(),console.log(`地图构建全部完成: ${e.id}`)}catch(t){console.error(`地图初始化失败: ${e.id}`,t),t instanceof Error&&console.error(`错误详情: ${t.message}`)}},r=()=>{this.map.once(`idle`,()=>{t?this.stashMixMapAllFeature():this.stashAllFeature()})};this.map.loaded()?n().then(r):this.map.on(`load`,()=>{n().then(r)})}async initMixMap(e){let t=async()=>{let t=await R();console.log(`图标列表 (${t.length}):`,t),t.forEach(e=>{this.map.hasImage(e.id)?console.warn(`图标已存在,跳过添加: ${e.id}`):this.map.addImage(e.id,e.image)});for(let t of e){if(Array.isArray(t.source)){let{sourceLayers:e}=this.mixingMapConfigs.get(t.id.split(`_`)[1]);if(!e)continue;t.source.forEach((t,n)=>{this.map.addSource(e[n],t)})}else this.map.getSource(t.id)?console.warn(`地图源已存在,跳过添加: ${t.id}`):this.map.addSource(t.id,t.source);t.layers&&t.layers.forEach(e=>{this.map.getLayer(e.id)?console.debug(`图层已存在: ${e.id}`):this.map.addLayer(e)})}this.measureTool=new ac(this.map);let n=this.map.getStyle()?.sources??{},r=Object.keys(n);console.log(`源列表 (${r.length}):`,r,n);let i=this.map.getStyle().layers??[],a=i.map(e=>e.id);console.log(`图层列表 (${a.length}):`,i);let o=r.filter(e=>e.endsWith(`_background`));a.filter(e=>e.endsWith(`_background`)).slice(1).forEach(e=>{this.map.getLayer(e)&&this.map.removeLayer(e)}),o.slice(1).forEach(e=>{this.map.getSource(e)&&this.map.removeSource(e)});let s=e[0],c=this.layerFeaturesCache.get(s.id.split(`_`)[1]+`_track`)?.[0]??null;if(c){let e=c.geometry;this.mapDir=e.coordinates[0][0]-e.coordinates[1][0]>0?`left`:`right`}this.stashMixMapAllFeature(),Vs.geojson(this)};this.map.loaded()?t():this.map.on(`load`,()=>{t()})}createCTCMap(e,t,n){let r=Hs.ctc(e,t,n);this.mapConfigs=r;let i=rt.graph(r.sourceUrl),a=qt.ctc(r),o={id:this.mapConfigs.id,source:i,layers:a};this.initMap(o),this.ctcTool=new Vs.ctc(this),this.ctcMenu=new Vs.ctcMenu(this),this.ctcClick=new Vs.ctcClick(this),this.ctcHoverTool=new Vs.ctcHover(this),this.sgfhqyTool=new Vs.sgfhqy(this),this.doorTool=new Vs.door(this)}createCTCEncryptedMap(e,t,n){Ws(this),this.mapConfigs=Hs.ctc(e,t,n);let r=rt.graph(this.mapConfigs.sourceUrl),i=qt.ctc(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a),this.ctcTool=new Vs.ctc(this),this.ctcMenu=new Vs.ctcMenu(this),this.ctcClick=new Vs.ctcClick(this),this.ctcHoverTool=new Vs.ctcHover(this),this.sgfhqyTool=new Vs.sgfhqy(this),this.doorTool=new Vs.door(this)}createRSWPMap(e){let t=Hs.rswp(e),n=rt.raster(t.sourceUrl),r=qt.raster(t.id),i=Hs.geojson(`rswp-geojson`),a=rt.geojson(),o={id:t.id,source:n,subSourceId:i.id,subSource:a,layers:r};this.mapConfigs=t,this.mapConfigs.subSourceId=i.id,this.initMap(o)}createGraphMap(e,t,n){this.mapConfigs=Hs.graph(e,t,n);let r=rt.graph(this.mapConfigs.sourceUrl),i=qt.graph(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a),Vs.graph(this)}createGraphEncryptedMap(e,t,n){Ws(this),this.mapConfigs=Hs.graph(e,t,n);let r=rt.graph(this.mapConfigs.sourceUrl),i=qt.ctc(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a),this.ctcTool=new Vs.ctc(this),this.ctcMenu=new Vs.ctcMenu(this),this.ctcClick=new Vs.ctcClick(this)}createGeomMap(e,t,n){this.mapConfigs=Hs.geom(e,t,n);let r=rt.geom(this.mapConfigs.sourceUrl),i=qt.geom(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a)}createGeomEncryptedMap(e,t,n){Ws(this),this.mapConfigs=Hs.geom(e,t,n);let r=rt.geom(this.mapConfigs.sourceUrl),i=qt.geom(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a)}async createGeoJsonGeomStationMap(e,t=!0){let n=e.map(e=>e.name),r=n.map(e=>`geojson_${e}`);this.mapConfigs=Hs.geojson(`geojson`),this.mapConfigs.layers=n,this.mapConfigs.sourceLayers=r;let i=await Promise.all(e.map(async(e,t)=>{let n=r[t],i=e.name;if(this.map.getSource(n))return;let a=e.data,o;return typeof a==`string`?(o=await(await fetch(a)).json(),Xs(i,o)):(o=a,Xs(i,o)),this.layerFeaturesCache.set(i,o.features),rt.geojson(o)})),a={id:this.mapConfigs.id,source:i,layers:qt.geojsonGeom(n,r)};if(this.initMap(a),t){let e=`gaode-satellite`;this.map.on(`load`,()=>{this.map.addSource(e,{type:`raster`,tiles:[`https://wprd03.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=6&x={x}&y={y}&z={z}`],tileSize:256,maxzoom:18}),this.map.addLayer({id:`gaode-satellite-layer`,type:`raster`,source:e})})}let o=e.find(e=>e.name===`track`)?.data;if(o){let e=D(o);this.map.fitBounds([[e[0],e[1]],[e[2],e[3]]],{padding:100,maxZoom:15,duration:0})}Vs.geojson(this)}async createMixGeoJsonGeomMap(e,t=!0){if(e.length===0)return;let n=await Promise.all(e.map(async e=>{if(e.type===`region`){let t=e.geojsonData.map(e=>e.name),n=t.map(t=>`geojson_region_${e.code}_${t}`);this.mixingMapConfigs.set(e.code,{id:`geojson_${e.code}`,layers:t,sourceLayers:n,type:`region`});let r=await Promise.all(e.geojsonData.map(async(t,r)=>{let i=n[r],a=t.name;if(this.map.getSource(i))return;let o=t.data,s;return typeof o==`string`?(s=await(await fetch(o)).json(),Xs(a,s)):(s=o,Xs(a,s)),this.layerFeaturesCache.set(`${e.code}_${a}`,s.features),rt.geojson(s)}));return{id:`geojson_${e.code}`,source:r,layers:qt.geojsonGeom(t,n)}}else{let t=e.geojsonData.map(e=>e.name),n=t.map(t=>`geojson_station_${e.code}_${t}`);this.mixingMapConfigs.set(e.code,{id:`geojson_${e.code}`,layers:t,sourceLayers:n,type:`station`});let r=await Promise.all(e.geojsonData.map(async(t,r)=>{let i=n[r],a=t.name;if(this.map.getSource(i))return;let o=t.data,s;return typeof o==`string`?(s=await(await fetch(o)).json(),Xs(a,s)):(s=o,Xs(a,s)),this.layerFeaturesCache.set(`${e.code}_${a}`,s.features),rt.geojson(s)}));return{id:`geojson_${e.code}`,source:r,layers:qt.geojsonGeom(t,n)}}}));if(this.initMixMap(n),t){let e=`gaode-satellite`;this.map.on(`load`,()=>{this.map.addSource(e,{type:`raster`,tiles:[`https://wprd03.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=6&x={x}&y={y}&z={z}`],tileSize:256,maxzoom:18}),this.map.addLayer({id:`gaode-satellite-layer`,type:`raster`,source:e})})}let r=e[1].geojsonData.find(e=>e.name===`track`)?.data;if(r){let e=D(r);this.map.fitBounds([[e[0],e[1]],[e[2],e[3]]],{padding:100,maxZoom:15,duration:0})}Vs.geojson(this)}async createGeoJsonStationMap(e){let t=e.map(e=>e.name),n=t.map(e=>`geojson_${e}`);this.mapConfigs=Hs.geojson(`geojson`),this.mapConfigs.layers=t,this.mapConfigs.sourceLayers=n;let r=await Promise.all(e.map(async(e,t)=>{let r=n[t],i=e.name;if(this.map.getSource(r))return;let a=e.data,o;return typeof a==`string`?(o=Ys(await(await fetch(a)).json()),Xs(i,o)):(o=Ys(a),Xs(i,o)),this.layerFeaturesCache.set(i,o.features),rt.geojson(o)})),i={id:this.mapConfigs.id,source:r,layers:qt.geojson(t,n)};this.initMap(i);let a=e.find(e=>e.name===`track`)?.data;if(a){let e=D(Ys(a));this.map.fitBounds([[e[0],e[1]],[e[2],e[3]]],{padding:100,maxZoom:15,duration:0})}Vs.geojson(this)}async createGeoJsonRegionMap(e,t){let n=t.map(e=>e.name),r=n.map(t=>`geojson_region_${e}_${t}`);this.mixingMapConfigs.set(e,{id:`geojson_${e}`,layers:n,sourceLayers:r,type:`region`});let i=await Promise.all(t.map(async(e,t)=>{let n=r[t],i=e.name;if(this.map.getSource(n))return;let a=e.data,o;return typeof a==`string`?(o=Ys(await(await fetch(a)).json()),Xs(i,o)):(o=Ys(a),Xs(i,o)),this.layerFeaturesCache.set(i,o.features),rt.geojson(o)})),a={id:`geojson_${e}`,source:i,layers:qt.geojson(n,r)};this.initMap(a,!0);let o=t.find(e=>e.name===`track`)?.data;if(o){let e=D(Ys(o));this.map.fitBounds([[e[0],e[1]],[e[2],e[3]]],{padding:100,maxZoom:15,duration:0})}Vs.geojson(this)}async createMixGeoJsonMap(e){if(e.length===0)return;let t=await Promise.all(e.map(async e=>{if(e.type===`region`){let t=e.geojsonData.map(e=>e.name),n=t.map(t=>`geojson_region_${e.code}_${t}`);this.mixingMapConfigs.set(e.code,{id:`geojson_${e.code}`,layers:t,sourceLayers:n,type:`region`});let r=await Promise.all(e.geojsonData.map(async(t,r)=>{let i=n[r],a=t.name;if(this.map.getSource(i))return;let o=t.data,s;return typeof o==`string`?(s=Ys(await(await fetch(o)).json()),Xs(a,s)):(s=Ys(o),Xs(a,s)),this.layerFeaturesCache.set(`${e.code}_${a}`,s.features),rt.geojson(s)}));return{id:`geojson_${e.code}`,source:r,layers:qt.geojson(t,n)}}else{let t=e.geojsonData.map(e=>e.name),n=t.map(t=>`geojson_station_${e.code}_${t}`);this.mixingMapConfigs.set(e.code,{id:`geojson_${e.code}`,layers:t,sourceLayers:n,type:`station`});let r=await Promise.all(e.geojsonData.map(async(t,r)=>{let i=n[r],a=t.name;if(this.map.getSource(i))return;let o=t.data,s;return typeof o==`string`?(s=Ys(Zs(await(await fetch(o)).json(),e.deltaInfo?.deltax||0,e.deltaInfo?.deltay||0)),Xs(a,s)):(s=Ys(Zs(o,e.deltaInfo?.deltax||0,e.deltaInfo?.deltay||0)),Xs(a,s)),this.layerFeaturesCache.set(`${e.code}_${a}`,s.features),rt.geojson(s)}));return{id:`geojson_${e.code}`,source:r,layers:qt.geojson(t,n)}}}));this.initMixMap(t);let n=e[1].geojsonData.find(e=>e.name===`track`)?.data;if(n){let e=D(Ys(n));this.map.fitBounds([[e[0],e[1]],[e[2],e[3]]],{padding:100,maxZoom:15,duration:0})}}createRasterMap(e){this.mapConfigs=Hs.raster(e);let t=rt.raster(this.mapConfigs.sourceUrl),n=qt.raster(this.mapConfigs.id),r={id:this.mapConfigs.id,source:t,layers:n};this.initMap(r)}createEncryptedRasterMap(e){Ws(this),this.mapConfigs=Hs.raster(e);let t=rt.raster(this.mapConfigs.sourceUrl),n=qt.raster(this.mapConfigs.id),r={id:this.mapConfigs.id,source:t,layers:n};this.initMap(r)}createRAGEMap(e,t,n){let r=[`track`,`signal`,`bumper`,`prevention`];Ws(this);let i=Hs.rage(e,t,n,r);this.mapConfigs=i;let a=rt.geom(i.sourceUrl),o=rt.raster(i.subSourceUrl),s=qt.geom(i),c=[...qt.raster(i.subSourceId),...s],l={id:i.id,source:a,subSourceId:i.subSourceId,subSource:o,layers:c};this.initMap(l)}getMap(){return this.map}getMapConfigs(){return this.mapConfigs}destroy(){this._activeBlinkCleanup?.(),this._activeBlinkCleanup=null,this.stashFeatures.clear(),this.layerFeaturesCache.clear(),this.mixingMapConfigs.clear(),this.map.remove()}async stashMixMapAllFeature(){if(this.mixingMapConfigs.size!==0)for(let[e,t]of this.mixingMapConfigs){let n=t.type,r=t.layers??[];await Promise.all(r.map(async t=>{let r=`geojson_${n}_${e}_${t}`,i=this.map.getSource(r);i&&(await i.getData()).features?.forEach(e=>{let t=e.properties?.code;t&&!this.stashFeatures.get(t)&&this.stashFeatures.set(t,{sourceLayer:r,properties:e.properties})})}))}}async stashAllFeature(){if(!this.mapConfigs)return;let e=this.mapConfigs.sourceLayers,t=this.mapConfigs.layers??[],n=this.mapConfigs.id;this.stashFeatures.clear(),e?.forEach((e,r)=>{if(e.includes(`prevention`))return;let i=this.map.querySourceFeatures(n,{sourceLayer:e}),a=new Map;i.forEach(t=>{let n=t.properties?.code;n&&(this.stashFeatures.set(n,{sourceLayer:e}),a.set(String(n),t))});let o=t[r];o&&this.layerFeaturesCache.set(o,Array.from(a.values()))}),await Promise.all(t.map(async e=>{let t=`geojson_${e}`,n=this.map.getSource(t);if(!n)return;let r=await n.getData(),i=r.features??[];r.features?.forEach(e=>{let n=e.properties?.code;n&&!this.stashFeatures.get(n)&&this.stashFeatures.set(n,{sourceLayer:t,properties:e.properties})}),i.length&&this.layerFeaturesCache.set(e,i)}))}updateFeatureState(e,t){let n=this.stashFeatures.get(e);if(n)if(Object.assign(n,t),n.sourceLayer?.startsWith(`geojson_`))this.map.setFeatureState({source:n.sourceLayer,id:e},n);else{if(!this.mapConfigs)return;this.map.setFeatureState({source:this.mapConfigs.id,sourceLayer:n.sourceLayer,id:e},n)}}getFeatureState(e){let t=this.stashFeatures.get(e);if(t)return t}locateGeojsonFeature(e,t=!0){let n=D(t?Ys(e):e);this.map.fitBounds([[n[0],n[1]],[n[2],n[3]]],{padding:50,maxZoom:18})}queryGeojsonFeatures(e){let t=Array.from(this.layerFeaturesCache.keys()).filter(t=>t.endsWith(e));return t.length?t.flatMap(e=>this.layerFeaturesCache.get(e)??[]):[]}getTrackCircuitFeaturesByCodes(e){let t=Array.from(this.layerFeaturesCache.keys()).filter(e=>e.endsWith(`track_circuit`));return t.length?t.flatMap(e=>this.layerFeaturesCache.get(e)??[]).filter(t=>e.includes(t.properties.code))??[]:[]}getGeojsonLayerFeaturesByCode(e,t){let n=Array.from(this.layerFeaturesCache.keys()).filter(e=>e.endsWith(t));if(n.length)return n.flatMap(e=>this.layerFeaturesCache.get(e)??[]).find(t=>t.properties.code===e)}locateFeatureByCode(e,t){let n=this.getGeojsonLayerFeaturesByCode(e,t);if(!n){console.warn(`未找到要素,无法定位: code=${e}, layerType=${t}`);return}let r={type:`FeatureCollection`,features:[n]};this.locateGeojsonFeature(r,!1)}smoothBlinkFeature(e,t,n={}){let r=this.getGeojsonLayerFeaturesByCode(e,t);if(!r)return console.warn(`未找到要素,无法高亮: code=${e}, layerType=${t}`),()=>{};let i={type:`FeatureCollection`,features:[r]},a=[`signal`,`switch`,`bumper`].includes(t)?`point`:`line`,o=`blink-temp-${e}-${t}`;this._activeBlinkCleanup?.(),this._activeBlinkCleanup=null,this.map.getSource(o)&&this.map.removeSource(o),this.map.addSource(o,{type:`geojson`,data:i});let s=`${o}-blink-highlight`,{duration:c=3e3,blinkSpeed:l=500,baseColor:u=[0,255,0],minAlpha:d=.3,maxAlpha:f=.7,strokeWidthBase:p=3,strokeWidthRange:m=2}=n,h=null,g=null;if(a===`point`){let e=`blink-point-icon-${o}`;if(!this.map.hasImage(e)){let t=document.createElement(`canvas`);t.width=36,t.height=36;let n=t.getContext(`2d`);n.beginPath(),n.arc(36/2,36/2,36/2-2,0,Math.PI*2),n.fillStyle=`rgba(${u.join(`,`)}, 0.3)`,n.fill(),n.beginPath(),n.arc(36/2,36/2,36/3,0,Math.PI*2),n.fillStyle=`rgb(${u.join(`,`)})`,n.fill(),n.strokeStyle=`#fff`,n.lineWidth=2,n.stroke();let r=n.getImageData(0,0,36,36);this.map.addImage(e,{width:36,height:36,data:r.data})}this.map.getLayer(s)&&this.map.removeLayer(s),this.map.addLayer({id:s,type:`symbol`,source:o,layout:{"icon-image":e,"icon-allow-overlap":!0,"icon-ignore-placement":!0},paint:{"icon-opacity":f}});let t=e=>{h||=e;let n=e-h;if(n<c){let e=Math.sin(n/l*Math.PI*2)*.5+.5,r=d+(f-d)*e;this.map.setPaintProperty(s,`icon-opacity`,r),g=requestAnimationFrame(t)}else this.map.getLayer(s)&&this.map.removeLayer(s),this.map.getSource(o)&&this.map.removeSource(o),g=null,this._activeBlinkCleanup=null};g=requestAnimationFrame(t);let n=()=>{g&&cancelAnimationFrame(g),this.map.getLayer(s)&&this.map.removeLayer(s),this.map.getSource(o)&&this.map.removeSource(o)};return this._activeBlinkCleanup=n,n}let _=`${s}-outline`;this.map.getLayer(_)&&this.map.removeLayer(_),this.map.addLayer({id:_,type:`line`,source:o,paint:{"line-color":`rgb(${u.join(`,`)})`,"line-width":p}});let v=e=>{h||=e;let t=e-h;if(t<c){let e=Math.sin(t/l*Math.PI*2)*.5+.5;d+(f-d)*e;let n=p+m*e;this.map.setPaintProperty(_,`line-width`,n),g=requestAnimationFrame(v)}else this.map.getLayer(_)&&this.map.removeLayer(_),this.map.getSource(o)&&this.map.removeSource(o),g=null,this._activeBlinkCleanup=null};g=requestAnimationFrame(v);let y=()=>{g&&cancelAnimationFrame(g),this.map.getLayer(_)&&this.map.removeLayer(_),this.map.getSource(o)&&this.map.removeSource(o)};return this._activeBlinkCleanup=y,y}};e.TeeeMap=oc,e.default=oc,e.transformGeoJsonFrom3857=Ys});
|
package/index.d.ts
CHANGED
|
@@ -232,6 +232,21 @@ export declare class DrawTool {
|
|
|
232
232
|
clearFeatures(): void;
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
// ─────────────────────────────────────────────
|
|
236
|
+
// 测量工具
|
|
237
|
+
// ─────────────────────────────────────────────
|
|
238
|
+
|
|
239
|
+
export declare class MeasureTool {
|
|
240
|
+
constructor(map: MaplibreMap);
|
|
241
|
+
|
|
242
|
+
/** 开始距离测量模式 */
|
|
243
|
+
startDistance(): void;
|
|
244
|
+
/** 开始面积测量模式 */
|
|
245
|
+
startArea(): void;
|
|
246
|
+
/** 清除所有测量图层、数据源和 DOM 元素 */
|
|
247
|
+
clear(): void;
|
|
248
|
+
}
|
|
249
|
+
|
|
235
250
|
// ─────────────────────────────────────────────
|
|
236
251
|
// 联锁协议 & 可视化
|
|
237
252
|
// ─────────────────────────────────────────────
|
|
@@ -376,6 +391,8 @@ export declare class TeeeMap {
|
|
|
376
391
|
public layerFeaturesCache: Map<string, GeoJSONFeature[]>;
|
|
377
392
|
/** 绘图工具(地图 load 事件后可用) */
|
|
378
393
|
public drawTool: DrawTool;
|
|
394
|
+
/** 测量工具(地图 load 事件后可用) */
|
|
395
|
+
public measureTool?: MeasureTool;
|
|
379
396
|
|
|
380
397
|
constructor(container: string | HTMLElement, mbtileDBClient?: any);
|
|
381
398
|
|