@teeechina/teee-map 0.1.0 → 0.1.2

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/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  'use strict';var ee=require('maplibre-gl'),z=require('@turf/turf'),vectorTile=require('@mapbox/vector-tile'),pbf=require('pbf');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var ee__namespace=/*#__PURE__*/_interopNamespace(ee);var z__namespace=/*#__PURE__*/_interopNamespace(z);/**
2
- * @teeechina/teee-map v0.1.0
2
+ * @teeechina/teee-map v0.1.2
3
3
  * 基于 maplibre-gl 封装的业务地图 SDK,面向太昌 GIS 业务流提供开箱即用的地图初始化、图层管理、要素状态控制及加密瓦片支持。
4
4
  * (c) 2026 TeeChina
5
5
  * Released under the MIT License
@@ -30,5 +30,4 @@ var vt=Object.defineProperty;var me=(t,e)=>{for(var o in e)vt(t,o,{get:e[o],enum
30
30
  color: #fff;
31
31
  }
32
32
  `,document.head.appendChild(e);}getSource(e){return this.map.getSource(e)}startDistance(){this.reset(),this.active=true,this.map.getCanvas().style.cursor="default",this.map.doubleClickZoom.enable(),this.tooltipEle=document.createElement("div"),this.tooltipEle.setAttribute("class","measure-result"),this.tooltip=new ee__namespace.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=true,this._onClick=e=>{if(!this.active)return;let o=[e.lngLat.lng,e.lngLat.lat];this.addMeasureRes(o),this.addDistancePoint(o),this.points.push(o);},this._onMousemove=e=>{if(!this.active)return;let o=[e.lngLat.lng,e.lngLat.lat];if(this.jsonPoint.features.length>0){let n=this.jsonPoint.features[this.jsonPoint.features.length-1].geometry.coordinates;this.getSource("line-move").setData({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[n,o]}}),this.tooltipEle.innerHTML=this.getLength(o);}else this.tooltipEle.innerHTML="\u70B9\u51FB\u5730\u56FE\u5F00\u59CB\u6D4B\u91CF\uFF0C\u53F3\u952E\u7ED3\u675F\u6D4B\u91CF";this.tooltip.setLngLat(o);},this._onContextmenu=e=>{if(this.map.__isPlacingLoco=false,!this.active)return;let o=[e.lngLat.lng,e.lngLat.lat];this.addDistancePoint(o),this.active=false,this.map.getCanvas().style.cursor="";let i=this.getLength(o);this.tooltipEle.innerHTML=`<span>${i}</span><span class="measure-close">\xD7</span>`,this.tooltip.setLngLat(o);let n=this.tooltipEle.querySelector(".measure-close");n.onclick=r=>{r.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 i=this.jsonPoint.features[this.jsonPoint.features.length-1].geometry.coordinates;this.jsonLine.features.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[i,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 o=document.createElement("div");o.setAttribute("class","measure-result"),o.innerHTML=this.points.length===0?"\u8D77\u70B9":this.getLength(e);let i=new ee__namespace.Marker({element:o,anchor:"left",offset:[8,0]}).setLngLat(e).addTo(this.map);this.markers.push(i);}getLength(e){let o=this.points.concat([e]),i=z__namespace.lineString(o),n=z__namespace.length(i);return n<1?(n=Number((n*1e3).toFixed(4)),n+"m"):(n=Number(n.toFixed(4)),n+"km")}startArea(){this.reset(),this.active=true,this.map.doubleClickZoom.disable(),this.map.getCanvas().style.cursor="default",this.tooltipEle=document.createElement("div"),this.tooltipEle.setAttribute("class","measure-result"),this.tooltip=new ee__namespace.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=true,this._onClick=e=>{if(!this.active)return;let o=[e.lngLat.lng,e.lngLat.lat];this.points.push(o),this.addAreaPoint(o);},this._onContextmenu=e=>{if(this.map.__isPlacingLoco=false,!this.active)return;let o=[e.lngLat.lng,e.lngLat.lat];this.points.push(o),this.active=false,this.tooltipEle.innerHTML=`<span>${this.getArea(o)}</span><span class="measure-close">\xD7</span>`,this.tooltip.setLngLat(o);let i=this.tooltipEle.querySelector(".measure-close");i.onclick=n=>{n.stopPropagation(),this.map.doubleClickZoom.enable(),this.clear();};},this._onMousemove=e=>{if(!this.active)return;let o=[e.lngLat.lng,e.lngLat.lat],i=this.jsonPoint.features.length;if(i===0)this.tooltipEle.innerHTML="\u70B9\u51FB\u5730\u56FE\u5F00\u59CB\u6D4B\u91CF\uFF0C\u53F3\u952E\u7ED3\u675F\u6D4B\u91CF";else if(i===1)this.tooltipEle.innerHTML="\u70B9\u51FB\u5730\u56FE\u7EE7\u7EED\u6D4B\u91CF\uFF0C\u53F3\u952E\u7ED3\u675F\u6D4B\u91CF";else {let n=this.points.concat([o]).concat([this.points[0]]);this.getSource("line-area").setData({type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[n]}}),this.tooltipEle.innerHTML=this.getArea(o);}this.tooltip.setLngLat(o);},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 o=this.points.concat([e]).concat([this.points[0]]),i=z__namespace.polygon([o]),n=z__namespace.area(i);return n<1e3?(n=Number(n.toFixed(4)),n+"m\xB2"):(n=Number((n/1e6).toFixed(4)),n+"km\xB2")}reset(){this.clear(),this.active=false,this.jsonPoint={type:"FeatureCollection",features:[]},this.jsonLine={type:"FeatureCollection",features:[]},this.points=[],this.markers=[],this.tooltip&&(this.tooltip.remove(),this.tooltip=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);});}};A.stylesInjected=false;var D=A;var Tt=class{constructor(e){this.mapDir="left";this.mixingMapConfigs=new Map;this.stashFeatures=new Map;this.layerFeaturesCache=new Map;this._activeBlinkCleanup=null;this._stashReady=Promise.resolve();this._stashReadyResolve=null;this._stashReadyReject=null;let o={version:8,sources:{},layers:[]};this.map=new ee__namespace.Map({container:e,style:o,center:[0,0],zoom:14,attributionControl:false,maxZoom:24}),v.base(this);}getMap(){return this.map}getMapConfigs(){return this.mapConfigs}destroy(){this._activeBlinkCleanup?.(),this._activeBlinkCleanup=null,this.invalidateStashReady(),this.stashFeatures.clear(),this.layerFeaturesCache.clear(),this.mixingMapConfigs.clear(),this.map.remove();}resetStashReady(){this._stashReadyResolve?.(),this._stashReady=new Promise((e,o)=>{this._stashReadyResolve=e,this._stashReadyReject=o;});}markStashReady(){this._stashReadyResolve?.(),this._stashReadyResolve=null,this._stashReadyReject=null;}invalidateStashReady(e){this._stashReadyReject?.(new Error(e??"TeeeMap \u5DF2\u9500\u6BC1\uFF1A\u8981\u7D20\u7F13\u5B58\u4E0D\u4F1A\u518D\u5C31\u7EEA")),this._stashReadyResolve=null,this._stashReadyReject=null;}whenStashed(e=3e4){return e<=0?this._stashReady:new Promise((o,i)=>{let n=setTimeout(()=>{i(new Error(`whenStashed \u8D85\u65F6(${e}ms)\uFF1A\u8981\u7D20\u7F13\u5B58\u672A\u5728\u9884\u671F\u65F6\u95F4\u5185\u5C31\u7EEA`));},e);this._stashReady.then(()=>{clearTimeout(n),o();},r=>{clearTimeout(n),i(r instanceof Error?r:new Error(String(r)));});})}onStashReady(e,o){this.whenStashed().then(e).catch(i=>{o?o(i):console.error("onStashReady: \u7B49\u5F85\u8981\u7D20\u7F13\u5B58\u5C31\u7EEA\u5931\u8D25",i);});}initMap(e,o=false){this.resetStashReady();let i=async()=>{try{if(console.log(`\u5F00\u59CB\u6784\u5EFA\u4E1A\u52A1\u5730\u56FE: ${e.id}`),Array.isArray(e.source))if(o){let{sourceLayers:h}=this.mixingMapConfigs.get(e.id.split("_")[1]);if(!h)return;e.source.forEach((g,S)=>{this.map.addSource(h[S],g);});}else {let{sourceLayers:h}=this.mapConfigs;if(!h)return;e.source.forEach((g,S)=>{this.map.addSource(h[S],g);});}else this.map.getSource(e.id)?console.warn(`\u5730\u56FE\u6E90\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u6DFB\u52A0: ${e.id}`):this.map.addSource(e.id,e.source);e.subSourceId&&e.subSource&&(this.map.getSource(e.subSourceId)?console.warn(`\u5730\u56FE\u6E90\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u6DFB\u52A0: ${e.subSourceId}`):this.map.addSource(e.subSourceId,e.subSource));let r=await J.createAllIcons();console.log(`\u56FE\u6807\u5217\u8868 (${r.length}):`,r),r.forEach(h=>{this.map.hasImage(h.id)?console.warn(`\u56FE\u6807\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u6DFB\u52A0: ${h.id}`):this.map.addImage(h.id,h.image);}),e.layers&&e.layers.forEach(h=>{this.map.getLayer(h.id)?console.debug(`\u56FE\u5C42\u5DF2\u5B58\u5728: ${h.id}`):this.map.addLayer(h);}),this.measureTool=new D(this.map);let s=this.map.getStyle()?.sources??{},l=Object.keys(s);console.log(`\u6E90\u5217\u8868 (${l.length}):`,l,s);let c=this.map.getStyle().layers??[],m=c.map(h=>h.id);console.log(`\u56FE\u5C42\u5217\u8868 (${m.length}):`,c);let u=this.map.listImages();console.log(`\u56FE\u6807\u5217\u8868 (${u.length}):`,u);let p=this.layerFeaturesCache.get("track")?.[0]??null;if(p){let h=p.geometry;this.mapDir=h.coordinates[0][0]-h.coordinates[1][0]>0?"left":"right";}console.groupEnd(),console.log(`\u5730\u56FE\u6784\u5EFA\u5168\u90E8\u5B8C\u6210: ${e.id}`);}catch(r){console.error(`\u5730\u56FE\u521D\u59CB\u5316\u5931\u8D25: ${e.id}`,r),r instanceof Error&&console.error(`\u9519\u8BEF\u8BE6\u60C5: ${r.message}`);}},n=()=>{this.map.once("idle",()=>{(o?this.stashMixMapAllFeature():this.stashAllFeature()).catch(a=>{console.error(`\u8981\u7D20\u7F13\u5B58\u5931\u8D25: ${e.id}`,a);}).finally(()=>this.markStashReady());});};this.map.loaded()?i().then(n).catch(r=>{console.error(r);}):this.map.on("load",()=>{i().then(n).catch(r=>{console.error(r);});});}initMixMap(e){this.resetStashReady();let o=async()=>{let n=await J.createAllIcons();console.log(`\u56FE\u6807\u5217\u8868 (${n.length}):`,n),n.forEach(g=>{this.map.hasImage(g.id)?console.warn(`\u56FE\u6807\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u6DFB\u52A0: ${g.id}`):this.map.addImage(g.id,g.image);});for(let g of e){if(Array.isArray(g.source)){let{sourceLayers:S}=this.mixingMapConfigs.get(g.id.split("_")[1]);if(!S)continue;g.source.forEach((b,_)=>{this.map.addSource(S[_],b);});}else this.map.getSource(g.id)?console.warn(`\u5730\u56FE\u6E90\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u6DFB\u52A0: ${g.id}`):this.map.addSource(g.id,g.source);g.layers&&g.layers.forEach(S=>{this.map.getLayer(S.id)?console.debug(`\u56FE\u5C42\u5DF2\u5B58\u5728: ${S.id}`):this.map.addLayer(S);});}this.measureTool=new D(this.map);let a=this.map.getStyle()?.sources??{},s=Object.keys(a);console.log(`\u6E90\u5217\u8868 (${s.length}):`,s,a);let l=this.map.getStyle().layers??[],c=l.map(g=>g.id);console.log(`\u56FE\u5C42\u5217\u8868 (${c.length}):`,l);let m=s.filter(g=>g.endsWith("_background"));c.filter(g=>g.endsWith("_background")).slice(1).forEach(g=>{this.map.getLayer(g)&&this.map.removeLayer(g);}),m.slice(1).forEach(g=>{this.map.getSource(g)&&this.map.removeSource(g);});let y=e[0],h=this.layerFeaturesCache.get(y?.id.split("_")[1]+"_track")?.[0]??null;if(h){let g=h.geometry;this.mapDir=g.coordinates[0][0]-g.coordinates[1][0]>0?"left":"right";}await this.stashMixMapAllFeature(),v.geojson(this);},i=async()=>{try{await o();}catch(n){console.error("\u6DF7\u5408\u5730\u56FE\u6784\u5EFA\u5931\u8D25",n);}finally{this.markStashReady();}};this.map.loaded()?i():this.map.once("load",()=>{i();});}createRSWPMap(e){let o=M.rswp(e),i=x.raster(o.sourceUrl),n=w.raster(o.id),r=M.geojson("rswp-geojson"),a=x.geojson(),s={id:o.id,source:i,subSourceId:r.id,subSource:a,layers:n};this.mapConfigs=o,this.mapConfigs.subSourceId=r.id,this.initMap(s);}createGraphMap(e,o,i){this.mapConfigs=M.graph(e,o,i);let n=x.graph(this.mapConfigs.sourceUrl),r=w.graph(this.mapConfigs),a={id:this.mapConfigs.id,source:n,layers:r};this.initMap(a),v.graph(this);}createSscsGraphMap(e){let o={normal:{color:"#1C5AFF",strokeColor:"#31E5FF"},reverse:{color:"#FFB400",strokeColor:"#31E5FF"},lock:{color:"#00C853",strokeColor:"#31E5FF"},fault:{color:"#E4002B",strokeColor:"#FFD700"},selected:{color:"#FFD700",strokeColor:"#FFFFFF"}},i="#1C5AFF",n="#31E5FF",r=(s,l)=>["match",["feature-state","state"],...Object.entries(o).flatMap(([c,m])=>[c,s(m)]),l],a={id:"sscs_graph",source:{type:"vector",tiles:[e],scheme:"tms",promoteId:"code"},layers:[{id:"sscs_graph_line",type:"line",source:"sscs_graph","source-layer":"cdst_trfc_line",paint:{"line-color":"orange","line-width":2}},{id:"sscs_graph_point",type:"circle",source:"sscs_graph","source-layer":"cdst_trfc_point",paint:{"circle-color":r(s=>s.color,i),"circle-radius":["interpolate",["linear"],["zoom"],10,5,13,15,22,20],"circle-opacity":.9,"circle-stroke-color":r(s=>s.strokeColor,n),"circle-stroke-width":2,"circle-blur":.2}},{id:"sscs_graph_line_label",type:"symbol",source:"sscs_graph","source-layer":"cdst_trfc_line",minzoom:10,layout:{"text-field":["get","name_abb"],"symbol-placement":"line","text-rotation-alignment":"map","text-size":["interpolate",["linear"],["zoom"],10,8,22,15]},paint:{"text-color":"#333333","text-halo-color":"#ffffff","text-halo-width":1.5}},{id:"sscs_graph_point_label",type:"symbol",source:"sscs_graph","source-layer":"cdst_trfc_point",minzoom:10,layout:{"text-field":["get","name"],"text-size":["interpolate",["linear"],["zoom"],10,5,13,9,22,15],"text-max-width":3},paint:{"text-color":"white"}}]};this.initMap(a);}setSscsPointState(e,o){this.map.setFeatureState({source:"sscs_graph",sourceLayer:"cdst_trfc_point",id:e},{state:o});}createGeomMap(e,o,i){this.mapConfigs=M.geom(e,o,i);let n=x.geom(this.mapConfigs.sourceUrl),r=w.geom(this.mapConfigs),a={id:this.mapConfigs.id,source:n,layers:r};this.initMap(a);}createGeomEncryptedMap(e,o,i){v.encrypt(this),this.mapConfigs=M.geom(e,o,i);let n=x.geom(this.mapConfigs.sourceUrl),r=w.geom(this.mapConfigs),a={id:this.mapConfigs.id,source:n,layers:r};this.initMap(a);}async createGeoJsonGeomStationMap(e,o=true){let i=e.map(l=>l.name),n=i.map(l=>`geojson_${l}`);this.mapConfigs=M.geojson("geojson"),this.mapConfigs.layers=i,this.mapConfigs.sourceLayers=n;let r=await Promise.all(e.map(async(l,c)=>{let m=n[c],u=l.name;if(this.map.getSource(m))return;let y=l.data,p;return typeof y=="string"?(p=await(await fetch(y)).json(),T(u,p)):(p=y,T(u,p)),this.layerFeaturesCache.set(u,p.features),x.geojson(p)})),a={id:this.mapConfigs.id,source:r,layers:w.geojsonGeom(i,n)};if(this.initMap(a),o){let l="gaode-satellite",c="gaode-satellite-layer";this.map.on("load",()=>{this.map.addSource(l,{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:c,type:"raster",source:l});});}let s=e.find(l=>l.name==="track")?.data;if(s){let l=z.bbox(s);this.map.fitBounds([[l[0],l[1]],[l[2],l[3]]],{padding:100,maxZoom:15,duration:0});}v.geojson(this);}async createMixGeoJsonGeomMap(e,o=true){if(e.length===0)return;let i=await Promise.all(e.map(async r=>{if(r.type==="region"){let a=r.geojsonData.map(c=>c.name),s=a.map(c=>`geojson_region_${r.code}_${c}`);this.mixingMapConfigs.set(r.code,{id:`geojson_${r.code}`,layers:a,sourceLayers:s,type:"region"});let l=await Promise.all(r.geojsonData.map(async(c,m)=>{let u=s[m],y=c.name;if(this.map.getSource(u))return;let p=c.data,h;return typeof p=="string"?(h=await(await fetch(p)).json(),T(y,h)):(h=p,T(y,h)),this.layerFeaturesCache.set(`${r.code}_${y}`,h.features),x.geojson(h)}));return {id:`geojson_${r.code}`,source:l,layers:w.geojsonGeom(a,s)}}else {let a=r.geojsonData.map(c=>c.name),s=a.map(c=>`geojson_station_${r.code}_${c}`);this.mixingMapConfigs.set(r.code,{id:`geojson_${r.code}`,layers:a,sourceLayers:s,type:"station"});let l=await Promise.all(r.geojsonData.map(async(c,m)=>{let u=s[m],y=c.name;if(this.map.getSource(u))return;let p=c.data,h;return typeof p=="string"?(h=await(await fetch(p)).json(),T(y,h)):(h=p,T(y,h)),this.layerFeaturesCache.set(`${r.code}_${y}`,h.features),x.geojson(h)}));return {id:`geojson_${r.code}`,source:l,layers:w.geojsonGeom(a,s)}}}));if(this.initMixMap(i),o){let r="gaode-satellite",a="gaode-satellite-layer";this.map.on("load",()=>{this.map.addSource(r,{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:a,type:"raster",source:r});});}let n=e[1]?.geojsonData.find(r=>r.name==="track")?.data;if(n){let r=z.bbox(n);this.map.fitBounds([[r[0],r[1]],[r[2],r[3]]],{padding:100,maxZoom:15,duration:0});}v.geojson(this);}async createGeoJsonStationMap(e){let o=e.map(s=>s.name),i=o.map(s=>`geojson_${s}`);this.mapConfigs=M.geojson("geojson"),this.mapConfigs.layers=o,this.mapConfigs.sourceLayers=i;let n=await Promise.all(e.map(async(s,l)=>{let c=i[l],m=s.name;if(this.map.getSource(c))return;let u=s.data,y;if(typeof u=="string"){let h=await(await fetch(u)).json();y=O(h),T(m,y);}else y=O(u),T(m,y);return this.layerFeaturesCache.set(m,y.features),x.geojson(y)})),r={id:this.mapConfigs.id,source:n,layers:w.geojson(o,i)};this.initMap(r);let a=e.find(s=>s.name==="track")?.data;if(a){let s=z.bbox(O(a));this.map.fitBounds([[s[0],s[1]],[s[2],s[3]]],{padding:100,maxZoom:15,duration:0});}v.geojson(this);}async createGeoJsonRegionMap(e,o){let i=o.map(l=>l.name),n=i.map(l=>`geojson_region_${e}_${l}`);this.mixingMapConfigs.set(e,{id:`geojson_${e}`,layers:i,sourceLayers:n,type:"region"});let r=await Promise.all(o.map(async(l,c)=>{let m=n[c],u=l.name;if(this.map.getSource(m))return;let y=l.data,p;if(typeof y=="string"){let g=await(await fetch(y)).json();p=O(g),T(u,p);}else p=O(y),T(u,p);return this.layerFeaturesCache.set(u,p.features),x.geojson(p)})),a={id:`geojson_${e}`,source:r,layers:w.geojson(i,n)};this.initMap(a,true);let s=o.find(l=>l.name==="track")?.data;if(s){let l=z.bbox(O(s));this.map.fitBounds([[l[0],l[1]],[l[2],l[3]]],{padding:100,maxZoom:15,duration:0});}v.geojson(this);}async createMixGeoJsonMap(e){if(e.length===0)return;let o=await Promise.all(e.map(async n=>{if(n.type==="region"){let r=n.geojsonData.map(l=>l.name),a=r.map(l=>`geojson_region_${n.code}_${l}`);this.mixingMapConfigs.set(n.code,{id:`geojson_${n.code}`,layers:r,sourceLayers:a,type:"region"});let s=await Promise.all(n.geojsonData.map(async(l,c)=>{let m=a[c],u=l.name;if(this.map.getSource(m))return;let y=l.data,p;if(typeof y=="string"){let g=await(await fetch(y)).json();p=O(g),T(u,p);}else p=O(y),T(u,p);return this.layerFeaturesCache.set(`${n.code}_${u}`,p.features),x.geojson(p)}));return {id:`geojson_${n.code}`,source:s,layers:w.geojson(r,a)}}else {let r=n.geojsonData.map(l=>l.name),a=r.map(l=>`geojson_station_${n.code}_${l}`);this.mixingMapConfigs.set(n.code,{id:`geojson_${n.code}`,layers:r,sourceLayers:a,type:"station"});let s=await Promise.all(n.geojsonData.map(async(l,c)=>{let m=a[c],u=l.name;if(this.map.getSource(m))return;let y=l.data,p;if(typeof y=="string"){let g=await(await fetch(y)).json(),S=ge(g,n.deltaInfo?.deltax||0,n.deltaInfo?.deltay||0);p=O(S),T(u,p);}else {let h=ge(y,n.deltaInfo?.deltax||0,n.deltaInfo?.deltay||0);p=O(h),T(u,p);}return this.layerFeaturesCache.set(`${n.code}_${u}`,p.features),x.geojson(p)}));return {id:`geojson_${n.code}`,source:s,layers:w.geojson(r,a)}}}));this.initMixMap(o);let i=e[1]?.geojsonData.find(n=>n.name==="track")?.data;if(i){let n=z.bbox(O(i));this.map.fitBounds([[n[0],n[1]],[n[2],n[3]]],{padding:100,maxZoom:15,duration:0});}}createRasterMap(e){this.mapConfigs=M.raster(e);let o=x.raster(this.mapConfigs.sourceUrl),i=w.raster(this.mapConfigs.id),n={id:this.mapConfigs.id,source:o,layers:i};this.initMap(n);}createEncryptedRasterMap(e){v.encrypt(this),this.mapConfigs=M.raster(e);let o=x.raster(this.mapConfigs.sourceUrl),i=w.raster(this.mapConfigs.id),n={id:this.mapConfigs.id,source:o,layers:i};this.initMap(n);}async stashMixMapAllFeature(){if(this.mixingMapConfigs.size!==0)for(let[e,o]of this.mixingMapConfigs){let i=o.type,n=o.layers??[];await Promise.all(n.map(async r=>{let a=`geojson_${i}_${e}_${r}`,s=this.map.getSource(a);if(!s)return;(await s.getData()).features?.forEach(m=>{let u=m.properties?.code;u&&!this.stashFeatures.get(u)&&this.stashFeatures.set(u,{sourceLayer:a,properties:m.properties});});}));}}async stashAllFeature(){if(!this.mapConfigs)return;let e=this.mapConfigs.sourceLayers,o=this.mapConfigs.layers??[],i=this.mapConfigs.id;this.stashFeatures.clear(),e?.forEach((n,r)=>{if(n.includes("prevention"))return;let a=this.map.querySourceFeatures(i,{sourceLayer:n}),s=new Map;a.forEach(c=>{let m=c.properties?.code;m&&(this.stashFeatures.set(m,{sourceLayer:n}),s.set(String(m),c));});let l=o[r];l&&this.layerFeaturesCache.set(l,Array.from(s.values()));}),await Promise.all(o.map(async n=>{let r=`geojson_${n}`,a=this.map.getSource(r);if(!a)return;let l=await a.getData(),c=l.features??[];l.features?.forEach(m=>{let u=m.properties?.code;u&&!this.stashFeatures.get(u)&&this.stashFeatures.set(u,{sourceLayer:r,properties:m.properties});}),c.length&&this.layerFeaturesCache.set(n,c);}));}updateFeatureState(e,o){let i=this.stashFeatures.get(e);if(!i)return;if(Object.assign(i,o),i.sourceLayer?.startsWith("geojson_"))this.map.setFeatureState({source:i.sourceLayer,id:e},i);else {if(!this.mapConfigs)return;this.map.setFeatureState({source:this.mapConfigs.id,sourceLayer:i.sourceLayer,id:e},i);}}getFeatureState(e){let o=this.stashFeatures.get(e);if(o)return o}locateGeojsonFeature(e,o=true){let i=z.bbox(o?O(e):e);this.map.fitBounds([[i[0],i[1]],[i[2],i[3]]],{padding:50,maxZoom:18});}queryGeojsonFeatures(e){let o=Array.from(this.layerFeaturesCache.keys()).filter(i=>i.endsWith(e));return o.length?o.flatMap(i=>this.layerFeaturesCache.get(i)??[]):[]}getTrackCircuitFeaturesByCodes(e){let o=Array.from(this.layerFeaturesCache.keys()).filter(i=>i.endsWith("track_circuit"));return o.length?o.flatMap(i=>this.layerFeaturesCache.get(i)??[]).filter(i=>e.includes(i.properties.code))??[]:[]}getGeojsonLayerFeaturesByCode(e,o){let i=Array.from(this.layerFeaturesCache.keys()).filter(n=>n.endsWith(o));if(i.length)return i.flatMap(n=>this.layerFeaturesCache.get(n)??[]).find(n=>n.properties.code===e)}locateFeatureByCode(e,o){let i=this.getGeojsonLayerFeaturesByCode(e,o);if(!i){console.warn(`\u672A\u627E\u5230\u8981\u7D20\uFF0C\u65E0\u6CD5\u5B9A\u4F4D: code=${e}, layerType=${o}`);return}let n={type:"FeatureCollection",features:[i]};this.locateGeojsonFeature(n,false);}smoothBlinkFeature(e,o,i={}){let n=this.getGeojsonLayerFeaturesByCode(e,o);if(!n){console.warn(`\u672A\u627E\u5230\u8981\u7D20\uFF0C\u65E0\u6CD5\u9AD8\u4EAE: code=${e}, layerType=${o}`);return}let r={type:"FeatureCollection",features:[n]},s=["signal","switch","bumper"].includes(o)?"point":"line",l=`blink-temp-${e}-${o}`;this._activeBlinkCleanup?.(),this._activeBlinkCleanup=null,this.map.getSource(l)&&this.map.removeSource(l),this.map.addSource(l,{type:"geojson",data:r});let c=`${l}-blink-highlight`,{duration:m=3e3,blinkSpeed:u=500,baseColor:y=[0,255,0],minAlpha:p=.3,maxAlpha:h=.7,strokeWidthBase:g=3,strokeWidthRange:S=2}=i,b=null,_=null;if(s==="point"){let $=`blink-point-icon-${l}`;if(!this.map.hasImage($)){let N=document.createElement("canvas");N.width=36,N.height=36;let C=N.getContext("2d");C.beginPath(),C.arc(36/2,36/2,36/2-2,0,Math.PI*2),C.fillStyle=`rgba(${y.join(",")}, 0.3)`,C.fill(),C.beginPath(),C.arc(36/2,36/2,36/3,0,Math.PI*2),C.fillStyle=`rgb(${y.join(",")})`,C.fill(),C.strokeStyle="#fff",C.lineWidth=2,C.stroke();let ie=C.getImageData(0,0,36,36);this.map.addImage($,{width:36,height:36,data:ie.data});}this.map.getLayer(c)&&this.map.removeLayer(c),this.map.addLayer({id:c,type:"symbol",source:l,layout:{"icon-image":$,"icon-allow-overlap":true,"icon-ignore-placement":true},paint:{"icon-opacity":h}});let E=U=>{b||(b=U);let N=U-b;if(N<m){let C=Math.sin(N/u*Math.PI*2)*.5+.5,ie=p+(h-p)*C;this.map.setPaintProperty(c,"icon-opacity",ie),_=requestAnimationFrame(E);}else this.map.getLayer(c)&&this.map.removeLayer(c),this.map.getSource(l)&&this.map.removeSource(l),_=null,this._activeBlinkCleanup=null;};_=requestAnimationFrame(E);let W=()=>{_&&cancelAnimationFrame(_),this.map.getLayer(c)&&this.map.removeLayer(c),this.map.getSource(l)&&this.map.removeSource(l);};return this._activeBlinkCleanup=W,W}let k=`${c}-outline`;this.map.getLayer(k)&&this.map.removeLayer(k),this.map.addLayer({id:k,type:"line",source:l,paint:{"line-color":`rgb(${y.join(",")})`,"line-width":g}});let G=$=>{b||(b=$);let E=$-b;if(E<m){let W=Math.sin(E/u*Math.PI*2)*.5+.5,N=g+S*W;this.map.setPaintProperty(k,"line-width",N),_=requestAnimationFrame(G);}else this.map.getLayer(k)&&this.map.removeLayer(k),this.map.getSource(l)&&this.map.removeSource(l),_=null,this._activeBlinkCleanup=null;};_=requestAnimationFrame(G);let te=()=>{_&&cancelAnimationFrame(_),this.map.getLayer(k)&&this.map.removeLayer(k),this.map.getSource(l)&&this.map.removeSource(l);};return this._activeBlinkCleanup=te,te}};var kt=t=>t?.type==="LineString"?[t.coordinates]:t?.type==="MultiLineString"?t.coordinates:[],wt=t=>kt(t.geometry).reduce((e,o)=>e+o.length,0),xi=(t,e)=>{let o=z__namespace.point(e.coordinates),i=null;for(let r of kt(t)){if(r.length<2)continue;let a=z__namespace.nearestPointOnLine(z__namespace.lineString(r),o),s=a.properties.pointDistance||Number.POSITIVE_INFINITY;(!i||s<i.dist)&&(i={dist:s,index:a.properties.segmentIndex||0,coords:r});}if(!i)return null;let n=Math.min(i.index,i.coords.length-2);return [i.coords[n]??[],i.coords[n+1]??[]]},Ot=(t,e)=>{let o=xi(t,e);if(!o)return 0;let[[i,n],[r,a]]=o;return Math.atan2(r-i,a-n)*180/Math.PI},In=(t,e)=>{let{sourceId:o,pointSourceLayer:i,trackSourceLayer:n,layerId:r,controlFeatures:a,filterPoint:s,angleOffset:l=0,layerSuffix:c}=e;if(!t.getLayer(r)){console.warn(`\u56FE\u5C42\u4E0D\u5B58\u5728: ${r}`);return}let m=new Map;for(let h of a){let g=h.properties?.code,S=h.properties?.trackCode;g&&S&&m.set(g,S);}let u=new Map;for(let h of t.querySourceFeatures(o,{sourceLayer:n})){let g=h,S=h.properties.code;if(!S)continue;let b=u.get(S);(!b||wt(g)>wt(b))&&u.set(S,g);}let y=new Map;for(let h of t.querySourceFeatures(o,{sourceLayer:i})){if(s&&!s(h)||h.geometry.type!=="Point")continue;let g=h.properties.code;if(!g||y.has(g))continue;let S=m.get(g),_=(S?u.get(S):void 0)?.geometry;if(!S||!_||_.type!=="LineString"&&_.type!=="MultiLineString"){y.set(g,l),console.error("\u672A\u627E\u5230\u5173\u8054\u80A1\u9053",g,S);continue}c==="jcw"?y.set(g,Ot(_,h.geometry)+l+90):y.set(g,Ot(_,h.geometry)+l);}if(y.size===0){t.setLayoutProperty(r,"icon-rotate",l);return}let p=["match",["to-string",["get","code"]],...[...y.entries()].flatMap(([h,g])=>[h,g]),l];t.setLayoutProperty(r,"icon-rotate",p);};
33
- exports.BS_SIGNAL_MAP=It;exports.BsSignalStateEnums=ke;exports.INTERLOCK_CIRCUIT_MAP=Mt;exports.INTERLOCK_SIGNAL_COLOR_MAP=Q;exports.INTERLOCK_SIGNAL_MAP=oe;exports.INTERLOCK_SWITCHLOC_MAP=I;exports.InterLockCircuitStateEnums=we;exports.InterLockInsulation=B;exports.InterLockSignalStateEnums=Te;exports.InterLockSwitchlocStateEnums=Oe;exports.InterLockVisualization=R;exports.InterlockProtocol=H;exports.MapColor=L;exports.MeasureTool=D;exports.PREVENTION_TYPES=Nt;exports.PreventionEnums=ve;exports.SignalColorEnums=Ce;exports.StationFeatureCodeEnums=xe;exports.TeeeMap=Tt;exports.attachTrackAngle=In;exports.canvasCreator=_e;exports.getTrackBearing=Ot;exports.imageCreater=J;exports.offsetFeatureCollection=ge;exports.transformGeoJsonFrom3857=O;exports.transformGeoJsonProperties=T;//# sourceMappingURL=index.cjs.map
34
- //# sourceMappingURL=index.cjs.map
33
+ exports.BS_SIGNAL_MAP=It;exports.BsSignalStateEnums=ke;exports.INTERLOCK_CIRCUIT_MAP=Mt;exports.INTERLOCK_SIGNAL_COLOR_MAP=Q;exports.INTERLOCK_SIGNAL_MAP=oe;exports.INTERLOCK_SWITCHLOC_MAP=I;exports.InterLockCircuitStateEnums=we;exports.InterLockInsulation=B;exports.InterLockSignalStateEnums=Te;exports.InterLockSwitchlocStateEnums=Oe;exports.InterLockVisualization=R;exports.InterlockProtocol=H;exports.MapColor=L;exports.MeasureTool=D;exports.PREVENTION_TYPES=Nt;exports.PreventionEnums=ve;exports.SignalColorEnums=Ce;exports.StationFeatureCodeEnums=xe;exports.TeeeMap=Tt;exports.attachTrackAngle=In;exports.canvasCreator=_e;exports.getTrackBearing=Ot;exports.imageCreater=J;exports.offsetFeatureCollection=ge;exports.transformGeoJsonFrom3857=O;exports.transformGeoJsonProperties=T;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as maplibregl from 'maplibre-gl';
2
2
  import { SourceSpecification, LayerSpecification, Map as Map$1 } from 'maplibre-gl';
3
3
 
4
+ type MapType = 'graph' | 'geom' | 'ctc' | 'raster';
4
5
  type LayerType = 'background' | 'signal' | 'track' | 'track_circuit' | 'bumper' | 'switch' | 'switch_loc' | 'insulation' | 'label' | 'prevention' | 'sgfhqy' | 'region' | 'display_polygon' | 'display_line' | 'display_point';
5
6
  type RegionLayerType = 'background' | 'track' | 'bridge' | 'tunnel' | 'region_signal' | 'curve' | 'floodcontrol' | 'ramp' | 'contactseparation' | 'callpost';
6
7
  interface MapForgeConfig {
@@ -25,6 +26,37 @@ interface IconType {
25
26
  id: string;
26
27
  image: HTMLImageElement;
27
28
  }
29
+ interface stateType {
30
+ state?: string | number;
31
+ select?: boolean;
32
+ visiable?: boolean;
33
+ subState1?: string;
34
+ subState2?: string;
35
+ subState3?: string;
36
+ subState4?: string;
37
+ }
38
+ interface layerSettingItem {
39
+ key: string;
40
+ label: string;
41
+ checked: boolean;
42
+ disabled: boolean;
43
+ }
44
+ interface FeatureInteractionPayload {
45
+ type: LayerType;
46
+ code: string;
47
+ state: stateType;
48
+ }
49
+ interface AppEvents {
50
+ 'map:inited': unknown;
51
+ 'map:feature-click': FeatureInteractionPayload;
52
+ 'map:path-selected': unknown;
53
+ 'map:node-insert': unknown;
54
+ 'map:sgfhqy-selected': unknown;
55
+ }
56
+ interface GeojsonStationDatas {
57
+ name: string;
58
+ data: GeoJSON.FeatureCollection | string;
59
+ }
28
60
 
29
61
  interface InterlockItem {
30
62
  name: string;
@@ -1385,4 +1417,4 @@ declare const getTrackBearing: (lineGeom: LineGeometry, pointGeom: GeoJSON.Point
1385
1417
  */
