@dvt3d/maplibre-three-plugin 1.0.0 → 1.2.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/README.md CHANGED
@@ -5,9 +5,9 @@
5
5
  ## Install
6
6
 
7
7
  ```shell
8
- npm install @dvgis/maplibre-three-plugin
8
+ npm install @dvt3d/maplibre-three-plugin
9
9
  ----------------------------------------
10
- yarn add @dvgis/maplibre-three-plugin
10
+ yarn add @dvt3d/maplibre-three-plugin
11
11
  ```
12
12
 
13
13
  ## Quickly Start
@@ -87,8 +87,8 @@ Object({
87
87
 
88
88
  #### event hooks
89
89
 
90
- - `preRest` : A hook that calls `renderer.resetState` before each animation frame
91
- - `postRest`: A hook that calls `renderer.resetState` after each animation frame
90
+ - `preReset` : A hook that calls `renderer.resetState` before each animation frame
91
+ - `postReset`: A hook that calls `renderer.resetState` after each animation frame
92
92
  - `preRender`: A hook that calls `renderer.render` before each animation frame
93
93
  - `postRender`: A hook that calls `renderer.render` after each animation frame
94
94
 
@@ -0,0 +1,293 @@
1
+ import * as three from 'three';
2
+ import { Scene, PerspectiveCamera, WebGLRenderer, Group, Object3DEventMap, 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<T extends Object3DEventMap = Object3DEventMap, D = Object3D> extends Object3D<T> {
65
+ /** Optional delegate object */
66
+ delegate?: D;
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<Object3DEventMap>;
86
+ get world(): Group<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): MapScene;
115
+ /**
116
+ *
117
+ * @param object
118
+ * @returns {MapScene}
119
+ */
120
+ removeObject(object: IObject3D): 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 it,PerspectiveCamera as vt,Scene as Et,WebGLRenderer as It,EventDispatcher as Pt,Box3 as Dt,Vector3 as Ct}from"three";var P=63710088e-1,D=2*Math.PI*P,m=Math.PI/180,Bt=180/Math.PI,C=1024e3/D,K=512;var j=class{static clamp(t,e,a){return Math.min(a,Math.max(e,t))}static makePerspectiveMatrix(t,e,a,r){let s=1/Math.tan(t/2),n=1/(a-r);return[s/e,0,0,0,0,s,0,0,0,0,(r+a)*n,-1,0,0,2*r*a*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,a){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 _=e.split(",");e={lng:_[0],lat:_[1],alt:_[2]||0}}let o=Math.max(a.x,a.y,a.z)/(2*Math.tan(r/2))*Math.cos(s)+e.alt,u=Math.abs(Math.cos(s)*t.cameraToCenterDistance),l=D*Math.abs(Math.cos(e.lat*m)),d=u/o*l,f=Math.round(Math.log2(d/t.tileSize));return{center:[e.lng,e.lat],cameraHeight:o,zoom:f}}static getHeightByZoom(t,e,a,r){let s=Math.abs(Math.cos(r*m)*t.cameraToCenterDistance),n=D*Math.abs(Math.cos(a*m)),o=Math.pow(2,e)*t.tileSize;return s*n/o}static getZoomByHeight(t,e,a,r){let s=Math.abs(Math.cos(r*m)*t.cameraToCenterDistance),n=D*Math.abs(Math.cos(a*m)),o=s/e*n;return Math.round(Math.log2(o/t.tileSize))}},T=j;import{Matrix4 as x,Vector3 as Rt}from"three";var Q=new x,$=new x,tt=85.051129,G=class{constructor(t,e,a){this._map=t,this._world=e,this._camera=a,this._translateCenter=new x().makeTranslation(1024e3/2,-1024e3/2,0),this._worldSizeRatio=K/1024e3,this._map.on("move",this.syncCamera.bind(this)),this._map.on("resize",this.syncCamera.bind(this))}syncCamera(){let t=this._map.transform;this._camera.aspect=t.width/t.height;let e=t.centerOffset||new Rt,a=t.fov*m,r=t.pitch*m,s=t.bearing*m;Q.elements=T.makePerspectiveMatrix(a,this._camera.aspect,t.height/50,t.farZ),this._camera.projectionMatrix=Q,this._camera.projectionMatrix.elements[8]=-e.x*2/t.width,this._camera.projectionMatrix.elements[9]=e.y*2/t.height,$.makeTranslation(0,0,t.cameraToCenterDistance);let n=new x().premultiply($).premultiply(new x().makeRotationX(r)).premultiply(new x().makeRotationZ(-s));t.elevation&&(n.elements[14]=t.cameraToCenterDistance*Math.cos(r)),this._camera.matrixWorld.copy(n);let o=t.scale*this._worldSizeRatio,u=new x().makeScale(o,o,o),l=t.x,d=t.y;if(!l||!d){let g=t.center,w=T.clamp(g.lat,-tt,tt);l=T.mercatorXFromLng(g.lng)*t.worldSize,d=T.mercatorYFromLat(w)*t.worldSize}let f=new x().makeTranslation(-l,d,0),_=new x().makeRotationZ(Math.PI);this._world.matrix=new x().premultiply(_).premultiply(this._translateCenter).premultiply(u).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()}render(){this._mapScene.render()}},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,a=0){let r=[0,0,0];return Array.isArray(t)?(r=[-P*m*t[0]*C,-P*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=[-P*m*t*C,-P*Math.log(Math.tan(Math.PI*.25+.5*m*e))*C],a?r.push(a*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/(P*m*C),e[1]=2*(Math.atan(Math.exp(t.y/(C*-P)))-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 Et,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 It({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 it,this._lights.name="lights",this._scene.add(this._lights),this._world=new it,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("style.load",this._onStyleLoad.bind(this)),this._event=new Pt}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}_onStyleLoad(){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:"preRest",frameState:t}),this.renderer.resetState(),this._event.dispatchEvent({type:"postRest",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(a=>a.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,a=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:a*1e3})}return this}zoomTo(t,e){return this.flyTo(t,e,0)}flyToPosition(t,e=[0,0,0],a=null,r=3){return a&&this._map.once("moveend",a),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],a=null,r=3){return this.flyToPosition(t,e,a,0)}on(t,e){return this._event.addEventListener(t,e),this}off(t,e){return this._event.removeEventListener(t,e),this}},at=F;import{Group as Wt,DirectionalLight as jt,HemisphereLight as Gt,Color as yt}from"three";var Z=Math.PI,h=Math.sin,c=Math.cos,B=Math.tan,st=Math.asin,b=Math.atan2,nt=Math.acos,p=Z/180,N=1e3*60*60*24,ot=2440588,ht=2451545;function zt(i){return i.valueOf()/N-.5+ot}function U(i){return new Date((i+.5-ot)*N)}function W(i){return zt(i)-ht}var H=p*23.4397;function ct(i,t){return b(h(i)*c(H)-B(t)*h(H),c(i))}function X(i,t){return st(h(t)*c(H)+c(t)*h(H)*h(i))}function lt(i,t,e){return b(h(i),c(i)*h(t)-B(e)*c(t))}function ut(i,t,e){return st(h(t)*h(e)+c(t)*c(e)*c(i))}function mt(i,t){return p*(280.16+360.9856235*i)-t}function bt(i){return i<0&&(i=0),2967e-7/Math.tan(i+.00312536/(i+.08901179))}function dt(i){return p*(357.5291+.98560028*i)}function pt(i){let t=p*(1.9148*h(i)+.02*h(2*i)+3e-4*h(3*i)),e=p*102.9372;return i+t+e+Z}function ft(i){let t=dt(i),e=pt(t);return{dec:X(e,0),ra:ct(e,0)}}var y={};y.getPosition=function(i,t,e){let a=p*-e,r=p*t,s=W(i),n=ft(s),o=mt(s,a)-n.ra;return{azimuth:lt(o,r,n.dec),altitude:ut(o,r,n.dec)}};var V=y.times=[[-.833,"sunrise","sunset"],[-.3,"sunriseEnd","sunsetStart"],[-6,"dawn","dusk"],[-12,"nauticalDawn","nauticalDusk"],[-18,"nightEnd","night"],[6,"goldenHourEnd","goldenHour"]];y.addTime=function(i,t,e){V.push([i,t,e])};var _t=9e-4;function Ut(i,t){return Math.round(i-_t-t/(2*Z))}function gt(i,t,e){return _t+(i+t)/(2*Z)+e}function Mt(i,t,e){return ht+i+.0053*h(t)-.0069*h(2*e)}function Ot(i,t,e){return nt((h(i)-h(t)*h(e))/(c(t)*c(e)))}function Ht(i){return-2.076*Math.sqrt(i)/60}function Zt(i,t,e,a,r,s,n){let o=Ot(i,e,a),u=gt(o,t,r);return Mt(u,s,n)}y.getTimes=function(i,t,e,a){a=a||0;let r=p*-e,s=p*t,n=Ht(a),o=W(i),u=Ut(o,r),l=gt(0,r,u),d=dt(l),f=pt(d),_=X(f,0),g=Mt(l,d,f),w,A,S,L,R,z,E={solarNoon:U(g),nadir:U(g-.5)};for(w=0,A=V.length;w<A;w+=1)S=V[w],L=(S[0]+n)*p,R=Zt(L,r,s,_,u,d,f),z=g-(R-g),E[S[1]]=U(z),E[S[2]]=U(R);return E};function wt(i){let t=p*(218.316+13.176396*i),e=p*(134.963+13.064993*i),a=p*(93.272+13.22935*i),r=t+p*6.289*h(e),s=p*5.128*h(a),n=385001-20905*c(e);return{ra:ct(r,s),dec:X(r,s),dist:n}}y.getMoonPosition=function(i,t,e){let a=p*-e,r=p*t,s=W(i),n=wt(s),o=mt(s,a)-n.ra,u=ut(o,r,n.dec),l=b(h(o),B(r)*c(n.dec)-h(n.dec)*c(o));return u=u+bt(u),{azimuth:lt(o,r,n.dec),altitude:u,distance:n.dist,parallacticAngle:l}};y.getMoonIllumination=function(i){let t=W(i||new Date),e=ft(t),a=wt(t),r=149598e3,s=nt(h(e.dec)*h(a.dec)+c(e.dec)*c(a.dec)*c(e.ra-a.ra)),n=b(r*h(s),a.dist-r*c(s)),o=b(c(e.dec)*h(e.ra-a.ra),h(e.dec)*c(a.dec)-c(e.dec)*h(a.dec)*c(e.ra-a.ra));return{fraction:(1+c(n))/2,phase:.5+.5*n*(o<0?-1:1)/Math.PI,angle:o}};function O(i,t){return new Date(i.valueOf()+t*N/24)}y.getMoonTimes=function(i,t,e,a){let r=new Date(i);a?r.setUTCHours(0,0,0,0):r.setHours(0,0,0,0);let s=.133*p,n=y.getMoonPosition(r,t,e).altitude-s,o,u,l,d,f,_,g,w,A,S,L,R,z;for(let I=1;I<=24&&(o=y.getMoonPosition(O(r,I),t,e).altitude-s,u=y.getMoonPosition(O(r,I+1),t,e).altitude-s,f=(n+u)/2-o,_=(u-n)/2,g=-_/(2*f),w=(f*g+_)*g+o,A=_*_-4*f*o,S=0,A>=0&&(z=Math.sqrt(A)/(Math.abs(f)*2),L=g-z,R=g+z,Math.abs(L)<=1&&S++,Math.abs(R)<=1&&S++,L<-1&&(L=R)),S===1?n<0?l=I+L:d=I+L:S===2&&(l=I+(w<0?R:L),d=I+(w<0?L:R)),!(l&&d));I+=2)n=u;let E={};return l&&(E.rise=O(r,l)),d&&(E.set=O(r,d)),!l&&!d&&(E[w>0?"alwaysUp":"alwaysDown"]=!0),E};var Lt=y;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 a=new Date(this._currentTime||new Date().getTime()),r=t.center,s=Lt.getPosition(a,r.lat,r.lng),n=s.altitude,o=Math.PI+s.azimuth,u=1024e3/2,l=Math.sin(n),d=Math.cos(n),f=Math.cos(o)*d,_=Math.sin(o)*d;this._sunLight.position.set(_,f,l),this._sunLight.position.multiplyScalar(u),this._sunLight.intensity=Math.max(l,0),this._hemiLight.intensity=Math.max(l*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,a){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)),a)r.scale.set(a[0]||1,a[1]||1,a[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,a){let r=this.createRTCGroup(t,e,a);if(!a){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,a=100){let r=new Ft(e,a),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,at 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,a){return Math.min(a,Math.max(t,e))}static makePerspectiveMatrix(e,t,a,n){let s=1/Math.tan(e/2),i=1/(a-n);return[s/t,0,0,0,0,s,0,0,0,0,(n+a)*i,-1,0,0,2*n*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 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(a.x,a.y,a.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,a,n){let s=Math.abs(Math.cos(n*l)*e.cameraToCenterDistance),i=C*Math.abs(Math.cos(a*l)),o=Math.pow(2,t)*e.tileSize;return s*i/o}static getZoomByHeight(e,t,a,n){let s=Math.abs(Math.cos(n*l)*e.cameraToCenterDistance),i=C*Math.abs(Math.cos(a*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,a){this._map=e,this._world=t,this._camera=a,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,a=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(a)).premultiply(new y().makeRotationZ(-n));t.elevation&&(s.elements[14]=t.cameraToCenterDistance*Math.cos(a)),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,a){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],a?n.push(a*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,.1,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){return this._world.add(e.delegate||e),this}removeObject(e){return this._world.remove(e),e.traverse(t=>{t.geometry&&t.geometry.dispose(),t.material&&(Array.isArray(t.material)?t.material.forEach(a=>a.dispose()):t.material.dispose()),t.texture&&t.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,a){if(e&&e.position){a&&this._map.once("moveend",a);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],a,n=3){return a&&this._map.once("moveend",a),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],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}};import{Group as He,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 Ee(r){return r.valueOf()/N-.5+se}function G(r){return new Date((r+.5-se)*N)}function W(r){return Ee(r)-oe}var H=d*23.4397;function me(r,e){return A(m(r)*u(H)-B(e)*m(H),u(r))}function X(r,e){return ae(m(e)*u(H)+u(e)*m(H)*m(r))}function ce(r,e,t){return A(m(r),u(r)*m(e)-B(t)*u(e))}function ue(r,e,t){return ae(m(e)*m(t)+u(e)*u(t)*u(r))}function he(r,e){return d*(280.16+360.9856235*r)-e}function ze(r){return r<0&&(r=0),2967e-7/Math.tan(r+.00312536/(r+.08901179))}function le(r){return d*(357.5291+.98560028*r)}function pe(r){let e=d*(1.9148*m(r)+.02*m(2*r)+3e-4*m(3*r)),t=d*102.9372;return r+e+t+U}function de(r){let e=le(r),t=pe(e);return{dec:X(t,0),ra:me(t,0)}}var M={};M.getPosition=function(r,e,t){let a=d*-t,n=d*e,s=W(r),i=de(s),o=he(s,a)-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(r,e,t){V.push([r,e,t])};var be=9e-4;function Ae(r,e){return Math.round(r-be-e/(2*U))}function fe(r,e,t){return be+(r+e)/(2*U)+t}function ge(r,e,t){return oe+r+.0053*m(e)-.0069*m(2*t)}function Oe(r,e,t){return ie((m(r)-m(e)*m(t))/(u(e)*u(t)))}function Ge(r){return-2.076*Math.sqrt(r)/60}function je(r,e,t,a,n,s,i){let o=Oe(r,t,a),c=fe(o,e,n);return ge(c,s,i)}M.getTimes=function(r,e,t,a=0){let n=d*-t,s=d*e,i=Ge(a),o=W(r),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,E,S,_,L,z,D={solarNoon:G(p),nadir:G(p-.5)};for(v=0,E=V.length;v<E;v+=1)S=V[v],_=(S[0]+i)*d,L=je(_,n,s,f,c,b,g),z=p-(L-p),D[S[1]]=G(z),D[S[2]]=G(L);return D};function _e(r){let e=d*(218.316+13.176396*r),t=d*(134.963+13.064993*r),a=d*(93.272+13.22935*r),n=e+d*6.289*m(t),s=d*5.128*m(a),i=385001-20905*u(t);return{ra:me(n,s),dec:X(n,s),dist:i}}M.getMoonPosition=function(r,e,t){let a=d*-t,n=d*e,s=W(r),i=_e(s),o=he(s,a)-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+ze(c),{azimuth:ce(o,n,i.dec),altitude:c,distance:i.dist,parallacticAngle:h}};M.getMoonIllumination=function(r){let e=W(r||new Date),t=de(e),a=_e(e),n=149598e3,s=ie(m(t.dec)*m(a.dec)+u(t.dec)*u(a.dec)*u(t.ra-a.ra)),i=A(n*m(s),a.dist-n*u(s)),o=A(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 j(r,e){return new Date(r.valueOf()+e*N/24)}M.getMoonTimes=function(r,e,t,a=!1){let n=new Date(r);a?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,E,S,_,L,z;for(let T=1;T<=24&&(o=M.getMoonPosition(j(n,T),e,t).altitude-s,c=M.getMoonPosition(j(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,E=f*f-4*g*o,S=0,E>=0&&(z=Math.sqrt(E)/(Math.abs(g)*2),_=p-z,L=p+z,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=j(n,h)),b&&(D.set=j(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 He,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 a=new Date(this._currentTime||new Date().getTime()),n=e.center,s=Me.getPosition(a,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,a){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)),a)n.scale.set(a[0]||1,a[1]||1,a[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,a){let n=this.createRTCGroup(e,t,a);if(!a){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,a){let n=new ke(t||100,a||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 Ut=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports);var Ht=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of At(t))!bt.call(i,r)&&r!==e&&rt(i,r,{get:()=>t[r],enumerable:!(s=Ct(t,r))||s.enumerable});return i};var Z=(i,t,e)=>(e=i!=null?Dt(zt(i)):{},Ht(t||!i||!i.__esModule?rt(e,"default",{value:i,enumerable:!0}):e,i));var O=Ut((Vt,it)=>{it.exports=THREE});var g=Z(O(),1);var C=63710088e-1,A=2*Math.PI*C,m=Math.PI/180,Bt=180/Math.PI,b=1024e3/A,st=512;var V=class{static clamp(t,e,s){return Math.min(s,Math.max(e,t))}static makePerspectiveMatrix(t,e,s,r){let a=1/Math.tan(t/2),n=1/(s-r);return[a/e,0,0,0,0,a,0,0,0,0,(r+s)*n,-1,0,0,2*r*s*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,s){let r=t.fov*m,a=t.pitch*m;if(Array.isArray(e)&&(e={lng:e[0],lat:e[1],alt:e[2]||0}),typeof e=="string"){let _=e.split(",");e={lng:_[0],lat:_[1],alt:_[2]||0}}let o=Math.max(s.x,s.y,s.z)/(2*Math.tan(r/2))*Math.cos(a)+e.alt,u=Math.abs(Math.cos(a)*t.cameraToCenterDistance),l=A*Math.abs(Math.cos(e.lat*m)),d=u/o*l,f=Math.round(Math.log2(d/t.tileSize));return{center:[e.lng,e.lat],cameraHeight:o,zoom:f}}static getHeightByZoom(t,e,s,r){let a=Math.abs(Math.cos(r*m)*t.cameraToCenterDistance),n=A*Math.abs(Math.cos(s*m)),o=Math.pow(2,e)*t.tileSize;return a*n/o}static getZoomByHeight(t,e,s,r){let a=Math.abs(Math.cos(r*m)*t.cameraToCenterDistance),n=A*Math.abs(Math.cos(s*m)),o=a/e*n;return Math.round(Math.log2(o/t.tileSize))}},E=V;var w=Z(O(),1),at=new w.Matrix4,nt=new w.Matrix4,ot=85.051129,B=class{constructor(t,e,s){this._map=t,this._world=e,this._camera=s,this._translateCenter=new w.Matrix4().makeTranslation(1024e3/2,-1024e3/2,0),this._worldSizeRatio=st/1024e3,this._map.on("move",this.syncCamera.bind(this)),this._map.on("resize",this.syncCamera.bind(this))}syncCamera(){let t=this._map.transform;this._camera.aspect=t.width/t.height;let e=t.centerOffset||new w.Vector3,s=t.fov*m,r=t.pitch*m,a=t.bearing*m;at.elements=E.makePerspectiveMatrix(s,this._camera.aspect,t.height/50,t.farZ),this._camera.projectionMatrix=at,this._camera.projectionMatrix.elements[8]=-e.x*2/t.width,this._camera.projectionMatrix.elements[9]=e.y*2/t.height,nt.makeTranslation(0,0,t.cameraToCenterDistance);let n=new w.Matrix4().premultiply(nt).premultiply(new w.Matrix4().makeRotationX(r)).premultiply(new w.Matrix4().makeRotationZ(-a));t.elevation&&(n.elements[14]=t.cameraToCenterDistance*Math.cos(r)),this._camera.matrixWorld.copy(n);let o=t.scale*this._worldSizeRatio,u=new w.Matrix4().makeScale(o,o,o),l=t.x,d=t.y;if(!l||!d){let M=t.center,y=E.clamp(M.lat,-ot,ot);l=E.mercatorXFromLng(M.lng)*t.worldSize,d=E.mercatorYFromLat(y)*t.worldSize}let f=new w.Matrix4().makeTranslation(-l,d,0),_=new w.Matrix4().makeRotationZ(Math.PI);this._world.matrix=new w.Matrix4().premultiply(_).premultiply(this._translateCenter).premultiply(u).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()}render(){this._mapScene.render()}},ct=N;var lt=Z(O(),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,s=0){let r=[0,0,0];return Array.isArray(t)?(r=[-C*m*t[0]*b,-C*Math.log(Math.tan(Math.PI*.25+.5*m*t[1]))*b],t[2]?r.push(t[2]*this.projectedUnitsPerMeter(t[1])):r.push(0)):(r=[-C*m*t*b,-C*Math.log(Math.tan(Math.PI*.25+.5*m*e))*b],s?r.push(s*this.projectedUnitsPerMeter(e)):r.push(0)),new lt.Vector3(r[0],r[1],r[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 Ot={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={...Ot,...e},this._canvas=t.getCanvas(),this._scene=this._options.scene||new g.Scene,this._camera=this._options.camera||new g.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 g.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 g.Group,this._lights.name="lights",this._scene.add(this._lights),this._world=new g.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("style.load",this._onStyleLoad.bind(this)),this._event=new g.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}_onStyleLoad(){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:"preRest",frameState:t}),this.renderer.resetState(),this._event.dispatchEvent({type:"postRest",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(s=>s.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,E.getHeightByZoom(t,t.zoom,e.lat,t.pitch)],heading:t.bearing,pitch:t.pitch}}flyTo(t,e=null,s=3){if(t&&t.position){e&&this._map.once("moveend",e);let r=t.size;r||(r=new g.Vector3,new g.Box3().setFromObject(t.delegate||t,!0).getSize(r));let a=E.getViewInfo(this._map.transform,L.vector3ToLngLat(t.position),r);this._map.flyTo({center:a.center,zoom:a.zoom,duration:s*1e3})}return this}zoomTo(t,e){return this.flyTo(t,e,0)}flyToPosition(t,e=[0,0,0],s=null,r=3){return s&&this._map.once("moveend",s),this._map.flyTo({center:[t[0],t[1]],zoom:E.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],s=null,r=3){return this.flyToPosition(t,e,s,0)}on(t,e){return this._event.addEventListener(t,e),this}off(t,e){return this._event.removeEventListener(t,e),this}},ut=Y;var I=Z(O(),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(i){return i.valueOf()/Q-.5+pt}function j(i){return new Date((i+.5-pt)*Q)}function F(i){return Zt(i)-ft}var k=p*23.4397;function _t(i,t){return W(h(i)*c(k)-K(t)*h(k),c(i))}function $(i,t){return mt(h(t)*c(k)+c(t)*h(k)*h(i))}function gt(i,t,e){return W(h(i),c(i)*h(t)-K(e)*c(t))}function Mt(i,t,e){return mt(h(t)*h(e)+c(t)*c(e)*c(i))}function wt(i,t){return p*(280.16+360.9856235*i)-t}function Wt(i){return i<0&&(i=0),2967e-7/Math.tan(i+.00312536/(i+.08901179))}function Lt(i){return p*(357.5291+.98560028*i)}function yt(i){let t=p*(1.9148*h(i)+.02*h(2*i)+3e-4*h(3*i)),e=p*102.9372;return i+t+e+J}function St(i){let t=Lt(i),e=yt(t);return{dec:$(e,0),ra:_t(e,0)}}var x={};x.getPosition=function(i,t,e){let s=p*-e,r=p*t,a=F(i),n=St(a),o=wt(a,s)-n.ra;return{azimuth:gt(o,r,n.dec),altitude:Mt(o,r,n.dec)}};var q=x.times=[[-.833,"sunrise","sunset"],[-.3,"sunriseEnd","sunsetStart"],[-6,"dawn","dusk"],[-12,"nauticalDawn","nauticalDusk"],[-18,"nightEnd","night"],[6,"goldenHourEnd","goldenHour"]];x.addTime=function(i,t,e){q.push([i,t,e])};var xt=9e-4;function jt(i,t){return Math.round(i-xt-t/(2*J))}function Rt(i,t,e){return xt+(i+t)/(2*J)+e}function Tt(i,t,e){return ft+i+.0053*h(t)-.0069*h(2*e)}function Gt(i,t,e){return dt((h(i)-h(t)*h(e))/(c(t)*c(e)))}function kt(i){return-2.076*Math.sqrt(i)/60}function Jt(i,t,e,s,r,a,n){let o=Gt(i,e,s),u=Rt(o,t,r);return Tt(u,a,n)}x.getTimes=function(i,t,e,s){s=s||0;let r=p*-e,a=p*t,n=kt(s),o=F(i),u=jt(o,r),l=Rt(0,r,u),d=Lt(l),f=yt(d),_=$(f,0),M=Tt(l,d,f),y,U,R,S,T,H,P={solarNoon:j(M),nadir:j(M-.5)};for(y=0,U=q.length;y<U;y+=1)R=q[y],S=(R[0]+n)*p,T=Jt(S,r,a,_,u,d,f),H=M-(T-M),P[R[1]]=j(H),P[R[2]]=j(T);return P};function Et(i){let t=p*(218.316+13.176396*i),e=p*(134.963+13.064993*i),s=p*(93.272+13.22935*i),r=t+p*6.289*h(e),a=p*5.128*h(s),n=385001-20905*c(e);return{ra:_t(r,a),dec:$(r,a),dist:n}}x.getMoonPosition=function(i,t,e){let s=p*-e,r=p*t,a=F(i),n=Et(a),o=wt(a,s)-n.ra,u=Mt(o,r,n.dec),l=W(h(o),K(r)*c(n.dec)-h(n.dec)*c(o));return u=u+Wt(u),{azimuth:gt(o,r,n.dec),altitude:u,distance:n.dist,parallacticAngle:l}};x.getMoonIllumination=function(i){let t=F(i||new Date),e=St(t),s=Et(t),r=149598e3,a=dt(h(e.dec)*h(s.dec)+c(e.dec)*c(s.dec)*c(e.ra-s.ra)),n=W(r*h(a),s.dist-r*c(a)),o=W(c(e.dec)*h(e.ra-s.ra),h(e.dec)*c(s.dec)-c(e.dec)*h(s.dec)*c(e.ra-s.ra));return{fraction:(1+c(n))/2,phase:.5+.5*n*(o<0?-1:1)/Math.PI,angle:o}};function G(i,t){return new Date(i.valueOf()+t*Q/24)}x.getMoonTimes=function(i,t,e,s){let r=new Date(i);s?r.setUTCHours(0,0,0,0):r.setHours(0,0,0,0);let a=.133*p,n=x.getMoonPosition(r,t,e).altitude-a,o,u,l,d,f,_,M,y,U,R,S,T,H;for(let D=1;D<=24&&(o=x.getMoonPosition(G(r,D),t,e).altitude-a,u=x.getMoonPosition(G(r,D+1),t,e).altitude-a,f=(n+u)/2-o,_=(u-n)/2,M=-_/(2*f),y=(f*M+_)*M+o,U=_*_-4*f*o,R=0,U>=0&&(H=Math.sqrt(U)/(Math.abs(f)*2),S=M-H,T=M+H,Math.abs(S)<=1&&R++,Math.abs(T)<=1&&R++,S<-1&&(S=T)),R===1?n<0?l=D+S:d=D+S:R===2&&(l=D+(y<0?T:S),d=D+(y<0?S:T)),!(l&&d));D+=2)n=u;let P={};return l&&(P.rise=G(r,l)),d&&(P.set=G(r,d)),!l&&!d&&(P[y>0?"alwaysUp":"alwaysDown"]=!0),P};var vt=x;var tt=class{constructor(){this._delegate=new I.Group,this._delegate.name="Sun",this._sunLight=new I.DirectionalLight(16777215,1),this._hemiLight=new I.HemisphereLight(new I.Color(16777215),new I.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 s=new Date(this._currentTime||new Date().getTime()),r=t.center,a=vt.getPosition(s,r.lat,r.lng),n=a.altitude,o=Math.PI+a.azimuth,u=1024e3/2,l=Math.sin(n),d=Math.cos(n),f=Math.cos(o)*d,_=Math.sin(o)*d;this._sunLight.position.set(_,f,l),this._sunLight.position.multiplyScalar(u),this._sunLight.intensity=Math.max(l,0),this._hemiLight.intensity=Math.max(l*1,.1),this._sunLight.updateMatrixWorld()}},It=tt;var z=Z(O(),1);var et=class{static createRTCGroup(t,e,s){let r=new z.Group;if(r.name="rtc",r.position.copy(L.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)),s)r.scale.set(s[0]||1,s[1]||1,s[2]||1);else{let a=1;Array.isArray(t)?a=L.projectedUnitsPerMeter(t[1]):typeof t=="string"&&(a=L.projectedUnitsPerMeter(t.split(",")[1])),r.scale.set(a,a,a)}return r}static createMercatorRTCGroup(t,e,s){let r=this.createRTCGroup(t,e,s);if(!s){let a=1,n=L.projectedMercatorUnitsPerMeter();Array.isArray(t)?a=L.projectedUnitsPerMeter(t[1]):typeof t=="string"&&(a=L.projectedUnitsPerMeter(t.split(",")[1])),r.scale.set(n,n,a)}return r}static createShadowGround(t,e=100,s=100){let r=new z.PlaneGeometry(e,s),a=new z.ShadowMaterial({opacity:.5,transparent:!0}),n=new z.Mesh(r,a);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 H=(n,e,t)=>(t=n!=null?Ce(ze(n)):{},ie(e||!n||!n.__esModule?Z(t,"default",{value:n,enumerable:!0}):t,n)),je=n=>ie(Z({},"__esModule",{value:!0}),n);var j=Oe((Ne,se)=>{"use strict";se.exports=THREE});var Ve={};Ge(Ve,{Creator:()=>ae,MapScene:()=>U,SceneTransform:()=>y,Sun:()=>ne});var _=H(j(),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=H(j(),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=H(j(),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 He={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={...He,...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,.1,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){return this._world.add(e.delegate||e),this}removeObject(e){return this._world.remove(e),e.traverse(t=>{t.geometry&&t.geometry.dispose(),t.material&&(Array.isArray(t.material)?t.material.forEach(a=>a.dispose()):t.material.dispose()),t.texture&&t.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=H(j(),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=H(j(),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 je(Ve);})();
package/package.json CHANGED
@@ -1,11 +1,18 @@
1
1
  {
2
2
  "name": "@dvt3d/maplibre-three-plugin",
3
- "version": "1.0.0",
4
- "main": "dist/index.js",
3
+ "version": "1.2.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
- "sass": "^1.62.1",
43
- "shelljs": "^0.8.5"
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"