gisviewer-vue3-arcgis 1.0.113 → 1.0.115
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/es/src/gis-map/utils/holo-flow/trace-holo-flow.d.ts +0 -2
- package/es/src/gis-map/utils/holo-flow/trace-holo-flow.mjs +58 -134
- package/es/src/gis-map/utils/holo-flow/trace-renderer-external.d.ts +4 -1
- package/es/src/gis-map/utils/holo-flow/trace-renderer-external.mjs +208 -116
- package/es/src/gis-map/utils/holo-flow/trace-renderer-layer.d.ts +3 -0
- package/es/src/gis-map/utils/holo-flow/trace-renderer-layer.mjs +42 -15
- package/es/src/types/index.d.ts +2 -0
- package/lib/src/gis-map/utils/holo-flow/trace-holo-flow.d.ts +0 -2
- package/lib/src/gis-map/utils/holo-flow/trace-holo-flow.js +2 -2
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-external.d.ts +4 -1
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-external.js +1 -1
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-layer.d.ts +3 -0
- package/lib/src/gis-map/utils/holo-flow/trace-renderer-layer.js +1 -1
- package/lib/src/types/index.d.ts +2 -0
- package/package.json +1 -1
- package/es/src/gis-map/utils/holo-flow/vehicle-pool.d.ts +0 -41
- package/es/src/gis-map/utils/holo-flow/vehicle-pool.mjs +0 -180
- package/lib/src/gis-map/utils/holo-flow/vehicle-pool.d.ts +0 -41
- package/lib/src/gis-map/utils/holo-flow/vehicle-pool.js +0 -1
|
@@ -12,7 +12,6 @@ export default class TraceRendererExternal implements ITraceRendererInterface {
|
|
|
12
12
|
private readonly metalness;
|
|
13
13
|
/** 默认车身材质 */
|
|
14
14
|
private defaultMaterial;
|
|
15
|
-
private readonly vehiclePool;
|
|
16
15
|
private createCarMaterial;
|
|
17
16
|
/** 车身颜色材质 */
|
|
18
17
|
private materialMap;
|
|
@@ -39,7 +38,11 @@ export default class TraceRendererExternal implements ITraceRendererInterface {
|
|
|
39
38
|
private vehicleObjectMap;
|
|
40
39
|
private needInterpolate;
|
|
41
40
|
private updateModel;
|
|
41
|
+
private appDataStore;
|
|
42
|
+
/** 轨迹日志 */
|
|
43
|
+
private logTable;
|
|
42
44
|
constructor(view: __esri.SceneView);
|
|
45
|
+
getLog(): (string | number | undefined)[][];
|
|
43
46
|
init(): Promise<void>;
|
|
44
47
|
setInterpolate(needInterpolate: boolean): void;
|
|
45
48
|
private context;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("@arcgis/core/core/promiseUtils.js"),y=require("@arcgis/core/core/reactiveUtils.js"),S=require("@arcgis/core/geometry/SpatialReference"),G=require("@arcgis/core/views/3d/externalRenderers"),C=require("three"),T=require("three/examples/jsm/loaders/GLTFLoader"),d=require("../../../types/index.js"),B=require("../../stores/index.js"),R=require("./vehicle-pool.js");function u(m){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(m){for(const e in m)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(m,e);Object.defineProperty(i,e,t.get?t:{enumerable:!0,get:()=>m[e]})}}return i.default=m,Object.freeze(i)}const I=u(v),V=u(y),M=u(G),l=u(C);class N{constructor(i){this.cameraHeightThreshold=1e3,this.roughness=.2,this.metalness=.8,this.defaultMaterial=new l.MeshPhongMaterial({color:16777215}),this.vehiclePool=new R.default,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.isInitialized=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.isPaused=!1,this.currentSpriteContent=d.EVehiclePlateState.None,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.needInterpolate=!0,this.updateModel=!1;const e=B.default.useAppDataStore;this.assetsRoot=JSON.parse(JSON.stringify(e.mapConfig)).assetsRoot,this.view=i,V.watch(()=>this.view.camera.position.z,(t,o)=>{(o<=this.cameraHeightThreshold&&t>this.cameraHeightThreshold||o>this.cameraHeightThreshold&&t<=this.cameraHeightThreshold)&&(this.updateModel=!0)})}createCarMaterial(i){return new l.MeshPhongMaterial({color:i})}async init(){const i=new T.GLTFLoader;await I.eachAlways([new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/car.glb`,t=>{this.carModel=t.scene,this.carModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/van.glb`,t=>{this.vanModel=t.scene,this.vanModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/truck.glb`,t=>{this.truckModel=t.scene,this.truckModel.scale.set(1.2,1,1.5),this.truckModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bus.glb`,t=>{this.busModel=t.scene,this.busModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bicycle.glb`,t=>{this.bicycleModel=t.scene,this.bicycleModel.rotation.x=l.MathUtils.degToRad(90),this.bicycleModel.rotation.y=l.MathUtils.degToRad(180),e()})}),new Promise(e=>{this.bluePlateBG=new Image,this.bluePlateBG.src=`${this.assetsRoot}/Images/PlateBG/blue.png`,this.bluePlateBG.onload=()=>{e()}}),new Promise(e=>{this.yellowPlateBG=new Image,this.yellowPlateBG.src=`${this.assetsRoot}/Images/PlateBG/yellow.png`,this.yellowPlateBG.onload=()=>{e()}}),new Promise(e=>{this.whitePlateBG=new Image,this.whitePlateBG.src=`${this.assetsRoot}/Images/PlateBG/white.png`,this.whitePlateBG.onload=()=>{e()}}),new Promise(e=>{this.blackPlateBG=new Image,this.blackPlateBG.src=`${this.assetsRoot}/Images/PlateBG/black.png`,this.blackPlateBG.onload=()=>{e()}}),new Promise(e=>{this.neoYellowPlateBG=new Image,this.neoYellowPlateBG.src=`${this.assetsRoot}/Images/PlateBG/neo_yellow.png`,this.neoYellowPlateBG.onload=()=>{e()}}),new Promise(e=>{this.neoGreenPlateBG=new Image,this.neoGreenPlateBG.src=`${this.assetsRoot}/Images/PlateBG/neo_green.png`,this.neoGreenPlateBG.onload=()=>{e()}}),new Promise(e=>{this.greyPlateBG=new Image,this.greyPlateBG.src=`${this.assetsRoot}/Images/PlateBG/grey.png`,this.greyPlateBG.onload=()=>{e()}})]),this.isInitialized=!0}setInterpolate(i){this.clearVehicles(),this.needInterpolate=i}async setup(i){this.context=i,this.renderer=new l.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 l.Scene;const{camera:t}=i;this.camera=new l.PerspectiveCamera(t.fovY,t.aspect,.1,1e5),this.ambient=new l.AmbientLight(16777215,2),this.scene.add(this.ambient),this.sun=new l.DirectionalLight(16777215,2),this.scene.add(this.sun),i.resetWebGLState()}async render(i){var o;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 l.Vector3(e.center[0],e.center[1],e.center[2])),this.camera.projectionMatrix.fromArray(e.projectionMatrix),!this.isPaused&&this.needInterpolate)for(const s of this.vehicleObjectMap.keys()){const n=(o=this.vehicleObjectMap.get(s))==null?void 0:o.model;if(!n)continue;const a=this.computeVehiclePosition(s);if(a){const h=this.toRenderCoordinates(a);n.position.set(h[0],h[1],h[2]),n.rotation.y=l.MathUtils.degToRad(-a[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 l.Color(t.diffuse.color[0],t.diffuse.color[1],t.diffuse.color[2]),this.ambient.intensity=t.ambient.intensity,this.ambient.color=new l.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),M.requestRender(this.view),i.resetWebGLState()}async addVehicles(i){if(!(this.isPaused||!this.isInitialized))for(const e of i){const{vehicleId:t,localTimestamp:o}=e,s=Number(e.x),n=Number(e.y),a=Number(e.heading);this.historyPositionMap.set(t,[{pos:[s,n,0],heading:a,time:o}]);const h=this.getVehicleModel(e);h.name=t,h.visible=!1;try{const r=await this.createPlateSprite(e);r&&(h.add(r),r.position.set(0,5,-4))}catch(r){console.log("createPlateSprite error:",r)}this.scene.add(h),this.vehicleObjectMap.set(t,{model:h,data:e,waitForDelete:!1,isMoving:!1})}}async updateVehicles(i){if(this.isPaused||!this.isInitialized)return;const e=[];for(const t of i){const{vehicleId:o,timestamp:s}=t,n=Number(t.x),a=Number(t.y);let h=Number(t.heading);const r=this.vehicleObjectMap.get(o),p=this.historyPositionMap.get(o);if(!r||!p)e.push(t);else{if(this.updateModel||r.data.vehicleColor!==t.vehicleColor||r.data.vehicleType!==t.vehicleType){this.vehiclePool.recycleInstance(r.model),r.model=this.getVehicleModel(t),r.model.visible=!0;const c=await this.createPlateSprite(t);c&&(r.model.add(c),c.position.set(0,5,-4)),this.scene.add(r.model)}if(r.data.showName!==t.showName||r.data.plateColor!==t.plateColor){const c=r.model.getObjectByName("VehiclePlate");c&&(r.model.remove(c),this.disposeModel(c));const g=await this.createPlateSprite(t);g&&(r.model.add(g),g.position.set(0,5,-4))}if(r.data=t,this.needInterpolate){const c=p[p.length-1];Math.abs(h-c.heading)>=180&&(h>c.heading?c.heading+=360:h+=360),p.push({pos:[n,a,0],heading:h,time:s})}else{this.historyPositionMap.set(o,[{pos:[n,a,0],heading:h,time:s}]);const c=this.toRenderCoordinates([n,a,0]);r.model.position.set(c[0],c[1],c[2]),r.model.rotation.y=l.MathUtils.degToRad(-h)}}}await this.addVehicles(e),this.updateModel=!1,this.needInterpolate||this.render(this.context)}toRenderCoordinates(i){const e=[0,0,0];return M.toRenderCoordinates(this.view,i,0,S.WGS84,e,0,1),e}deleteVehicles(i){this.isPaused||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.vehiclePool.recycleInstance(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===d.EVehiclePlateState.None?await this.updatePanelContent(d.EVehiclePlateState.PlateNumber):await this.updatePanelContent(i.visible?this.currentSpriteContent:d.EVehiclePlateState.None))}togglePause(i){this.isPaused=i}clearVehicles(){for(const i of this.vehicleObjectMap.keys()){const e=this.vehicleObjectMap.get(i);e&&this.vehiclePool.recycleInstance(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 o=t.model.getObjectByName("VehiclePlate");if(o&&(t.model.remove(o),this.disposeModel(o)),i!==d.EVehiclePlateState.None){const s=await this.createPlateSprite(t.data);s&&(t.model.add(s),s.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 l.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 o=Date.now();t.isMoving=!0,t.data.roadLayer==="1"?t.model.visible=this.showGroundVehicle:t.model.visible=this.showElevatedVehicle,t.segmentStartTime||(t.segmentStartTime=o,t.segmentTotalTime=e[1].time-e[0].time);const s=o-t.segmentStartTime,n=Math.min(s/t.segmentTotalTime,1);if(n===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("hide 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 if(e.length>=2){const a=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*n,h=e[0].pos[1]+(e[1].pos[1]-e[0].pos[1])*n,r=e[0].heading+(e[1].heading-e[0].heading)*n;return[a,h,0,r]}else return}getVehicleModel(i){if(this.view.camera.position.z>=this.cameraHeightThreshold){const e=new l.SphereGeometry(5,32,32),t=new l.MeshPhysicalMaterial({color:325253,emissive:0,roughness:this.roughness,metalness:this.metalness});return new l.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 o=!1;e.traverse(s=>{!o&&s instanceof l.Mesh&&(s.material=t,o=!0)})}return e}}createCanvas(i,e,t){const o=document.createElement("canvas"),s=i.width,n=i.height;o.width=s,o.height=n;const a=o.getContext("2d");if(!a){console.log("canvas创建失败");return}return a.fillStyle="rgba(0,0,0,0.0)",a.fillRect(0,0,s,n),a.drawImage(i,0,0,s,n),a.beginPath(),a.translate(s/2,n/2),a.fillStyle=t,a.font="bold 32px 宋体",a.textBaseline="middle",a.textAlign="center",a.fillText(e,0,0),o}createPlateSprite(i){return new Promise((e,t)=>{var r,p;const o=!i.plateNo||i.plateNo==="0"||i.plateNo==="000000";if(this.currentSpriteContent===d.EVehiclePlateState.None||this.currentSpriteContent===d.EVehiclePlateState.PlateNumber&&o){e(void 0);return}let s=new Image,n="",a="";if(this.currentSpriteContent===d.EVehiclePlateState.PlateNumber||this.currentSpriteContent===d.EVehiclePlateState.Mix)if(o)s=this.greyPlateBG,n=i.ptcId,a="#ffffff";else switch(n=((r=i.showName)==null?void 0:r.substring(0,2))+"•"+((p=i.showName)==null?void 0:p.substring(2)),i.plateColor){case 1:s=this.bluePlateBG,a="#ffffff";break;case 2:s=this.yellowPlateBG,a="#000000";break;case 3:s=this.whitePlateBG,a="#000000";break;case 4:s=this.blackPlateBG,a="#ffffff";break;case 5:s=this.neoYellowPlateBG,a="#000000";break;case 6:s=this.neoGreenPlateBG,a="#000000";break;default:s=this.greyPlateBG,n=i.plateNo,a="#ffffff";break}else this.currentSpriteContent===d.EVehiclePlateState.Id&&(s=this.greyPlateBG,n=i.ptcId,a="#ffffff");const h=this.createCanvas(s,n,a);if(h){const c=new l.CanvasTexture(h),g=new l.SpriteMaterial({map:c,transparent:!1}),f=new l.Sprite(g),P=.05,w=h.width*P,b=h.height*P;f.scale.set(w,b,1),f.name="VehiclePlate",e(f)}else{t("canvas创建失败");return}s.onerror=c=>{console.log(`号牌背景加载失败: ${s.src}`,c),t(c)}})}}exports.default=N;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("@arcgis/core/core/promiseUtils.js"),y=require("@arcgis/core/core/reactiveUtils.js"),T=require("@arcgis/core/geometry/SpatialReference"),S=require("@arcgis/core/views/3d/externalRenderers"),C=require("three"),G=require("three/examples/jsm/loaders/GLTFLoader"),m=require("../../../types/index.js"),B=require("../../stores/index.js");function f(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 R=f(v),I=f(y),M=f(S),l=f(C);class V{constructor(i){this.cameraHeightThreshold=1e3,this.roughness=.2,this.metalness=.8,this.defaultMaterial=new l.MeshPhongMaterial({color:16777215}),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.isInitialized=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.isPaused=!1,this.currentSpriteContent=m.EVehiclePlateState.None,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.needInterpolate=!0,this.updateModel=!1,this.appDataStore=B.default.useAppDataStore,this.logTable=[["ptcId","plateno","timestamp","localTimestamp","speed","longitude","latitude","ptcType","vehicleType","vehicleColor","plateColor","heading","fixAngle","roadLayer","step","receiveTimestamp","queueLength","status"]],this.assetsRoot=JSON.parse(JSON.stringify(this.appDataStore.mapConfig)).assetsRoot,this.view=i,I.watch(()=>this.view.camera.position.z,(e,t)=>{(t<=this.cameraHeightThreshold&&e>this.cameraHeightThreshold||t>this.cameraHeightThreshold&&e<=this.cameraHeightThreshold)&&(this.updateModel=!0)})}createCarMaterial(i){return new l.MeshPhongMaterial({color:i})}getLog(){return this.logTable}async init(){const i=new G.GLTFLoader;await R.eachAlways([new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/car.glb`,t=>{this.carModel=t.scene,this.carModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/van.glb`,t=>{this.vanModel=t.scene,this.vanModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/truck.glb`,t=>{this.truckModel=t.scene,this.truckModel.scale.set(1.2,1,1.5),this.truckModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bus.glb`,t=>{this.busModel=t.scene,this.busModel.rotation.x=l.MathUtils.degToRad(90),e()})}),new Promise(e=>{i.load(`${this.assetsRoot}/3DModels/bicycle.glb`,t=>{this.bicycleModel=t.scene,this.bicycleModel.rotation.x=l.MathUtils.degToRad(90),this.bicycleModel.rotation.y=l.MathUtils.degToRad(180),e()})}),new Promise(e=>{this.bluePlateBG=new Image,this.bluePlateBG.src=`${this.assetsRoot}/Images/PlateBG/blue.png`,this.bluePlateBG.onload=()=>{e()}}),new Promise(e=>{this.yellowPlateBG=new Image,this.yellowPlateBG.src=`${this.assetsRoot}/Images/PlateBG/yellow.png`,this.yellowPlateBG.onload=()=>{e()}}),new Promise(e=>{this.whitePlateBG=new Image,this.whitePlateBG.src=`${this.assetsRoot}/Images/PlateBG/white.png`,this.whitePlateBG.onload=()=>{e()}}),new Promise(e=>{this.blackPlateBG=new Image,this.blackPlateBG.src=`${this.assetsRoot}/Images/PlateBG/black.png`,this.blackPlateBG.onload=()=>{e()}}),new Promise(e=>{this.neoYellowPlateBG=new Image,this.neoYellowPlateBG.src=`${this.assetsRoot}/Images/PlateBG/neo_yellow.png`,this.neoYellowPlateBG.onload=()=>{e()}}),new Promise(e=>{this.neoGreenPlateBG=new Image,this.neoGreenPlateBG.src=`${this.assetsRoot}/Images/PlateBG/neo_green.png`,this.neoGreenPlateBG.onload=()=>{e()}}),new Promise(e=>{this.greyPlateBG=new Image,this.greyPlateBG.src=`${this.assetsRoot}/Images/PlateBG/grey.png`,this.greyPlateBG.onload=()=>{e()}})]),this.isInitialized=!0}setInterpolate(i){this.clearVehicles(),this.needInterpolate=i}async setup(i){this.context=i,this.renderer=new l.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=s=>{e(s),s==null&&i.bindRenderTarget()},this.scene=new l.Scene;const{camera:t}=i;this.camera=new l.PerspectiveCamera(t.fovY,t.aspect,.1,1e5),this.ambient=new l.AmbientLight(16777215,2),this.scene.add(this.ambient),this.sun=new l.DirectionalLight(16777215,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 l.Vector3(e.center[0],e.center[1],e.center[2])),this.camera.projectionMatrix.fromArray(e.projectionMatrix),!this.isPaused&&this.needInterpolate)for(const a of this.vehicleObjectMap.keys()){const n=(s=this.vehicleObjectMap.get(a))==null?void 0:s.model;if(!n)continue;const o=this.computeVehiclePosition(a);if(o){const d=this.toRenderCoordinates(o);n.position.set(d[0],d[1],d[2]),n.rotation.y=l.MathUtils.degToRad(-o[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 l.Color(t.diffuse.color[0],t.diffuse.color[1],t.diffuse.color[2]),this.ambient.intensity=t.ambient.intensity,this.ambient.color=new l.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),M.requestRender(this.view),i.resetWebGLState()}async addVehicles(i){if(this.isPaused||!this.isInitialized)return;const e=Date.now();for(const t of i){this.appDataStore.saveTrackLog&&this.logTable.push([t.ptcId,t.plateNo,t.timestamp,t.localTimestamp,t.speed,t.x,t.y,t.ptcType,t.vehicleType,t.vehicleColor,t.plateColor,t.heading,t.fixAngle,t.roadLayer,t.step,e,0,0]);const{vehicleId:s,localTimestamp:a}=t,n=Number(t.x),o=Number(t.y),d=Number(t.heading);this.historyPositionMap.set(s,[{pos:[n,o,0],heading:d,time:a}]);const h=this.getVehicleModel(t);h.name=s,h.visible=!1;try{const r=await this.createPlateSprite(t);r&&(h.add(r),r.position.set(0,5,-4))}catch(r){console.log("createPlateSprite error:",r)}this.scene.add(h),this.vehicleObjectMap.set(s,{model:h,data:t,waitForDelete:!1,isMoving:!1})}}async updateVehicles(i){if(this.isPaused||!this.isInitialized)return;const e=[],t=Date.now();for(const s of i){const{vehicleId:a,timestamp:n}=s,o=Number(s.x),d=Number(s.y);let h=Number(s.heading);const r=this.vehicleObjectMap.get(a),p=this.historyPositionMap.get(a);if(!r||!p)e.push(s);else{if(this.appDataStore.saveTrackLog&&this.logTable.push([s.ptcId,s.plateNo,s.timestamp,s.localTimestamp,s.speed,s.x,s.y,s.ptcType,s.vehicleType,s.vehicleColor,s.plateColor,s.heading,s.fixAngle,s.roadLayer,s.step,t,p.length,1]),this.updateModel||r.data.vehicleColor!==s.vehicleColor||r.data.vehicleType!==s.vehicleType){this.scene.remove(r.model),this.disposeModel(r.model),r.model=this.getVehicleModel(s),r.model.visible=!0;const c=await this.createPlateSprite(s);c&&(r.model.add(c),c.position.set(0,5,-4)),this.scene.add(r.model)}if(r.data.showName!==s.showName||r.data.plateColor!==s.plateColor){const c=r.model.getObjectByName("VehiclePlate");c&&(r.model.remove(c),this.disposeModel(c));const g=await this.createPlateSprite(s);g&&(r.model.add(g),g.position.set(0,5,-4))}if(r.data=s,this.needInterpolate){const c=p[p.length-1];Math.abs(h-c.heading)>=180&&(h>c.heading?c.heading+=360:h+=360),p.push({pos:[o,d,0],heading:h,time:n})}else{this.historyPositionMap.set(a,[{pos:[o,d,0],heading:h,time:n}]);const c=this.toRenderCoordinates([o,d,0]);r.model.position.set(c[0],c[1],c[2]),r.model.rotation.y=l.MathUtils.degToRad(-h)}}}await this.addVehicles(e),this.updateModel=!1,this.needInterpolate||this.render(this.context)}toRenderCoordinates(i){const e=[0,0,0];return M.toRenderCoordinates(this.view,i,0,T.WGS84,e,0,1),e}deleteVehicles(i){if(this.isPaused)return;const e=Date.now();i.forEach(t=>{if(this.appDataStore.saveTrackLog){const a=this.historyPositionMap.get(t);this.logTable.push([t,"","","","","","","","","","","","","","",e,a?a.length:0,2])}const s=this.vehicleObjectMap.get(t);s&&(this.needInterpolate?s.isMoving?s.waitForDelete=!0:this.deleteVehicle(s):this.deleteVehicle(s))})}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===m.EVehiclePlateState.None?await this.updatePanelContent(m.EVehiclePlateState.PlateNumber):await this.updatePanelContent(i.visible?this.currentSpriteContent:m.EVehiclePlateState.None))}togglePause(i){this.isPaused=i}clearVehicles(){for(const i of this.vehicleObjectMap.keys()){const e=this.vehicleObjectMap.get(i);e&&(this.scene.remove(e.model),this.disposeModel(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!==m.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 l.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,n=Math.min(a/t.segmentTotalTime,1);if(n===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("hide vehicle",i));return}else{const o=a-t.segmentTotalTime;return t.segmentStartTime=Date.now(),t.segmentTotalTime=e[1].time-e[0].time-(o>0?o:0),(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 if(e.length>=2){const o=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*n,d=e[0].pos[1]+(e[1].pos[1]-e[0].pos[1])*n,h=e[0].heading+(e[1].heading-e[0].heading)*n;return[o,d,0,h]}else return}getVehicleModel(i){if(this.view.camera.position.z>=this.cameraHeightThreshold){const e=new l.SphereGeometry(5,32,32),t=new l.MeshPhysicalMaterial({color:325253,emissive:0,roughness:this.roughness,metalness:this.metalness});return new l.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 l.Mesh&&(a.material=t,s=!0)})}return e}}createCanvas(i,e,t){const s=document.createElement("canvas"),a=i.width,n=i.height;s.width=a,s.height=n;const o=s.getContext("2d");if(!o){console.log("canvas创建失败");return}return o.fillStyle="rgba(0,0,0,0.0)",o.fillRect(0,0,a,n),o.drawImage(i,0,0,a,n),o.beginPath(),o.translate(a/2,n/2),o.fillStyle=t,o.font="bold 32px 宋体",o.textBaseline="middle",o.textAlign="center",o.fillText(e,0,0),s}createPlateSprite(i){return new Promise((e,t)=>{var h,r;const s=!i.plateNo||i.plateNo==="0"||i.plateNo==="000000";if(this.currentSpriteContent===m.EVehiclePlateState.None||this.currentSpriteContent===m.EVehiclePlateState.PlateNumber&&s){e(void 0);return}let a=new Image,n="",o="";if(this.currentSpriteContent===m.EVehiclePlateState.PlateNumber||this.currentSpriteContent===m.EVehiclePlateState.Mix)if(s)a=this.greyPlateBG,n=i.ptcId,o="#ffffff";else switch(n=((h=i.showName)==null?void 0:h.substring(0,2))+"•"+((r=i.showName)==null?void 0:r.substring(2)),i.plateColor){case 1:a=this.bluePlateBG,o="#ffffff";break;case 2:a=this.yellowPlateBG,o="#000000";break;case 3:a=this.whitePlateBG,o="#000000";break;case 4:a=this.blackPlateBG,o="#ffffff";break;case 5:a=this.neoYellowPlateBG,o="#000000";break;case 6:a=this.neoGreenPlateBG,o="#000000";break;default:a=this.greyPlateBG,n=i.plateNo,o="#ffffff";break}else this.currentSpriteContent===m.EVehiclePlateState.Id&&(a=this.greyPlateBG,n=i.ptcId,o="#ffffff");const d=this.createCanvas(a,n,o);if(d){const p=new l.CanvasTexture(d),c=new l.SpriteMaterial({map:p,transparent:!1}),g=new l.Sprite(c),P=.05,w=d.width*P,b=d.height*P;g.scale.set(w,b,1),g.name="VehiclePlate",e(g)}else{t("canvas创建失败");return}a.onerror=p=>{console.log(`号牌背景加载失败: ${a.src}`,p),t(p)}})}}exports.default=V;
|
|
@@ -4,7 +4,10 @@ export default class TraceRendererLayer implements ITraceRendererInterface {
|
|
|
4
4
|
private readonly vehicleLayer;
|
|
5
5
|
private mapConfig;
|
|
6
6
|
private rafSignal;
|
|
7
|
+
private appDataStore;
|
|
8
|
+
private logTable;
|
|
7
9
|
constructor(view: __esri.MapView);
|
|
10
|
+
getLog(): (string | number)[][];
|
|
8
11
|
init(): Promise<void>;
|
|
9
12
|
private needInterpolate;
|
|
10
13
|
private isPaused;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("@arcgis/core/Graphic"),p=require("@arcgis/core/layers/GraphicsLayer"),m=require("../../stores/index.js");class g{constructor(i){this.needInterpolate=!0,this.isPaused=!1,this.showVehiclePlate=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.view=i
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("@arcgis/core/Graphic"),p=require("@arcgis/core/layers/GraphicsLayer"),m=require("../../stores/index.js");class g{constructor(i){this.appDataStore=m.default.useAppDataStore,this.logTable=[["uuid","ptcId","plateno","timestamp","localTimestamp","timestamp_str","speed","laneNo","objHeight","objLength","latitude","longitude","ptcType","vehicleType","vehicleColor","plateColor","sbdm","heading","fixAngle","roadLayer","status","step","receiveTimestamp"]],this.needInterpolate=!0,this.isPaused=!1,this.showVehiclePlate=!1,this.showGroundVehicle=!0,this.showElevatedVehicle=!0,this.historyPositionMap=new Map,this.vehicleObjectMap=new Map,this.view=i,this.mapConfig=JSON.parse(JSON.stringify(this.appDataStore.mapConfig)),this.vehicleLayer=new p({id:"vehicleLayer"}),this.view.map.add(this.vehicleLayer),this.rafSignal=requestAnimationFrame(()=>this.render())}getLog(){return this.logTable}async init(){console.log("init")}addVehicles(i){return new Promise(e=>{if(this.isPaused){e();return}const t=i.map(s=>{const{vehicleId:o,heading:a,localTimestamp:h}=s,r=Number(s.x),l=Number(s.y);this.historyPositionMap.set(o,[{pos:[r,l,0],heading:a,time:h}]);const n=new c({geometry:{type:"point",x:r,y:l},attributes:{...s},symbol:this.createCIMSymbol(s)});return n.visible=!1,this.vehicleObjectMap.set(o,{graphic:n,data:s,waitForDelete:!1,isMoving:!1}),n});this.vehicleLayer.addMany(t),e()})}updateVehicles(i){return new Promise(e=>{if(this.isPaused){e();return}const t=[];i.forEach(s=>{const{vehicleId:o,heading:a,localTimestamp:h}=s,r=Number(s.x),l=Number(s.y),n=this.vehicleObjectMap.get(o);n?(n.data=s,this.historyPositionMap.get(o).push({pos:[r,l,0],heading:a,time:h})):t.push(s)}),this.addVehicles(t),e()})}deleteVehicles(i){this.isPaused||i.forEach(e=>{const t=this.vehicleObjectMap.get(e);t&&(t.waitForDelete=!0)})}clearVehicles(){this.vehicleLayer.removeAll(),this.vehicleObjectMap.clear(),this.historyPositionMap.clear()}toggleGroundVehicle(i){this.showGroundVehicle=i}toggleElevatedVehicle(i){this.showElevatedVehicle=i}toggleTrafficInfo(i){i.name==="vehiclePlate"&&(this.showVehiclePlate=i.visible)}togglePause(i){this.isPaused=i,this.isPaused?cancelAnimationFrame(this.rafSignal):this.rafSignal=requestAnimationFrame(()=>this.render())}updatePanelContent(i){console.log(i)}setInterpolate(i){this.needInterpolate=i}render(){this.isPaused||this.vehicleObjectMap.forEach((i,e)=>{this.updatePosition(e)}),this.rafSignal=requestAnimationFrame(()=>this.render())}updatePosition(i){const e=this.historyPositionMap.get(i),t=this.vehicleObjectMap.get(i);if(!e||!t||!t.isMoving&&e.length<=2)return;t.isMoving=!0,(t.graphic.getAttribute("roadLayer")||"1")==="1"?t.graphic.visible=this.showGroundVehicle:t.graphic.visible=this.showElevatedVehicle,t.segmentStartTime||(t.segmentStartTime=Date.now(),t.segmentTotalTime=e[1].time-e[0].time);const o=Date.now()-t.segmentStartTime,a=Math.min(1,o/t.segmentTotalTime);if(a===1)if(e.shift(),e.length===1){t.waitForDelete?(this.vehicleLayer.remove(t.graphic),this.vehicleObjectMap.delete(i),this.historyPositionMap.delete(i)):(t.segmentStartTime=void 0,t.segmentTotalTime=void 0,t.graphic.visible=!1,t.isMoving=!1);return}else 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),t.graphic.geometry={type:"point",x:e[0].pos[0],y:e[0].pos[1]};else{const h=e[0].pos[0]+(e[1].pos[0]-e[0].pos[0])*a,r=e[0].pos[1]+(e[1].pos[1]-e[0].pos[1])*a,l=e[0].heading+(e[1].heading-e[0].heading)*a;t.graphic.geometry={type:"point",x:h,y:r},t.data.heading=l,t.graphic.symbol=this.createCIMSymbol(t.data)}}createCIMSymbol(i){const e=this.getPlateFontColor(i.plateColor);return{type:"cim",data:{type:"CIMSymbolReference",primitiveOverrides:[{type:"CIMPrimitiveOverride",primitiveName:"textGraphic",propertyName:"TextString",valueExpressionInfo:{type:"CIMExpressionInfo",title:"Custom",expression:"$feature.showName",returnType:"Default"}}],symbol:{type:"CIMPointSymbol",symbolLayers:[{type:"CIMVectorMarker",enable:this.showVehiclePlate,size:32,colorLocked:!0,anchorPointUnits:"Relative",frame:{xmin:-8,ymin:-8,xmax:8,ymax:8},markerGraphics:[{type:"CIMMarkerGraphic",primitiveName:"textGraphic",geometry:{x:0,y:0},symbol:{type:"CIMTextSymbol",height:4,horizontalAlignment:"Center",offsetX:0,offsetY:8,haloSize:1,haloSymbol:{type:"CIMPolygonSymbol",symbolLayers:[{type:"CIMSolidFill",enable:!0,color:e.backgroundColor}]},symbol:{type:"CIMPolygonSymbol",symbolLayers:[{type:"CIMSolidFill",enable:!0,color:e.fillColor}]},verticalAlignment:"Center"},textString:""}],scaleSymbolsProportionally:!0,respectFrame:!0},{type:"CIMPictureMarker",enable:!0,anchorPoint:{x:0,y:0},anchorPointUnits:"Relative",size:30,rotation:i.heading,rotateClockwise:!0,textureFilter:"Picture",url:`${this.mapConfig.assetsRoot}Images/car/${this.getCarPic(i.vehicleColor)}`}]}}}}getCarPic(i){if(this.view.zoom<=15)return"point.png";let e="grey";switch(typeof i=="string"&&(i=i.toLowerCase()),i){case"a":case 1:e="white";break;case"b":case 2:e="grey";break;case"c":case 3:e="yellow";break;case"d":case 4:e="pink";break;case"e":case 5:e="red";break;case"f":case 10:e="purple";break;case"g":case 6:e="green";break;case"h":case 7:e="blue";break;case"i":case 8:e="brown";break;case"j":case 9:e="black";break}return e+".png"}getPlateFontColor(i){let e=[255,255,255,255],t=[169,169,169,255];switch(i){case 0:e=[0,0,0,255],t=[255,255,255,255];break;case 1:e=[0,0,0,255],t=[244,164,96,255];break;case 2:e=[255,255,255,255],t=[65,105,225,255];break;case 3:e=[255,255,255,255],t=[0,0,0,255];break;case 15:e=[244,164,96,255],t=[0,250,154,255];break;case 16:e=[0,0,0,255],t=[0,250,154,255];break}return{fillColor:e,backgroundColor:t}}}exports.default=g;
|
package/lib/src/types/index.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export interface IVehicleTrack {
|
|
|
37
37
|
speed?: number;
|
|
38
38
|
plateNo?: string;
|
|
39
39
|
roadLayer?: string;
|
|
40
|
+
step?: number;
|
|
40
41
|
}
|
|
41
42
|
export interface IVehicleRecord {
|
|
42
43
|
model: Three.Group | Three.Mesh;
|
|
@@ -151,6 +152,7 @@ export interface IToggleTrafficInfoParams {
|
|
|
151
152
|
}
|
|
152
153
|
export interface ITraceRendererInterface {
|
|
153
154
|
init(): Promise<void>;
|
|
155
|
+
getLog(): (string | number | undefined)[][];
|
|
154
156
|
addVehicles(objects: IVehicleTrack[]): Promise<void>;
|
|
155
157
|
updateVehicles(objects: IVehicleTrack[]): Promise<void>;
|
|
156
158
|
deleteVehicles(idList: string[]): void;
|
package/package.json
CHANGED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as Three from 'three';
|
|
2
|
-
import { IVehicleTrack } from '../../../types';
|
|
3
|
-
export declare enum EModelStatus {
|
|
4
|
-
/** 未使用 */
|
|
5
|
-
UNUSED = "unused",
|
|
6
|
-
/** 使用中 */
|
|
7
|
-
USED = "used",
|
|
8
|
-
/** 已销毁 */
|
|
9
|
-
DESTROYED = "destroyed"
|
|
10
|
-
}
|
|
11
|
-
declare type VehicleModelType = Three.Group | Three.Mesh;
|
|
12
|
-
export default class VehiclePool {
|
|
13
|
-
private createCarMaterial;
|
|
14
|
-
/** 车身颜色材质 */
|
|
15
|
-
private materialMap;
|
|
16
|
-
private readonly carPool;
|
|
17
|
-
private readonly vanPool;
|
|
18
|
-
private readonly truckPool;
|
|
19
|
-
private readonly busPool;
|
|
20
|
-
private bicyclePool;
|
|
21
|
-
private ballPool;
|
|
22
|
-
private readonly poolSize;
|
|
23
|
-
private view;
|
|
24
|
-
/** 车辆模型变化的阈值 */
|
|
25
|
-
private readonly cameraHeightThreshold;
|
|
26
|
-
initPool(assetsRoot: string, view: __esri.SceneView): Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* 获取实例
|
|
29
|
-
* @param data
|
|
30
|
-
*/
|
|
31
|
-
getInstance(data: IVehicleTrack): VehicleModelType;
|
|
32
|
-
/**
|
|
33
|
-
* 回收实例
|
|
34
|
-
* @param instance
|
|
35
|
-
*/
|
|
36
|
-
recycleInstance(instance: VehicleModelType): void;
|
|
37
|
-
private getInstanceFromPool;
|
|
38
|
-
private getInstanceFromList;
|
|
39
|
-
private materialModel;
|
|
40
|
-
}
|
|
41
|
-
export {};
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import * as h from "@arcgis/core/core/promiseUtils.js";
|
|
2
|
-
import * as i from "three";
|
|
3
|
-
import { GLTFLoader as u } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
4
|
-
class d {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.materialMap = /* @__PURE__ */ new Map([
|
|
7
|
-
[1, this.createCarMaterial(16777215)],
|
|
8
|
-
[2, this.createCarMaterial(7833753)],
|
|
9
|
-
[3, this.createCarMaterial(16766720)],
|
|
10
|
-
[4, this.createCarMaterial(16758465)],
|
|
11
|
-
[5, this.createCarMaterial(14423100)],
|
|
12
|
-
[6, this.createCarMaterial(3329330)],
|
|
13
|
-
[7, this.createCarMaterial(2003183)],
|
|
14
|
-
[8, this.createCarMaterial(16032864)],
|
|
15
|
-
[9, this.createCarMaterial(2105376)],
|
|
16
|
-
[10, this.createCarMaterial(9662683)],
|
|
17
|
-
[99, this.createCarMaterial(6908265)]
|
|
18
|
-
]), this.carPool = /* @__PURE__ */ new Map(), this.vanPool = /* @__PURE__ */ new Map(), this.truckPool = /* @__PURE__ */ new Map(), this.busPool = /* @__PURE__ */ new Map(), this.bicyclePool = [], this.ballPool = [], this.poolSize = 20, this.cameraHeightThreshold = 1e3;
|
|
19
|
-
}
|
|
20
|
-
createCarMaterial(t) {
|
|
21
|
-
return new i.MeshPhongMaterial({
|
|
22
|
-
color: t
|
|
23
|
-
// // emissive: 0xc3c3c3,
|
|
24
|
-
// roughness: this.roughness,
|
|
25
|
-
// metalness: this.metalness
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
async initPool(t, a) {
|
|
29
|
-
this.view = a;
|
|
30
|
-
const s = new u();
|
|
31
|
-
await h.eachAlways([
|
|
32
|
-
new Promise((o) => {
|
|
33
|
-
s.load(`${t}/3DModels/car.glb`, (l) => {
|
|
34
|
-
const e = l.scene;
|
|
35
|
-
e.rotation.x = i.MathUtils.degToRad(90), e.userData = {
|
|
36
|
-
status: "unused"
|
|
37
|
-
/* UNUSED */
|
|
38
|
-
}, this.materialMap.forEach((n, c) => {
|
|
39
|
-
const r = e.clone();
|
|
40
|
-
this.materialModel(r, n), this.carPool.set(
|
|
41
|
-
c,
|
|
42
|
-
Array.from({ length: this.poolSize }, () => r.clone())
|
|
43
|
-
);
|
|
44
|
-
}), o();
|
|
45
|
-
});
|
|
46
|
-
}),
|
|
47
|
-
new Promise((o) => {
|
|
48
|
-
s.load(`${t}/3DModels/van.glb`, (l) => {
|
|
49
|
-
const e = l.scene;
|
|
50
|
-
e.rotation.x = i.MathUtils.degToRad(90), e.userData = {
|
|
51
|
-
status: "unused"
|
|
52
|
-
/* UNUSED */
|
|
53
|
-
}, this.materialMap.forEach((n, c) => {
|
|
54
|
-
const r = e.clone();
|
|
55
|
-
this.materialModel(r, n), this.vanPool.set(
|
|
56
|
-
c,
|
|
57
|
-
Array.from({ length: this.poolSize }, () => r.clone())
|
|
58
|
-
);
|
|
59
|
-
}), o();
|
|
60
|
-
});
|
|
61
|
-
}),
|
|
62
|
-
new Promise((o) => {
|
|
63
|
-
s.load(`${t}/3DModels/truck.glb`, (l) => {
|
|
64
|
-
const e = l.scene;
|
|
65
|
-
e.scale.set(1.2, 1, 1.5), e.rotation.x = i.MathUtils.degToRad(90), e.userData = {
|
|
66
|
-
status: "unused"
|
|
67
|
-
/* UNUSED */
|
|
68
|
-
}, this.materialMap.forEach((n, c) => {
|
|
69
|
-
const r = e.clone();
|
|
70
|
-
this.materialModel(r, n), this.truckPool.set(
|
|
71
|
-
c,
|
|
72
|
-
Array.from({ length: this.poolSize }, () => r.clone())
|
|
73
|
-
);
|
|
74
|
-
}), o();
|
|
75
|
-
});
|
|
76
|
-
}),
|
|
77
|
-
new Promise((o) => {
|
|
78
|
-
s.load(`${t}/3DModels/bus.glb`, (l) => {
|
|
79
|
-
const e = l.scene;
|
|
80
|
-
e.rotation.x = i.MathUtils.degToRad(90), e.userData = {
|
|
81
|
-
status: "unused"
|
|
82
|
-
/* UNUSED */
|
|
83
|
-
}, this.materialMap.forEach((n, c) => {
|
|
84
|
-
const r = e.clone();
|
|
85
|
-
r.userData = {
|
|
86
|
-
status: "unused"
|
|
87
|
-
/* UNUSED */
|
|
88
|
-
}, this.materialModel(r, n), this.busPool.set(
|
|
89
|
-
c,
|
|
90
|
-
Array.from({ length: this.poolSize }, () => r.clone())
|
|
91
|
-
);
|
|
92
|
-
}), o();
|
|
93
|
-
});
|
|
94
|
-
}),
|
|
95
|
-
new Promise((o) => {
|
|
96
|
-
s.load(`${t}/3DModels/bicycle.glb`, (l) => {
|
|
97
|
-
const e = l.scene;
|
|
98
|
-
e.userData = {
|
|
99
|
-
status: "unused"
|
|
100
|
-
/* UNUSED */
|
|
101
|
-
}, e.rotation.x = i.MathUtils.degToRad(90), e.rotation.y = i.MathUtils.degToRad(180), e.userData = {
|
|
102
|
-
status: "unused"
|
|
103
|
-
/* UNUSED */
|
|
104
|
-
}, this.bicyclePool = Array.from(
|
|
105
|
-
{ length: this.poolSize },
|
|
106
|
-
() => e.clone()
|
|
107
|
-
), o();
|
|
108
|
-
});
|
|
109
|
-
}),
|
|
110
|
-
new Promise((o) => {
|
|
111
|
-
const l = new i.SphereGeometry(5, 32, 32), e = new i.MeshPhysicalMaterial({
|
|
112
|
-
color: 325253,
|
|
113
|
-
emissive: 0,
|
|
114
|
-
roughness: 0.2,
|
|
115
|
-
metalness: 0.8
|
|
116
|
-
});
|
|
117
|
-
this.ballPool = Array.from({ length: 100 }, () => {
|
|
118
|
-
const n = new i.Mesh(l, e);
|
|
119
|
-
return n.userData = {
|
|
120
|
-
status: "unused"
|
|
121
|
-
/* UNUSED */
|
|
122
|
-
}, n;
|
|
123
|
-
}), o();
|
|
124
|
-
})
|
|
125
|
-
]);
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* 获取实例
|
|
129
|
-
* @param data
|
|
130
|
-
*/
|
|
131
|
-
getInstance(t) {
|
|
132
|
-
if (this.view.camera.position.z >= this.cameraHeightThreshold)
|
|
133
|
-
return this.getInstanceFromList(this.ballPool);
|
|
134
|
-
{
|
|
135
|
-
const a = t.vehicleColor;
|
|
136
|
-
if (t.ptcType === 2)
|
|
137
|
-
return this.getInstanceFromList(this.bicyclePool);
|
|
138
|
-
switch (t.vehicleType) {
|
|
139
|
-
case 1:
|
|
140
|
-
case 10:
|
|
141
|
-
return this.getInstanceFromPool(a, this.carPool);
|
|
142
|
-
case 20:
|
|
143
|
-
return this.getInstanceFromPool(a, this.vanPool);
|
|
144
|
-
case 25:
|
|
145
|
-
return this.getInstanceFromPool(a, this.truckPool);
|
|
146
|
-
case 50:
|
|
147
|
-
return this.getInstanceFromPool(a, this.busPool);
|
|
148
|
-
default:
|
|
149
|
-
return this.getInstanceFromPool(a, this.carPool);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* 回收实例
|
|
155
|
-
* @param instance
|
|
156
|
-
*/
|
|
157
|
-
recycleInstance(t) {
|
|
158
|
-
t.visible = !1, t.userData.status = "unused";
|
|
159
|
-
}
|
|
160
|
-
getInstanceFromPool(t, a) {
|
|
161
|
-
let s = a.get(t);
|
|
162
|
-
return s || (s = a.get(99)), this.getInstanceFromList(s);
|
|
163
|
-
}
|
|
164
|
-
getInstanceFromList(t) {
|
|
165
|
-
let a = t.find(
|
|
166
|
-
(s) => s.userData.status === "unused"
|
|
167
|
-
/* UNUSED */
|
|
168
|
-
);
|
|
169
|
-
return a || (a = t[0].clone(), t.push(a), console.log("increase pool. pool size:", t.length)), a.userData.status = "used", a;
|
|
170
|
-
}
|
|
171
|
-
materialModel(t, a) {
|
|
172
|
-
let s = !1;
|
|
173
|
-
t.traverse((o) => {
|
|
174
|
-
!s && o instanceof i.Mesh && (o.material = a, s = !0);
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
export {
|
|
179
|
-
d as default
|
|
180
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as Three from 'three';
|
|
2
|
-
import { IVehicleTrack } from '../../../types';
|
|
3
|
-
export declare enum EModelStatus {
|
|
4
|
-
/** 未使用 */
|
|
5
|
-
UNUSED = "unused",
|
|
6
|
-
/** 使用中 */
|
|
7
|
-
USED = "used",
|
|
8
|
-
/** 已销毁 */
|
|
9
|
-
DESTROYED = "destroyed"
|
|
10
|
-
}
|
|
11
|
-
declare type VehicleModelType = Three.Group | Three.Mesh;
|
|
12
|
-
export default class VehiclePool {
|
|
13
|
-
private createCarMaterial;
|
|
14
|
-
/** 车身颜色材质 */
|
|
15
|
-
private materialMap;
|
|
16
|
-
private readonly carPool;
|
|
17
|
-
private readonly vanPool;
|
|
18
|
-
private readonly truckPool;
|
|
19
|
-
private readonly busPool;
|
|
20
|
-
private bicyclePool;
|
|
21
|
-
private ballPool;
|
|
22
|
-
private readonly poolSize;
|
|
23
|
-
private view;
|
|
24
|
-
/** 车辆模型变化的阈值 */
|
|
25
|
-
private readonly cameraHeightThreshold;
|
|
26
|
-
initPool(assetsRoot: string, view: __esri.SceneView): Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* 获取实例
|
|
29
|
-
* @param data
|
|
30
|
-
*/
|
|
31
|
-
getInstance(data: IVehicleTrack): VehicleModelType;
|
|
32
|
-
/**
|
|
33
|
-
* 回收实例
|
|
34
|
-
* @param instance
|
|
35
|
-
*/
|
|
36
|
-
recycleInstance(instance: VehicleModelType): void;
|
|
37
|
-
private getInstanceFromPool;
|
|
38
|
-
private getInstanceFromList;
|
|
39
|
-
private materialModel;
|
|
40
|
-
}
|
|
41
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("@arcgis/core/core/promiseUtils.js"),M=require("three"),m=require("three/examples/jsm/loaders/GLTFLoader.js");function u(h){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(h){for(const a in h)if(a!=="default"){const s=Object.getOwnPropertyDescriptor(h,a);Object.defineProperty(e,a,s.get?s:{enumerable:!0,get:()=>h[a]})}}return e.default=h,Object.freeze(e)}const g=u(d),i=u(M);class P{constructor(){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.carPool=new Map,this.vanPool=new Map,this.truckPool=new Map,this.busPool=new Map,this.bicyclePool=[],this.ballPool=[],this.poolSize=20,this.cameraHeightThreshold=1e3}createCarMaterial(e){return new i.MeshPhongMaterial({color:e})}async initPool(e,a){this.view=a;const s=new m.GLTFLoader;await g.eachAlways([new Promise(o=>{s.load(`${e}/3DModels/car.glb`,l=>{const t=l.scene;t.rotation.x=i.MathUtils.degToRad(90),t.userData={status:"unused"},this.materialMap.forEach((n,c)=>{const r=t.clone();this.materialModel(r,n),this.carPool.set(c,Array.from({length:this.poolSize},()=>r.clone()))}),o()})}),new Promise(o=>{s.load(`${e}/3DModels/van.glb`,l=>{const t=l.scene;t.rotation.x=i.MathUtils.degToRad(90),t.userData={status:"unused"},this.materialMap.forEach((n,c)=>{const r=t.clone();this.materialModel(r,n),this.vanPool.set(c,Array.from({length:this.poolSize},()=>r.clone()))}),o()})}),new Promise(o=>{s.load(`${e}/3DModels/truck.glb`,l=>{const t=l.scene;t.scale.set(1.2,1,1.5),t.rotation.x=i.MathUtils.degToRad(90),t.userData={status:"unused"},this.materialMap.forEach((n,c)=>{const r=t.clone();this.materialModel(r,n),this.truckPool.set(c,Array.from({length:this.poolSize},()=>r.clone()))}),o()})}),new Promise(o=>{s.load(`${e}/3DModels/bus.glb`,l=>{const t=l.scene;t.rotation.x=i.MathUtils.degToRad(90),t.userData={status:"unused"},this.materialMap.forEach((n,c)=>{const r=t.clone();r.userData={status:"unused"},this.materialModel(r,n),this.busPool.set(c,Array.from({length:this.poolSize},()=>r.clone()))}),o()})}),new Promise(o=>{s.load(`${e}/3DModels/bicycle.glb`,l=>{const t=l.scene;t.userData={status:"unused"},t.rotation.x=i.MathUtils.degToRad(90),t.rotation.y=i.MathUtils.degToRad(180),t.userData={status:"unused"},this.bicyclePool=Array.from({length:this.poolSize},()=>t.clone()),o()})}),new Promise(o=>{const l=new i.SphereGeometry(5,32,32),t=new i.MeshPhysicalMaterial({color:325253,emissive:0,roughness:.2,metalness:.8});this.ballPool=Array.from({length:100},()=>{const n=new i.Mesh(l,t);return n.userData={status:"unused"},n}),o()})])}getInstance(e){if(this.view.camera.position.z>=this.cameraHeightThreshold)return this.getInstanceFromList(this.ballPool);{const a=e.vehicleColor;if(e.ptcType===2)return this.getInstanceFromList(this.bicyclePool);switch(e.vehicleType){case 1:case 10:return this.getInstanceFromPool(a,this.carPool);case 20:return this.getInstanceFromPool(a,this.vanPool);case 25:return this.getInstanceFromPool(a,this.truckPool);case 50:return this.getInstanceFromPool(a,this.busPool);default:return this.getInstanceFromPool(a,this.carPool)}}}recycleInstance(e){e.visible=!1,e.userData.status="unused"}getInstanceFromPool(e,a){let s=a.get(e);return s||(s=a.get(99)),this.getInstanceFromList(s)}getInstanceFromList(e){let a=e.find(s=>s.userData.status==="unused");return a||(a=e[0].clone(),e.push(a),console.log("increase pool. pool size:",e.length)),a.userData.status="used",a}materialModel(e,a){let s=!1;e.traverse(o=>{!s&&o instanceof i.Mesh&&(o.material=a,s=!0)})}}exports.default=P;
|