1386
1418
  declare const attachTrackAngle: (map: Map$1, options: AttachTrackAngleOptions) => void;
1387
1419
 
1388
- export { type AttachTrackAngleOptions, BS_SIGNAL_MAP, BsSignalStateEnums, type FeatureState, INTERLOCK_CIRCUIT_MAP, INTERLOCK_SIGNAL_COLOR_MAP, INTERLOCK_SIGNAL_MAP, INTERLOCK_SWITCHLOC_MAP, type InsulationSignals, InterLockCircuitStateEnums, InterLockInsulation, InterLockSignalStateEnums, InterLockSwitchlocStateEnums, InterLockVisualization, type InterlockData, type InterlockItem, InterlockProtocol, type InterlockVisualizationOptions, MapColor, MeasureTool, PREVENTION_TYPES, PreventionEnums, SignalColorEnums, StationFeatureCodeEnums, TeeeMap, attachTrackAngle, index$1 as canvasCreator, getTrackBearing, index as imageCreater, offsetFeatureCollection, transformGeoJsonFrom3857, transformGeoJsonProperties };
1420
+ export { type AppEvents, type AttachTrackAngleOptions, BS_SIGNAL_MAP, BsSignalStateEnums, type FeatureInteractionPayload, type FeatureState, type GeojsonStationDatas, INTERLOCK_CIRCUIT_MAP, INTERLOCK_SIGNAL_COLOR_MAP, INTERLOCK_SIGNAL_MAP, INTERLOCK_SWITCHLOC_MAP, type IconType, type InsulationSignals, InterLockCircuitStateEnums, InterLockInsulation, InterLockSignalStateEnums, InterLockSwitchlocStateEnums, InterLockVisualization, type InterlockData, type InterlockItem, InterlockProtocol, type InterlockVisualizationOptions, type LayerType, MapColor, type MapForgeConfig, type MapParams, type MapType, MeasureTool, PREVENTION_TYPES, PreventionEnums, type RegionLayerType, SignalColorEnums, StationFeatureCodeEnums, TeeeMap, attachTrackAngle, index$1 as canvasCreator, getTrackBearing, index as imageCreater, type layerSettingItem, offsetFeatureCollection, type stateType, transformGeoJsonFrom3857, transformGeoJsonProperties };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as maplibregl from 'maplibre-gl';
2
2
  import { SourceSpecification, LayerSpecification, Map as Map$1 } from 'maplibre-gl';
