gisviewer-vue3-arcgis 1.0.104 → 1.0.105

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.
@@ -5,7 +5,7 @@ import * as h from "three";
5
5
  import { GLTFLoader as R } from "three/examples/jsm/loaders/GLTFLoader.js";
6
6
  import { EVehiclePlateState as p } from "../../../types/index.mjs";
7
7
  import C from "../../stores/index.mjs";
8
- class N {
8
+ class k {
9
9
  constructor(i) {
10
10
  this.zoomThreshold = 18.5, this.roughness = 0.4, this.metalness = 0.5, this.defaultMaterial = new h.MeshPhysicalMaterial({
11
11
  color: 16777215,
@@ -217,7 +217,7 @@ class N {
217
217
  this.vehicleObjectMap.delete(e), this.historyPositionMap.delete(e);
218
218
  }
219
219
  async toggleTrafficInfo(i) {
220
- i.name === "vehiclePlate" && (i.visible === !0 && this.currentSpriteContent === p.None ? await this.updatePanelContent(p.Id) : await this.updatePanelContent(
220
+ i.name === "vehiclePlate" && (i.visible === !0 && this.currentSpriteContent === p.None ? await this.updatePanelContent(p.PlateNumber) : await this.updatePanelContent(
221
221
  i.visible ? this.currentSpriteContent : p.None
222
222
  ));
223
223
  }
@@ -403,5 +403,5 @@ class N {
403
403
  }
404
404
  }
405
405
  export {
406
- N as default
406
+ k as default
407
407
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const R=require("@arcgis/core/core/reactiveUtils.js"),P=require("@arcgis/core/geometry/SpatialReference"),S=require("@arcgis/core/views/3d/externalRenderers"),C=require("three"),T=require("three/examples/jsm/loaders/GLTFLoader.js"),p=require("../../../types/index.js"),V=require("../../stores/index.js");function g(u){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const e in u)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(u,e);Object.defineProperty(i,e,t.get?t:{enumerable:!0,get:()=>u[e]})}}return i.default=u,Object.freeze(i)}const k=g(R),b=g(S),h=g(C);class x{constructor(i){this.zoomThreshold=18.5,this.roughness=.4,this.metalness=.5,this.defaultMaterial=new h.MeshPhysicalMaterial({color:16777215,emissive:0,roughness:this.roughness,metalness:this.metalness}),this.materialMap=new Map([[1,this.createCarMaterial(16777215)],[2,this.createCarMaterial(7833753)],[3,this.createCarMaterial(16766720)],[4,this.createCarMaterial(16758465)],[5,this.createCarMaterial(14423100)],[6,this.createCarMaterial(3329330)],[7,this.createCarMaterial(2003183)],[8,this.createCarMaterial(16032864)],[9,this.createCarMaterial(2105376)],[10,this.createCarMaterial(9662683)],[99,this.createCarMaterial(6908265)]]),this.carModelReady=!1,this.vanModelReady=!1,this.truckModelReady=!1,this.busModelReady=!1,this.bicycleModelReady=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.currentSpriteContent=p.EVehiclePlateState.None,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.needInterpolate=!0,this.updateModel=!1;const e=V.default.useAppDataStore;this.assetsRoot=JSON.parse(JSON.stringify(e.mapConfig)).assetsRoot,this.view=i;const t=new T.GLTFLoader;t.load(`${this.assetsRoot}/3DModels/car.glb`,s=>{this.carModel=s.scene,this.carModel.rotation.x=h.MathUtils.degToRad(90),this.carModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/van.glb`,s=>{this.vanModel=s.scene,this.vanModel.rotation.x=h.MathUtils.degToRad(90),this.vanModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/truck.glb`,s=>{this.truckModel=s.scene,this.truckModel.scale.set(1.2,1,1.5),this.truckModel.rotation.x=h.MathUtils.degToRad(90),this.truckModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/bus.glb`,s=>{this.busModel=s.scene,this.busModel.rotation.x=h.MathUtils.degToRad(90),this.busModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/bicycle.glb`,s=>{this.bicycleModel=s.scene,this.bicycleModel.rotation.x=h.MathUtils.degToRad(90),this.bicycleModel.rotation.y=h.MathUtils.degToRad(180),this.bicycleModelReady=!0}),document.addEventListener("visibilitychange",()=>{this.clearVehicles(),this.needInterpolate=!document.hidden},!1),k.watch(()=>this.view.zoom,(s,a)=>{(a<=this.zoomThreshold&&s>this.zoomThreshold||a>this.zoomThreshold&&s<=this.zoomThreshold)&&(this.updateModel=!0)})}createCarMaterial(i){return new h.MeshPhysicalMaterial({color:i,emissive:0,roughness:this.roughness,metalness:this.metalness})}setInterpolate(i){this.clearVehicles(),this.needInterpolate=i}async setup(i){this.context=i,this.renderer=new h.WebGLRenderer({context:i.gl,premultipliedAlpha:!0,logarithmicDepthBuffer:!0,antialias:!0,powerPreference:"high-performance"}),this.renderer.shadowMap.enabled=!0,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setViewport(0,0,this.view.width,this.view.height),this.renderer.autoClearDepth=!1,this.renderer.autoClearStencil=!1,this.renderer.autoClearColor=!1;const e=this.renderer.setRenderTarget.bind(this.renderer);this.renderer.setRenderTarget=o=>{e(o),o==null&&i.bindRenderTarget()},this.scene=new h.Scene;const{camera:t}=i;this.camera=new h.PerspectiveCamera(t.fovY,t.aspect,.1,1e5),this.ambient=new h.AmbientLight(16777215,2e4),this.scene.add(this.ambient),this.sun=new h.DirectionalLight(16777215,2e4);const s=[121.46790813287619,31.239514870157972,1e3],a=this.toRenderCoordinates(s);this.sun.position.set(a[0],a[1],a[2]),this.scene.add(this.sun),i.resetWebGLState()}async render(i){var s;const e=i.camera;if(this.camera.position.set(e.eye[0],e.eye[1],e.eye[2]),this.camera.up.set(e.up[0],e.up[1],e.up[2]),this.camera.lookAt(new h.Vector3(e.center[0],e.center[1],e.center[2])),this.camera.projectionMatrix.fromArray(e.projectionMatrix),this.needInterpolate)for(const a of this.vehicleObjectMap.keys()){const o=(s=this.vehicleObjectMap.get(a))==null?void 0:s.model;if(!o)continue;const r=this.computeVehiclePosition(a);if(r){const n=this.toRenderCoordinates(r);o.position.set(n[0],n[1],n[2]),o.rotation.y=h.MathUtils.degToRad(-r[3])}}const t=i.sunLight;this.sun.position.set(t.direction[0],t.direction[1],t.direction[2]),this.sun.intensity=t.diffuse.intensity,this.sun.color=new h.Color(t.diffuse.color[0],t.diffuse.color[1],t.diffuse.color[2]),this.ambient.intensity=t.ambient.intensity,this.ambient.color=new h.Color(t.ambient.color[0],t.ambient.color[1],t.ambient.color[2]),this.renderer.resetState(),i.bindRenderTarget(),this.renderer.render(this.scene,this.camera),b.requestRender(this.view),i.resetWebGLState()}async addVehicles(i){if(!(!this.carModelReady||!this.vanModelReady||!this.truckModelReady||!this.busModelReady||!this.bicycleModelReady))for(const e of i){const{vehicleId:t,localTimestamp:s}=e,a=Number(e.x),o=Number(e.y),r=Number(e.heading);this.historyPositionMap.set(t,[{pos:[a,o,0],heading:r,time:s}]);const n=this.getVehicleModel(e);n.name=t,n.visible=!this.needInterpolate;try{const l=await this.createPlateSprite(e);l&&(n.add(l),l.position.set(0,5,-4)),this.scene.add(n),this.vehicleObjectMap.set(t,{model:n,data:e,waitForDelete:!1,isMoving:!1})}catch(l){console.log("createPlateSprite error:",l)}}}async updateVehicles(i){if(!this.carModelReady||!this.vanModelReady||!this.truckModelReady||!this.busModelReady||!this.bicycleModelReady)return;const e=[];for(const t of i){const{vehicleId:s,localTimestamp:a}=t,o=Number(t.x),r=Number(t.y);let n=Number(t.heading);const l=this.vehicleObjectMap.get(s);if(!l)e.push(t);else{if(this.updateModel||l.data.vehicleColor!==t.vehicleColor||l.data.vehicleType!==t.vehicleType){this.scene.remove(l.model),this.disposeModel(l.model),l.model=this.getVehicleModel(t);const c=await this.createPlateSprite(t);c&&(l.model.add(c),c.position.set(0,5,-4)),this.scene.add(l.model)}if(l.data.showName!==t.showName||l.data.plateColor!==t.plateColor){const c=l.model.getObjectByName("VehiclePlate");c&&(l.model.remove(c),this.disposeModel(c));const d=await this.createPlateSprite(t);d&&(l.model.add(d),d.position.set(0,5,-4))}if(l.data=t,this.needInterpolate){const c=this.historyPositionMap.get(s),d=c[c.length-1];Math.abs(n-d.heading)>=180&&(n>d.heading?d.heading+=360:n+=360),c.push({pos:[o,r,0],heading:n,time:a})}else{this.historyPositionMap.set(s,[{pos:[o,r,0],heading:n,time:a}]);const c=this.toRenderCoordinates([o,r,0]);l.model.position.set(c[0],c[1],c[2]),l.model.rotation.y=h.MathUtils.degToRad(-n)}}}this.addVehicles(e),this.updateModel=!1,this.needInterpolate||this.render(this.context)}toRenderCoordinates(i){const e=[0,0,0];return b.toRenderCoordinates(this.view,i,0,P.WGS84,e,0,1),e}deleteVehicles(i){i.forEach(e=>{const t=this.vehicleObjectMap.get(e);t&&(this.needInterpolate?t.isMoving?t.waitForDelete=!0:this.deleteVehicle(t):this.deleteVehicle(t))})}deleteVehicle(i){this.scene.remove(i.model),this.disposeModel(i.model);const e=i.data.vehicleId;this.vehicleObjectMap.delete(e),this.historyPositionMap.delete(e)}async toggleTrafficInfo(i){i.name==="vehiclePlate"&&(i.visible===!0&&this.currentSpriteContent===p.EVehiclePlateState.None?await this.updatePanelContent(p.EVehiclePlateState.Id):await this.updatePanelContent(i.visible?this.currentSpriteContent:p.EVehiclePlateState.None))}clearVehicles(){for(const i of this.vehicleObjectMap.keys()){const e=this.vehicleObjectMap.get(i);e&&(this.disposeModel(e.model),this.scene.remove(e.model))}this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}async updatePanelContent(i){if(i!==this.currentSpriteContent){this.currentSpriteContent=i;for(const e of this.vehicleObjectMap.keys()){const t=this.vehicleObjectMap.get(e);if(t){const s=t.model.getObjectByName("VehiclePlate");if(s&&(t.model.remove(s),this.disposeModel(s)),i!==p.EVehiclePlateState.None){const a=await this.createPlateSprite(t.data);a&&(t.model.add(a),a.position.set(0,5,-4))}}}}}toggleGroundVehicle(i){console.log("toggleGroundVehicle",i),this.showGroundVehicle=i}toggleElevatedVehicle(i){this.showElevatedVehicle=i}disposeModel(i){i.traverse(e=>{e instanceof h.Mesh&&(e.geometry.dispose(),e.material.dispose())})}computeVehiclePosition(i){const e=this.historyPositionMap.get(i),t=this.vehicleObjectMap.get(i);if(!t||!e||!t.isMoving&&e.length<=2)return;const s=Date.now();t.isMoving=!0,t.data.roadLayer==="1"?t.model.visible=this.showGroundVehicle:t.model.visible=this.showElevatedVehicle,t.segmentStartTime||(t.segmentStartTime=s,t.segmentTotalTime=e[1].time-e[0].time);const a=s-t.segmentStartTime,o=Math.min(a/t.segmentTotalTime,1);if(o===1)if(e.shift(),e.length===1){t.waitForDelete===!0?this.deleteVehicle(t):(t.segmentStartTime=void 0,t.segmentTotalTime=void 0,t.model.visible=!1,t.isMoving=!1,console.log("pause vehicle",i));return}else return t.segmentStartTime=Date.now(),t.segmentTotalTime=e[1].time-e[0].time,(e[1].heading>=270&&e[0].heading<=90||e[1].heading<=90&&e[0].heading>=270)&&(e[1].heading>e[0].heading?e[0].heading+=360:e[1].heading+=360),e[0].pos.concat(e[0].heading);else{const r=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*o,n=e[0].pos[1]+(e[1].pos[1]-e[0].pos[1])*o,l=e[0].heading+(e[1].heading-e[0].heading)*o;return[r,n,0,l]}}getVehicleModel(i){if(this.view.zoom<=this.zoomThreshold){const e=new h.SphereGeometry(5,32,32),t=new h.MeshPhysicalMaterial({color:325253,emissive:0,roughness:this.roughness,metalness:this.metalness});return new h.Mesh(e,t)}else{let e;if(i.ptcType===2)e=this.bicycleModel.clone();else{switch(i.vehicleType){case 10:e=this.carModel.clone();break;case 20:e=this.vanModel.clone();break;case 25:e=this.truckModel.clone();break;case 50:e=this.busModel.clone();break;default:e=this.carModel.clone();break}const t=this.materialMap.get(i.vehicleColor)||this.defaultMaterial;let s=!1;e.traverse(a=>{!s&&a instanceof h.Mesh&&(a.material=t,s=!0)})}return e}}createCanvas(i,e,t){const s=document.createElement("canvas"),a=i.width,o=i.height;s.width=a,s.height=o;const r=s.getContext("2d");if(!r){console.log("canvas创建失败");return}return r.fillStyle="rgba(0,0,0,0.0)",r.fillRect(0,0,a,o),r.drawImage(i,0,0,a,o),r.beginPath(),r.translate(a/2,o/2),r.fillStyle=t,r.font="bold 32px 宋体",r.textBaseline="middle",r.textAlign="center",r.fillText(e,0,0),s}createPlateSprite(i){return new Promise((e,t)=>{var l,c;const s=!i.plateNo||i.plateNo==="0"||i.plateNo==="000000";if(this.currentSpriteContent===p.EVehiclePlateState.None||this.currentSpriteContent===p.EVehiclePlateState.PlateNumber&&s){e(void 0);return}const a=new Image;let o="",r="",n="";if(this.currentSpriteContent===p.EVehiclePlateState.PlateNumber||this.currentSpriteContent===p.EVehiclePlateState.Mix)if(s)o="grey",r=i.ptcId,n="#ffffff";else switch(r=((l=i.showName)==null?void 0:l.substring(0,2))+"•"+((c=i.showName)==null?void 0:c.substring(2)),i.plateColor){case 1:o="blue",n="#ffffff";break;case 2:o="yellow",n="#000000";break;case 3:o="white",n="#000000";break;case 4:o="black";break;case 5:o="neo_yellow",n="#000000";break;case 6:o="neo_green",n="#000000";break;default:o="grey",r=i.plateNo,n="#ffffff";break}else this.currentSpriteContent===p.EVehiclePlateState.Id&&(o="grey",r=i.ptcId,n="#ffffff");a.src=`${this.assetsRoot}/Images/PlateBG/${o}.png`,a.onload=()=>{const d=this.createCanvas(a,r,n);if(!d)t("canvas创建失败");else{const f=new h.CanvasTexture(d),v=new h.SpriteMaterial({map:f,transparent:!1}),m=new h.Sprite(v),M=.05,y=d.width*M,w=d.height*M;m.scale.set(y,w,1),m.name="VehiclePlate",e(m)}a.onerror=f=>{console.log(`号牌背景加载失败: ${a.src}`,f),t(f)}}})}}exports.default=x;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const P=require("@arcgis/core/core/reactiveUtils.js"),R=require("@arcgis/core/geometry/SpatialReference"),S=require("@arcgis/core/views/3d/externalRenderers"),C=require("three"),T=require("three/examples/jsm/loaders/GLTFLoader.js"),p=require("../../../types/index.js"),V=require("../../stores/index.js");function g(u){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const e in u)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(u,e);Object.defineProperty(i,e,t.get?t:{enumerable:!0,get:()=>u[e]})}}return i.default=u,Object.freeze(i)}const N=g(P),b=g(S),h=g(C);class k{constructor(i){this.zoomThreshold=18.5,this.roughness=.4,this.metalness=.5,this.defaultMaterial=new h.MeshPhysicalMaterial({color:16777215,emissive:0,roughness:this.roughness,metalness:this.metalness}),this.materialMap=new Map([[1,this.createCarMaterial(16777215)],[2,this.createCarMaterial(7833753)],[3,this.createCarMaterial(16766720)],[4,this.createCarMaterial(16758465)],[5,this.createCarMaterial(14423100)],[6,this.createCarMaterial(3329330)],[7,this.createCarMaterial(2003183)],[8,this.createCarMaterial(16032864)],[9,this.createCarMaterial(2105376)],[10,this.createCarMaterial(9662683)],[99,this.createCarMaterial(6908265)]]),this.carModelReady=!1,this.vanModelReady=!1,this.truckModelReady=!1,this.busModelReady=!1,this.bicycleModelReady=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.currentSpriteContent=p.EVehiclePlateState.None,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.needInterpolate=!0,this.updateModel=!1;const e=V.default.useAppDataStore;this.assetsRoot=JSON.parse(JSON.stringify(e.mapConfig)).assetsRoot,this.view=i;const t=new T.GLTFLoader;t.load(`${this.assetsRoot}/3DModels/car.glb`,s=>{this.carModel=s.scene,this.carModel.rotation.x=h.MathUtils.degToRad(90),this.carModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/van.glb`,s=>{this.vanModel=s.scene,this.vanModel.rotation.x=h.MathUtils.degToRad(90),this.vanModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/truck.glb`,s=>{this.truckModel=s.scene,this.truckModel.scale.set(1.2,1,1.5),this.truckModel.rotation.x=h.MathUtils.degToRad(90),this.truckModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/bus.glb`,s=>{this.busModel=s.scene,this.busModel.rotation.x=h.MathUtils.degToRad(90),this.busModelReady=!0}),t.load(`${this.assetsRoot}/3DModels/bicycle.glb`,s=>{this.bicycleModel=s.scene,this.bicycleModel.rotation.x=h.MathUtils.degToRad(90),this.bicycleModel.rotation.y=h.MathUtils.degToRad(180),this.bicycleModelReady=!0}),document.addEventListener("visibilitychange",()=>{this.clearVehicles(),this.needInterpolate=!document.hidden},!1),N.watch(()=>this.view.zoom,(s,a)=>{(a<=this.zoomThreshold&&s>this.zoomThreshold||a>this.zoomThreshold&&s<=this.zoomThreshold)&&(this.updateModel=!0)})}createCarMaterial(i){return new h.MeshPhysicalMaterial({color:i,emissive:0,roughness:this.roughness,metalness:this.metalness})}setInterpolate(i){this.clearVehicles(),this.needInterpolate=i}async setup(i){this.context=i,this.renderer=new h.WebGLRenderer({context:i.gl,premultipliedAlpha:!0,logarithmicDepthBuffer:!0,antialias:!0,powerPreference:"high-performance"}),this.renderer.shadowMap.enabled=!0,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setViewport(0,0,this.view.width,this.view.height),this.renderer.autoClearDepth=!1,this.renderer.autoClearStencil=!1,this.renderer.autoClearColor=!1;const e=this.renderer.setRenderTarget.bind(this.renderer);this.renderer.setRenderTarget=o=>{e(o),o==null&&i.bindRenderTarget()},this.scene=new h.Scene;const{camera:t}=i;this.camera=new h.PerspectiveCamera(t.fovY,t.aspect,.1,1e5),this.ambient=new h.AmbientLight(16777215,2e4),this.scene.add(this.ambient),this.sun=new h.DirectionalLight(16777215,2e4);const s=[121.46790813287619,31.239514870157972,1e3],a=this.toRenderCoordinates(s);this.sun.position.set(a[0],a[1],a[2]),this.scene.add(this.sun),i.resetWebGLState()}async render(i){var s;const e=i.camera;if(this.camera.position.set(e.eye[0],e.eye[1],e.eye[2]),this.camera.up.set(e.up[0],e.up[1],e.up[2]),this.camera.lookAt(new h.Vector3(e.center[0],e.center[1],e.center[2])),this.camera.projectionMatrix.fromArray(e.projectionMatrix),this.needInterpolate)for(const a of this.vehicleObjectMap.keys()){const o=(s=this.vehicleObjectMap.get(a))==null?void 0:s.model;if(!o)continue;const r=this.computeVehiclePosition(a);if(r){const n=this.toRenderCoordinates(r);o.position.set(n[0],n[1],n[2]),o.rotation.y=h.MathUtils.degToRad(-r[3])}}const t=i.sunLight;this.sun.position.set(t.direction[0],t.direction[1],t.direction[2]),this.sun.intensity=t.diffuse.intensity,this.sun.color=new h.Color(t.diffuse.color[0],t.diffuse.color[1],t.diffuse.color[2]),this.ambient.intensity=t.ambient.intensity,this.ambient.color=new h.Color(t.ambient.color[0],t.ambient.color[1],t.ambient.color[2]),this.renderer.resetState(),i.bindRenderTarget(),this.renderer.render(this.scene,this.camera),b.requestRender(this.view),i.resetWebGLState()}async addVehicles(i){if(!(!this.carModelReady||!this.vanModelReady||!this.truckModelReady||!this.busModelReady||!this.bicycleModelReady))for(const e of i){const{vehicleId:t,localTimestamp:s}=e,a=Number(e.x),o=Number(e.y),r=Number(e.heading);this.historyPositionMap.set(t,[{pos:[a,o,0],heading:r,time:s}]);const n=this.getVehicleModel(e);n.name=t,n.visible=!this.needInterpolate;try{const l=await this.createPlateSprite(e);l&&(n.add(l),l.position.set(0,5,-4)),this.scene.add(n),this.vehicleObjectMap.set(t,{model:n,data:e,waitForDelete:!1,isMoving:!1})}catch(l){console.log("createPlateSprite error:",l)}}}async updateVehicles(i){if(!this.carModelReady||!this.vanModelReady||!this.truckModelReady||!this.busModelReady||!this.bicycleModelReady)return;const e=[];for(const t of i){const{vehicleId:s,localTimestamp:a}=t,o=Number(t.x),r=Number(t.y);let n=Number(t.heading);const l=this.vehicleObjectMap.get(s);if(!l)e.push(t);else{if(this.updateModel||l.data.vehicleColor!==t.vehicleColor||l.data.vehicleType!==t.vehicleType){this.scene.remove(l.model),this.disposeModel(l.model),l.model=this.getVehicleModel(t);const c=await this.createPlateSprite(t);c&&(l.model.add(c),c.position.set(0,5,-4)),this.scene.add(l.model)}if(l.data.showName!==t.showName||l.data.plateColor!==t.plateColor){const c=l.model.getObjectByName("VehiclePlate");c&&(l.model.remove(c),this.disposeModel(c));const d=await this.createPlateSprite(t);d&&(l.model.add(d),d.position.set(0,5,-4))}if(l.data=t,this.needInterpolate){const c=this.historyPositionMap.get(s),d=c[c.length-1];Math.abs(n-d.heading)>=180&&(n>d.heading?d.heading+=360:n+=360),c.push({pos:[o,r,0],heading:n,time:a})}else{this.historyPositionMap.set(s,[{pos:[o,r,0],heading:n,time:a}]);const c=this.toRenderCoordinates([o,r,0]);l.model.position.set(c[0],c[1],c[2]),l.model.rotation.y=h.MathUtils.degToRad(-n)}}}this.addVehicles(e),this.updateModel=!1,this.needInterpolate||this.render(this.context)}toRenderCoordinates(i){const e=[0,0,0];return b.toRenderCoordinates(this.view,i,0,R.WGS84,e,0,1),e}deleteVehicles(i){i.forEach(e=>{const t=this.vehicleObjectMap.get(e);t&&(this.needInterpolate?t.isMoving?t.waitForDelete=!0:this.deleteVehicle(t):this.deleteVehicle(t))})}deleteVehicle(i){this.scene.remove(i.model),this.disposeModel(i.model);const e=i.data.vehicleId;this.vehicleObjectMap.delete(e),this.historyPositionMap.delete(e)}async toggleTrafficInfo(i){i.name==="vehiclePlate"&&(i.visible===!0&&this.currentSpriteContent===p.EVehiclePlateState.None?await this.updatePanelContent(p.EVehiclePlateState.PlateNumber):await this.updatePanelContent(i.visible?this.currentSpriteContent:p.EVehiclePlateState.None))}clearVehicles(){for(const i of this.vehicleObjectMap.keys()){const e=this.vehicleObjectMap.get(i);e&&(this.disposeModel(e.model),this.scene.remove(e.model))}this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}async updatePanelContent(i){if(i!==this.currentSpriteContent){this.currentSpriteContent=i;for(const e of this.vehicleObjectMap.keys()){const t=this.vehicleObjectMap.get(e);if(t){const s=t.model.getObjectByName("VehiclePlate");if(s&&(t.model.remove(s),this.disposeModel(s)),i!==p.EVehiclePlateState.None){const a=await this.createPlateSprite(t.data);a&&(t.model.add(a),a.position.set(0,5,-4))}}}}}toggleGroundVehicle(i){console.log("toggleGroundVehicle",i),this.showGroundVehicle=i}toggleElevatedVehicle(i){this.showElevatedVehicle=i}disposeModel(i){i.traverse(e=>{e instanceof h.Mesh&&(e.geometry.dispose(),e.material.dispose())})}computeVehiclePosition(i){const e=this.historyPositionMap.get(i),t=this.vehicleObjectMap.get(i);if(!t||!e||!t.isMoving&&e.length<=2)return;const s=Date.now();t.isMoving=!0,t.data.roadLayer==="1"?t.model.visible=this.showGroundVehicle:t.model.visible=this.showElevatedVehicle,t.segmentStartTime||(t.segmentStartTime=s,t.segmentTotalTime=e[1].time-e[0].time);const a=s-t.segmentStartTime,o=Math.min(a/t.segmentTotalTime,1);if(o===1)if(e.shift(),e.length===1){t.waitForDelete===!0?this.deleteVehicle(t):(t.segmentStartTime=void 0,t.segmentTotalTime=void 0,t.model.visible=!1,t.isMoving=!1,console.log("pause vehicle",i));return}else return t.segmentStartTime=Date.now(),t.segmentTotalTime=e[1].time-e[0].time,(e[1].heading>=270&&e[0].heading<=90||e[1].heading<=90&&e[0].heading>=270)&&(e[1].heading>e[0].heading?e[0].heading+=360:e[1].heading+=360),e[0].pos.concat(e[0].heading);else{const r=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*o,n=e[0].pos[1]+(e[1].pos[1]-e[0].pos[1])*o,l=e[0].heading+(e[1].heading-e[0].heading)*o;return[r,n,0,l]}}getVehicleModel(i){if(this.view.zoom<=this.zoomThreshold){const e=new h.SphereGeometry(5,32,32),t=new h.MeshPhysicalMaterial({color:325253,emissive:0,roughness:this.roughness,metalness:this.metalness});return new h.Mesh(e,t)}else{let e;if(i.ptcType===2)e=this.bicycleModel.clone();else{switch(i.vehicleType){case 10:e=this.carModel.clone();break;case 20:e=this.vanModel.clone();break;case 25:e=this.truckModel.clone();break;case 50:e=this.busModel.clone();break;default:e=this.carModel.clone();break}const t=this.materialMap.get(i.vehicleColor)||this.defaultMaterial;let s=!1;e.traverse(a=>{!s&&a instanceof h.Mesh&&(a.material=t,s=!0)})}return e}}createCanvas(i,e,t){const s=document.createElement("canvas"),a=i.width,o=i.height;s.width=a,s.height=o;const r=s.getContext("2d");if(!r){console.log("canvas创建失败");return}return r.fillStyle="rgba(0,0,0,0.0)",r.fillRect(0,0,a,o),r.drawImage(i,0,0,a,o),r.beginPath(),r.translate(a/2,o/2),r.fillStyle=t,r.font="bold 32px 宋体",r.textBaseline="middle",r.textAlign="center",r.fillText(e,0,0),s}createPlateSprite(i){return new Promise((e,t)=>{var l,c;const s=!i.plateNo||i.plateNo==="0"||i.plateNo==="000000";if(this.currentSpriteContent===p.EVehiclePlateState.None||this.currentSpriteContent===p.EVehiclePlateState.PlateNumber&&s){e(void 0);return}const a=new Image;let o="",r="",n="";if(this.currentSpriteContent===p.EVehiclePlateState.PlateNumber||this.currentSpriteContent===p.EVehiclePlateState.Mix)if(s)o="grey",r=i.ptcId,n="#ffffff";else switch(r=((l=i.showName)==null?void 0:l.substring(0,2))+"•"+((c=i.showName)==null?void 0:c.substring(2)),i.plateColor){case 1:o="blue",n="#ffffff";break;case 2:o="yellow",n="#000000";break;case 3:o="white",n="#000000";break;case 4:o="black";break;case 5:o="neo_yellow",n="#000000";break;case 6:o="neo_green",n="#000000";break;default:o="grey",r=i.plateNo,n="#ffffff";break}else this.currentSpriteContent===p.EVehiclePlateState.Id&&(o="grey",r=i.ptcId,n="#ffffff");a.src=`${this.assetsRoot}/Images/PlateBG/${o}.png`,a.onload=()=>{const d=this.createCanvas(a,r,n);if(!d)t("canvas创建失败");else{const m=new h.CanvasTexture(d),v=new h.SpriteMaterial({map:m,transparent:!1}),f=new h.Sprite(v),M=.05,y=d.width*M,w=d.height*M;f.scale.set(y,w,1),f.name="VehiclePlate",e(f)}a.onerror=m=>{console.log(`号牌背景加载失败: ${a.src}`,m),t(m)}}})}}exports.default=k;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gisviewer-vue3-arcgis",
3
- "version": "1.0.104",
3
+ "version": "1.0.105",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.mjs",
6
6
  "files": [