@dvt3d/maplibre-three-plugin 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +293 -0
- package/dist/index.js +1 -1
- package/dist/mtp.min.js +1 -1
- package/package.json +13 -9
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import * as three from 'three';
|
|
2
|
+
import { Scene, PerspectiveCamera, WebGLRenderer, Group, Light, Object3D, Vector3, DirectionalLight, HemisphereLight, Mesh } from 'three';
|
|
3
|
+
|
|
4
|
+
interface IMap {
|
|
5
|
+
transform: any;
|
|
6
|
+
on(type: string, listener: () => any): any;
|
|
7
|
+
getCanvas(): HTMLCanvasElement;
|
|
8
|
+
getLayer(id: string): any;
|
|
9
|
+
addLayer(options: any): any;
|
|
10
|
+
getCenter(): {
|
|
11
|
+
lng: number;
|
|
12
|
+
lat: number;
|
|
13
|
+
};
|
|
14
|
+
once(type: string, completed: any): void;
|
|
15
|
+
flyTo(param: {
|
|
16
|
+
center: any[];
|
|
17
|
+
zoom: number;
|
|
18
|
+
bearing: number;
|
|
19
|
+
pitch: number;
|
|
20
|
+
duration: number;
|
|
21
|
+
}): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Configuration options for initializing a MapScene
|
|
25
|
+
*/
|
|
26
|
+
interface IMapSceneOptions {
|
|
27
|
+
/** Existing Three.js Scene instance (optional) */
|
|
28
|
+
scene: null | Scene;
|
|
29
|
+
/** Existing Three.js PerspectiveCamera instance (optional) */
|
|
30
|
+
camera: null | PerspectiveCamera;
|
|
31
|
+
/** Existing Three.js WebGLRenderer instance (optional) */
|
|
32
|
+
renderer: null | WebGLRenderer;
|
|
33
|
+
/** Custom render loop function (optional) */
|
|
34
|
+
renderLoop: null | ((mapScene: MapScene) => void);
|
|
35
|
+
/** Whether to preserve the drawing buffer (optional) */
|
|
36
|
+
preserveDrawingBuffer: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Frame state information passed to event listeners
|
|
40
|
+
*/
|
|
41
|
+
interface IFrameState {
|
|
42
|
+
/** Current map center coordinates */
|
|
43
|
+
center: {
|
|
44
|
+
lng: number;
|
|
45
|
+
lat: number;
|
|
46
|
+
};
|
|
47
|
+
/** Three.js Scene instance */
|
|
48
|
+
scene: Scene;
|
|
49
|
+
/** Three.js PerspectiveCamera instance */
|
|
50
|
+
camera: PerspectiveCamera;
|
|
51
|
+
/** Three.js WebGLRenderer instance */
|
|
52
|
+
renderer: WebGLRenderer;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Extended Three.js Light interface with optional delegate
|
|
56
|
+
*/
|
|
57
|
+
interface ILight extends Light {
|
|
58
|
+
/** Optional delegate light source */
|
|
59
|
+
delegate?: Light;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Extended Three.js Object3D interface with optional delegate and size
|
|
63
|
+
*/
|
|
64
|
+
interface IObject3D {
|
|
65
|
+
/** Optional delegate object */
|
|
66
|
+
delegate: Object3D;
|
|
67
|
+
/** Optional size vector */
|
|
68
|
+
size?: Vector3;
|
|
69
|
+
}
|
|
70
|
+
declare class MapScene {
|
|
71
|
+
private readonly _map;
|
|
72
|
+
private _options;
|
|
73
|
+
private readonly _canvas;
|
|
74
|
+
private readonly _scene;
|
|
75
|
+
private readonly _camera;
|
|
76
|
+
private readonly _renderer;
|
|
77
|
+
private readonly _lights;
|
|
78
|
+
private readonly _world;
|
|
79
|
+
private _event;
|
|
80
|
+
constructor(map: IMap, options?: Partial<IMapSceneOptions>);
|
|
81
|
+
get map(): IMap;
|
|
82
|
+
get canvas(): HTMLCanvasElement;
|
|
83
|
+
get camera(): PerspectiveCamera;
|
|
84
|
+
get scene(): Scene;
|
|
85
|
+
get lights(): Group<three.Object3DEventMap>;
|
|
86
|
+
get world(): Group<three.Object3DEventMap>;
|
|
87
|
+
get renderer(): WebGLRenderer;
|
|
88
|
+
/**
|
|
89
|
+
*
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
92
|
+
_onMapRender(): void;
|
|
93
|
+
/**
|
|
94
|
+
*
|
|
95
|
+
* @returns {MapScene}
|
|
96
|
+
*/
|
|
97
|
+
render(): MapScene;
|
|
98
|
+
/**
|
|
99
|
+
*
|
|
100
|
+
* @param light
|
|
101
|
+
* @returns {MapScene}
|
|
102
|
+
*/
|
|
103
|
+
addLight(light: ILight): MapScene;
|
|
104
|
+
/**
|
|
105
|
+
*
|
|
106
|
+
* @param light
|
|
107
|
+
*/
|
|
108
|
+
removeLight(light: ILight): this;
|
|
109
|
+
/**
|
|
110
|
+
*
|
|
111
|
+
* @param object
|
|
112
|
+
* @returns {MapScene}
|
|
113
|
+
*/
|
|
114
|
+
addObject(object: IObject3D | Object3D): MapScene;
|
|
115
|
+
/**
|
|
116
|
+
*
|
|
117
|
+
* @param object
|
|
118
|
+
* @returns {MapScene}
|
|
119
|
+
*/
|
|
120
|
+
removeObject(object: IObject3D | Object3D): MapScene;
|
|
121
|
+
/**
|
|
122
|
+
*
|
|
123
|
+
* @returns {{position: *[], heading: *, pitch}}
|
|
124
|
+
*/
|
|
125
|
+
getViewPosition(): {
|
|
126
|
+
position: number[];
|
|
127
|
+
heading: number;
|
|
128
|
+
pitch: number;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
*
|
|
132
|
+
* @param target
|
|
133
|
+
* @param completed
|
|
134
|
+
* @param duration
|
|
135
|
+
* @returns {MapScene}
|
|
136
|
+
*/
|
|
137
|
+
flyTo(target: {
|
|
138
|
+
position: {
|
|
139
|
+
x: number;
|
|
140
|
+
y: number;
|
|
141
|
+
z: number;
|
|
142
|
+
};
|
|
143
|
+
size?: any;
|
|
144
|
+
delegate?: any;
|
|
145
|
+
}, duration?: number, completed?: () => void): MapScene;
|
|
146
|
+
/**
|
|
147
|
+
*
|
|
148
|
+
* @param target
|
|
149
|
+
* @param completed
|
|
150
|
+
* @returns {MapScene}
|
|
151
|
+
*/
|
|
152
|
+
zoomTo(target: {
|
|
153
|
+
position: {
|
|
154
|
+
x: number;
|
|
155
|
+
y: number;
|
|
156
|
+
z: number;
|
|
157
|
+
};
|
|
158
|
+
size?: any;
|
|
159
|
+
delegate?: any;
|
|
160
|
+
}, completed?: () => void): MapScene;
|
|
161
|
+
/**
|
|
162
|
+
*
|
|
163
|
+
* @returns {MapScene}
|
|
164
|
+
*/
|
|
165
|
+
flyToPosition(position: number[], hpr?: number[], completed?: () => void, duration?: number): MapScene;
|
|
166
|
+
/**
|
|
167
|
+
*
|
|
168
|
+
* @returns {MapScene}
|
|
169
|
+
*/
|
|
170
|
+
zoomToPosition(position: any, hpr?: number[], completed?: () => void): MapScene;
|
|
171
|
+
/**
|
|
172
|
+
*
|
|
173
|
+
* @param type
|
|
174
|
+
* @param callback
|
|
175
|
+
* @returns {MapScene}
|
|
176
|
+
*/
|
|
177
|
+
on(type: string, callback: (event: {
|
|
178
|
+
frameState: IFrameState;
|
|
179
|
+
}) => void): MapScene;
|
|
180
|
+
/**
|
|
181
|
+
*
|
|
182
|
+
* @param type
|
|
183
|
+
* @param callback
|
|
184
|
+
* @returns {MapScene}
|
|
185
|
+
*/
|
|
186
|
+
off(type: string, callback: () => void): MapScene;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
declare class SceneTransform {
|
|
190
|
+
/**
|
|
191
|
+
*
|
|
192
|
+
* @returns {number}
|
|
193
|
+
*/
|
|
194
|
+
static projectedMercatorUnitsPerMeter(): number;
|
|
195
|
+
/**
|
|
196
|
+
*
|
|
197
|
+
* @param lat
|
|
198
|
+
* @returns {number}
|
|
199
|
+
*/
|
|
200
|
+
static projectedUnitsPerMeter(lat: number): number;
|
|
201
|
+
/**
|
|
202
|
+
*
|
|
203
|
+
* @param lng
|
|
204
|
+
* @param lat
|
|
205
|
+
* @param alt
|
|
206
|
+
* @returns {Vector3}
|
|
207
|
+
*/
|
|
208
|
+
static lngLatToVector3(lng: number | number[], lat?: number, alt?: number): Vector3;
|
|
209
|
+
/**
|
|
210
|
+
*
|
|
211
|
+
* @param v
|
|
212
|
+
* @returns {number[]}
|
|
213
|
+
*/
|
|
214
|
+
static vector3ToLngLat(v: {
|
|
215
|
+
x: number;
|
|
216
|
+
y: number;
|
|
217
|
+
z: number;
|
|
218
|
+
}): number[];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
interface ShadowOptions {
|
|
222
|
+
/** Blur radius for shadow edges */
|
|
223
|
+
radius: number;
|
|
224
|
+
/** Width and height of the shadow map */
|
|
225
|
+
mapSize: [number, number];
|
|
226
|
+
/** Top and right boundaries of the shadow camera frustum */
|
|
227
|
+
topRight: number;
|
|
228
|
+
/** Bottom and left boundaries of the shadow camera frustum */
|
|
229
|
+
bottomLeft: number;
|
|
230
|
+
/** Near clipping plane of the shadow camera */
|
|
231
|
+
near: number;
|
|
232
|
+
/** Far clipping plane of the shadow camera */
|
|
233
|
+
far: number;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
*
|
|
237
|
+
*/
|
|
238
|
+
declare class Sun {
|
|
239
|
+
private readonly _delegate;
|
|
240
|
+
private readonly _sunLight;
|
|
241
|
+
private readonly _hemiLight;
|
|
242
|
+
private _currentTime;
|
|
243
|
+
constructor();
|
|
244
|
+
get delegate(): Group<three.Object3DEventMap>;
|
|
245
|
+
set castShadow(castShadow: boolean);
|
|
246
|
+
get castShadow(): boolean;
|
|
247
|
+
set currentTime(currentTime: string | number | Date);
|
|
248
|
+
get currentTime(): string | number | Date;
|
|
249
|
+
get sunLight(): DirectionalLight;
|
|
250
|
+
get hemiLight(): HemisphereLight;
|
|
251
|
+
/**
|
|
252
|
+
*
|
|
253
|
+
* @param shadow
|
|
254
|
+
* @returns {Sun}
|
|
255
|
+
*/
|
|
256
|
+
setShadow(shadow?: Partial<ShadowOptions>): Sun;
|
|
257
|
+
/**
|
|
258
|
+
*
|
|
259
|
+
* @param frameState
|
|
260
|
+
*/
|
|
261
|
+
update(frameState: IFrameState): void;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* @Author: Caven Chen
|
|
266
|
+
*/
|
|
267
|
+
|
|
268
|
+
declare class Creator {
|
|
269
|
+
/**
|
|
270
|
+
*
|
|
271
|
+
* @param center
|
|
272
|
+
* @param rotation
|
|
273
|
+
* @param scale
|
|
274
|
+
*/
|
|
275
|
+
static createRTCGroup(center: number | number[], rotation: number[], scale: number[]): Group;
|
|
276
|
+
/**
|
|
277
|
+
*
|
|
278
|
+
* @param center
|
|
279
|
+
* @param rotation
|
|
280
|
+
* @param scale
|
|
281
|
+
*/
|
|
282
|
+
static createMercatorRTCGroup(center: number | number[], rotation: number[], scale: number[]): Group;
|
|
283
|
+
/**
|
|
284
|
+
*
|
|
285
|
+
* @param center
|
|
286
|
+
* @param width
|
|
287
|
+
* @param height
|
|
288
|
+
* @returns {Mesh}
|
|
289
|
+
*/
|
|
290
|
+
static createShadowGround(center: number | number[], width?: number, height?: number): Mesh;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export { Creator, MapScene, SceneTransform, Sun };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Group as at,PerspectiveCamera as vt,Scene as It,WebGLRenderer as Pt,EventDispatcher as Et,Box3 as Dt,Vector3 as Ct}from"three";var E=63710088e-1,D=2*Math.PI*E,m=Math.PI/180,Bt=180/Math.PI,C=1024e3/D,K=512;var j=class{static clamp(t,e,i){return Math.min(i,Math.max(e,t))}static makePerspectiveMatrix(t,e,i,r){let s=1/Math.tan(t/2),n=1/(i-r);return[s/e,0,0,0,0,s,0,0,0,0,(r+i)*n,-1,0,0,2*r*i*n,0]}static mercatorXFromLng(t){return(180+t)/360}static mercatorYFromLat(t){return(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+t*Math.PI/360)))/360}static getViewInfo(t,e,i){let r=t.fov*m,s=t.pitch*m;if(Array.isArray(e)&&(e={lng:e[0],lat:e[1],alt:e[2]||0}),typeof e=="string"){let d=e.split(",");e={lng:d[0],lat:d[1],alt:d[2]||0}}let o=Math.max(i.x,i.y,i.z)/(2*Math.tan(r/2))*Math.cos(s)+e.alt,l=Math.abs(Math.cos(s)*t.cameraToCenterDistance),u=D*Math.abs(Math.cos(e.lat*m)),f=l/o*u,_=Math.round(Math.log2(f/t.tileSize));return{center:[e.lng,e.lat],cameraHeight:o,zoom:_}}static getHeightByZoom(t,e,i,r){let s=Math.abs(Math.cos(r*m)*t.cameraToCenterDistance),n=D*Math.abs(Math.cos(i*m)),o=Math.pow(2,e)*t.tileSize;return s*n/o}static getZoomByHeight(t,e,i,r){let s=Math.abs(Math.cos(r*m)*t.cameraToCenterDistance),n=D*Math.abs(Math.cos(i*m)),o=s/e*n;return Math.round(Math.log2(o/t.tileSize))}},T=j;import{Matrix4 as S,Vector3 as Rt}from"three";var Q=new S,$=new S,tt=85.051129,G=class{constructor(t,e,i){this._map=t,this._world=e,this._camera=i,this._translateCenter=new S().makeTranslation(1024e3/2,-1024e3/2,0),this._worldSizeRatio=K/1024e3,this._map.on("move",()=>{this.syncCamera(!1)}),this._map.on("resize",()=>{this.syncCamera(!0)})}syncCamera(t){let e=this._map.transform,i=e.pitch*m,r=e.bearing*m;if(t){let d=e.fov*m,g=e.centerOffset||new Rt;this._camera.aspect=e.width/e.height,Q.elements=T.makePerspectiveMatrix(d,this._camera.aspect,e.height/50,e.farZ),this._camera.projectionMatrix=Q,this._camera.projectionMatrix.elements[8]=-g.x*2/e.width,this._camera.projectionMatrix.elements[9]=g.y*2/e.height}$.makeTranslation(0,0,e.cameraToCenterDistance);let s=new S().premultiply($).premultiply(new S().makeRotationX(i)).premultiply(new S().makeRotationZ(-r));e.elevation&&(s.elements[14]=e.cameraToCenterDistance*Math.cos(i)),this._camera.matrixWorld.copy(s);let n=e.scale*this._worldSizeRatio,o=new S().makeScale(n,n,n),l=e.x,u=e.y;if(!l||!u){let d=e.center,g=T.clamp(d.lat,-tt,tt);l=T.mercatorXFromLng(d.lng)*e.worldSize,u=T.mercatorYFromLat(g)*e.worldSize}let f=new S().makeTranslation(-l,u,0),_=new S().makeRotationZ(Math.PI);this._world.matrix=new S().premultiply(_).premultiply(this._translateCenter).premultiply(o).premultiply(f)}},et=G;var k=class{constructor(t,e){this._id=t,this._mapScene=e,this._cameraSync=new et(this._mapScene.map,this._mapScene.world,this._mapScene.camera)}get id(){return this._id}get type(){return"custom"}get renderingMode(){return"3d"}onAdd(t,e){this._cameraSync.syncCamera(!0)}render(){this._mapScene.render()}onRemove(){this._cameraSync=null,this._mapScene=null}},rt=k;import{Vector3 as Tt}from"three";var J=class{static projectedMercatorUnitsPerMeter(){return Math.abs(1024e3/D)}static projectedUnitsPerMeter(t){return Math.abs(1024e3/Math.cos(m*t)/D)}static lngLatToVector3(t,e,i=0){let r=[0,0,0];return Array.isArray(t)?(r=[-E*m*t[0]*C,-E*Math.log(Math.tan(Math.PI*.25+.5*m*t[1]))*C],t[2]?r.push(t[2]*this.projectedUnitsPerMeter(t[1])):r.push(0)):(r=[-E*m*t*C,-E*Math.log(Math.tan(Math.PI*.25+.5*m*e))*C],i?r.push(i*this.projectedUnitsPerMeter(e)):r.push(0)),new Tt(r[0],r[1],r[2])}static vector3ToLngLat(t){let e=[0,0,0];return t&&(e[0]=-t.x/(E*m*C),e[1]=2*(Math.atan(Math.exp(t.y/(C*-E)))-Math.PI/4)/m,e[2]=t.z/this.projectedUnitsPerMeter(e[1])),e}},M=J;var At={scene:null,camera:null,renderer:null,renderLoop:null,preserveDrawingBuffer:!1},F=class{constructor(t,e={}){if(!t)throw"missing map";this._map=t,this._options={...At,...e},this._canvas=t.getCanvas(),this._scene=this._options.scene||new It,this._camera=this._options.camera||new vt(this._map.transform.fov,this._map.transform.width/this._map.transform.height,.1,1e21),this._camera.matrixAutoUpdate=!1,this._renderer=this._options.renderer||new Pt({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 at,this._lights.name="lights",this._scene.add(this._lights),this._world=new at,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._map.on("render",this._onMapRender.bind(this)),this._event=new Et}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}_onMapRender(){this._map.getLayer("map_scene_layer")||this._map.addLayer(new rt("map_scene_layer",this))}render(){if(this._options.renderLoop)this._options.renderLoop(this);else{let t={center:this._map.getCenter(),scene:this._scene,camera:this._camera,renderer:this._renderer};this._event.dispatchEvent({type:"preReset",frameState:t}),this.renderer.resetState(),this._event.dispatchEvent({type:"postReset",frameState:t}),this._event.dispatchEvent({type:"preRender",frameState:t}),this.renderer.render(this._scene,this._camera),this._event.dispatchEvent({type:"postRender",frameState:t})}return this}addLight(t){return this._lights.add(t.delegate||t),this}removeLight(t){return this._lights.remove(t.delegate||t),this}addObject(t){return this._world.add(t.delegate||t),this}removeObject(t){return this._world.remove(t),t.traverse(e=>{e.geometry&&e.geometry.dispose(),e.material&&(Array.isArray(e.material)?e.material.forEach(i=>i.dispose()):e.material.dispose()),e.texture&&e.texture.dispose()}),this}getViewPosition(){let t=this._map.transform,e=t.center;return{position:[e.lng,e.lat,T.getHeightByZoom(t,t.zoom,e.lat,t.pitch)],heading:t.bearing,pitch:t.pitch}}flyTo(t,e=null,i=3){if(t&&t.position){e&&this._map.once("moveend",e);let r=t.size;r||(r=new Ct,new Dt().setFromObject(t.delegate||t,!0).getSize(r));let s=T.getViewInfo(this._map.transform,M.vector3ToLngLat(t.position),r);this._map.flyTo({center:s.center,zoom:s.zoom,duration:i*1e3})}return this}zoomTo(t,e){return this.flyTo(t,e,0)}flyToPosition(t,e=[0,0,0],i=null,r=3){return i&&this._map.once("moveend",i),this._map.flyTo({center:[t[0],t[1]],zoom:T.getZoomByHeight(this._map.transform,t[2],t[1],e[1]||0),bearing:e[0],pitch:e[1],duration:r*1e3}),this}zoomToPosition(t,e=[0,0,0],i=null,r=3){return this.flyToPosition(t,e,i,0)}on(t,e){return this._event.addEventListener(t,e),this}off(t,e){return this._event.removeEventListener(t,e),this}},it=F;import{Group as Wt,DirectionalLight as jt,HemisphereLight as Gt,Color as yt}from"three";var H=Math.PI,h=Math.sin,c=Math.cos,B=Math.tan,st=Math.asin,b=Math.atan2,nt=Math.acos,p=H/180,N=1e3*60*60*24,ot=2440588,ht=2451545;function zt(a){return a.valueOf()/N-.5+ot}function O(a){return new Date((a+.5-ot)*N)}function W(a){return zt(a)-ht}var Z=p*23.4397;function ct(a,t){return b(h(a)*c(Z)-B(t)*h(Z),c(a))}function X(a,t){return st(h(t)*c(Z)+c(t)*h(Z)*h(a))}function lt(a,t,e){return b(h(a),c(a)*h(t)-B(e)*c(t))}function ut(a,t,e){return st(h(t)*h(e)+c(t)*c(e)*c(a))}function mt(a,t){return p*(280.16+360.9856235*a)-t}function bt(a){return a<0&&(a=0),2967e-7/Math.tan(a+.00312536/(a+.08901179))}function dt(a){return p*(357.5291+.98560028*a)}function pt(a){let t=p*(1.9148*h(a)+.02*h(2*a)+3e-4*h(3*a)),e=p*102.9372;return a+t+e+H}function ft(a){let t=dt(a),e=pt(t);return{dec:X(e,0),ra:ct(e,0)}}var L={};L.getPosition=function(a,t,e){let i=p*-e,r=p*t,s=W(a),n=ft(s),o=mt(s,i)-n.ra;return{azimuth:lt(o,r,n.dec),altitude:ut(o,r,n.dec)}};var V=L.times=[[-.833,"sunrise","sunset"],[-.3,"sunriseEnd","sunsetStart"],[-6,"dawn","dusk"],[-12,"nauticalDawn","nauticalDusk"],[-18,"nightEnd","night"],[6,"goldenHourEnd","goldenHour"]];L.addTime=function(a,t,e){V.push([a,t,e])};var _t=9e-4;function Ot(a,t){return Math.round(a-_t-t/(2*H))}function gt(a,t,e){return _t+(a+t)/(2*H)+e}function Mt(a,t,e){return ht+a+.0053*h(t)-.0069*h(2*e)}function Ut(a,t,e){return nt((h(a)-h(t)*h(e))/(c(t)*c(e)))}function Zt(a){return-2.076*Math.sqrt(a)/60}function Ht(a,t,e,i,r,s,n){let o=Ut(a,e,i),l=gt(o,t,r);return Mt(l,s,n)}L.getTimes=function(a,t,e,i){i=i||0;let r=p*-e,s=p*t,n=Zt(i),o=W(a),l=Ot(o,r),u=gt(0,r,l),f=dt(u),_=pt(f),d=X(_,0),g=Mt(u,f,_),x,A,y,w,R,z,I={solarNoon:O(g),nadir:O(g-.5)};for(x=0,A=V.length;x<A;x+=1)y=V[x],w=(y[0]+n)*p,R=Ht(w,r,s,d,l,f,_),z=g-(R-g),I[y[1]]=O(z),I[y[2]]=O(R);return I};function wt(a){let t=p*(218.316+13.176396*a),e=p*(134.963+13.064993*a),i=p*(93.272+13.22935*a),r=t+p*6.289*h(e),s=p*5.128*h(i),n=385001-20905*c(e);return{ra:ct(r,s),dec:X(r,s),dist:n}}L.getMoonPosition=function(a,t,e){let i=p*-e,r=p*t,s=W(a),n=wt(s),o=mt(s,i)-n.ra,l=ut(o,r,n.dec),u=b(h(o),B(r)*c(n.dec)-h(n.dec)*c(o));return l=l+bt(l),{azimuth:lt(o,r,n.dec),altitude:l,distance:n.dist,parallacticAngle:u}};L.getMoonIllumination=function(a){let t=W(a||new Date),e=ft(t),i=wt(t),r=149598e3,s=nt(h(e.dec)*h(i.dec)+c(e.dec)*c(i.dec)*c(e.ra-i.ra)),n=b(r*h(s),i.dist-r*c(s)),o=b(c(e.dec)*h(e.ra-i.ra),h(e.dec)*c(i.dec)-c(e.dec)*h(i.dec)*c(e.ra-i.ra));return{fraction:(1+c(n))/2,phase:.5+.5*n*(o<0?-1:1)/Math.PI,angle:o}};function U(a,t){return new Date(a.valueOf()+t*N/24)}L.getMoonTimes=function(a,t,e,i){let r=new Date(a);i?r.setUTCHours(0,0,0,0):r.setHours(0,0,0,0);let s=.133*p,n=L.getMoonPosition(r,t,e).altitude-s,o,l,u,f,_,d,g,x,A,y,w,R,z;for(let P=1;P<=24&&(o=L.getMoonPosition(U(r,P),t,e).altitude-s,l=L.getMoonPosition(U(r,P+1),t,e).altitude-s,_=(n+l)/2-o,d=(l-n)/2,g=-d/(2*_),x=(_*g+d)*g+o,A=d*d-4*_*o,y=0,A>=0&&(z=Math.sqrt(A)/(Math.abs(_)*2),w=g-z,R=g+z,Math.abs(w)<=1&&y++,Math.abs(R)<=1&&y++,w<-1&&(w=R)),y===1?n<0?u=P+w:f=P+w:y===2&&(u=P+(x<0?R:w),f=P+(x<0?w:R)),!(u&&f));P+=2)n=l;let I={};return u&&(I.rise=U(r,u)),f&&(I.set=U(r,f)),!u&&!f&&(I[x>0?"alwaysUp":"alwaysDown"]=!0),I};var Lt=L;var Y=class{constructor(){this._delegate=new Wt,this._delegate.name="Sun",this._sunLight=new jt(16777215,1),this._hemiLight=new Gt(new yt(16777215),new yt(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=null}get delegate(){return this._delegate}set castShadow(t){this._sunLight.castShadow=t}get castShadow(){return this._sunLight.castShadow}set currentTime(t){this._currentTime=t}get currentTime(){return this._currentTime}get sunLight(){return this._sunLight}get hemiLight(){return this._hemiLight}setShadow(t={}){return this._sunLight.shadow.radius=t.radius||2,this._sunLight.shadow.mapSize.width=t.mapSize?t.mapSize[0]:8192,this._sunLight.shadow.mapSize.height=t.mapSize?t.mapSize[1]:8192,this._sunLight.shadow.camera.top=this._sunLight.shadow.camera.right=t.topRight||1e3,this._sunLight.shadow.camera.bottom=this._sunLight.shadow.camera.left=t.bottomLeft||-1e3,this._sunLight.shadow.camera.near=t.near||1,this._sunLight.shadow.camera.far=t.far||1e8,this._sunLight.shadow.camera.visible=!0,this}update(t){let i=new Date(this._currentTime||new Date().getTime()),r=t.center,s=Lt.getPosition(i,r.lat,r.lng),n=s.altitude,o=Math.PI+s.azimuth,l=1024e3/2,u=Math.sin(n),f=Math.cos(n),_=Math.cos(o)*f,d=Math.sin(o)*f;this._sunLight.position.set(d,_,u),this._sunLight.position.multiplyScalar(l),this._sunLight.intensity=Math.max(u,0),this._hemiLight.intensity=Math.max(u*1,.1),this._sunLight.updateMatrixWorld()}},St=Y;import{Group as kt,Mesh as Jt,PlaneGeometry as Ft,ShadowMaterial as Vt}from"three";var q=class{static createRTCGroup(t,e,i){let r=new kt;if(r.name="rtc",r.position.copy(M.lngLatToVector3(t)),e?(r.rotateX(e[0]||0),r.rotateY(e[1]||0),r.rotateZ(e[2]||0)):(r.rotateX(Math.PI/2),r.rotateY(Math.PI)),i)r.scale.set(i[0]||1,i[1]||1,i[2]||1);else{let s=1;Array.isArray(t)?s=M.projectedUnitsPerMeter(t[1]):typeof t=="string"&&(s=M.projectedUnitsPerMeter(t.split(",")[1])),r.scale.set(s,s,s)}return r}static createMercatorRTCGroup(t,e,i){let r=this.createRTCGroup(t,e,i);if(!i){let s=1,n=M.projectedMercatorUnitsPerMeter();Array.isArray(t)?s=M.projectedUnitsPerMeter(t[1]):typeof t=="string"&&(s=M.projectedUnitsPerMeter(t.split(",")[1])),r.scale.set(n,n,s)}return r}static createShadowGround(t,e=100,i=100){let r=new Ft(e,i),s=new Vt({opacity:.5,transparent:!0}),n=new Jt(r,s);return n.position.copy(M.lngLatToVector3(t)),n.receiveShadow=!0,n.name="shadow-ground",n}},xt=q;export{xt as Creator,it as MapScene,M as SceneTransform,St as Sun};
|
|
1
|
+
import{Group as re,PerspectiveCamera as Ie,Scene as De,WebGLRenderer as Te,EventDispatcher as Re,Box3 as xe,Vector3 as Ce}from"three";var R=63710088e-1,C=2*Math.PI*R,l=Math.PI/180,Ve=180/Math.PI,P=1024e3/C,K=512;var Z=class{static clamp(e,t,r){return Math.min(r,Math.max(t,e))}static makePerspectiveMatrix(e,t,r,n){let s=1/Math.tan(e/2),i=1/(r-n);return[s/t,0,0,0,0,s,0,0,0,0,(n+r)*i,-1,0,0,2*n*r*i,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,r){let n=e.fov*l,s=e.pitch*l,i=null;if(Array.isArray(t)&&(i={lng:t[0],lat:t[1],alt:t[2]||0}),typeof t=="string"){let p=t.split(",");i={lng:+p[0],lat:+p[1],alt:+p[2]||0}}let c=Math.max(r.x,r.y,r.z)/(2*Math.tan(n/2))*Math.cos(s)+i.alt,h=Math.abs(Math.cos(s)*e.cameraToCenterDistance),b=C*Math.abs(Math.cos(i.lat*l)),g=h/c*b,f=Math.round(Math.log2(g/e.tileSize));return{center:[i.lng,i.lat],cameraHeight:c,zoom:f}}static getHeightByZoom(e,t,r,n){let s=Math.abs(Math.cos(n*l)*e.cameraToCenterDistance),i=C*Math.abs(Math.cos(r*l)),o=Math.pow(2,t)*e.tileSize;return s*i/o}static getZoomByHeight(e,t,r,n){let s=Math.abs(Math.cos(n*l)*e.cameraToCenterDistance),i=C*Math.abs(Math.cos(r*l)),o=s/t*i;return Math.round(Math.log2(o/e.tileSize))}},I=Z;import{Matrix4 as y,Vector3 as ve}from"three";var Q=new y,$=new y,ee=85.051129,F=class{_map;_world;_camera;_translateCenter;_worldSizeRatio;constructor(e,t,r){this._map=e,this._world=t,this._camera=r,this._translateCenter=new y().makeTranslation(1024e3/2,-1024e3/2,0),this._worldSizeRatio=K/1024e3,this._map.on("move",()=>{this.syncCamera(!1)}),this._map.on("resize",()=>{this.syncCamera(!0)})}syncCamera(e){let t=this._map.transform,r=t.pitch*l,n=t.bearing*l;if(e){let f=t.fov*l,p=t.centerOffset||new ve;this._camera.aspect=t.width/t.height,Q.elements=I.makePerspectiveMatrix(f,this._camera.aspect,t.height/50,t.farZ),this._camera.projectionMatrix=Q,this._camera.projectionMatrix.elements[8]=-p.x*2/t.width,this._camera.projectionMatrix.elements[9]=p.y*2/t.height}$.makeTranslation(0,0,t.cameraToCenterDistance);let s=new y().premultiply($).premultiply(new y().makeRotationX(r)).premultiply(new y().makeRotationZ(-n));t.elevation&&(s.elements[14]=t.cameraToCenterDistance*Math.cos(r)),this._camera.matrixWorld.copy(s);let i=t.scale*this._worldSizeRatio,o=new y().makeScale(i,i,i),c=t.x,h=t.y;if(!c||!h){let f=t.center,p=I.clamp(f.lat,-ee,ee);c=I.mercatorXFromLng(f.lng)*t.worldSize,h=I.mercatorYFromLat(p)*t.worldSize}let b=new y().makeTranslation(-c,h,0),g=new y().makeRotationZ(Math.PI);this._world.matrix=new y().premultiply(g).premultiply(this._translateCenter).premultiply(o).premultiply(b)}},te=F;var k=class{_id;_mapScene;_cameraSync;constructor(e,t){this._id=e,this._mapScene=t,this._cameraSync=new te(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=k;import{Vector3 as Le}from"three";var J=class{static projectedMercatorUnitsPerMeter(){return this.projectedUnitsPerMeter(0)}static projectedUnitsPerMeter(e){return Math.abs(1024e3/Math.cos(l*e)/C)}static lngLatToVector3(e,t,r){let n=[0,0,0];return Array.isArray(e)?(n=[-R*l*e[0]*P,-R*Math.log(Math.tan(Math.PI*.25+.5*l*e[1]))*P],e[2]?n.push(e[2]*this.projectedUnitsPerMeter(e[1])):n.push(0)):(n=[-R*l*e*P,-R*Math.log(Math.tan(Math.PI*.25+.5*l*(t||0)))*P],r?n.push(r*this.projectedUnitsPerMeter(t||0)):n.push(0)),new Le(n[0],n[1],n[2])}static vector3ToLngLat(e){let t=[0,0,0];return e&&(t[0]=-e.x/(R*l*P),t[1]=2*(Math.atan(Math.exp(e.y/(P*-R)))-Math.PI/4)/l,t[2]=e.z/this.projectedUnitsPerMeter(t[1])),t}},w=J;var Pe={scene:null,camera:null,renderer:null,renderLoop:null,preserveDrawingBuffer:!1},O=class{_map;_options;_canvas;_scene;_camera;_renderer;_lights;_world;_event;constructor(e,t={}){if(!e)throw"missing map";this._map=e,this._options={...Pe,...t},this._canvas=e.getCanvas(),this._scene=this._options.scene||new De,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 Te({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 re,this._lights.name="lights",this._scene.add(this._lights),this._world=new re,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._map.on("render",this._onMapRender.bind(this)),this._event=new Re}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}_onMapRender(){this._map.getLayer("map_scene_layer")||this._map.addLayer(new ne("map_scene_layer",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.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(r=>{r.geometry&&r.geometry.dispose(),r.material&&(Array.isArray(r.material)?r.material.forEach(n=>n.dispose()):r.material.dispose()),r.texture&&r.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,r){if(e&&e.position){r&&this._map.once("moveend",r);let n=e.size;n||(n=new Ce,new xe().setFromObject(e.delegate||e,!0).getSize(n));let s=I.getViewInfo(this._map.transform,w.vector3ToLngLat(e.position),n);this._map.flyTo({center:s.center,zoom:s.zoom,duration:(t||3)*1e3})}return this}zoomTo(e,t){return this.flyTo(e,0,t)}flyToPosition(e,t=[0,0,0],r,n=3){return r&&this._map.once("moveend",r),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:n*1e3}),this}zoomToPosition(e,t=[0,0,0],r){return this.flyToPosition(e,t,r,0)}on(e,t){return this._event.addEventListener(e,t),this}off(e,t){return this._event.removeEventListener(e,t),this}};import{Group as je,DirectionalLight as Ue,HemisphereLight as We,Color as Se}from"three";var U=Math.PI,m=Math.sin,u=Math.cos,B=Math.tan,ae=Math.asin,A=Math.atan2,ie=Math.acos,d=U/180,N=1e3*60*60*24,se=2440588,oe=2451545;function ze(a){return a.valueOf()/N-.5+se}function G(a){return new Date((a+.5-se)*N)}function W(a){return ze(a)-oe}var j=d*23.4397;function me(a,e){return A(m(a)*u(j)-B(e)*m(j),u(a))}function X(a,e){return ae(m(e)*u(j)+u(e)*m(j)*m(a))}function ce(a,e,t){return A(m(a),u(a)*m(e)-B(t)*u(e))}function ue(a,e,t){return ae(m(e)*m(t)+u(e)*u(t)*u(a))}function he(a,e){return d*(280.16+360.9856235*a)-e}function Ee(a){return a<0&&(a=0),2967e-7/Math.tan(a+.00312536/(a+.08901179))}function le(a){return d*(357.5291+.98560028*a)}function pe(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+U}function de(a){let e=le(a),t=pe(e);return{dec:X(t,0),ra:me(t,0)}}var M={};M.getPosition=function(a,e,t){let r=d*-t,n=d*e,s=W(a),i=de(s),o=he(s,r)-i.ra;return{azimuth:ce(o,n,i.dec),altitude:ue(o,n,i.dec)}};var V=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){V.push([a,e,t])};var be=9e-4;function Ae(a,e){return Math.round(a-be-e/(2*U))}function fe(a,e,t){return be+(a+e)/(2*U)+t}function ge(a,e,t){return oe+a+.0053*m(e)-.0069*m(2*t)}function Oe(a,e,t){return ie((m(a)-m(e)*m(t))/(u(e)*u(t)))}function Ge(a){return-2.076*Math.sqrt(a)/60}function He(a,e,t,r,n,s,i){let o=Oe(a,t,r),c=fe(o,e,n);return ge(c,s,i)}M.getTimes=function(a,e,t,r=0){let n=d*-t,s=d*e,i=Ge(r),o=W(a),c=Ae(o,n),h=fe(0,n,c),b=le(h),g=pe(b),f=X(g,0),p=ge(h,b,g),v,z,S,_,L,E,D={solarNoon:G(p),nadir:G(p-.5)};for(v=0,z=V.length;v<z;v+=1)S=V[v],_=(S[0]+i)*d,L=He(_,n,s,f,c,b,g),E=p-(L-p),D[S[1]]=G(E),D[S[2]]=G(L);return D};function _e(a){let e=d*(218.316+13.176396*a),t=d*(134.963+13.064993*a),r=d*(93.272+13.22935*a),n=e+d*6.289*m(t),s=d*5.128*m(r),i=385001-20905*u(t);return{ra:me(n,s),dec:X(n,s),dist:i}}M.getMoonPosition=function(a,e,t){let r=d*-t,n=d*e,s=W(a),i=_e(s),o=he(s,r)-i.ra,c=ue(o,n,i.dec),h=A(m(o),B(n)*u(i.dec)-m(i.dec)*u(o));return c=c+Ee(c),{azimuth:ce(o,n,i.dec),altitude:c,distance:i.dist,parallacticAngle:h}};M.getMoonIllumination=function(a){let e=W(a||new Date),t=de(e),r=_e(e),n=149598e3,s=ie(m(t.dec)*m(r.dec)+u(t.dec)*u(r.dec)*u(t.ra-r.ra)),i=A(n*m(s),r.dist-n*u(s)),o=A(u(t.dec)*m(t.ra-r.ra),m(t.dec)*u(r.dec)-u(t.dec)*m(r.dec)*u(t.ra-r.ra));return{fraction:(1+u(i))/2,phase:.5+.5*i*(o<0?-1:1)/Math.PI,angle:o}};function H(a,e){return new Date(a.valueOf()+e*N/24)}M.getMoonTimes=function(a,e,t,r=!1){let n=new Date(a);r?n.setUTCHours(0,0,0,0):n.setHours(0,0,0,0);let s=.133*d,i=M.getMoonPosition(n,e,t).altitude-s,o,c,h,b,g,f,p,v,z,S,_,L,E;for(let T=1;T<=24&&(o=M.getMoonPosition(H(n,T),e,t).altitude-s,c=M.getMoonPosition(H(n,T+1),e,t).altitude-s,g=(i+c)/2-o,f=(c-i)/2,p=-f/(2*g),v=(g*p+f)*p+o,z=f*f-4*g*o,S=0,z>=0&&(E=Math.sqrt(z)/(Math.abs(g)*2),_=p-E,L=p+E,Math.abs(_)<=1&&S++,Math.abs(L)<=1&&S++,_<-1&&(_=L)),S===1?i<0?h=T+_:b=T+_:S===2&&(h=T+(v<0?L:_),b=T+(v<0?_:L)),!(h&&b));T+=2)i=c;let D={};return h&&(D.rise=H(n,h)),b&&(D.set=H(n,b)),!h&&!b&&(D[v>0?"alwaysUp":"alwaysDown"]=!0),D};var Me=M;var Y=class{_delegate;_sunLight;_hemiLight;_currentTime;constructor(){this._delegate=new je,this._delegate.name="Sun",this._sunLight=new Ue(16777215,1),this._hemiLight=new We(new Se(16777215),new Se(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 r=new Date(this._currentTime||new Date().getTime()),n=e.center,s=Me.getPosition(r,n.lat,n.lng),i=s.altitude,o=Math.PI+s.azimuth,c=1024e3/2,h=Math.sin(i),b=Math.cos(i),g=Math.cos(o)*b,f=Math.sin(o)*b;this._sunLight.position.set(f,g,h),this._sunLight.position.multiplyScalar(c),this._sunLight.intensity=Math.max(h,0),this._hemiLight.intensity=Math.max(h*1,.1),this._sunLight.updateMatrixWorld()}},ye=Y;import{Group as Ze,Mesh as Fe,PlaneGeometry as ke,ShadowMaterial as Je}from"three";var q=class{static createRTCGroup(e,t,r){let n=new Ze;if(n.name="rtc",n.position.copy(w.lngLatToVector3(e)),t?(n.rotateX(t[0]||0),n.rotateY(t[1]||0),n.rotateZ(t[2]||0)):(n.rotateX(Math.PI/2),n.rotateY(Math.PI)),r)n.scale.set(r[0]||1,r[1]||1,r[2]||1);else{let s=1;Array.isArray(e)&&(s=w.projectedUnitsPerMeter(e[1])),n.scale.set(s,s,s)}return n}static createMercatorRTCGroup(e,t,r){let n=this.createRTCGroup(e,t,r);if(!r){let s=1,i=w.projectedMercatorUnitsPerMeter();Array.isArray(e)&&(s=w.projectedUnitsPerMeter(e[1])),n.scale.set(i,i,s)}return n}static createShadowGround(e,t,r){let n=new ke(t||100,r||100),s=new Je({opacity:.5,transparent:!0}),i=new Fe(n,s);return i.position.copy(w.lngLatToVector3(e)),i.receiveShadow=!0,i.name="shadow-ground",i}},we=q;export{we as Creator,O as MapScene,w as SceneTransform,ye as Sun};
|
package/dist/mtp.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var Dt=Object.create;var rt=Object.defineProperty;var Ct=Object.getOwnPropertyDescriptor;var At=Object.getOwnPropertyNames;var zt=Object.getPrototypeOf,bt=Object.prototype.hasOwnProperty;var Ot=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports);var Ut=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of At(t))!bt.call(r,a)&&a!==e&&rt(r,a,{get:()=>t[a],enumerable:!(i=Ct(t,a))||i.enumerable});return r};var Z=(r,t,e)=>(e=r!=null?Dt(zt(r)):{},Ut(t||!r||!r.__esModule?rt(e,"default",{value:r,enumerable:!0}):e,r));var H=Ot((Vt,at)=>{at.exports=THREE});var M=Z(H(),1);var C=63710088e-1,A=2*Math.PI*C,m=Math.PI/180,Bt=180/Math.PI,b=1024e3/A,it=512;var V=class{static clamp(t,e,i){return Math.min(i,Math.max(e,t))}static makePerspectiveMatrix(t,e,i,a){let s=1/Math.tan(t/2),n=1/(i-a);return[s/e,0,0,0,0,s,0,0,0,0,(a+i)*n,-1,0,0,2*a*i*n,0]}static mercatorXFromLng(t){return(180+t)/360}static mercatorYFromLat(t){return(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+t*Math.PI/360)))/360}static getViewInfo(t,e,i){let a=t.fov*m,s=t.pitch*m;if(Array.isArray(e)&&(e={lng:e[0],lat:e[1],alt:e[2]||0}),typeof e=="string"){let d=e.split(",");e={lng:d[0],lat:d[1],alt:d[2]||0}}let o=Math.max(i.x,i.y,i.z)/(2*Math.tan(a/2))*Math.cos(s)+e.alt,l=Math.abs(Math.cos(s)*t.cameraToCenterDistance),u=A*Math.abs(Math.cos(e.lat*m)),f=l/o*u,_=Math.round(Math.log2(f/t.tileSize));return{center:[e.lng,e.lat],cameraHeight:o,zoom:_}}static getHeightByZoom(t,e,i,a){let s=Math.abs(Math.cos(a*m)*t.cameraToCenterDistance),n=A*Math.abs(Math.cos(i*m)),o=Math.pow(2,e)*t.tileSize;return s*n/o}static getZoomByHeight(t,e,i,a){let s=Math.abs(Math.cos(a*m)*t.cameraToCenterDistance),n=A*Math.abs(Math.cos(i*m)),o=s/e*n;return Math.round(Math.log2(o/t.tileSize))}},v=V;var w=Z(H(),1),st=new w.Matrix4,nt=new w.Matrix4,ot=85.051129,B=class{constructor(t,e,i){this._map=t,this._world=e,this._camera=i,this._translateCenter=new w.Matrix4().makeTranslation(1024e3/2,-1024e3/2,0),this._worldSizeRatio=it/1024e3,this._map.on("move",()=>{this.syncCamera(!1)}),this._map.on("resize",()=>{this.syncCamera(!0)})}syncCamera(t){let e=this._map.transform,i=e.pitch*m,a=e.bearing*m;if(t){let d=e.fov*m,g=e.centerOffset||new w.Vector3;this._camera.aspect=e.width/e.height,st.elements=v.makePerspectiveMatrix(d,this._camera.aspect,e.height/50,e.farZ),this._camera.projectionMatrix=st,this._camera.projectionMatrix.elements[8]=-g.x*2/e.width,this._camera.projectionMatrix.elements[9]=g.y*2/e.height}nt.makeTranslation(0,0,e.cameraToCenterDistance);let s=new w.Matrix4().premultiply(nt).premultiply(new w.Matrix4().makeRotationX(i)).premultiply(new w.Matrix4().makeRotationZ(-a));e.elevation&&(s.elements[14]=e.cameraToCenterDistance*Math.cos(i)),this._camera.matrixWorld.copy(s);let n=e.scale*this._worldSizeRatio,o=new w.Matrix4().makeScale(n,n,n),l=e.x,u=e.y;if(!l||!u){let d=e.center,g=v.clamp(d.lat,-ot,ot);l=v.mercatorXFromLng(d.lng)*e.worldSize,u=v.mercatorYFromLat(g)*e.worldSize}let f=new w.Matrix4().makeTranslation(-l,u,0),_=new w.Matrix4().makeRotationZ(Math.PI);this._world.matrix=new w.Matrix4().premultiply(_).premultiply(this._translateCenter).premultiply(o).premultiply(f)}},ht=B;var N=class{constructor(t,e){this._id=t,this._mapScene=e,this._cameraSync=new ht(this._mapScene.map,this._mapScene.world,this._mapScene.camera)}get id(){return this._id}get type(){return"custom"}get renderingMode(){return"3d"}onAdd(t,e){this._cameraSync.syncCamera(!0)}render(){this._mapScene.render()}onRemove(){this._cameraSync=null,this._mapScene=null}},ct=N;var lt=Z(H(),1);var X=class{static projectedMercatorUnitsPerMeter(){return Math.abs(1024e3/A)}static projectedUnitsPerMeter(t){return Math.abs(1024e3/Math.cos(m*t)/A)}static lngLatToVector3(t,e,i=0){let a=[0,0,0];return Array.isArray(t)?(a=[-C*m*t[0]*b,-C*Math.log(Math.tan(Math.PI*.25+.5*m*t[1]))*b],t[2]?a.push(t[2]*this.projectedUnitsPerMeter(t[1])):a.push(0)):(a=[-C*m*t*b,-C*Math.log(Math.tan(Math.PI*.25+.5*m*e))*b],i?a.push(i*this.projectedUnitsPerMeter(e)):a.push(0)),new lt.Vector3(a[0],a[1],a[2])}static vector3ToLngLat(t){let e=[0,0,0];return t&&(e[0]=-t.x/(C*m*b),e[1]=2*(Math.atan(Math.exp(t.y/(b*-C)))-Math.PI/4)/m,e[2]=t.z/this.projectedUnitsPerMeter(e[1])),e}},L=X;var Ht={scene:null,camera:null,renderer:null,renderLoop:null,preserveDrawingBuffer:!1},Y=class{constructor(t,e={}){if(!t)throw"missing map";this._map=t,this._options={...Ht,...e},this._canvas=t.getCanvas(),this._scene=this._options.scene||new M.Scene,this._camera=this._options.camera||new M.PerspectiveCamera(this._map.transform.fov,this._map.transform.width/this._map.transform.height,.1,1e21),this._camera.matrixAutoUpdate=!1,this._renderer=this._options.renderer||new M.WebGLRenderer({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 M.Group,this._lights.name="lights",this._scene.add(this._lights),this._world=new M.Group,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._map.on("render",this._onMapRender.bind(this)),this._event=new M.EventDispatcher}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}_onMapRender(){this._map.getLayer("map_scene_layer")||this._map.addLayer(new ct("map_scene_layer",this))}render(){if(this._options.renderLoop)this._options.renderLoop(this);else{let t={center:this._map.getCenter(),scene:this._scene,camera:this._camera,renderer:this._renderer};this._event.dispatchEvent({type:"preReset",frameState:t}),this.renderer.resetState(),this._event.dispatchEvent({type:"postReset",frameState:t}),this._event.dispatchEvent({type:"preRender",frameState:t}),this.renderer.render(this._scene,this._camera),this._event.dispatchEvent({type:"postRender",frameState:t})}return this}addLight(t){return this._lights.add(t.delegate||t),this}removeLight(t){return this._lights.remove(t.delegate||t),this}addObject(t){return this._world.add(t.delegate||t),this}removeObject(t){return this._world.remove(t),t.traverse(e=>{e.geometry&&e.geometry.dispose(),e.material&&(Array.isArray(e.material)?e.material.forEach(i=>i.dispose()):e.material.dispose()),e.texture&&e.texture.dispose()}),this}getViewPosition(){let t=this._map.transform,e=t.center;return{position:[e.lng,e.lat,v.getHeightByZoom(t,t.zoom,e.lat,t.pitch)],heading:t.bearing,pitch:t.pitch}}flyTo(t,e=null,i=3){if(t&&t.position){e&&this._map.once("moveend",e);let a=t.size;a||(a=new M.Vector3,new M.Box3().setFromObject(t.delegate||t,!0).getSize(a));let s=v.getViewInfo(this._map.transform,L.vector3ToLngLat(t.position),a);this._map.flyTo({center:s.center,zoom:s.zoom,duration:i*1e3})}return this}zoomTo(t,e){return this.flyTo(t,e,0)}flyToPosition(t,e=[0,0,0],i=null,a=3){return i&&this._map.once("moveend",i),this._map.flyTo({center:[t[0],t[1]],zoom:v.getZoomByHeight(this._map.transform,t[2],t[1],e[1]||0),bearing:e[0],pitch:e[1],duration:a*1e3}),this}zoomToPosition(t,e=[0,0,0],i=null,a=3){return this.flyToPosition(t,e,i,0)}on(t,e){return this._event.addEventListener(t,e),this}off(t,e){return this._event.removeEventListener(t,e),this}},ut=Y;var E=Z(H(),1);var J=Math.PI,h=Math.sin,c=Math.cos,K=Math.tan,mt=Math.asin,W=Math.atan2,dt=Math.acos,p=J/180,Q=1e3*60*60*24,pt=2440588,ft=2451545;function Zt(r){return r.valueOf()/Q-.5+pt}function j(r){return new Date((r+.5-pt)*Q)}function F(r){return Zt(r)-ft}var k=p*23.4397;function _t(r,t){return W(h(r)*c(k)-K(t)*h(k),c(r))}function $(r,t){return mt(h(t)*c(k)+c(t)*h(k)*h(r))}function gt(r,t,e){return W(h(r),c(r)*h(t)-K(e)*c(t))}function Mt(r,t,e){return mt(h(t)*h(e)+c(t)*c(e)*c(r))}function wt(r,t){return p*(280.16+360.9856235*r)-t}function Wt(r){return r<0&&(r=0),2967e-7/Math.tan(r+.00312536/(r+.08901179))}function Lt(r){return p*(357.5291+.98560028*r)}function yt(r){let t=p*(1.9148*h(r)+.02*h(2*r)+3e-4*h(3*r)),e=p*102.9372;return r+t+e+J}function St(r){let t=Lt(r),e=yt(t);return{dec:$(e,0),ra:_t(e,0)}}var S={};S.getPosition=function(r,t,e){let i=p*-e,a=p*t,s=F(r),n=St(s),o=wt(s,i)-n.ra;return{azimuth:gt(o,a,n.dec),altitude:Mt(o,a,n.dec)}};var q=S.times=[[-.833,"sunrise","sunset"],[-.3,"sunriseEnd","sunsetStart"],[-6,"dawn","dusk"],[-12,"nauticalDawn","nauticalDusk"],[-18,"nightEnd","night"],[6,"goldenHourEnd","goldenHour"]];S.addTime=function(r,t,e){q.push([r,t,e])};var xt=9e-4;function jt(r,t){return Math.round(r-xt-t/(2*J))}function Rt(r,t,e){return xt+(r+t)/(2*J)+e}function Tt(r,t,e){return ft+r+.0053*h(t)-.0069*h(2*e)}function Gt(r,t,e){return dt((h(r)-h(t)*h(e))/(c(t)*c(e)))}function kt(r){return-2.076*Math.sqrt(r)/60}function Jt(r,t,e,i,a,s,n){let o=Gt(r,e,i),l=Rt(o,t,a);return Tt(l,s,n)}S.getTimes=function(r,t,e,i){i=i||0;let a=p*-e,s=p*t,n=kt(i),o=F(r),l=jt(o,a),u=Rt(0,a,l),f=Lt(u),_=yt(f),d=$(_,0),g=Tt(u,f,_),R,O,x,y,T,U,P={solarNoon:j(g),nadir:j(g-.5)};for(R=0,O=q.length;R<O;R+=1)x=q[R],y=(x[0]+n)*p,T=Jt(y,a,s,d,l,f,_),U=g-(T-g),P[x[1]]=j(U),P[x[2]]=j(T);return P};function vt(r){let t=p*(218.316+13.176396*r),e=p*(134.963+13.064993*r),i=p*(93.272+13.22935*r),a=t+p*6.289*h(e),s=p*5.128*h(i),n=385001-20905*c(e);return{ra:_t(a,s),dec:$(a,s),dist:n}}S.getMoonPosition=function(r,t,e){let i=p*-e,a=p*t,s=F(r),n=vt(s),o=wt(s,i)-n.ra,l=Mt(o,a,n.dec),u=W(h(o),K(a)*c(n.dec)-h(n.dec)*c(o));return l=l+Wt(l),{azimuth:gt(o,a,n.dec),altitude:l,distance:n.dist,parallacticAngle:u}};S.getMoonIllumination=function(r){let t=F(r||new Date),e=St(t),i=vt(t),a=149598e3,s=dt(h(e.dec)*h(i.dec)+c(e.dec)*c(i.dec)*c(e.ra-i.ra)),n=W(a*h(s),i.dist-a*c(s)),o=W(c(e.dec)*h(e.ra-i.ra),h(e.dec)*c(i.dec)-c(e.dec)*h(i.dec)*c(e.ra-i.ra));return{fraction:(1+c(n))/2,phase:.5+.5*n*(o<0?-1:1)/Math.PI,angle:o}};function G(r,t){return new Date(r.valueOf()+t*Q/24)}S.getMoonTimes=function(r,t,e,i){let a=new Date(r);i?a.setUTCHours(0,0,0,0):a.setHours(0,0,0,0);let s=.133*p,n=S.getMoonPosition(a,t,e).altitude-s,o,l,u,f,_,d,g,R,O,x,y,T,U;for(let D=1;D<=24&&(o=S.getMoonPosition(G(a,D),t,e).altitude-s,l=S.getMoonPosition(G(a,D+1),t,e).altitude-s,_=(n+l)/2-o,d=(l-n)/2,g=-d/(2*_),R=(_*g+d)*g+o,O=d*d-4*_*o,x=0,O>=0&&(U=Math.sqrt(O)/(Math.abs(_)*2),y=g-U,T=g+U,Math.abs(y)<=1&&x++,Math.abs(T)<=1&&x++,y<-1&&(y=T)),x===1?n<0?u=D+y:f=D+y:x===2&&(u=D+(R<0?T:y),f=D+(R<0?y:T)),!(u&&f));D+=2)n=l;let P={};return u&&(P.rise=G(a,u)),f&&(P.set=G(a,f)),!u&&!f&&(P[R>0?"alwaysUp":"alwaysDown"]=!0),P};var It=S;var tt=class{constructor(){this._delegate=new E.Group,this._delegate.name="Sun",this._sunLight=new E.DirectionalLight(16777215,1),this._hemiLight=new E.HemisphereLight(new E.Color(16777215),new E.Color(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=null}get delegate(){return this._delegate}set castShadow(t){this._sunLight.castShadow=t}get castShadow(){return this._sunLight.castShadow}set currentTime(t){this._currentTime=t}get currentTime(){return this._currentTime}get sunLight(){return this._sunLight}get hemiLight(){return this._hemiLight}setShadow(t={}){return this._sunLight.shadow.radius=t.radius||2,this._sunLight.shadow.mapSize.width=t.mapSize?t.mapSize[0]:8192,this._sunLight.shadow.mapSize.height=t.mapSize?t.mapSize[1]:8192,this._sunLight.shadow.camera.top=this._sunLight.shadow.camera.right=t.topRight||1e3,this._sunLight.shadow.camera.bottom=this._sunLight.shadow.camera.left=t.bottomLeft||-1e3,this._sunLight.shadow.camera.near=t.near||1,this._sunLight.shadow.camera.far=t.far||1e8,this._sunLight.shadow.camera.visible=!0,this}update(t){let i=new Date(this._currentTime||new Date().getTime()),a=t.center,s=It.getPosition(i,a.lat,a.lng),n=s.altitude,o=Math.PI+s.azimuth,l=1024e3/2,u=Math.sin(n),f=Math.cos(n),_=Math.cos(o)*f,d=Math.sin(o)*f;this._sunLight.position.set(d,_,u),this._sunLight.position.multiplyScalar(l),this._sunLight.intensity=Math.max(u,0),this._hemiLight.intensity=Math.max(u*1,.1),this._sunLight.updateMatrixWorld()}},Et=tt;var z=Z(H(),1);var et=class{static createRTCGroup(t,e,i){let a=new z.Group;if(a.name="rtc",a.position.copy(L.lngLatToVector3(t)),e?(a.rotateX(e[0]||0),a.rotateY(e[1]||0),a.rotateZ(e[2]||0)):(a.rotateX(Math.PI/2),a.rotateY(Math.PI)),i)a.scale.set(i[0]||1,i[1]||1,i[2]||1);else{let s=1;Array.isArray(t)?s=L.projectedUnitsPerMeter(t[1]):typeof t=="string"&&(s=L.projectedUnitsPerMeter(t.split(",")[1])),a.scale.set(s,s,s)}return a}static createMercatorRTCGroup(t,e,i){let a=this.createRTCGroup(t,e,i);if(!i){let s=1,n=L.projectedMercatorUnitsPerMeter();Array.isArray(t)?s=L.projectedUnitsPerMeter(t[1]):typeof t=="string"&&(s=L.projectedUnitsPerMeter(t.split(",")[1])),a.scale.set(n,n,s)}return a}static createShadowGround(t,e=100,i=100){let a=new z.PlaneGeometry(e,i),s=new z.ShadowMaterial({opacity:.5,transparent:!0}),n=new z.Mesh(a,s);return n.position.copy(L.lngLatToVector3(t)),n.receiveShadow=!0,n.name="shadow-ground",n}},Pt=et;})();
|
|
1
|
+
"use strict";var MTP=(()=>{var Ce=Object.create;var Z=Object.defineProperty;var Pe=Object.getOwnPropertyDescriptor;var Ee=Object.getOwnPropertyNames;var ze=Object.getPrototypeOf,Ae=Object.prototype.hasOwnProperty;var Oe=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Ge=(n,e)=>{for(var t in e)Z(n,t,{get:e[t],enumerable:!0})},ie=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ee(e))!Ae.call(n,r)&&r!==t&&Z(n,r,{get:()=>e[r],enumerable:!(a=Pe(e,r))||a.enumerable});return n};var j=(n,e,t)=>(t=n!=null?Ce(ze(n)):{},ie(e||!n||!n.__esModule?Z(t,"default",{value:n,enumerable:!0}):t,n)),He=n=>ie(Z({},"__esModule",{value:!0}),n);var H=Oe((Ne,se)=>{"use strict";se.exports=THREE});var Ve={};Ge(Ve,{Creator:()=>ae,MapScene:()=>U,SceneTransform:()=>y,Sun:()=>ne});var _=j(H(),1);var C=63710088e-1,z=2*Math.PI*C,l=Math.PI/180,Xe=180/Math.PI,A=1024e3/z,oe=512;var N=class{static clamp(e,t,a){return Math.min(a,Math.max(t,e))}static makePerspectiveMatrix(e,t,a,r){let s=1/Math.tan(e/2),i=1/(a-r);return[s/t,0,0,0,0,s,0,0,0,0,(r+a)*i,-1,0,0,2*r*a*i,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,a){let r=e.fov*l,s=e.pitch*l,i=null;if(Array.isArray(t)&&(i={lng:t[0],lat:t[1],alt:t[2]||0}),typeof t=="string"){let p=t.split(",");i={lng:+p[0],lat:+p[1],alt:+p[2]||0}}let c=Math.max(a.x,a.y,a.z)/(2*Math.tan(r/2))*Math.cos(s)+i.alt,h=Math.abs(Math.cos(s)*e.cameraToCenterDistance),b=z*Math.abs(Math.cos(i.lat*l)),g=h/c*b,f=Math.round(Math.log2(g/e.tileSize));return{center:[i.lng,i.lat],cameraHeight:c,zoom:f}}static getHeightByZoom(e,t,a,r){let s=Math.abs(Math.cos(r*l)*e.cameraToCenterDistance),i=z*Math.abs(Math.cos(a*l)),o=Math.pow(2,t)*e.tileSize;return s*i/o}static getZoomByHeight(e,t,a,r){let s=Math.abs(Math.cos(r*l)*e.cameraToCenterDistance),i=z*Math.abs(Math.cos(a*l)),o=s/t*i;return Math.round(Math.log2(o/e.tileSize))}},D=N;var M=j(H(),1),me=new M.Matrix4,ce=new M.Matrix4,ue=85.051129,X=class{_map;_world;_camera;_translateCenter;_worldSizeRatio;constructor(e,t,a){this._map=e,this._world=t,this._camera=a,this._translateCenter=new M.Matrix4().makeTranslation(1024e3/2,-1024e3/2,0),this._worldSizeRatio=oe/1024e3,this._map.on("move",()=>{this.syncCamera(!1)}),this._map.on("resize",()=>{this.syncCamera(!0)})}syncCamera(e){let t=this._map.transform,a=t.pitch*l,r=t.bearing*l;if(e){let f=t.fov*l,p=t.centerOffset||new M.Vector3;this._camera.aspect=t.width/t.height,me.elements=D.makePerspectiveMatrix(f,this._camera.aspect,t.height/50,t.farZ),this._camera.projectionMatrix=me,this._camera.projectionMatrix.elements[8]=-p.x*2/t.width,this._camera.projectionMatrix.elements[9]=p.y*2/t.height}ce.makeTranslation(0,0,t.cameraToCenterDistance);let s=new M.Matrix4().premultiply(ce).premultiply(new M.Matrix4().makeRotationX(a)).premultiply(new M.Matrix4().makeRotationZ(-r));t.elevation&&(s.elements[14]=t.cameraToCenterDistance*Math.cos(a)),this._camera.matrixWorld.copy(s);let i=t.scale*this._worldSizeRatio,o=new M.Matrix4().makeScale(i,i,i),c=t.x,h=t.y;if(!c||!h){let f=t.center,p=D.clamp(f.lat,-ue,ue);c=D.mercatorXFromLng(f.lng)*t.worldSize,h=D.mercatorYFromLat(p)*t.worldSize}let b=new M.Matrix4().makeTranslation(-c,h,0),g=new M.Matrix4().makeRotationZ(Math.PI);this._world.matrix=new M.Matrix4().premultiply(g).premultiply(this._translateCenter).premultiply(o).premultiply(b)}},he=X;var Y=class{_id;_mapScene;_cameraSync;constructor(e,t){this._id=e,this._mapScene=t,this._cameraSync=new he(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}},le=Y;var pe=j(H(),1);var q=class{static projectedMercatorUnitsPerMeter(){return this.projectedUnitsPerMeter(0)}static projectedUnitsPerMeter(e){return Math.abs(1024e3/Math.cos(l*e)/z)}static lngLatToVector3(e,t,a){let r=[0,0,0];return Array.isArray(e)?(r=[-C*l*e[0]*A,-C*Math.log(Math.tan(Math.PI*.25+.5*l*e[1]))*A],e[2]?r.push(e[2]*this.projectedUnitsPerMeter(e[1])):r.push(0)):(r=[-C*l*e*A,-C*Math.log(Math.tan(Math.PI*.25+.5*l*(t||0)))*A],a?r.push(a*this.projectedUnitsPerMeter(t||0)):r.push(0)),new pe.Vector3(r[0],r[1],r[2])}static vector3ToLngLat(e){let t=[0,0,0];return e&&(t[0]=-e.x/(C*l*A),t[1]=2*(Math.atan(Math.exp(e.y/(A*-C)))-Math.PI/4)/l,t[2]=e.z/this.projectedUnitsPerMeter(t[1])),t}},y=q;var je={scene:null,camera:null,renderer:null,renderLoop:null,preserveDrawingBuffer:!1},U=class{_map;_options;_canvas;_scene;_camera;_renderer;_lights;_world;_event;constructor(e,t={}){if(!e)throw"missing map";this._map=e,this._options={...je,...t},this._canvas=e.getCanvas(),this._scene=this._options.scene||new _.Scene,this._camera=this._options.camera||new _.PerspectiveCamera(this._map.transform.fov,this._map.transform.width/this._map.transform.height,.001,1e21),this._camera.matrixAutoUpdate=!1,this._renderer=this._options.renderer||new _.WebGLRenderer({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 _.Group,this._lights.name="lights",this._scene.add(this._lights),this._world=new _.Group,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._map.on("render",this._onMapRender.bind(this)),this._event=new _.EventDispatcher}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}_onMapRender(){this._map.getLayer("map_scene_layer")||this._map.addLayer(new le("map_scene_layer",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.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(a=>{a.geometry&&a.geometry.dispose(),a.material&&(Array.isArray(a.material)?a.material.forEach(r=>r.dispose()):a.material.dispose()),a.texture&&a.texture.dispose()}),this}getViewPosition(){let e=this._map.transform,t=e.center;return{position:[t.lng,t.lat,D.getHeightByZoom(e,e.zoom,t.lat,e.pitch)],heading:e.bearing,pitch:e.pitch}}flyTo(e,t,a){if(e&&e.position){a&&this._map.once("moveend",a);let r=e.size;r||(r=new _.Vector3,new _.Box3().setFromObject(e.delegate||e,!0).getSize(r));let s=D.getViewInfo(this._map.transform,y.vector3ToLngLat(e.position),r);this._map.flyTo({center:s.center,zoom:s.zoom,duration:(t||3)*1e3})}return this}zoomTo(e,t){return this.flyTo(e,0,t)}flyToPosition(e,t=[0,0,0],a,r=3){return a&&this._map.once("moveend",a),this._map.flyTo({center:[e[0],e[1]],zoom:D.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],a){return this.flyToPosition(e,t,a,0)}on(e,t){return this._event.addEventListener(e,t),this}off(e,t){return this._event.removeEventListener(e,t),this}};var T=j(H(),1);var V=Math.PI,m=Math.sin,u=Math.cos,Q=Math.tan,de=Math.asin,W=Math.atan2,be=Math.acos,d=V/180,$=1e3*60*60*24,fe=2440588,ge=2451545;function Ue(n){return n.valueOf()/$-.5+fe}function F(n){return new Date((n+.5-fe)*$)}function B(n){return Ue(n)-ge}var J=d*23.4397;function _e(n,e){return W(m(n)*u(J)-Q(e)*m(J),u(n))}function ee(n,e){return de(m(e)*u(J)+u(e)*m(J)*m(n))}function Me(n,e,t){return W(m(n),u(n)*m(e)-Q(t)*u(e))}function Se(n,e,t){return de(m(e)*m(t)+u(e)*u(t)*u(n))}function ye(n,e){return d*(280.16+360.9856235*n)-e}function We(n){return n<0&&(n=0),2967e-7/Math.tan(n+.00312536/(n+.08901179))}function we(n){return d*(357.5291+.98560028*n)}function ve(n){let e=d*(1.9148*m(n)+.02*m(2*n)+3e-4*m(3*n)),t=d*102.9372;return n+e+t+V}function Le(n){let e=we(n),t=ve(e);return{dec:ee(t,0),ra:_e(t,0)}}var w={};w.getPosition=function(n,e,t){let a=d*-t,r=d*e,s=B(n),i=Le(s),o=ye(s,a)-i.ra;return{azimuth:Me(o,r,i.dec),altitude:Se(o,r,i.dec)}};var K=w.times=[[-.833,"sunrise","sunset"],[-.3,"sunriseEnd","sunsetStart"],[-6,"dawn","dusk"],[-12,"nauticalDawn","nauticalDusk"],[-18,"nightEnd","night"],[6,"goldenHourEnd","goldenHour"]];w.addTime=function(n,e,t){K.push([n,e,t])};var Ie=9e-4;function Ze(n,e){return Math.round(n-Ie-e/(2*V))}function De(n,e,t){return Ie+(n+e)/(2*V)+t}function Te(n,e,t){return ge+n+.0053*m(e)-.0069*m(2*t)}function Fe(n,e,t){return be((m(n)-m(e)*m(t))/(u(e)*u(t)))}function ke(n){return-2.076*Math.sqrt(n)/60}function Je(n,e,t,a,r,s,i){let o=Fe(n,t,a),c=De(o,e,r);return Te(c,s,i)}w.getTimes=function(n,e,t,a=0){let r=d*-t,s=d*e,i=ke(a),o=B(n),c=Ze(o,r),h=De(0,r,c),b=we(h),g=ve(b),f=ee(g,0),p=Te(h,b,g),L,O,v,S,I,G,R={solarNoon:F(p),nadir:F(p-.5)};for(L=0,O=K.length;L<O;L+=1)v=K[L],S=(v[0]+i)*d,I=Je(S,r,s,f,c,b,g),G=p-(I-p),R[v[1]]=F(G),R[v[2]]=F(I);return R};function Re(n){let e=d*(218.316+13.176396*n),t=d*(134.963+13.064993*n),a=d*(93.272+13.22935*n),r=e+d*6.289*m(t),s=d*5.128*m(a),i=385001-20905*u(t);return{ra:_e(r,s),dec:ee(r,s),dist:i}}w.getMoonPosition=function(n,e,t){let a=d*-t,r=d*e,s=B(n),i=Re(s),o=ye(s,a)-i.ra,c=Se(o,r,i.dec),h=W(m(o),Q(r)*u(i.dec)-m(i.dec)*u(o));return c=c+We(c),{azimuth:Me(o,r,i.dec),altitude:c,distance:i.dist,parallacticAngle:h}};w.getMoonIllumination=function(n){let e=B(n||new Date),t=Le(e),a=Re(e),r=149598e3,s=be(m(t.dec)*m(a.dec)+u(t.dec)*u(a.dec)*u(t.ra-a.ra)),i=W(r*m(s),a.dist-r*u(s)),o=W(u(t.dec)*m(t.ra-a.ra),m(t.dec)*u(a.dec)-u(t.dec)*m(a.dec)*u(t.ra-a.ra));return{fraction:(1+u(i))/2,phase:.5+.5*i*(o<0?-1:1)/Math.PI,angle:o}};function k(n,e){return new Date(n.valueOf()+e*$/24)}w.getMoonTimes=function(n,e,t,a=!1){let r=new Date(n);a?r.setUTCHours(0,0,0,0):r.setHours(0,0,0,0);let s=.133*d,i=w.getMoonPosition(r,e,t).altitude-s,o,c,h,b,g,f,p,L,O,v,S,I,G;for(let x=1;x<=24&&(o=w.getMoonPosition(k(r,x),e,t).altitude-s,c=w.getMoonPosition(k(r,x+1),e,t).altitude-s,g=(i+c)/2-o,f=(c-i)/2,p=-f/(2*g),L=(g*p+f)*p+o,O=f*f-4*g*o,v=0,O>=0&&(G=Math.sqrt(O)/(Math.abs(g)*2),S=p-G,I=p+G,Math.abs(S)<=1&&v++,Math.abs(I)<=1&&v++,S<-1&&(S=I)),v===1?i<0?h=x+S:b=x+S:v===2&&(h=x+(L<0?I:S),b=x+(L<0?S:I)),!(h&&b));x+=2)i=c;let R={};return h&&(R.rise=k(r,h)),b&&(R.set=k(r,b)),!h&&!b&&(R[L>0?"alwaysUp":"alwaysDown"]=!0),R};var xe=w;var te=class{_delegate;_sunLight;_hemiLight;_currentTime;constructor(){this._delegate=new T.Group,this._delegate.name="Sun",this._sunLight=new T.DirectionalLight(16777215,1),this._hemiLight=new T.HemisphereLight(new T.Color(16777215),new T.Color(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 a=new Date(this._currentTime||new Date().getTime()),r=e.center,s=xe.getPosition(a,r.lat,r.lng),i=s.altitude,o=Math.PI+s.azimuth,c=1024e3/2,h=Math.sin(i),b=Math.cos(i),g=Math.cos(o)*b,f=Math.sin(o)*b;this._sunLight.position.set(f,g,h),this._sunLight.position.multiplyScalar(c),this._sunLight.intensity=Math.max(h,0),this._hemiLight.intensity=Math.max(h*1,.1),this._sunLight.updateMatrixWorld()}},ne=te;var E=j(H(),1);var re=class{static createRTCGroup(e,t,a){let r=new E.Group;if(r.name="rtc",r.position.copy(y.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)),a)r.scale.set(a[0]||1,a[1]||1,a[2]||1);else{let s=1;Array.isArray(e)&&(s=y.projectedUnitsPerMeter(e[1])),r.scale.set(s,s,s)}return r}static createMercatorRTCGroup(e,t,a){let r=this.createRTCGroup(e,t,a);if(!a){let s=1,i=y.projectedMercatorUnitsPerMeter();Array.isArray(e)&&(s=y.projectedUnitsPerMeter(e[1])),r.scale.set(i,i,s)}return r}static createShadowGround(e,t,a){let r=new E.PlaneGeometry(t||100,a||100),s=new E.ShadowMaterial({opacity:.5,transparent:!0}),i=new E.Mesh(r,s);return i.position.copy(y.lngLatToVector3(e)),i.receiveShadow=!0,i.name="shadow-ground",i}},ae=re;return He(Ve);})();
|
package/package.json
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dvt3d/maplibre-three-plugin",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"main": "dist/index.js",
|
|
3
|
+
"version": "1.3.0",
|
|
5
4
|
"repository": "https://github.com/dvt3d/maplibre-three-plugin.git",
|
|
6
5
|
"author": "cavencj <cavencj@gmail.com>",
|
|
7
6
|
"license": "MIT",
|
|
8
7
|
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"types": "dist/index.d.ts",
|
|
9
16
|
"scripts": {
|
|
10
17
|
"dev": "rimraf dist && gulp dev",
|
|
11
18
|
"build": "rimraf dist && gulp build",
|
|
@@ -21,11 +28,9 @@
|
|
|
21
28
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
22
29
|
"@babel/plugin-transform-runtime": "^7.21.4",
|
|
23
30
|
"@babel/preset-env": "^7.21.5",
|
|
31
|
+
"@types/three": "^0.179.0",
|
|
24
32
|
"chalk": "^5.2.0",
|
|
25
|
-
"esbuild": "^0.20.2",
|
|
26
33
|
"esbuild-plugin-globals": "^0.2.0",
|
|
27
|
-
"esbuild-plugin-inline-image": "^0.0.9",
|
|
28
|
-
"esbuild-sass-plugin": "^3.1.0",
|
|
29
34
|
"eslint": "^8.40.0",
|
|
30
35
|
"eslint-config-prettier": "^8.8.0",
|
|
31
36
|
"eslint-plugin-import": "^2.27.5",
|
|
@@ -35,12 +40,11 @@
|
|
|
35
40
|
"express": "^4.18.2",
|
|
36
41
|
"fs-extra": "^11.1.1",
|
|
37
42
|
"gulp": "^4.0.2",
|
|
38
|
-
"gulp-clean": "^0.4.0",
|
|
39
|
-
"portfinder": "^1.0.32",
|
|
40
43
|
"prettier": "^2.8.8",
|
|
41
44
|
"rimraf": "^5.0.0",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
45
|
+
"shelljs": "^0.8.5",
|
|
46
|
+
"tsup": "^8.5.0",
|
|
47
|
+
"typescript": "^5.9.2"
|
|
44
48
|
},
|
|
45
49
|
"peerDependencies": {
|
|
46
50
|
"three": "^0.178.0"
|