@dvt3d/maplibre-three-plugin 1.5.0 → 1.5.1
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/README.md +79 -79
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,17 +25,17 @@ yarn add @dvt3d/maplibre-three-plugin
|
|
|
25
25
|
|
|
26
26
|
import maplibregl from 'maplibre-gl'
|
|
27
27
|
import * as THREE from 'three'
|
|
28
|
-
import {GLTFLoader} from 'three/addons/loaders/GLTFLoader.js'
|
|
28
|
+
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'
|
|
29
29
|
import * as MTP from '@dvt3d/maplibre-three-plugin'
|
|
30
30
|
|
|
31
31
|
const map = new maplibregl.Map({
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
container: 'map-container', // container id
|
|
33
|
+
style: 'https://api.maptiler.com/maps/basic-v2/style.json?key=get_access_key',
|
|
34
|
+
zoom: 18,
|
|
35
|
+
center: [148.9819, -35.3981],
|
|
36
|
+
pitch: 60,
|
|
37
|
+
canvasContextAttributes: { antialias: true },
|
|
38
|
+
maxPitch: 85,
|
|
39
39
|
})
|
|
40
40
|
|
|
41
41
|
//init three scene
|
|
@@ -48,9 +48,9 @@ mapScene.addLight(new THREE.AmbientLight())
|
|
|
48
48
|
const glTFLoader = new GLTFLoader()
|
|
49
49
|
|
|
50
50
|
glTFLoader.load('./assets/34M_17/34M_17.gltf', (gltf) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
let rtcGroup = MTP.Creator.createRTCGroup([148.9819, -35.39847])
|
|
52
|
+
rtcGroup.add(gltf.scene)
|
|
53
|
+
mapScene.addObject(rtcGroup)
|
|
54
54
|
})
|
|
55
55
|
```
|
|
56
56
|
|
|
@@ -84,67 +84,67 @@ const mapScene = new MapScene(map)
|
|
|
84
84
|
```js
|
|
85
85
|
// config
|
|
86
86
|
Object({
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Existing THREE.Scene instance.
|
|
89
|
+
* If not provided, an internal default scene will be created.
|
|
90
|
+
*/
|
|
91
|
+
scene: null,
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Existing THREE.Camera instance.
|
|
95
|
+
* If not provided, an internal default camera will be created.
|
|
96
|
+
*/
|
|
97
|
+
camera: null,
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Existing THREE.WebGLRenderer instance.
|
|
101
|
+
* If not provided, an internal default renderer will be created.
|
|
102
|
+
*/
|
|
103
|
+
renderer: null,
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Whether to preserve the drawing buffer.
|
|
107
|
+
* When enabled, the canvas content will be retained after rendering,
|
|
108
|
+
* which is useful for screenshots or readPixels operations.
|
|
109
|
+
* Note: Enabling this may have a performance impact.
|
|
110
|
+
*/
|
|
111
|
+
preserveDrawingBuffer: false,
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Whether to enable post-processing rendering.
|
|
115
|
+
* When enabled, Three.js content will be rendered through
|
|
116
|
+
* an offscreen render target before being composited onto the map.
|
|
117
|
+
* When disabled, Three.js renders directly into the shared MapLibre canvas
|
|
118
|
+
* for maximum performance and stability.
|
|
119
|
+
*/
|
|
120
|
+
enablePostProcessing: false,
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Custom frame render loop.
|
|
124
|
+
*
|
|
125
|
+
* This function will be called every frame.
|
|
126
|
+
* If not provided, the internal default render loop will be used.
|
|
127
|
+
*
|
|
128
|
+
* ⚠️ Note:
|
|
129
|
+
* Providing a custom renderLoop means you take full control
|
|
130
|
+
* of the render lifecycle. The built-in rendering pipeline
|
|
131
|
+
* will be bypassed.
|
|
132
|
+
*
|
|
133
|
+
* As a result, the following internal event hooks will
|
|
134
|
+
* NOT be triggered automatically:
|
|
135
|
+
*
|
|
136
|
+
* - preReset
|
|
137
|
+
* - postReset
|
|
138
|
+
* - preRender
|
|
139
|
+
* - postRender
|
|
140
|
+
*
|
|
141
|
+
* If needed, you must manually call the corresponding logic
|
|
142
|
+
* inside your custom renderLoop.
|
|
143
|
+
*
|
|
144
|
+
* @param {MapScene} ins - The current MapScene instance
|
|
145
|
+
*/
|
|
146
|
+
renderLoop: (ins) => {
|
|
147
|
+
}
|
|
148
148
|
})
|
|
149
149
|
```
|
|
150
150
|
|
|
@@ -168,7 +168,7 @@ These hooks are only triggered when using the internal render loop.
|
|
|
168
168
|
- `{THREE.WebGLRenderer} renderer` : `readonly`
|
|
169
169
|
- `{EffectComposer} composer` : `readonly`
|
|
170
170
|
- `{RenderPass} renderPass` : `readonly`
|
|
171
|
-
- `{
|
|
171
|
+
- `{OutputPass} outputPass` : `readonly`
|
|
172
172
|
|
|
173
173
|
#### methods
|
|
174
174
|
|
|
@@ -215,8 +215,8 @@ These hooks are only triggered when using the internal render loop.
|
|
|
215
215
|
|
|
216
216
|
- params
|
|
217
217
|
- `{THREE.Object3D | CustomObject} target `
|
|
218
|
-
- `{Function} completed
|
|
219
|
-
- `{Number} duration
|
|
218
|
+
- `{Function} completed `
|
|
219
|
+
- `{Number} duration `
|
|
220
220
|
- returns
|
|
221
221
|
- `this`
|
|
222
222
|
|
|
@@ -226,7 +226,7 @@ These hooks are only triggered when using the internal render loop.
|
|
|
226
226
|
|
|
227
227
|
- params
|
|
228
228
|
- `{Ojbect} target `
|
|
229
|
-
- `{Function} completed
|
|
229
|
+
- `{Function} completed `
|
|
230
230
|
- returns
|
|
231
231
|
- `this`
|
|
232
232
|
|
|
@@ -236,7 +236,7 @@ These hooks are only triggered when using the internal render loop.
|
|
|
236
236
|
|
|
237
237
|
- params
|
|
238
238
|
- `{String} type `
|
|
239
|
-
- `{Function} callback
|
|
239
|
+
- `{Function} callback `
|
|
240
240
|
- returns
|
|
241
241
|
- `this`
|
|
242
242
|
|
|
@@ -246,7 +246,7 @@ These hooks are only triggered when using the internal render loop.
|
|
|
246
246
|
|
|
247
247
|
- params
|
|
248
248
|
- `{String} type `
|
|
249
|
-
- `{Function} callback
|
|
249
|
+
- `{Function} callback `
|
|
250
250
|
- returns
|
|
251
251
|
- `this`
|
|
252
252
|
|
|
@@ -331,7 +331,7 @@ const sun = new Sun()
|
|
|
331
331
|
|
|
332
332
|
- `{THREE.Group} delegate ` : `readonly`
|
|
333
333
|
- `{Boolean} castShadow `
|
|
334
|
-
- `{Date
|
|
334
|
+
- `{Date | String} currentTime `
|
|
335
335
|
- `{THREE.DirectionalLight} sunLight` : `readonly`
|
|
336
336
|
- `{THREE.HemisphereLight} hemiLight`: `readonly`
|
|
337
337
|
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Scene, PerspectiveCamera, WebGLRenderer, Group, Light, Object3D, Vector
|
|
|
3
3
|
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
|
|
4
4
|
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
|
|
5
5
|
import { Pass } from 'three/addons/postprocessing/Pass.js';
|
|
6
|
-
import {
|
|
6
|
+
import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';
|
|
7
7
|
|
|
8
8
|
interface IMap {
|
|
9
9
|
transform: any;
|
|
@@ -96,7 +96,7 @@ declare class MapScene {
|
|
|
96
96
|
private readonly _world;
|
|
97
97
|
private readonly _composer;
|
|
98
98
|
private readonly _renderPass;
|
|
99
|
-
private readonly
|
|
99
|
+
private readonly _outputPass;
|
|
100
100
|
private _event;
|
|
101
101
|
constructor(map: IMap, options?: Partial<IMapSceneOptions>);
|
|
102
102
|
get map(): IMap;
|
|
@@ -108,7 +108,7 @@ declare class MapScene {
|
|
|
108
108
|
get renderer(): WebGLRenderer;
|
|
109
109
|
get composer(): EffectComposer | undefined;
|
|
110
110
|
get renderPass(): RenderPass | undefined;
|
|
111
|
-
get
|
|
111
|
+
get outputPass(): OutputPass | undefined;
|
|
112
112
|
/**
|
|
113
113
|
*
|
|
114
114
|
* @private
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
import{Group as se,PerspectiveCamera as Le,Scene as Ie,WebGLRenderer as De,EventDispatcher as Te,Box3 as xe,Vector3 as Re,NormalBlending as Ce}from"three";import{EffectComposer as Ee}from"three/addons/postprocessing/EffectComposer.js";import{RenderPass as ze}from"three/addons/postprocessing/RenderPass.js";import"three/addons/postprocessing/Pass.js";import{ShaderPass as Oe}from"three/addons/postprocessing/ShaderPass.js";var T=63710088e-1,R=2*Math.PI*T,l=Math.PI/180,Ke=180/Math.PI,C=1024e3/R,Q=512;var W=class{static clamp(e,t,n){return Math.min(n,Math.max(t,e))}static makePerspectiveMatrix(e,t,n,r){let i=1/Math.tan(e/2),s=1/(n-r);return[i/t,0,0,0,0,i,0,0,0,0,(r+n)*s,-1,0,0,2*r*n*s,0]}static mercatorXFromLng(e){return(180+e)/360}static mercatorYFromLat(e){return(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+e*Math.PI/360)))/360}static getViewInfo(e,t,n){let r=e.fov*l,i=e.pitch*l,s=null;if(Array.isArray(t)&&(s={lng:t[0],lat:t[1],alt:t[2]||0}),typeof t=="string"){let p=t.split(",");s={lng:+p[0],lat:+p[1],alt:+p[2]||0}}let c=Math.max(n.x,n.y,n.z)/(2*Math.tan(r/2))*Math.cos(i)+s.alt,h=Math.abs(Math.cos(i)*e.cameraToCenterDistance),b=R*Math.abs(Math.cos(s.lat*l)),_=h/c*b,f=Math.round(Math.log2(_/e.tileSize));return{center:[s.lng,s.lat],cameraHeight:c,zoom:Math.min(f,e.maxZoom)}}static getHeightByZoom(e,t,n,r){let i=Math.abs(Math.cos(r*l)*e.cameraToCenterDistance),s=R*Math.abs(Math.cos(n*l)),o=Math.pow(2,t)*e.tileSize;return i*s/o}static getZoomByHeight(e,t,n,r){let i=Math.abs(Math.cos(r*l)*e.cameraToCenterDistance),s=R*Math.abs(Math.cos(n*l)),o=i/t*s;return Math.round(Math.log2(o/e.tileSize))}},P=W;import{Matrix4 as S,Vector3 as we}from"three";var $=new S,ee=new S,te=85.051129,Z=class{_map;_world;_camera;_translateCenter;_worldSizeRatio;constructor(e,t,n){this._map=e,this._world=t,this._camera=n,this._translateCenter=new S().makeTranslation(1024e3/2,-1024e3/2,0),this._worldSizeRatio=Q/1024e3,this._map.on("move",()=>{this.syncCamera(!1)}),this._map.on("resize",()=>{this.syncCamera(!0)})}syncCamera(e){let t=this._map.transform,n=t.pitch*l,r=t.bearing*l;if(e){let f=t.fov*l,p=t.centerOffset||new we;this._camera.aspect=t.width/t.height,$.elements=P.makePerspectiveMatrix(f,this._camera.aspect,t.height/50,t.farZ),this._camera.projectionMatrix=$,this._camera.projectionMatrix.elements[8]=-p.x*2/t.width,this._camera.projectionMatrix.elements[9]=p.y*2/t.height}ee.makeTranslation(0,0,t.cameraToCenterDistance);let i=new S().premultiply(ee).premultiply(new S().makeRotationX(n)).premultiply(new S().makeRotationZ(-r));t.elevation&&(i.elements[14]=t.cameraToCenterDistance*Math.cos(n)),this._camera.matrixWorld.copy(i);let s=t.scale*this._worldSizeRatio,o=new S().makeScale(s,s,s),c=t.x,h=t.y;if(!c||!h){let f=t.center,p=P.clamp(f.lat,-te,te);c=P.mercatorXFromLng(f.lng)*t.worldSize,h=P.mercatorYFromLat(p)*t.worldSize}let b=new S().makeTranslation(-c,h,0),_=new S().makeRotationZ(Math.PI);this._world.matrix=new S().premultiply(_).premultiply(this._translateCenter).premultiply(o).premultiply(b)}},re=Z;var F=class{_id;_mapScene;_cameraSync;constructor(e,t){this._id=e,this._mapScene=t,this._cameraSync=new re(this._mapScene.map,this._mapScene.world,this._mapScene.camera)}get id(){return this._id}get type(){return"custom"}get renderingMode(){return"3d"}onAdd(){this._cameraSync.syncCamera(!0)}render(){this._mapScene.render()}onRemove(){this._cameraSync=null,this._mapScene=null}},ne=F;import{Vector3 as Pe}from"three";var B=class{static projectedMercatorUnitsPerMeter(){return this.projectedUnitsPerMeter(0)}static projectedUnitsPerMeter(e){return Math.abs(1024e3/Math.cos(l*e)/R)}static lngLatToVector3(e,t,n){let r=[0,0,0];return Array.isArray(e)?(r=[-T*l*e[0]*C,-T*Math.log(Math.tan(Math.PI*.25+.5*l*e[1]))*C],e[2]?r.push(e[2]*this.projectedUnitsPerMeter(e[1])):r.push(0)):(r=[-T*l*e*C,-T*Math.log(Math.tan(Math.PI*.25+.5*l*(t||0)))*C],n?r.push(n*this.projectedUnitsPerMeter(t||0)):r.push(0)),new Pe(r[0],r[1],r[2])}static vector3ToLngLat(e){let t=[0,0,0];return e&&(t[0]=-e.x/(T*l*C),t[1]=2*(Math.atan(Math.exp(e.y/(C*-T)))-Math.PI/4)/l,t[2]=e.z/this.projectedUnitsPerMeter(t[1])),t}},L=B;var ae={name:"CustomOutputShader",uniforms:{tDiffuse:{value:null}},vertexShader:`
|
|
2
|
-
precision highp float;
|
|
3
|
-
varying vec2 vUv;
|
|
4
|
-
void main() {
|
|
5
|
-
vUv = uv;
|
|
6
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
7
|
-
|
|
8
|
-
}`,fragmentShader:`
|
|
9
|
-
precision highp float;
|
|
10
|
-
uniform sampler2D tDiffuse;
|
|
11
|
-
varying vec2 vUv;
|
|
12
|
-
void main() {
|
|
13
|
-
vec4 color = texture2D(tDiffuse, vUv);
|
|
14
|
-
color.rgb = pow(color.rgb, vec3(1.0/2.2));
|
|
15
|
-
color.rgb *= color.a;
|
|
16
|
-
gl_FragColor = color;
|
|
17
|
-
}`};var Ae={scene:null,camera:null,renderer:null,preserveDrawingBuffer:!1,renderLoop:null,enablePostProcessing:!1},V="map_scene_layer",k=class{_map;_options;_canvas;_scene;_camera;_renderer;_lights;_world;_composer;_renderPass;_customOutPass;_event;constructor(e,t={}){if(!e)throw"missing map";this._map=e,this._options={...Ae,...t},this._canvas=e.getCanvas(),this._scene=this._options.scene||new Ie,this._camera=this._options.camera||new Le(this._map.transform.fov,this._map.transform.width/this._map.transform.height,.001,1e21),this._camera.matrixAutoUpdate=!1,this._renderer=this._options.renderer||new De({alpha:!0,antialias:!0,preserveDrawingBuffer:this._options.preserveDrawingBuffer,canvas:this._canvas,context:this._canvas.getContext("webgl2")}),this._renderer.setPixelRatio(window.devicePixelRatio),this._renderer.setSize(this._canvas.clientWidth,this._canvas.clientHeight),this._renderer.autoClear=!1,this._lights=new se,this._lights.name="lights",this._scene.add(this._lights),this._world=new se,this._world.name="world",this._world.userData={isWorld:!0,name:"world"},this._world.position.set(1024e3/2,1024e3/2,0),this._world.matrixAutoUpdate=!1,this._scene.add(this._world),this._options.enablePostProcessing&&(this._composer=new Ee(this._renderer),this._composer.setSize(this._canvas.clientWidth,this._canvas.clientHeight),this._composer.renderTarget1.depthBuffer=!0,this._composer.renderTarget2.depthBuffer=!0,this._renderPass=new ze(this._scene,this._camera),this._renderer.setClearColor(0,0),this._composer.addPass(this._renderPass),this._customOutPass=new Oe(ae),this._customOutPass.renderToScreen=!0,this._customOutPass.material.transparent=!0,this._customOutPass.material.blending=Ce,this._customOutPass.clear=!1,this._composer.addPass(this._customOutPass)),this._map.on("render",this._onMapRender.bind(this)),this._event=new Te}get map(){return this._map}get canvas(){return this._canvas}get camera(){return this._camera}get scene(){return this._scene}get lights(){return this._lights}get world(){return this._world}get renderer(){return this._renderer}get composer(){return this._composer}get renderPass(){return this._renderPass}get customOutPass(){return this._customOutPass}_onMapRender(){this._map.getLayer(V)||this._map.addLayer(new ne(V,this))}render(){if(this._options.renderLoop)this._options.renderLoop(this);else{let e={center:this._map.getCenter(),scene:this._scene,camera:this._camera,renderer:this._renderer};this._event.dispatchEvent({type:"preReset",frameState:e}),this.renderer.resetState(),this._event.dispatchEvent({type:"postReset",frameState:e}),this._event.dispatchEvent({type:"preRender",frameState:e}),this._composer?this._composer.render():this._renderer.render(this._scene,this._camera),this._event.dispatchEvent({type:"postRender",frameState:e})}return this}addLight(e){return this._lights.add(e.delegate||e),this}removeLight(e){return this._lights.remove(e.delegate||e),this}addObject(e){let t="delegate"in e?e.delegate:e;return this._world.add(t),this}removeObject(e){let t="delegate"in e?e.delegate:e;return this._world.remove(t),t.traverse(n=>{n.geometry&&n.geometry.dispose(),n.material&&(Array.isArray(n.material)?n.material.forEach(r=>r.dispose()):n.material.dispose()),n.texture&&n.texture.dispose()}),this}getViewPosition(){let e=this._map.transform,t=e.center;return{position:[t.lng,t.lat,P.getHeightByZoom(e,e.zoom,t.lat,e.pitch)],heading:e.bearing,pitch:e.pitch}}flyTo(e,t,n){if(e&&e.position){n&&this._map.once("moveend",n);let r=e.size;r||(r=new Re,new xe().setFromObject(e.delegate||e,!0).getSize(r));let i=P.getViewInfo(this._map.transform,L.vector3ToLngLat(e.position),r);this._map.flyTo({center:i.center,zoom:i.zoom,duration:(t||3)*1e3})}return this}zoomTo(e,t){return this.flyTo(e,0,t)}flyToPosition(e,t=[0,0,0],n,r=3){return n&&this._map.once("moveend",n),this._map.flyTo({center:[e[0],e[1]],zoom:P.getZoomByHeight(this._map.transform,e[2],e[1],t[1]||0),bearing:t[0],pitch:t[1],duration:r*1e3}),this}zoomToPosition(e,t=[0,0,0],n){return this.flyToPosition(e,t,n,0)}on(e,t){return this._event.addEventListener(e,t),this}off(e,t){return this._event.removeEventListener(e,t),this}layerBeforeTo(e){return this._map.moveLayer(V,e),this}addPass(e){if(!this._options.enablePostProcessing||!e||!this._composer)return this;let t=this._customOutPass;if(this._composer.passes.includes(e))return this;let n=t?this._composer.passes.indexOf(t):-1;return n>=0?this._composer.insertPass(e,n):this._composer.addPass(e),this}removePass(e){return!this._options.enablePostProcessing||!e||!this._composer?this:(this._composer.removePass(e),this)}};import{Group as Fe,DirectionalLight as Be,HemisphereLight as Ve,Color as ye}from"three";var H=Math.PI,m=Math.sin,u=Math.cos,N=Math.tan,ie=Math.asin,O=Math.atan2,oe=Math.acos,d=H/180,X=1e3*60*60*24,me=2440588,ce=2451545;function Ue(a){return a.valueOf()/X-.5+me}function A(a){return new Date((a+.5-me)*X)}function j(a){return Ue(a)-ce}var G=d*23.4397;function ue(a,e){return O(m(a)*u(G)-N(e)*m(G),u(a))}function Y(a,e){return ie(m(e)*u(G)+u(e)*m(G)*m(a))}function he(a,e,t){return O(m(a),u(a)*m(e)-N(t)*u(e))}function le(a,e,t){return ie(m(e)*m(t)+u(e)*u(t)*u(a))}function pe(a,e){return d*(280.16+360.9856235*a)-e}function Ge(a){return a<0&&(a=0),2967e-7/Math.tan(a+.00312536/(a+.08901179))}function de(a){return d*(357.5291+.98560028*a)}function be(a){let e=d*(1.9148*m(a)+.02*m(2*a)+3e-4*m(3*a)),t=d*102.9372;return a+e+t+H}function fe(a){let e=de(a),t=be(e);return{dec:Y(t,0),ra:ue(t,0)}}var M={};M.getPosition=function(a,e,t){let n=d*-t,r=d*e,i=j(a),s=fe(i),o=pe(i,n)-s.ra;return{azimuth:he(o,r,s.dec),altitude:le(o,r,s.dec)}};var J=M.times=[[-.833,"sunrise","sunset"],[-.3,"sunriseEnd","sunsetStart"],[-6,"dawn","dusk"],[-12,"nauticalDawn","nauticalDusk"],[-18,"nightEnd","night"],[6,"goldenHourEnd","goldenHour"]];M.addTime=function(a,e,t){J.push([a,e,t])};var _e=9e-4;function He(a,e){return Math.round(a-_e-e/(2*H))}function ge(a,e,t){return _e+(a+e)/(2*H)+t}function Me(a,e,t){return ce+a+.0053*m(e)-.0069*m(2*t)}function je(a,e,t){return oe((m(a)-m(e)*m(t))/(u(e)*u(t)))}function We(a){return-2.076*Math.sqrt(a)/60}function Ze(a,e,t,n,r,i,s){let o=je(a,t,n),c=ge(o,e,r);return Me(c,i,s)}M.getTimes=function(a,e,t,n=0){let r=d*-t,i=d*e,s=We(n),o=j(a),c=He(o,r),h=ge(0,r,c),b=de(h),_=be(b),f=Y(_,0),p=Me(h,b,_),y,E,v,g,w,z,I={solarNoon:A(p),nadir:A(p-.5)};for(y=0,E=J.length;y<E;y+=1)v=J[y],g=(v[0]+s)*d,w=Ze(g,r,i,f,c,b,_),z=p-(w-p),I[v[1]]=A(z),I[v[2]]=A(w);return I};function ve(a){let e=d*(218.316+13.176396*a),t=d*(134.963+13.064993*a),n=d*(93.272+13.22935*a),r=e+d*6.289*m(t),i=d*5.128*m(n),s=385001-20905*u(t);return{ra:ue(r,i),dec:Y(r,i),dist:s}}M.getMoonPosition=function(a,e,t){let n=d*-t,r=d*e,i=j(a),s=ve(i),o=pe(i,n)-s.ra,c=le(o,r,s.dec),h=O(m(o),N(r)*u(s.dec)-m(s.dec)*u(o));return c=c+Ge(c),{azimuth:he(o,r,s.dec),altitude:c,distance:s.dist,parallacticAngle:h}};M.getMoonIllumination=function(a){let e=j(a||new Date),t=fe(e),n=ve(e),r=149598e3,i=oe(m(t.dec)*m(n.dec)+u(t.dec)*u(n.dec)*u(t.ra-n.ra)),s=O(r*m(i),n.dist-r*u(i)),o=O(u(t.dec)*m(t.ra-n.ra),m(t.dec)*u(n.dec)-u(t.dec)*m(n.dec)*u(t.ra-n.ra));return{fraction:(1+u(s))/2,phase:.5+.5*s*(o<0?-1:1)/Math.PI,angle:o}};function U(a,e){return new Date(a.valueOf()+e*X/24)}M.getMoonTimes=function(a,e,t,n=!1){let r=new Date(a);n?r.setUTCHours(0,0,0,0):r.setHours(0,0,0,0);let i=.133*d,s=M.getMoonPosition(r,e,t).altitude-i,o,c,h,b,_,f,p,y,E,v,g,w,z;for(let D=1;D<=24&&(o=M.getMoonPosition(U(r,D),e,t).altitude-i,c=M.getMoonPosition(U(r,D+1),e,t).altitude-i,_=(s+c)/2-o,f=(c-s)/2,p=-f/(2*_),y=(_*p+f)*p+o,E=f*f-4*_*o,v=0,E>=0&&(z=Math.sqrt(E)/(Math.abs(_)*2),g=p-z,w=p+z,Math.abs(g)<=1&&v++,Math.abs(w)<=1&&v++,g<-1&&(g=w)),v===1?s<0?h=D+g:b=D+g:v===2&&(h=D+(y<0?w:g),b=D+(y<0?g:w)),!(h&&b));D+=2)s=c;let I={};return h&&(I.rise=U(r,h)),b&&(I.set=U(r,b)),!h&&!b&&(I[y>0?"alwaysUp":"alwaysDown"]=!0),I};var Se=M;var q=class{_delegate;_sunLight;_hemiLight;_currentTime;constructor(){this._delegate=new Fe,this._delegate.name="Sun",this._sunLight=new Be(16777215,1),this._hemiLight=new Ve(new ye(16777215),new ye(16777215),.6),this._hemiLight.color.setHSL(.661,.96,.12),this._hemiLight.groundColor.setHSL(.11,.96,.14),this._hemiLight.position.set(0,0,50),this._delegate.add(this._sunLight),this._delegate.add(this._hemiLight),this._currentTime=new Date().getTime()}get delegate(){return this._delegate}set castShadow(e){this._sunLight.castShadow=e}get castShadow(){return this._sunLight.castShadow}set currentTime(e){this._currentTime=e}get currentTime(){return this._currentTime}get sunLight(){return this._sunLight}get hemiLight(){return this._hemiLight}setShadow(e={}){return this._sunLight.shadow.radius=e.radius||2,this._sunLight.shadow.mapSize.width=e.mapSize?e.mapSize[0]:8192,this._sunLight.shadow.mapSize.height=e.mapSize?e.mapSize[1]:8192,this._sunLight.shadow.camera.top=this._sunLight.shadow.camera.right=e.topRight||1e3,this._sunLight.shadow.camera.bottom=this._sunLight.shadow.camera.left=e.bottomLeft||-1e3,this._sunLight.shadow.camera.near=e.near||1,this._sunLight.shadow.camera.far=e.far||1e8,this._sunLight.shadow.camera.visible=!0,this}update(e){let n=new Date(this._currentTime||new Date().getTime()),r=e.center,i=Se.getPosition(n,r.lat,r.lng),s=i.altitude,o=Math.PI+i.azimuth,c=1024e3/2,h=Math.sin(s),b=Math.cos(s),_=Math.cos(o)*b,f=Math.sin(o)*b;this._sunLight.position.set(f,_,h),this._sunLight.position.multiplyScalar(c),this._sunLight.intensity=Math.max(h,0),this._hemiLight.intensity=Math.max(h*1,.1),this._sunLight.updateMatrixWorld()}},ke=q;import{Group as Je,Mesh as Ne,PlaneGeometry as Xe,ShadowMaterial as Ye}from"three";var K=class{static createRTCGroup(e,t,n){let r=new Je;if(r.name="rtc",r.position.copy(L.lngLatToVector3(e)),t?(r.rotateX(t[0]||0),r.rotateY(t[1]||0),r.rotateZ(t[2]||0)):(r.rotateX(Math.PI/2),r.rotateY(Math.PI)),n)r.scale.set(n[0]||1,n[1]||1,n[2]||1);else{let i=1;Array.isArray(e)&&(i=L.projectedUnitsPerMeter(e[1])),r.scale.set(i,i,i)}return r}static createMercatorRTCGroup(e,t,n){let r=this.createRTCGroup(e,t,n);if(!n){let i=1,s=L.projectedMercatorUnitsPerMeter();Array.isArray(e)&&(i=L.projectedUnitsPerMeter(e[1])),r.scale.set(s,s,i)}return r}static createShadowGround(e,t,n){let r=new Xe(t||100,n||100),i=new Ye({opacity:.5,transparent:!0}),s=new Ne(r,i);return s.position.copy(L.lngLatToVector3(e)),s.receiveShadow=!0,s.name="shadow-ground",s}},qe=K;export{qe as Creator,k as MapScene,L as SceneTransform,ke as Sun};
|
|
1
|
+
import{Group as ae,PerspectiveCamera as Ie,Scene as Le,WebGLRenderer as De,EventDispatcher as Te,Box3 as Re,Vector3 as xe,NormalBlending as Ce}from"three";import{EffectComposer as Ee}from"three/addons/postprocessing/EffectComposer.js";import{RenderPass as ze}from"three/addons/postprocessing/RenderPass.js";import"three/addons/postprocessing/Pass.js";import{OutputPass as Ae}from"three/addons/postprocessing/OutputPass.js";var T=63710088e-1,x=2*Math.PI*T,l=Math.PI/180,qe=180/Math.PI,C=1024e3/x,Q=512;var W=class{static clamp(e,t,n){return Math.min(n,Math.max(t,e))}static makePerspectiveMatrix(e,t,n,r){let i=1/Math.tan(e/2),s=1/(n-r);return[i/t,0,0,0,0,i,0,0,0,0,(r+n)*s,-1,0,0,2*r*n*s,0]}static mercatorXFromLng(e){return(180+e)/360}static mercatorYFromLat(e){return(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+e*Math.PI/360)))/360}static getViewInfo(e,t,n){let r=e.fov*l,i=e.pitch*l,s=null;if(Array.isArray(t)&&(s={lng:t[0],lat:t[1],alt:t[2]||0}),typeof t=="string"){let p=t.split(",");s={lng:+p[0],lat:+p[1],alt:+p[2]||0}}let c=Math.max(n.x,n.y,n.z)/(2*Math.tan(r/2))*Math.cos(i)+s.alt,h=Math.abs(Math.cos(i)*e.cameraToCenterDistance),b=x*Math.abs(Math.cos(s.lat*l)),f=h/c*b,_=Math.round(Math.log2(f/e.tileSize));return{center:[s.lng,s.lat],cameraHeight:c,zoom:Math.min(_,e.maxZoom)}}static getHeightByZoom(e,t,n,r){let i=Math.abs(Math.cos(r*l)*e.cameraToCenterDistance),s=x*Math.abs(Math.cos(n*l)),o=Math.pow(2,t)*e.tileSize;return i*s/o}static getZoomByHeight(e,t,n,r){let i=Math.abs(Math.cos(r*l)*e.cameraToCenterDistance),s=x*Math.abs(Math.cos(n*l)),o=i/t*s;return Math.round(Math.log2(o/e.tileSize))}},I=W;import{Matrix4 as y,Vector3 as we}from"three";var $=new y,ee=new y,te=85.051129,Z=class{_map;_world;_camera;_translateCenter;_worldSizeRatio;constructor(e,t,n){this._map=e,this._world=t,this._camera=n,this._translateCenter=new y().makeTranslation(1024e3/2,-1024e3/2,0),this._worldSizeRatio=Q/1024e3,this._map.on("move",()=>{this.syncCamera(!1)}),this._map.on("resize",()=>{this.syncCamera(!0)})}syncCamera(e){let t=this._map.transform,n=t.pitch*l,r=t.bearing*l;if(e){let _=t.fov*l,p=t.centerOffset||new we;this._camera.aspect=t.width/t.height,$.elements=I.makePerspectiveMatrix(_,this._camera.aspect,t.height/50,t.farZ),this._camera.projectionMatrix=$,this._camera.projectionMatrix.elements[8]=-p.x*2/t.width,this._camera.projectionMatrix.elements[9]=p.y*2/t.height}ee.makeTranslation(0,0,t.cameraToCenterDistance);let i=new y().premultiply(ee).premultiply(new y().makeRotationX(n)).premultiply(new y().makeRotationZ(-r));t.elevation&&(i.elements[14]=t.cameraToCenterDistance*Math.cos(n)),this._camera.matrixWorld.copy(i);let s=t.scale*this._worldSizeRatio,o=new y().makeScale(s,s,s),c=t.x,h=t.y;if(!c||!h){let _=t.center,p=I.clamp(_.lat,-te,te);c=I.mercatorXFromLng(_.lng)*t.worldSize,h=I.mercatorYFromLat(p)*t.worldSize}let b=new y().makeTranslation(-c,h,0),f=new y().makeRotationZ(Math.PI);this._world.matrix=new y().premultiply(f).premultiply(this._translateCenter).premultiply(o).premultiply(b)}},re=Z;var F=class{_id;_mapScene;_cameraSync;constructor(e,t){this._id=e,this._mapScene=t,this._cameraSync=new re(this._mapScene.map,this._mapScene.world,this._mapScene.camera)}get id(){return this._id}get type(){return"custom"}get renderingMode(){return"3d"}onAdd(){this._cameraSync.syncCamera(!0)}render(){this._mapScene.render()}onRemove(){this._cameraSync=null,this._mapScene=null}},ne=F;import{Vector3 as Pe}from"three";var B=class{static projectedMercatorUnitsPerMeter(){return this.projectedUnitsPerMeter(0)}static projectedUnitsPerMeter(e){return Math.abs(1024e3/Math.cos(l*e)/x)}static lngLatToVector3(e,t,n){let r=[0,0,0];return Array.isArray(e)?(r=[-T*l*e[0]*C,-T*Math.log(Math.tan(Math.PI*.25+.5*l*e[1]))*C],e[2]?r.push(e[2]*this.projectedUnitsPerMeter(e[1])):r.push(0)):(r=[-T*l*e*C,-T*Math.log(Math.tan(Math.PI*.25+.5*l*(t||0)))*C],n?r.push(n*this.projectedUnitsPerMeter(t||0)):r.push(0)),new Pe(r[0],r[1],r[2])}static vector3ToLngLat(e){let t=[0,0,0];return e&&(t[0]=-e.x/(T*l*C),t[1]=2*(Math.atan(Math.exp(e.y/(C*-T)))-Math.PI/4)/l,t[2]=e.z/this.projectedUnitsPerMeter(t[1])),t}},v=B;var Oe={scene:null,camera:null,renderer:null,preserveDrawingBuffer:!1,renderLoop:null,enablePostProcessing:!1},V="map_scene_layer",k=class{_map;_options;_canvas;_scene;_camera;_renderer;_lights;_world;_composer;_renderPass;_outputPass;_event;constructor(e,t={}){if(!e)throw"missing map";this._map=e,this._options={...Oe,...t},this._canvas=e.getCanvas(),this._scene=this._options.scene||new Le,this._camera=this._options.camera||new Ie(this._map.transform.fov,this._map.transform.width/this._map.transform.height,.001,1e21),this._camera.matrixAutoUpdate=!1,this._renderer=this._options.renderer||new De({alpha:!0,antialias:!0,preserveDrawingBuffer:this._options.preserveDrawingBuffer,canvas:this._canvas,context:this._canvas.getContext("webgl2")}),this._renderer.setPixelRatio(window.devicePixelRatio),this._renderer.setSize(this._canvas.clientWidth,this._canvas.clientHeight),this._renderer.autoClear=!1,this._lights=new ae,this._lights.name="lights",this._scene.add(this._lights),this._world=new ae,this._world.name="world",this._world.userData={isWorld:!0,name:"world"},this._world.position.set(1024e3/2,1024e3/2,0),this._world.matrixAutoUpdate=!1,this._scene.add(this._world),this._options.enablePostProcessing&&(this._composer=new Ee(this._renderer),this._composer.setSize(this._canvas.clientWidth,this._canvas.clientHeight),this._composer.renderTarget1.depthBuffer=!0,this._composer.renderTarget2.depthBuffer=!0,this._renderPass=new ze(this._scene,this._camera),this._renderer.setClearColor(0,0),this._composer.addPass(this._renderPass),this._outputPass=new Ae,this._outputPass.renderToScreen=!0,this._outputPass.material.transparent=!0,this._outputPass.material.blending=Ce,this._outputPass.clear=!1,this._composer.addPass(this._outputPass)),this._map.on("render",this._onMapRender.bind(this)),this._event=new Te}get map(){return this._map}get canvas(){return this._canvas}get camera(){return this._camera}get scene(){return this._scene}get lights(){return this._lights}get world(){return this._world}get renderer(){return this._renderer}get composer(){return this._composer}get renderPass(){return this._renderPass}get outputPass(){return this._outputPass}_onMapRender(){this._map.getLayer(V)||this._map.addLayer(new ne(V,this))}render(){if(this._options.renderLoop)this._options.renderLoop(this);else{let e={center:this._map.getCenter(),scene:this._scene,camera:this._camera,renderer:this._renderer};this._event.dispatchEvent({type:"preReset",frameState:e}),this.renderer.resetState(),this._event.dispatchEvent({type:"postReset",frameState:e}),this._event.dispatchEvent({type:"preRender",frameState:e}),this._composer?this._composer.render():this._renderer.render(this._scene,this._camera),this._event.dispatchEvent({type:"postRender",frameState:e})}return this}addLight(e){return this._lights.add(e.delegate||e),this}removeLight(e){return this._lights.remove(e.delegate||e),this}addObject(e){let t="delegate"in e?e.delegate:e;return this._world.add(t),this}removeObject(e){let t="delegate"in e?e.delegate:e;return this._world.remove(t),t.traverse(n=>{n.geometry&&n.geometry.dispose(),n.material&&(Array.isArray(n.material)?n.material.forEach(r=>r.dispose()):n.material.dispose()),n.texture&&n.texture.dispose()}),this}getViewPosition(){let e=this._map.transform,t=e.center;return{position:[t.lng,t.lat,I.getHeightByZoom(e,e.zoom,t.lat,e.pitch)],heading:e.bearing,pitch:e.pitch}}flyTo(e,t,n){if(e&&e.position){n&&this._map.once("moveend",n);let r=e.size;r||(r=new xe,new Re().setFromObject(e.delegate||e,!0).getSize(r));let i=I.getViewInfo(this._map.transform,v.vector3ToLngLat(e.position),r);this._map.flyTo({center:i.center,zoom:i.zoom,duration:(t||3)*1e3})}return this}zoomTo(e,t){return this.flyTo(e,0,t)}flyToPosition(e,t=[0,0,0],n,r=3){return n&&this._map.once("moveend",n),this._map.flyTo({center:[e[0],e[1]],zoom:I.getZoomByHeight(this._map.transform,e[2],e[1],t[1]||0),bearing:t[0],pitch:t[1],duration:r*1e3}),this}zoomToPosition(e,t=[0,0,0],n){return this.flyToPosition(e,t,n,0)}on(e,t){return this._event.addEventListener(e,t),this}off(e,t){return this._event.removeEventListener(e,t),this}layerBeforeTo(e){return this._map.moveLayer(V,e),this}addPass(e){if(!this._options.enablePostProcessing)return console.warn("[MapScene] PostProcessing is disabled."),this;if(!e||!this._composer)return this;if(this._composer.passes.includes(e))return this;let t=this._outputPass?this._composer.passes.indexOf(this._outputPass):-1;return t>=0?this._composer.insertPass(e,t):this._composer.addPass(e),this}removePass(e){return this._options.enablePostProcessing?!e||!this._composer?this:(this._composer.removePass(e),this):(console.warn("[MapScene] PostProcessing is disabled."),this)}};import{Group as Fe,DirectionalLight as Be,HemisphereLight as Ve,Color as ye}from"three";var j=Math.PI,m=Math.sin,u=Math.cos,N=Math.tan,se=Math.asin,A=Math.atan2,ie=Math.acos,d=j/180,X=1e3*60*60*24,oe=2440588,me=2451545;function Ge(a){return a.valueOf()/X-.5+oe}function O(a){return new Date((a+.5-oe)*X)}function U(a){return Ge(a)-me}var H=d*23.4397;function ce(a,e){return A(m(a)*u(H)-N(e)*m(H),u(a))}function Y(a,e){return se(m(e)*u(H)+u(e)*m(H)*m(a))}function ue(a,e,t){return A(m(a),u(a)*m(e)-N(t)*u(e))}function he(a,e,t){return se(m(e)*m(t)+u(e)*u(t)*u(a))}function le(a,e){return d*(280.16+360.9856235*a)-e}function He(a){return a<0&&(a=0),2967e-7/Math.tan(a+.00312536/(a+.08901179))}function pe(a){return d*(357.5291+.98560028*a)}function de(a){let e=d*(1.9148*m(a)+.02*m(2*a)+3e-4*m(3*a)),t=d*102.9372;return a+e+t+j}function be(a){let e=pe(a),t=de(e);return{dec:Y(t,0),ra:ce(t,0)}}var M={};M.getPosition=function(a,e,t){let n=d*-t,r=d*e,i=U(a),s=be(i),o=le(i,n)-s.ra;return{azimuth:ue(o,r,s.dec),altitude:he(o,r,s.dec)}};var J=M.times=[[-.833,"sunrise","sunset"],[-.3,"sunriseEnd","sunsetStart"],[-6,"dawn","dusk"],[-12,"nauticalDawn","nauticalDusk"],[-18,"nightEnd","night"],[6,"goldenHourEnd","goldenHour"]];M.addTime=function(a,e,t){J.push([a,e,t])};var _e=9e-4;function je(a,e){return Math.round(a-_e-e/(2*j))}function fe(a,e,t){return _e+(a+e)/(2*j)+t}function ge(a,e,t){return me+a+.0053*m(e)-.0069*m(2*t)}function Ue(a,e,t){return ie((m(a)-m(e)*m(t))/(u(e)*u(t)))}function We(a){return-2.076*Math.sqrt(a)/60}function Ze(a,e,t,n,r,i,s){let o=Ue(a,t,n),c=fe(o,e,r);return ge(c,i,s)}M.getTimes=function(a,e,t,n=0){let r=d*-t,i=d*e,s=We(n),o=U(a),c=je(o,r),h=fe(0,r,c),b=pe(h),f=de(b),_=Y(f,0),p=ge(h,b,f),w,E,S,g,P,z,L={solarNoon:O(p),nadir:O(p-.5)};for(w=0,E=J.length;w<E;w+=1)S=J[w],g=(S[0]+s)*d,P=Ze(g,r,i,_,c,b,f),z=p-(P-p),L[S[1]]=O(z),L[S[2]]=O(P);return L};function Me(a){let e=d*(218.316+13.176396*a),t=d*(134.963+13.064993*a),n=d*(93.272+13.22935*a),r=e+d*6.289*m(t),i=d*5.128*m(n),s=385001-20905*u(t);return{ra:ce(r,i),dec:Y(r,i),dist:s}}M.getMoonPosition=function(a,e,t){let n=d*-t,r=d*e,i=U(a),s=Me(i),o=le(i,n)-s.ra,c=he(o,r,s.dec),h=A(m(o),N(r)*u(s.dec)-m(s.dec)*u(o));return c=c+He(c),{azimuth:ue(o,r,s.dec),altitude:c,distance:s.dist,parallacticAngle:h}};M.getMoonIllumination=function(a){let e=U(a||new Date),t=be(e),n=Me(e),r=149598e3,i=ie(m(t.dec)*m(n.dec)+u(t.dec)*u(n.dec)*u(t.ra-n.ra)),s=A(r*m(i),n.dist-r*u(i)),o=A(u(t.dec)*m(t.ra-n.ra),m(t.dec)*u(n.dec)-u(t.dec)*m(n.dec)*u(t.ra-n.ra));return{fraction:(1+u(s))/2,phase:.5+.5*s*(o<0?-1:1)/Math.PI,angle:o}};function G(a,e){return new Date(a.valueOf()+e*X/24)}M.getMoonTimes=function(a,e,t,n=!1){let r=new Date(a);n?r.setUTCHours(0,0,0,0):r.setHours(0,0,0,0);let i=.133*d,s=M.getMoonPosition(r,e,t).altitude-i,o,c,h,b,f,_,p,w,E,S,g,P,z;for(let D=1;D<=24&&(o=M.getMoonPosition(G(r,D),e,t).altitude-i,c=M.getMoonPosition(G(r,D+1),e,t).altitude-i,f=(s+c)/2-o,_=(c-s)/2,p=-_/(2*f),w=(f*p+_)*p+o,E=_*_-4*f*o,S=0,E>=0&&(z=Math.sqrt(E)/(Math.abs(f)*2),g=p-z,P=p+z,Math.abs(g)<=1&&S++,Math.abs(P)<=1&&S++,g<-1&&(g=P)),S===1?s<0?h=D+g:b=D+g:S===2&&(h=D+(w<0?P:g),b=D+(w<0?g:P)),!(h&&b));D+=2)s=c;let L={};return h&&(L.rise=G(r,h)),b&&(L.set=G(r,b)),!h&&!b&&(L[w>0?"alwaysUp":"alwaysDown"]=!0),L};var Se=M;var q=class{_delegate;_sunLight;_hemiLight;_currentTime;constructor(){this._delegate=new Fe,this._delegate.name="Sun",this._sunLight=new Be(16777215,1),this._hemiLight=new Ve(new ye(16777215),new ye(16777215),.6),this._hemiLight.color.setHSL(.661,.96,.12),this._hemiLight.groundColor.setHSL(.11,.96,.14),this._hemiLight.position.set(0,0,50),this._delegate.add(this._sunLight),this._delegate.add(this._hemiLight),this._currentTime=new Date().getTime()}get delegate(){return this._delegate}set castShadow(e){this._sunLight.castShadow=e}get castShadow(){return this._sunLight.castShadow}set currentTime(e){this._currentTime=e}get currentTime(){return this._currentTime}get sunLight(){return this._sunLight}get hemiLight(){return this._hemiLight}setShadow(e={}){return this._sunLight.shadow.radius=e.radius||2,this._sunLight.shadow.mapSize.width=e.mapSize?e.mapSize[0]:8192,this._sunLight.shadow.mapSize.height=e.mapSize?e.mapSize[1]:8192,this._sunLight.shadow.camera.top=this._sunLight.shadow.camera.right=e.topRight||1e3,this._sunLight.shadow.camera.bottom=this._sunLight.shadow.camera.left=e.bottomLeft||-1e3,this._sunLight.shadow.camera.near=e.near||1,this._sunLight.shadow.camera.far=e.far||1e8,this._sunLight.shadow.camera.visible=!0,this}update(e){let n=new Date(this._currentTime||new Date().getTime()),r=e.center,i=Se.getPosition(n,r.lat,r.lng),s=i.altitude,o=Math.PI+i.azimuth,c=1024e3/2,h=Math.sin(s),b=Math.cos(s),f=Math.cos(o)*b,_=Math.sin(o)*b;this._sunLight.position.set(_,f,h),this._sunLight.position.multiplyScalar(c),this._sunLight.intensity=Math.max(h,0),this._hemiLight.intensity=Math.max(h*1,.1),this._sunLight.updateMatrixWorld()}},ke=q;import{Group as ve,Mesh as Je,PlaneGeometry as Ne,ShadowMaterial as Xe}from"three";var K=class{static createRTCGroup(e,t,n){let r=new ve;if(r.name="rtc",r.position.copy(v.lngLatToVector3(e)),t?r.rotation.set(t[0]||0,t[1]||0,t[2]||0):r.rotation.set(Math.PI/2,Math.PI,0),n)r.scale.set(n[0]||1,n[1]||1,n[2]||1);else{let i=1;Array.isArray(e)&&(i=v.projectedUnitsPerMeter(e[1])),r.scale.set(i,i,i)}return r}static createMercatorRTCGroup(e,t,n){let r=new ve;if(r.name="rtc",r.position.copy(v.lngLatToVector3(e)),t?r.rotation.set(t[0]||0,t[1]||0,t[2]||0):r.rotation.set(Math.PI/2,Math.PI,0),n)r.scale.set(n[0]||1,n[1]||1,n[2]||1);else{let i=1,s=v.projectedMercatorUnitsPerMeter();Array.isArray(e)&&(i=v.projectedUnitsPerMeter(e[1])),r.scale.set(s,s,i)}return r}static createShadowGround(e,t,n){let r=new Ne(t||100,n||100),i=new Xe({opacity:.5,transparent:!0}),s=new Je(r,i);return s.position.copy(v.lngLatToVector3(e)),s.receiveShadow=!0,s.name="shadow-ground",s}},Ye=K;export{Ye as Creator,k as MapScene,v as SceneTransform,ke as Sun};
|