3
3
 
4
+ type MapType = 'graph' | 'geom' | 'ctc' | 'raster';
4
5
  type LayerType = 'background' | 'signal' | 'track' | 'track_circuit' | 'bumper' | 'switch' | 'switch_loc' | 'insulation' | 'label' | 'prevention' | 'sgfhqy' | 'region' | 'display_polygon' | 'display_line' | 'display_point';
5
6
  type RegionLayerType = 'background' | 'track' | 'bridge' | 'tunnel' | 'region_signal' | 'curve' | 'floodcontrol' | 'ramp' | 'contactseparation' | 'callpost';
6
7
  interface MapForgeConfig {
@@ -25,6 +26,37 @@ interface IconType {
25
26
  id: string;
26
27
  image: HTMLImageElement;
27
28
  }
29
+ interface stateType {
30
+ state?: string | number;
31
+ select?: boolean;
32
+ visiable?: boolean;
33
+ subState1?: string;
34
+ subState2?: string;
35
+ subState3?: string;
36
+ subState4?: string;
37
+ }
38
+ interface layerSettingItem {
39
+ key: string;
40
+ label: string;
41
+ checked: boolean;
42
+ disabled: boolean;
43
+ }
44
+ interface FeatureInteractionPayload {
45
+ type: LayerType;
46
+ code: string;
47
+ state: stateType;
48
+ }
49
+ interface AppEvents {
50
+ 'map:inited': unknown;
51
+ 'map:feature-click': FeatureInteractionPayload;
52
+ 'map:path-selected': unknown;
53
+ 'map:node-insert': unknown;
54
+ 'map:sgfhqy-selected': unknown;
55
+ }
56
+ interface GeojsonStationDatas {
57
+ name: string;
58
+ data: GeoJSON.FeatureCollection | string;
59
+ }
28
60
 
29
61
  interface InterlockItem {
30
62
  name: string;
@@ -1385,4 +1417,4 @@ declare const getTrackBearing: (lineGeom: LineGeometry, pointGeom: GeoJSON.Point
1385
1417
  */
1386
1418
  declare const attachTrackAngle: (map: Map$1, options: AttachTrackAngleOptions) => void;
1387
1419
 
1388
- export { type AttachTrackAngleOptions, BS_SIGNAL_MAP, BsSignalStateEnums, type FeatureState, INTERLOCK_CIRCUIT_MAP, INTERLOCK_SIGNAL_COLOR_MAP, INTERLOCK_SIGNAL_MAP, INTERLOCK_SWITCHLOC_MAP, type InsulationSignals, InterLockCircuitStateEnums, InterLockInsulation, InterLockSignalStateEnums, InterLockSwitchlocStateEnums, InterLockVisualization, type InterlockData, type InterlockItem, InterlockProtocol, type InterlockVisualizationOptions, MapColor, MeasureTool, PREVENTION_TYPES, PreventionEnums, SignalColorEnums, StationFeatureCodeEnums, TeeeMap, attachTrackAngle, index$1 as canvasCreator, getTrackBearing, index as imageCreater, offsetFeatureCollection, transformGeoJsonFrom3857, transformGeoJsonProperties };
1420
+ export { type AppEvents, type AttachTrackAngleOptions, BS_SIGNAL_MAP, BsSignalStateEnums, type FeatureInteractionPayload, type FeatureState, type GeojsonStationDatas, INTERLOCK_CIRCUIT_MAP, INTERLOCK_SIGNAL_COLOR_MAP, INTERLOCK_SIGNAL_MAP, INTERLOCK_SWITCHLOC_MAP, type IconType, type InsulationSignals, InterLockCircuitStateEnums, InterLockInsulation, InterLockSignalStateEnums, InterLockSwitchlocStateEnums, InterLockVisualization, type InterlockData, type InterlockItem, InterlockProtocol, type InterlockVisualizationOptions, type LayerType, MapColor, type MapForgeConfig, type MapParams, type MapType, MeasureTool, PREVENTION_TYPES, PreventionEnums, type RegionLayerType, SignalColorEnums, StationFeatureCodeEnums, TeeeMap, attachTrackAngle, index$1 as canvasCreator, getTrackBearing, index as imageCreater, type layerSettingItem, offsetFeatureCollection, type stateType, transformGeoJsonFrom3857, transformGeoJsonProperties };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import*as ee from'maplibre-gl';import*as z from'@turf/turf';import {bbox}from'@turf/turf';import {VectorTile}from'@mapbox/vector-tile';import {PbfReader}from'pbf';/**
2
- * @teeechina/teee-map v0.1.0
2
+ * @teeechina/teee-map v0.1.2
3
3
  * 基于 maplibre-gl 封装的业务地图 SDK,面向太昌 GIS 业务流提供开箱即用的地图初始化、图层管理、要素状态控制及加密瓦片支持。
4
4
  * (c) 2026 TeeChina
5
5
  * Released under the MIT License
@@ -30,5 +30,4 @@ var vt=Object.defineProperty;var me=(t,e)=>{for(var o in e)vt(t,o,{get:e[o],enum
30
30
  color: #fff;
31
31
  }
32
32
  `,document.head.appendChild(e);}getSource(e){return this.map.getSource(e)}startDistance(){this.reset(),this.active=true,this.map.getCanvas().style.cursor="default",this.map.doubleClickZoom.enable(),this.tooltipEle=document.createElement("div"),this.tooltipEle.setAttribute("class","measure-result"),this.tooltip=new ee.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=true,this._onClick=e=>{if(!this.active)return;let o=[e.lngLat.lng,e.lngLat.lat];this.addMeasureRes(o),this.addDistancePoint(o),this.points.push(o);},this._onMousemove=e=>{if(!this.active)return;let o=[e.lngLat.lng,e.lngLat.lat];if(this.jsonPoint.features.length>0){let n=this.jsonPoint.features[this.jsonPoint.features.length-1].geometry.coordinates;this.getSource("line-move").setData({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[n,o]}}),this.tooltipEle.innerHTML=this.getLength(o);}else this.tooltipEle.innerHTML="\u70B9\u51FB\u5730\u56FE\u5F00\u59CB\u6D4B\u91CF\uFF0C\u53F3\u952E\u7ED3\u675F\u6D4B\u91CF";this.tooltip.setLngLat(o);},this._onContextmenu=e=>{if(this.map.__isPlacingLoco=false,!this.active)return;let o=[e.lngLat.lng,e.lngLat.lat];this.addDistancePoint(o),this.active=false,this.map.getCanvas().style.cursor="";let i=this.getLength(o);this.tooltipEle.innerHTML=`<span>${i}</span><span class="measure-close">\xD7</span>`,this.tooltip.setLngLat(o);let n=this.tooltipEle.querySelector(".measure-close");n.onclick=r=>{r.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 i=this.jsonPoint.features[this.jsonPoint.features.length-1].geometry.coordinates;this.jsonLine.features.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[i,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 o=document.createElement("div");o.setAttribute("class","measure-result"),o.innerHTML=this.points.length===0?"\u8D77\u70B9":this.getLength(e);let i=new ee.Marker({element:o,anchor:"left",offset:[8,0]}).setLngLat(e).addTo(this.map);this.markers.push(i);}getLength(e){let o=this.points.concat([e]),i=z.lineString(o),n=z.length(i);return n<1?(n=Number((n*1e3).toFixed(4)),n+"m"):(n=Number(n.toFixed(4)),n+"km")}startArea(){this.reset(),this.active=true,this.map.doubleClickZoom.disable(),this.map.getCanvas().style.cursor="default",this.tooltipEle=document.createElement("div"),this.tooltipEle.setAttribute("class","measure-result"),this.tooltip=new ee.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=true,this._onClick=e=>{if(!this.active)return;let o=[e.lngLat.lng,e.lngLat.lat];this.points.push(o),this.addAreaPoint(o);},this._onContextmenu=e=>{if(this.map.__isPlacingLoco=false,!this.active)return;let o=[e.lngLat.lng,e.lngLat.lat];this.points.push(o),this.active=false,this.tooltipEle.innerHTML=`<span>${this.getArea(o)}</span><span class="measure-close">\xD7</span>`,this.tooltip.setLngLat(o);let i=this.tooltipEle.querySelector(".measure-close");i.onclick=n=>{n.stopPropagation(),this.map.doubleClickZoom.enable(),this.clear();};},this._onMousemove=e=>{if(!this.active)return;let o=[e.lngLat.lng,e.lngLat.lat],i=this.jsonPoint.features.length;if(i===0)this.tooltipEle.innerHTML="\u70B9\u51FB\u5730\u56FE\u5F00\u59CB\u6D4B\u91CF\uFF0C\u53F3\u952E\u7ED3\u675F\u6D4B\u91CF";else if(i===1)this.tooltipEle.innerHTML="\u70B9\u51FB\u5730\u56FE\u7EE7\u7EED\u6D4B\u91CF\uFF0C\u53F3\u952E\u7ED3\u675F\u6D4B\u91CF";else {let n=this.points.concat([o]).concat([this.points[0]]);this.getSource("line-area").setData({type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[n]}}),this.tooltipEle.innerHTML=this.getArea(o);}this.tooltip.setLngLat(o);},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 o=this.points.concat([e]).concat([this.points[0]]),i=z.polygon([o]),n=z.area(i);return n<1e3?(n=Number(n.toFixed(4)),n+"m\xB2"):(n=Number((n/1e6).toFixed(4)),n+"km\xB2")}reset(){this.clear(),this.active=false,this.jsonPoint={type:"FeatureCollection",features:[]},this.jsonLine={type:"FeatureCollection",features:[]},this.points=[],this.markers=[],this.tooltip&&(this.tooltip.remove(),this.tooltip=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);});}};A.stylesInjected=false;var D=A;var Tt=class{constructor(e){this.mapDir="left";this.mixingMapConfigs=new Map;this.stashFeatures=new Map;this.layerFeaturesCache=new Map;this._activeBlinkCleanup=null;this._stashReady=Promise.resolve();this._stashReadyResolve=null;this._stashReadyReject=null;let o={version:8,sources:{},layers:[]};this.map=new ee.Map({container:e,style:o,center:[0,0],zoom:14,attributionControl:false,maxZoom:24}),v.base(this);}getMap(){return this.map}getMapConfigs(){return this.mapConfigs}destroy(){this._activeBlinkCleanup?.(),this._activeBlinkCleanup=null,this.invalidateStashReady(),this.stashFeatures.clear(),this.layerFeaturesCache.clear(),this.mixingMapConfigs.clear(),this.map.remove();}resetStashReady(){this._stashReadyResolve?.(),this._stashReady=new Promise((e,o)=>{this._stashReadyResolve=e,this._stashReadyReject=o;});}markStashReady(){this._stashReadyResolve?.(),this._stashReadyResolve=null,this._stashReadyReject=null;}invalidateStashReady(e){this._stashReadyReject?.(new Error(e??"TeeeMap \u5DF2\u9500\u6BC1\uFF1A\u8981\u7D20\u7F13\u5B58\u4E0D\u4F1A\u518D\u5C31\u7EEA")),this._stashReadyResolve=null,this._stashReadyReject=null;}whenStashed(e=3e4){return e<=0?this._stashReady:new Promise((o,i)=>{let n=setTimeout(()=>{i(new Error(`whenStashed \u8D85\u65F6(${e}ms)\uFF1A\u8981\u7D20\u7F13\u5B58\u672A\u5728\u9884\u671F\u65F6\u95F4\u5185\u5C31\u7EEA`));},e);this._stashReady.then(()=>{clearTimeout(n),o();},r=>{clearTimeout(n),i(r instanceof Error?r:new Error(String(r)));});})}onStashReady(e,o){this.whenStashed().then(e).catch(i=>{o?o(i):console.error("onStashReady: \u7B49\u5F85\u8981\u7D20\u7F13\u5B58\u5C31\u7EEA\u5931\u8D25",i);});}initMap(e,o=false){this.resetStashReady();let i=async()=>{try{if(console.log(`\u5F00\u59CB\u6784\u5EFA\u4E1A\u52A1\u5730\u56FE: ${e.id}`),Array.isArray(e.source))if(o){let{sourceLayers:h}=this.mixingMapConfigs.get(e.id.split("_")[1]);if(!h)return;e.source.forEach((g,S)=>{this.map.addSource(h[S],g);});}else {let{sourceLayers:h}=this.mapConfigs;if(!h)return;e.source.forEach((g,S)=>{this.map.addSource(h[S],g);});}else this.map.getSource(e.id)?console.warn(`\u5730\u56FE\u6E90\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u6DFB\u52A0: ${e.id}`):this.map.addSource(e.id,e.source);e.subSourceId&&e.subSource&&(this.map.getSource(e.subSourceId)?console.warn(`\u5730\u56FE\u6E90\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u6DFB\u52A0: ${e.subSourceId}`):this.map.addSource(e.subSourceId,e.subSource));let r=await J.createAllIcons();console.log(`\u56FE\u6807\u5217\u8868 (${r.length}):`,r),r.forEach(h=>{this.map.hasImage(h.id)?console.warn(`\u56FE\u6807\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u6DFB\u52A0: ${h.id}`):this.map.addImage(h.id,h.image);}),e.layers&&e.layers.forEach(h=>{this.map.getLayer(h.id)?console.debug(`\u56FE\u5C42\u5DF2\u5B58\u5728: ${h.id}`):this.map.addLayer(h);}),this.measureTool=new D(this.map);let s=this.map.getStyle()?.sources??{},l=Object.keys(s);console.log(`\u6E90\u5217\u8868 (${l.length}):`,l,s);let c=this.map.getStyle().layers??[],m=c.map(h=>h.id);console.log(`\u56FE\u5C42\u5217\u8868 (${m.length}):`,c);let u=this.map.listImages();console.log(`\u56FE\u6807\u5217\u8868 (${u.length}):`,u);let p=this.layerFeaturesCache.get("track")?.[0]??null;if(p){let h=p.geometry;this.mapDir=h.coordinates[0][0]-h.coordinates[1][0]>0?"left":"right";}console.groupEnd(),console.log(`\u5730\u56FE\u6784\u5EFA\u5168\u90E8\u5B8C\u6210: ${e.id}`);}catch(r){console.error(`\u5730\u56FE\u521D\u59CB\u5316\u5931\u8D25: ${e.id}`,r),r instanceof Error&&console.error(`\u9519\u8BEF\u8BE6\u60C5: ${r.message}`);}},n=()=>{this.map.once("idle",()=>{(o?this.stashMixMapAllFeature():this.stashAllFeature()).catch(a=>{console.error(`\u8981\u7D20\u7F13\u5B58\u5931\u8D25: ${e.id}`,a);}).finally(()=>this.markStashReady());});};this.map.loaded()?i().then(n).catch(r=>{console.error(r);}):this.map.on("load",()=>{i().then(n).catch(r=>{console.error(r);});});}initMixMap(e){this.resetStashReady();let o=async()=>{let n=await J.createAllIcons();console.log(`\u56FE\u6807\u5217\u8868 (${n.length}):`,n),n.forEach(g=>{this.map.hasImage(g.id)?console.warn(`\u56FE\u6807\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u6DFB\u52A0: ${g.id}`):this.map.addImage(g.id,g.image);});for(let g of e){if(Array.isArray(g.source)){let{sourceLayers:S}=this.mixingMapConfigs.get(g.id.split("_")[1]);if(!S)continue;g.source.forEach((b,_)=>{this.map.addSource(S[_],b);});}else this.map.getSource(g.id)?console.warn(`\u5730\u56FE\u6E90\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u6DFB\u52A0: ${g.id}`):this.map.addSource(g.id,g.source);g.layers&&g.layers.forEach(S=>{this.map.getLayer(S.id)?console.debug(`\u56FE\u5C42\u5DF2\u5B58\u5728: ${S.id}`):this.map.addLayer(S);});}this.measureTool=new D(this.map);let a=this.map.getStyle()?.sources??{},s=Object.keys(a);console.log(`\u6E90\u5217\u8868 (${s.length}):`,s,a);let l=this.map.getStyle().layers??[],c=l.map(g=>g.id);console.log(`\u56FE\u5C42\u5217\u8868 (${c.length}):`,l);let m=s.filter(g=>g.endsWith("_background"));c.filter(g=>g.endsWith("_background")).slice(1).forEach(g=>{this.map.getLayer(g)&&this.map.removeLayer(g);}),m.slice(1).forEach(g=>{this.map.getSource(g)&&this.map.removeSource(g);});let y=e[0],h=this.layerFeaturesCache.get(y?.id.split("_")[1]+"_track")?.[0]??null;if(h){let g=h.geometry;this.mapDir=g.coordinates[0][0]-g.coordinates[1][0]>0?"left":"right";}await this.stashMixMapAllFeature(),v.geojson(this);},i=async()=>{try{await o();}catch(n){console.error("\u6DF7\u5408\u5730\u56FE\u6784\u5EFA\u5931\u8D25",n);}finally{this.markStashReady();}};this.map.loaded()?i():this.map.once("load",()=>{i();});}createRSWPMap(e){let o=M.rswp(e),i=x.raster(o.sourceUrl),n=w.raster(o.id),r=M.geojson("rswp-geojson"),a=x.geojson(),s={id:o.id,source:i,subSourceId:r.id,subSource:a,layers:n};this.mapConfigs=o,this.mapConfigs.subSourceId=r.id,this.initMap(s);}createGraphMap(e,o,i){this.mapConfigs=M.graph(e,o,i);let n=x.graph(this.mapConfigs.sourceUrl),r=w.graph(this.mapConfigs),a={id:this.mapConfigs.id,source:n,layers:r};this.initMap(a),v.graph(this);}createSscsGraphMap(e){let o={normal:{color:"#1C5AFF",strokeColor:"#31E5FF"},reverse:{color:"#FFB400",strokeColor:"#31E5FF"},lock:{color:"#00C853",strokeColor:"#31E5FF"},fault:{color:"#E4002B",strokeColor:"#FFD700"},selected:{color:"#FFD700",strokeColor:"#FFFFFF"}},i="#1C5AFF",n="#31E5FF",r=(s,l)=>["match",["feature-state","state"],...Object.entries(o).flatMap(([c,m])=>[c,s(m)]),l],a={id:"sscs_graph",source:{type:"vector",tiles:[e],scheme:"tms",promoteId:"code"},layers:[{id:"sscs_graph_line",type:"line",source:"sscs_graph","source-layer":"cdst_trfc_line",paint:{"line-color":"orange","line-width":2}},{id:"sscs_graph_point",type:"circle",source:"sscs_graph","source-layer":"cdst_trfc_point",paint:{"circle-color":r(s=>s.color,i),"circle-radius":["interpolate",["linear"],["zoom"],10,5,13,15,22,20],"circle-opacity":.9,"circle-stroke-color":r(s=>s.strokeColor,n),"circle-stroke-width":2,"circle-blur":.2}},{id:"sscs_graph_line_label",type:"symbol",source:"sscs_graph","source-layer":"cdst_trfc_line",minzoom:10,layout:{"text-field":["get","name_abb"],"symbol-placement":"line","text-rotation-alignment":"map","text-size":["interpolate",["linear"],["zoom"],10,8,22,15]},paint:{"text-color":"#333333","text-halo-color":"#ffffff","text-halo-width":1.5}},{id:"sscs_graph_point_label",type:"symbol",source:"sscs_graph","source-layer":"cdst_trfc_point",minzoom:10,layout:{"text-field":["get","name"],"text-size":["interpolate",["linear"],["zoom"],10,5,13,9,22,15],"text-max-width":3},paint:{"text-color":"white"}}]};this.initMap(a);}setSscsPointState(e,o){this.map.setFeatureState({source:"sscs_graph",sourceLayer:"cdst_trfc_point",id:e},{state:o});}createGeomMap(e,o,i){this.mapConfigs=M.geom(e,o,i);let n=x.geom(this.mapConfigs.sourceUrl),r=w.geom(this.mapConfigs),a={id:this.mapConfigs.id,source:n,layers:r};this.initMap(a);}createGeomEncryptedMap(e,o,i){v.encrypt(this),this.mapConfigs=M.geom(e,o,i);let n=x.geom(this.mapConfigs.sourceUrl),r=w.geom(this.mapConfigs),a={id:this.mapConfigs.id,source:n,layers:r};this.initMap(a);}async createGeoJsonGeomStationMap(e,o=true){let i=e.map(l=>l.name),n=i.map(l=>`geojson_${l}`);this.mapConfigs=M.geojson("geojson"),this.mapConfigs.layers=i,this.mapConfigs.sourceLayers=n;let r=await Promise.all(e.map(async(l,c)=>{let m=n[c],u=l.name;if(this.map.getSource(m))return;let y=l.data,p;return typeof y=="string"?(p=await(await fetch(y)).json(),T(u,p)):(p=y,T(u,p)),this.layerFeaturesCache.set(u,p.features),x.geojson(p)})),a={id:this.mapConfigs.id,source:r,layers:w.geojsonGeom(i,n)};if(this.initMap(a),o){let l="gaode-satellite",c="gaode-satellite-layer";this.map.on("load",()=>{this.map.addSource(l,{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:c,type:"raster",source:l});});}let s=e.find(l=>l.name==="track")?.data;if(s){let l=bbox(s);this.map.fitBounds([[l[0],l[1]],[l[2],l[3]]],{padding:100,maxZoom:15,duration:0});}v.geojson(this);}async createMixGeoJsonGeomMap(e,o=true){if(e.length===0)return;let i=await Promise.all(e.map(async r=>{if(r.type==="region"){let a=r.geojsonData.map(c=>c.name),s=a.map(c=>`geojson_region_${r.code}_${c}`);this.mixingMapConfigs.set(r.code,{id:`geojson_${r.code}`,layers:a,sourceLayers:s,type:"region"});let l=await Promise.all(r.geojsonData.map(async(c,m)=>{let u=s[m],y=c.name;if(this.map.getSource(u))return;let p=c.data,h;return typeof p=="string"?(h=await(await fetch(p)).json(),T(y,h)):(h=p,T(y,h)),this.layerFeaturesCache.set(`${r.code}_${y}`,h.features),x.geojson(h)}));return {id:`geojson_${r.code}`,source:l,layers:w.geojsonGeom(a,s)}}else {let a=r.geojsonData.map(c=>c.name),s=a.map(c=>`geojson_station_${r.code}_${c}`);this.mixingMapConfigs.set(r.code,{id:`geojson_${r.code}`,layers:a,sourceLayers:s,type:"station"});let l=await Promise.all(r.geojsonData.map(async(c,m)=>{let u=s[m],y=c.name;if(this.map.getSource(u))return;let p=c.data,h;return typeof p=="string"?(h=await(await fetch(p)).json(),T(y,h)):(h=p,T(y,h)),this.layerFeaturesCache.set(`${r.code}_${y}`,h.features),x.geojson(h)}));return {id:`geojson_${r.code}`,source:l,layers:w.geojsonGeom(a,s)}}}));if(this.initMixMap(i),o){let r="gaode-satellite",a="gaode-satellite-layer";this.map.on("load",()=>{this.map.addSource(r,{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:a,type:"raster",source:r});});}let n=e[1]?.geojsonData.find(r=>r.name==="track")?.data;if(n){let r=bbox(n);this.map.fitBounds([[r[0],r[1]],[r[2],r[3]]],{padding:100,maxZoom:15,duration:0});}v.geojson(this);}async createGeoJsonStationMap(e){let o=e.map(s=>s.name),i=o.map(s=>`geojson_${s}`);this.mapConfigs=M.geojson("geojson"),this.mapConfigs.layers=o,this.mapConfigs.sourceLayers=i;let n=await Promise.all(e.map(async(s,l)=>{let c=i[l],m=s.name;if(this.map.getSource(c))return;let u=s.data,y;if(typeof u=="string"){let h=await(await fetch(u)).json();y=O(h),T(m,y);}else y=O(u),T(m,y);return this.layerFeaturesCache.set(m,y.features),x.geojson(y)})),r={id:this.mapConfigs.id,source:n,layers:w.geojson(o,i)};this.initMap(r);let a=e.find(s=>s.name==="track")?.data;if(a){let s=bbox(O(a));this.map.fitBounds([[s[0],s[1]],[s[2],s[3]]],{padding:100,maxZoom:15,duration:0});}v.geojson(this);}async createGeoJsonRegionMap(e,o){let i=o.map(l=>l.name),n=i.map(l=>`geojson_region_${e}_${l}`);this.mixingMapConfigs.set(e,{id:`geojson_${e}`,layers:i,sourceLayers:n,type:"region"});let r=await Promise.all(o.map(async(l,c)=>{let m=n[c],u=l.name;if(this.map.getSource(m))return;let y=l.data,p;if(typeof y=="string"){let g=await(await fetch(y)).json();p=O(g),T(u,p);}else p=O(y),T(u,p);return this.layerFeaturesCache.set(u,p.features),x.geojson(p)})),a={id:`geojson_${e}`,source:r,layers:w.geojson(i,n)};this.initMap(a,true);let s=o.find(l=>l.name==="track")?.data;if(s){let l=bbox(O(s));this.map.fitBounds([[l[0],l[1]],[l[2],l[3]]],{padding:100,maxZoom:15,duration:0});}v.geojson(this);}async createMixGeoJsonMap(e){if(e.length===0)return;let o=await Promise.all(e.map(async n=>{if(n.type==="region"){let r=n.geojsonData.map(l=>l.name),a=r.map(l=>`geojson_region_${n.code}_${l}`);this.mixingMapConfigs.set(n.code,{id:`geojson_${n.code}`,layers:r,sourceLayers:a,type:"region"});let s=await Promise.all(n.geojsonData.map(async(l,c)=>{let m=a[c],u=l.name;if(this.map.getSource(m))return;let y=l.data,p;if(typeof y=="string"){let g=await(await fetch(y)).json();p=O(g),T(u,p);}else p=O(y),T(u,p);return this.layerFeaturesCache.set(`${n.code}_${u}`,p.features),x.geojson(p)}));return {id:`geojson_${n.code}`,source:s,layers:w.geojson(r,a)}}else {let r=n.geojsonData.map(l=>l.name),a=r.map(l=>`geojson_station_${n.code}_${l}`);this.mixingMapConfigs.set(n.code,{id:`geojson_${n.code}`,layers:r,sourceLayers:a,type:"station"});let s=await Promise.all(n.geojsonData.map(async(l,c)=>{let m=a[c],u=l.name;if(this.map.getSource(m))return;let y=l.data,p;if(typeof y=="string"){let g=await(await fetch(y)).json(),S=ge(g,n.deltaInfo?.deltax||0,n.deltaInfo?.deltay||0);p=O(S),T(u,p);}else {let h=ge(y,n.deltaInfo?.deltax||0,n.deltaInfo?.deltay||0);p=O(h),T(u,p);}return this.layerFeaturesCache.set(`${n.code}_${u}`,p.features),x.geojson(p)}));return {id:`geojson_${n.code}`,source:s,layers:w.geojson(r,a)}}}));this.initMixMap(o);let i=e[1]?.geojsonData.find(n=>n.name==="track")?.data;if(i){let n=bbox(O(i));this.map.fitBounds([[n[0],n[1]],[n[2],n[3]]],{padding:100,maxZoom:15,duration:0});}}createRasterMap(e){this.mapConfigs=M.raster(e);let o=x.raster(this.mapConfigs.sourceUrl),i=w.raster(this.mapConfigs.id),n={id:this.mapConfigs.id,source:o,layers:i};this.initMap(n);}createEncryptedRasterMap(e){v.encrypt(this),this.mapConfigs=M.raster(e);let o=x.raster(this.mapConfigs.sourceUrl),i=w.raster(this.mapConfigs.id),n={id:this.mapConfigs.id,source:o,layers:i};this.initMap(n);}async stashMixMapAllFeature(){if(this.mixingMapConfigs.size!==0)for(let[e,o]of this.mixingMapConfigs){let i=o.type,n=o.layers??[];await Promise.all(n.map(async r=>{let a=`geojson_${i}_${e}_${r}`,s=this.map.getSource(a);if(!s)return;(await s.getData()).features?.forEach(m=>{let u=m.properties?.code;u&&!this.stashFeatures.get(u)&&this.stashFeatures.set(u,{sourceLayer:a,properties:m.properties});});}));}}async stashAllFeature(){if(!this.mapConfigs)return;let e=this.mapConfigs.sourceLayers,o=this.mapConfigs.layers??[],i=this.mapConfigs.id;this.stashFeatures.clear(),e?.forEach((n,r)=>{if(n.includes("prevention"))return;let a=this.map.querySourceFeatures(i,{sourceLayer:n}),s=new Map;a.forEach(c=>{let m=c.properties?.code;m&&(this.stashFeatures.set(m,{sourceLayer:n}),s.set(String(m),c));});let l=o[r];l&&this.layerFeaturesCache.set(l,Array.from(s.values()));}),await Promise.all(o.map(async n=>{let r=`geojson_${n}`,a=this.map.getSource(r);if(!a)return;let l=await a.getData(),c=l.features??[];l.features?.forEach(m=>{let u=m.properties?.code;u&&!this.stashFeatures.get(u)&&this.stashFeatures.set(u,{sourceLayer:r,properties:m.properties});}),c.length&&this.layerFeaturesCache.set(n,c);}));}updateFeatureState(e,o){let i=this.stashFeatures.get(e);if(!i)return;if(Object.assign(i,o),i.sourceLayer?.startsWith("geojson_"))this.map.setFeatureState({source:i.sourceLayer,id:e},i);else {if(!this.mapConfigs)return;this.map.setFeatureState({source:this.mapConfigs.id,sourceLayer:i.sourceLayer,id:e},i);}}getFeatureState(e){let o=this.stashFeatures.get(e);if(o)return o}locateGeojsonFeature(e,o=true){let i=bbox(o?O(e):e);this.map.fitBounds([[i[0],i[1]],[i[2],i[3]]],{padding:50,maxZoom:18});}queryGeojsonFeatures(e){let o=Array.from(this.layerFeaturesCache.keys()).filter(i=>i.endsWith(e));return o.length?o.flatMap(i=>this.layerFeaturesCache.get(i)??[]):[]}getTrackCircuitFeaturesByCodes(e){let o=Array.from(this.layerFeaturesCache.keys()).filter(i=>i.endsWith("track_circuit"));return o.length?o.flatMap(i=>this.layerFeaturesCache.get(i)??[]).filter(i=>e.includes(i.properties.code))??[]:[]}getGeojsonLayerFeaturesByCode(e,o){let i=Array.from(this.layerFeaturesCache.keys()).filter(n=>n.endsWith(o));if(i.length)return i.flatMap(n=>this.layerFeaturesCache.get(n)??[]).find(n=>n.properties.code===e)}locateFeatureByCode(e,o){let i=this.getGeojsonLayerFeaturesByCode(e,o);if(!i){console.warn(`\u672A\u627E\u5230\u8981\u7D20\uFF0C\u65E0\u6CD5\u5B9A\u4F4D: code=${e}, layerType=${o}`);return}let n={type:"FeatureCollection",features:[i]};this.locateGeojsonFeature(n,false);}smoothBlinkFeature(e,o,i={}){let n=this.getGeojsonLayerFeaturesByCode(e,o);if(!n){console.warn(`\u672A\u627E\u5230\u8981\u7D20\uFF0C\u65E0\u6CD5\u9AD8\u4EAE: code=${e}, layerType=${o}`);return}let r={type:"FeatureCollection",features:[n]},s=["signal","switch","bumper"].includes(o)?"point":"line",l=`blink-temp-${e}-${o}`;this._activeBlinkCleanup?.(),this._activeBlinkCleanup=null,this.map.getSource(l)&&this.map.removeSource(l),this.map.addSource(l,{type:"geojson",data:r});let c=`${l}-blink-highlight`,{duration:m=3e3,blinkSpeed:u=500,baseColor:y=[0,255,0],minAlpha:p=.3,maxAlpha:h=.7,strokeWidthBase:g=3,strokeWidthRange:S=2}=i,b=null,_=null;if(s==="point"){let $=`blink-point-icon-${l}`;if(!this.map.hasImage($)){let N=document.createElement("canvas");N.width=36,N.height=36;let C=N.getContext("2d");C.beginPath(),C.arc(36/2,36/2,36/2-2,0,Math.PI*2),C.fillStyle=`rgba(${y.join(",")}, 0.3)`,C.fill(),C.beginPath(),C.arc(36/2,36/2,36/3,0,Math.PI*2),C.fillStyle=`rgb(${y.join(",")})`,C.fill(),C.strokeStyle="#fff",C.lineWidth=2,C.stroke();let ie=C.getImageData(0,0,36,36);this.map.addImage($,{width:36,height:36,data:ie.data});}this.map.getLayer(c)&&this.map.removeLayer(c),this.map.addLayer({id:c,type:"symbol",source:l,layout:{"icon-image":$,"icon-allow-overlap":true,"icon-ignore-placement":true},paint:{"icon-opacity":h}});let E=U=>{b||(b=U);let N=U-b;if(N<m){let C=Math.sin(N/u*Math.PI*2)*.5+.5,ie=p+(h-p)*C;this.map.setPaintProperty(c,"icon-opacity",ie),_=requestAnimationFrame(E);}else this.map.getLayer(c)&&this.map.removeLayer(c),this.map.getSource(l)&&this.map.removeSource(l),_=null,this._activeBlinkCleanup=null;};_=requestAnimationFrame(E);let W=()=>{_&&cancelAnimationFrame(_),this.map.getLayer(c)&&this.map.removeLayer(c),this.map.getSource(l)&&this.map.removeSource(l);};return this._activeBlinkCleanup=W,W}let k=`${c}-outline`;this.map.getLayer(k)&&this.map.removeLayer(k),this.map.addLayer({id:k,type:"line",source:l,paint:{"line-color":`rgb(${y.join(",")})`,"line-width":g}});let G=$=>{b||(b=$);let E=$-b;if(E<m){let W=Math.sin(E/u*Math.PI*2)*.5+.5,N=g+S*W;this.map.setPaintProperty(k,"line-width",N),_=requestAnimationFrame(G);}else this.map.getLayer(k)&&this.map.removeLayer(k),this.map.getSource(l)&&this.map.removeSource(l),_=null,this._activeBlinkCleanup=null;};_=requestAnimationFrame(G);let te=()=>{_&&cancelAnimationFrame(_),this.map.getLayer(k)&&this.map.removeLayer(k),this.map.getSource(l)&&this.map.removeSource(l);};return this._activeBlinkCleanup=te,te}};var kt=t=>t?.type==="LineString"?[t.coordinates]:t?.type==="MultiLineString"?t.coordinates:[],wt=t=>kt(t.geometry).reduce((e,o)=>e+o.length,0),xi=(t,e)=>{let o=z.point(e.coordinates),i=null;for(let r of kt(t)){if(r.length<2)continue;let a=z.nearestPointOnLine(z.lineString(r),o),s=a.properties.pointDistance||Number.POSITIVE_INFINITY;(!i||s<i.dist)&&(i={dist:s,index:a.properties.segmentIndex||0,coords:r});}if(!i)return null;let n=Math.min(i.index,i.coords.length-2);return [i.coords[n]??[],i.coords[n+1]??[]]},Ot=(t,e)=>{let o=xi(t,e);if(!o)return 0;let[[i,n],[r,a]]=o;return Math.atan2(r-i,a-n)*180/Math.PI},In=(t,e)=>{let{sourceId:o,pointSourceLayer:i,trackSourceLayer:n,layerId:r,controlFeatures:a,filterPoint:s,angleOffset:l=0,layerSuffix:c}=e;if(!t.getLayer(r)){console.warn(`\u56FE\u5C42\u4E0D\u5B58\u5728: ${r}`);return}let m=new Map;for(let h of a){let g=h.properties?.code,S=h.properties?.trackCode;g&&S&&m.set(g,S);}let u=new Map;for(let h of t.querySourceFeatures(o,{sourceLayer:n})){let g=h,S=h.properties.code;if(!S)continue;let b=u.get(S);(!b||wt(g)>wt(b))&&u.set(S,g);}let y=new Map;for(let h of t.querySourceFeatures(o,{sourceLayer:i})){if(s&&!s(h)||h.geometry.type!=="Point")continue;let g=h.properties.code;if(!g||y.has(g))continue;let S=m.get(g),_=(S?u.get(S):void 0)?.geometry;if(!S||!_||_.type!=="LineString"&&_.type!=="MultiLineString"){y.set(g,l),console.error("\u672A\u627E\u5230\u5173\u8054\u80A1\u9053",g,S);continue}c==="jcw"?y.set(g,Ot(_,h.geometry)+l+90):y.set(g,Ot(_,h.geometry)+l);}if(y.size===0){t.setLayoutProperty(r,"icon-rotate",l);return}let p=["match",["to-string",["get","code"]],...[...y.entries()].flatMap(([h,g])=>[h,g]),l];t.setLayoutProperty(r,"icon-rotate",p);};
33
- export{It as BS_SIGNAL_MAP,ke as BsSignalStateEnums,Mt as INTERLOCK_CIRCUIT_MAP,Q as INTERLOCK_SIGNAL_COLOR_MAP,oe as INTERLOCK_SIGNAL_MAP,I as INTERLOCK_SWITCHLOC_MAP,we as InterLockCircuitStateEnums,B as InterLockInsulation,Te as InterLockSignalStateEnums,Oe as InterLockSwitchlocStateEnums,R as InterLockVisualization,H as InterlockProtocol,L as MapColor,D as MeasureTool,Nt as PREVENTION_TYPES,ve as PreventionEnums,Ce as SignalColorEnums,xe as StationFeatureCodeEnums,Tt as TeeeMap,In as attachTrackAngle,_e as canvasCreator,Ot as getTrackBearing,J as imageCreater,ge as offsetFeatureCollection,O as transformGeoJsonFrom3857,T as transformGeoJsonProperties};//# sourceMappingURL=index.js.map
34
- //# sourceMappingURL=index.js.map
33
+ export{It as BS_SIGNAL_MAP,ke as BsSignalStateEnums,Mt as INTERLOCK_CIRCUIT_MAP,Q as INTERLOCK_SIGNAL_COLOR_MAP,oe as INTERLOCK_SIGNAL_MAP,I as INTERLOCK_SWITCHLOC_MAP,we as InterLockCircuitStateEnums,B as InterLockInsulation,Te as InterLockSignalStateEnums,Oe as InterLockSwitchlocStateEnums,R as InterLockVisualization,H as InterlockProtocol,L as MapColor,D as MeasureTool,Nt as PREVENTION_TYPES,ve as PreventionEnums,Ce as SignalColorEnums,xe as StationFeatureCodeEnums,Tt as TeeeMap,In as attachTrackAngle,_e as canvasCreator,Ot as getTrackBearing,J as imageCreater,ge as offsetFeatureCollection,O as transformGeoJsonFrom3857,T as transformGeoJsonProperties};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teeechina/teee-map",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "基于 maplibre-gl 封装的业务地图 SDK,面向太昌 GIS 业务流提供开箱即用的地图初始化、图层管理、要素状态控制及加密瓦片支持。",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -33,7 +33,7 @@
33
33
  ],
34
34
  "sideEffects": false,
35
35
  "peerDependencies": {
36
- "maplibre-gl": "^5.0.0 || ^6.0.0"
36
+ "maplibre-gl": "^6.0.0"
37
37
  },
38
38
  "scripts": {
39
39
  "dev": "tsup --watch",