@dvt3d/maplibre-three-plugin 1.4.0 → 1.5.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/LICENSE +201 -0
- package/README.md +105 -20
- package/dist/index.d.ts +36 -1
- package/dist/index.js +17 -1
- package/package.json +10 -3
- package/dist/mtp.min.js +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 Caven Chen
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -25,17 +25,17 @@ yarn add @dvt3d/maplibre-three-plugin
|
|
|
25
25
|
|
|
26
26
|
import maplibregl from 'maplibre-gl'
|
|
27
27
|
import * as THREE from 'three'
|
|
28
|
-
import {
|
|
28
|
+
import {GLTFLoader} from 'three/addons/loaders/GLTFLoader.js'
|
|
29
29
|
import * as MTP from '@dvt3d/maplibre-three-plugin'
|
|
30
30
|
|
|
31
31
|
const map = new maplibregl.Map({
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
container: 'map-container', // container id
|
|
33
|
+
style: 'https://api.maptiler.com/maps/basic-v2/style.json?key=get_access_key',
|
|
34
|
+
zoom: 18,
|
|
35
|
+
center: [148.9819, -35.3981],
|
|
36
|
+
pitch: 60,
|
|
37
|
+
canvasContextAttributes: {antialias: true},
|
|
38
|
+
maxPitch: 85,
|
|
39
39
|
})
|
|
40
40
|
|
|
41
41
|
//init three scene
|
|
@@ -48,9 +48,9 @@ mapScene.addLight(new THREE.AmbientLight())
|
|
|
48
48
|
const glTFLoader = new GLTFLoader()
|
|
49
49
|
|
|
50
50
|
glTFLoader.load('./assets/34M_17/34M_17.gltf', (gltf) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
let rtcGroup = MTP.Creator.createRTCGroup([148.9819, -35.39847])
|
|
52
|
+
rtcGroup.add(gltf.scene)
|
|
53
|
+
mapScene.addObject(rtcGroup)
|
|
54
54
|
})
|
|
55
55
|
```
|
|
56
56
|
|
|
@@ -84,17 +84,74 @@ const mapScene = new MapScene(map)
|
|
|
84
84
|
```js
|
|
85
85
|
// config
|
|
86
86
|
Object({
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Existing THREE.Scene instance.
|
|
89
|
+
* If not provided, an internal default scene will be created.
|
|
90
|
+
*/
|
|
91
|
+
scene: null,
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Existing THREE.Camera instance.
|
|
95
|
+
* If not provided, an internal default camera will be created.
|
|
96
|
+
*/
|
|
97
|
+
camera: null,
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Existing THREE.WebGLRenderer instance.
|
|
101
|
+
* If not provided, an internal default renderer will be created.
|
|
102
|
+
*/
|
|
103
|
+
renderer: null,
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Whether to preserve the drawing buffer.
|
|
107
|
+
* When enabled, the canvas content will be retained after rendering,
|
|
108
|
+
* which is useful for screenshots or readPixels operations.
|
|
109
|
+
* Note: Enabling this may have a performance impact.
|
|
110
|
+
*/
|
|
111
|
+
preserveDrawingBuffer: false,
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Whether to enable post-processing rendering.
|
|
115
|
+
* When enabled, Three.js content will be rendered through
|
|
116
|
+
* an offscreen render target before being composited onto the map.
|
|
117
|
+
* When disabled, Three.js renders directly into the shared MapLibre canvas
|
|
118
|
+
* for maximum performance and stability.
|
|
119
|
+
*/
|
|
120
|
+
enablePostProcessing: false,
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Custom frame render loop.
|
|
124
|
+
*
|
|
125
|
+
* This function will be called every frame.
|
|
126
|
+
* If not provided, the internal default render loop will be used.
|
|
127
|
+
*
|
|
128
|
+
* ⚠️ Note:
|
|
129
|
+
* Providing a custom renderLoop means you take full control
|
|
130
|
+
* of the render lifecycle. The built-in rendering pipeline
|
|
131
|
+
* will be bypassed.
|
|
132
|
+
*
|
|
133
|
+
* As a result, the following internal event hooks will
|
|
134
|
+
* NOT be triggered automatically:
|
|
135
|
+
*
|
|
136
|
+
* - preReset
|
|
137
|
+
* - postReset
|
|
138
|
+
* - preRender
|
|
139
|
+
* - postRender
|
|
140
|
+
*
|
|
141
|
+
* If needed, you must manually call the corresponding logic
|
|
142
|
+
* inside your custom renderLoop.
|
|
143
|
+
*
|
|
144
|
+
* @param {MapScene} ins - The current MapScene instance
|
|
145
|
+
*/
|
|
146
|
+
renderLoop: (ins) => {
|
|
147
|
+
}
|
|
93
148
|
})
|
|
94
149
|
```
|
|
95
150
|
|
|
96
151
|
#### event hooks
|
|
97
152
|
|
|
153
|
+
These hooks are only triggered when using the internal render loop.
|
|
154
|
+
|
|
98
155
|
- `preReset` : A hook that calls `renderer.resetState` before each animation frame
|
|
99
156
|
- `postReset`: A hook that calls `renderer.resetState` after each animation frame
|
|
100
157
|
- `preRender`: A hook that calls `renderer.render` before each animation frame
|
|
@@ -109,6 +166,9 @@ Object({
|
|
|
109
166
|
- `{THREE.Group} lights`: `readonly`
|
|
110
167
|
- `{THREE.Group} world` : `readonly`
|
|
111
168
|
- `{THREE.WebGLRenderer} renderer` : `readonly`
|
|
169
|
+
- `{EffectComposer} composer` : `readonly`
|
|
170
|
+
- `{RenderPass} renderPass` : `readonly`
|
|
171
|
+
- `{ShaderPass} customOutPass` : `readonly`
|
|
112
172
|
|
|
113
173
|
#### methods
|
|
114
174
|
|
|
@@ -171,6 +231,9 @@ Object({
|
|
|
171
231
|
- `this`
|
|
172
232
|
|
|
173
233
|
- **_on(type,callback)_**
|
|
234
|
+
|
|
235
|
+
Registers an event listener for the specified event type
|
|
236
|
+
|
|
174
237
|
- params
|
|
175
238
|
- `{String} type `
|
|
176
239
|
- `{Function} callback `:
|
|
@@ -178,6 +241,9 @@ Object({
|
|
|
178
241
|
- `this`
|
|
179
242
|
|
|
180
243
|
- **_off(type,callback)_**
|
|
244
|
+
|
|
245
|
+
Removes a previously registered event listener for the specified event type
|
|
246
|
+
|
|
181
247
|
- params
|
|
182
248
|
- `{String} type `
|
|
183
249
|
- `{Function} callback `:
|
|
@@ -194,6 +260,25 @@ Object({
|
|
|
194
260
|
- returns
|
|
195
261
|
- `this`
|
|
196
262
|
|
|
263
|
+
- **_addPass(pass)_**
|
|
264
|
+
|
|
265
|
+
Adds a post-processing pass to the internal EffectComposer. The pass will be inserted before the final output pass to
|
|
266
|
+
ensure correct rendering order.
|
|
267
|
+
|
|
268
|
+
- params
|
|
269
|
+
- `{THREE.Pass} pass `
|
|
270
|
+
- returns
|
|
271
|
+
- `this`
|
|
272
|
+
|
|
273
|
+
- **_removePass(pass)_**
|
|
274
|
+
|
|
275
|
+
Removes a previously added post-processing pass from the internal EffectComposer.
|
|
276
|
+
|
|
277
|
+
- params
|
|
278
|
+
- `{THREE.Pass} pass `
|
|
279
|
+
- returns
|
|
280
|
+
- `this`
|
|
281
|
+
|
|
197
282
|
### SceneTransform
|
|
198
283
|
|
|
199
284
|
#### examples
|
|
@@ -274,7 +359,7 @@ const rtcGroup = Creator.createRTCGroup([-1000, 0, 0])
|
|
|
274
359
|
- `{Array} rotation`: default value is [0,0,0]
|
|
275
360
|
- `{Array} scale`: scale corresponding to the current latitude
|
|
276
361
|
- returns
|
|
277
|
-
- `{THREE.Group}
|
|
362
|
+
- `{THREE.Group} group`
|
|
278
363
|
|
|
279
364
|
- **_createMercatorRTCGroup(center, [rotation], [scale])_**
|
|
280
365
|
- params
|
|
@@ -282,7 +367,7 @@ const rtcGroup = Creator.createRTCGroup([-1000, 0, 0])
|
|
|
282
367
|
- `{Array} rotation`: default value is [0,0,0]
|
|
283
368
|
- `{Array} scale`: scale corresponding to the current latitude
|
|
284
369
|
- returns
|
|
285
|
-
- `{THREE.Group}
|
|
370
|
+
- `{THREE.Group} group`
|
|
286
371
|
|
|
287
372
|
- **_createShadowGround(center, [width], [height])_**
|
|
288
373
|
- params
|
|
@@ -290,4 +375,4 @@ const rtcGroup = Creator.createRTCGroup([-1000, 0, 0])
|
|
|
290
375
|
- `{Number} width`: default value is 100
|
|
291
376
|
- `{Number} height` : default value is 100
|
|
292
377
|
- returns
|
|
293
|
-
- `{
|
|
378
|
+
- `{THREE.Mesh} mesh`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import * as three from 'three';
|
|
2
2
|
import { Scene, PerspectiveCamera, WebGLRenderer, Group, Light, Object3D, Vector3, DirectionalLight, HemisphereLight, Mesh } from 'three';
|
|
3
|
+
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
|
|
4
|
+
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
|
|
5
|
+
import { Pass } from 'three/addons/postprocessing/Pass.js';
|
|
6
|
+
import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
|
|
3
7
|
|
|
4
8
|
interface IMap {
|
|
5
9
|
transform: any;
|
|
@@ -33,8 +37,21 @@ interface IMapSceneOptions {
|
|
|
33
37
|
renderer: null | WebGLRenderer;
|
|
34
38
|
/** Custom render loop function (optional) */
|
|
35
39
|
renderLoop: null | ((mapScene: MapScene) => void);
|
|
36
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Whether to preserve the drawing buffer.
|
|
42
|
+
* When enabled, the canvas content will be retained after rendering,
|
|
43
|
+
* which is useful for screenshots or readPixels operations.
|
|
44
|
+
* Note: Enabling this may have a performance impact.
|
|
45
|
+
*/
|
|
37
46
|
preserveDrawingBuffer: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Whether to enable post-processing rendering.
|
|
49
|
+
* When enabled, Three.js content will be rendered through
|
|
50
|
+
* an offscreen render target before being composited onto the map.
|
|
51
|
+
* When disabled, Three.js renders directly into the shared MapLibre canvas
|
|
52
|
+
* for maximum performance and stability.
|
|
53
|
+
*/
|
|
54
|
+
enablePostProcessing: boolean;
|
|
38
55
|
}
|
|
39
56
|
/**
|
|
40
57
|
* Frame state information passed to event listeners
|
|
@@ -77,6 +94,9 @@ declare class MapScene {
|
|
|
77
94
|
private readonly _renderer;
|
|
78
95
|
private readonly _lights;
|
|
79
96
|
private readonly _world;
|
|
97
|
+
private readonly _composer;
|
|
98
|
+
private readonly _renderPass;
|
|
99
|
+
private readonly _customOutPass;
|
|
80
100
|
private _event;
|
|
81
101
|
constructor(map: IMap, options?: Partial<IMapSceneOptions>);
|
|
82
102
|
get map(): IMap;
|
|
@@ -86,6 +106,9 @@ declare class MapScene {
|
|
|
86
106
|
get lights(): Group<three.Object3DEventMap>;
|
|
87
107
|
get world(): Group<three.Object3DEventMap>;
|
|
88
108
|
get renderer(): WebGLRenderer;
|
|
109
|
+
get composer(): EffectComposer | undefined;
|
|
110
|
+
get renderPass(): RenderPass | undefined;
|
|
111
|
+
get customOutPass(): ShaderPass | undefined;
|
|
89
112
|
/**
|
|
90
113
|
*
|
|
91
114
|
* @private
|
|
@@ -188,8 +211,20 @@ declare class MapScene {
|
|
|
188
211
|
/**
|
|
189
212
|
*
|
|
190
213
|
* @param beforeId
|
|
214
|
+
* @returns {MapScene}
|
|
191
215
|
*/
|
|
192
216
|
layerBeforeTo(beforeId?: String): MapScene;
|
|
217
|
+
/**
|
|
218
|
+
* @param pass
|
|
219
|
+
* @returns {MapScene}
|
|
220
|
+
*/
|
|
221
|
+
addPass(pass: Pass): MapScene;
|
|
222
|
+
/**
|
|
223
|
+
*
|
|
224
|
+
* @param pass
|
|
225
|
+
* @returns {MapScene}
|
|
226
|
+
*/
|
|
227
|
+
removePass(pass: Pass): MapScene;
|
|
193
228
|
}
|
|
194
229
|
|
|
195
230
|
declare class SceneTransform {
|
package/dist/index.js
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
|
-
import{Group as ae,PerspectiveCamera as De,Scene as Te,WebGLRenderer as Re,EventDispatcher as xe,Box3 as Ce,Vector3 as Pe}from"three";var R=63710088e-1,C=2*Math.PI*R,l=Math.PI/180,Be=180/Math.PI,P=1024e3/C,Q=512;var W=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)),f=h/c*b,g=Math.round(Math.log2(f/e.tileSize));return{center:[i.lng,i.lat],cameraHeight:c,zoom:Math.min(g,e.maxZoom)}}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=W;import{Matrix4 as y,Vector3 as Le}from"three";var $=new y,ee=new y,te=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=Q/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 g=t.fov*l,p=t.centerOffset||new Le;this._camera.aspect=t.width/t.height,$.elements=I.makePerspectiveMatrix(g,this._camera.aspect,t.height/50,t.farZ),this._camera.projectionMatrix=$,this._camera.projectionMatrix.elements[8]=-p.x*2/t.width,this._camera.projectionMatrix.elements[9]=p.y*2/t.height}ee.makeTranslation(0,0,t.cameraToCenterDistance);let s=new y().premultiply(ee).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 g=t.center,p=I.clamp(g.lat,-te,te);c=I.mercatorXFromLng(g.lng)*t.worldSize,h=I.mercatorYFromLat(p)*t.worldSize}let b=new y().makeTranslation(-c,h,0),f=new y().makeRotationZ(Math.PI);this._world.matrix=new y().premultiply(f).premultiply(this._translateCenter).premultiply(o).premultiply(b)}},ne=F;var k=class{_id;_mapScene;_cameraSync;constructor(e,t){this._id=e,this._mapScene=t,this._cameraSync=new ne(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}},re=k;import{Vector3 as Ie}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 Ie(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 ze={scene:null,camera:null,renderer:null,renderLoop:null,preserveDrawingBuffer:!1},V="map_scene_layer",O=class{_map;_options;_canvas;_scene;_camera;_renderer;_lights;_world;_event;constructor(e,t={}){if(!e)throw"missing map";this._map=e,this._options={...ze,...t},this._canvas=e.getCanvas(),this._scene=this._options.scene||new Te,this._camera=this._options.camera||new De(this._map.transform.fov,this._map.transform.width/this._map.transform.height,.001,1e21),this._camera.matrixAutoUpdate=!1,this._renderer=this._options.renderer||new Re({alpha:!0,antialias:!0,preserveDrawingBuffer:this._options.preserveDrawingBuffer,canvas:this._canvas,context:this._canvas.getContext("webgl2")}),this._renderer.setPixelRatio(window.devicePixelRatio),this._renderer.setSize(this._canvas.clientWidth,this._canvas.clientHeight),this._renderer.autoClear=!1,this._lights=new ae,this._lights.name="lights",this._scene.add(this._lights),this._world=new ae,this._world.name="world",this._world.userData={isWorld:!0,name:"world"},this._world.position.set(1024e3/2,1024e3/2,0),this._world.matrixAutoUpdate=!1,this._scene.add(this._world),this._map.on("render",this._onMapRender.bind(this)),this._event=new xe}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(V)||this._map.addLayer(new re(V,this))}render(){if(this._options.renderLoop)this._options.renderLoop(this);else{let e={center:this._map.getCenter(),scene:this._scene,camera:this._camera,renderer:this._renderer};this._event.dispatchEvent({type:"preReset",frameState:e}),this.renderer.resetState(),this._event.dispatchEvent({type:"postReset",frameState:e}),this._event.dispatchEvent({type:"preRender",frameState:e}),this.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 Pe,new Ce().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}layerBeforeTo(e){return this._map.moveLayer(V,e),this}};import{Group as Ue,DirectionalLight as Ze,HemisphereLight as We,Color as ye}from"three";var U=Math.PI,m=Math.sin,u=Math.cos,N=Math.tan,ie=Math.asin,A=Math.atan2,se=Math.acos,d=U/180,X=1e3*60*60*24,oe=2440588,me=2451545;function Ee(a){return a.valueOf()/X-.5+oe}function G(a){return new Date((a+.5-oe)*X)}function Z(a){return Ee(a)-me}var j=d*23.4397;function ce(a,e){return A(m(a)*u(j)-N(e)*m(j),u(a))}function Y(a,e){return ie(m(e)*u(j)+u(e)*m(j)*m(a))}function ue(a,e,t){return A(m(a),u(a)*m(e)-N(t)*u(e))}function he(a,e,t){return ie(m(e)*m(t)+u(e)*u(t)*u(a))}function le(a,e){return d*(280.16+360.9856235*a)-e}function Ae(a){return a<0&&(a=0),2967e-7/Math.tan(a+.00312536/(a+.08901179))}function pe(a){return d*(357.5291+.98560028*a)}function de(a){let e=d*(1.9148*m(a)+.02*m(2*a)+3e-4*m(3*a)),t=d*102.9372;return a+e+t+U}function be(a){let e=pe(a),t=de(e);return{dec:Y(t,0),ra:ce(t,0)}}var M={};M.getPosition=function(a,e,t){let r=d*-t,n=d*e,s=Z(a),i=be(s),o=le(s,r)-i.ra;return{azimuth:ue(o,n,i.dec),altitude:he(o,n,i.dec)}};var B=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){B.push([a,e,t])};var ge=9e-4;function Oe(a,e){return Math.round(a-ge-e/(2*U))}function fe(a,e,t){return ge+(a+e)/(2*U)+t}function _e(a,e,t){return me+a+.0053*m(e)-.0069*m(2*t)}function Ge(a,e,t){return se((m(a)-m(e)*m(t))/(u(e)*u(t)))}function He(a){return-2.076*Math.sqrt(a)/60}function je(a,e,t,r,n,s,i){let o=Ge(a,t,r),c=fe(o,e,n);return _e(c,s,i)}M.getTimes=function(a,e,t,r=0){let n=d*-t,s=d*e,i=He(r),o=Z(a),c=Oe(o,n),h=fe(0,n,c),b=pe(h),f=de(b),g=Y(f,0),p=_e(h,b,f),v,z,S,_,L,E,D={solarNoon:G(p),nadir:G(p-.5)};for(v=0,z=B.length;v<z;v+=1)S=B[v],_=(S[0]+i)*d,L=je(_,n,s,g,c,b,f),E=p-(L-p),D[S[1]]=G(E),D[S[2]]=G(L);return D};function Me(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:ce(n,s),dec:Y(n,s),dist:i}}M.getMoonPosition=function(a,e,t){let r=d*-t,n=d*e,s=Z(a),i=Me(s),o=le(s,r)-i.ra,c=he(o,n,i.dec),h=A(m(o),N(n)*u(i.dec)-m(i.dec)*u(o));return c=c+Ae(c),{azimuth:ue(o,n,i.dec),altitude:c,distance:i.dist,parallacticAngle:h}};M.getMoonIllumination=function(a){let e=Z(a||new Date),t=be(e),r=Me(e),n=149598e3,s=se(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*X/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,f,g,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,f=(i+c)/2-o,g=(c-i)/2,p=-g/(2*f),v=(f*p+g)*p+o,z=g*g-4*f*o,S=0,z>=0&&(E=Math.sqrt(z)/(Math.abs(f)*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 Se=M;var q=class{_delegate;_sunLight;_hemiLight;_currentTime;constructor(){this._delegate=new Ue,this._delegate.name="Sun",this._sunLight=new Ze(16777215,1),this._hemiLight=new We(new ye(16777215),new ye(16777215),.6),this._hemiLight.color.setHSL(.661,.96,.12),this._hemiLight.groundColor.setHSL(.11,.96,.14),this._hemiLight.position.set(0,0,50),this._delegate.add(this._sunLight),this._delegate.add(this._hemiLight),this._currentTime=new Date().getTime()}get delegate(){return this._delegate}set castShadow(e){this._sunLight.castShadow=e}get castShadow(){return this._sunLight.castShadow}set currentTime(e){this._currentTime=e}get currentTime(){return this._currentTime}get sunLight(){return this._sunLight}get hemiLight(){return this._hemiLight}setShadow(e={}){return this._sunLight.shadow.radius=e.radius||2,this._sunLight.shadow.mapSize.width=e.mapSize?e.mapSize[0]:8192,this._sunLight.shadow.mapSize.height=e.mapSize?e.mapSize[1]:8192,this._sunLight.shadow.camera.top=this._sunLight.shadow.camera.right=e.topRight||1e3,this._sunLight.shadow.camera.bottom=this._sunLight.shadow.camera.left=e.bottomLeft||-1e3,this._sunLight.shadow.camera.near=e.near||1,this._sunLight.shadow.camera.far=e.far||1e8,this._sunLight.shadow.camera.visible=!0,this}update(e){let r=new Date(this._currentTime||new Date().getTime()),n=e.center,s=Se.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),f=Math.cos(o)*b,g=Math.sin(o)*b;this._sunLight.position.set(g,f,h),this._sunLight.position.multiplyScalar(c),this._sunLight.intensity=Math.max(h,0),this._hemiLight.intensity=Math.max(h*1,.1),this._sunLight.updateMatrixWorld()}},we=q;import{Group as Fe,Mesh as ke,PlaneGeometry as Je,ShadowMaterial as Ve}from"three";var K=class{static createRTCGroup(e,t,r){let n=new Fe;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 Je(t||100,r||100),s=new Ve({opacity:.5,transparent:!0}),i=new ke(n,s);return i.position.copy(w.lngLatToVector3(e)),i.receiveShadow=!0,i.name="shadow-ground",i}},ve=K;export{ve as Creator,O as MapScene,w as SceneTransform,we as Sun};
|
|
1
|
+
import{Group as se,PerspectiveCamera as Le,Scene as Ie,WebGLRenderer as De,EventDispatcher as Te,Box3 as xe,Vector3 as Re,NormalBlending as Ce}from"three";import{EffectComposer as Ee}from"three/addons/postprocessing/EffectComposer.js";import{RenderPass as ze}from"three/addons/postprocessing/RenderPass.js";import"three/addons/postprocessing/Pass.js";import{ShaderPass as Oe}from"three/addons/postprocessing/ShaderPass.js";var T=63710088e-1,R=2*Math.PI*T,l=Math.PI/180,Ke=180/Math.PI,C=1024e3/R,Q=512;var W=class{static clamp(e,t,n){return Math.min(n,Math.max(t,e))}static makePerspectiveMatrix(e,t,n,r){let i=1/Math.tan(e/2),s=1/(n-r);return[i/t,0,0,0,0,i,0,0,0,0,(r+n)*s,-1,0,0,2*r*n*s,0]}static mercatorXFromLng(e){return(180+e)/360}static mercatorYFromLat(e){return(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+e*Math.PI/360)))/360}static getViewInfo(e,t,n){let r=e.fov*l,i=e.pitch*l,s=null;if(Array.isArray(t)&&(s={lng:t[0],lat:t[1],alt:t[2]||0}),typeof t=="string"){let p=t.split(",");s={lng:+p[0],lat:+p[1],alt:+p[2]||0}}let c=Math.max(n.x,n.y,n.z)/(2*Math.tan(r/2))*Math.cos(i)+s.alt,h=Math.abs(Math.cos(i)*e.cameraToCenterDistance),b=R*Math.abs(Math.cos(s.lat*l)),_=h/c*b,f=Math.round(Math.log2(_/e.tileSize));return{center:[s.lng,s.lat],cameraHeight:c,zoom:Math.min(f,e.maxZoom)}}static getHeightByZoom(e,t,n,r){let i=Math.abs(Math.cos(r*l)*e.cameraToCenterDistance),s=R*Math.abs(Math.cos(n*l)),o=Math.pow(2,t)*e.tileSize;return i*s/o}static getZoomByHeight(e,t,n,r){let i=Math.abs(Math.cos(r*l)*e.cameraToCenterDistance),s=R*Math.abs(Math.cos(n*l)),o=i/t*s;return Math.round(Math.log2(o/e.tileSize))}},P=W;import{Matrix4 as S,Vector3 as we}from"three";var $=new S,ee=new S,te=85.051129,Z=class{_map;_world;_camera;_translateCenter;_worldSizeRatio;constructor(e,t,n){this._map=e,this._world=t,this._camera=n,this._translateCenter=new S().makeTranslation(1024e3/2,-1024e3/2,0),this._worldSizeRatio=Q/1024e3,this._map.on("move",()=>{this.syncCamera(!1)}),this._map.on("resize",()=>{this.syncCamera(!0)})}syncCamera(e){let t=this._map.transform,n=t.pitch*l,r=t.bearing*l;if(e){let f=t.fov*l,p=t.centerOffset||new we;this._camera.aspect=t.width/t.height,$.elements=P.makePerspectiveMatrix(f,this._camera.aspect,t.height/50,t.farZ),this._camera.projectionMatrix=$,this._camera.projectionMatrix.elements[8]=-p.x*2/t.width,this._camera.projectionMatrix.elements[9]=p.y*2/t.height}ee.makeTranslation(0,0,t.cameraToCenterDistance);let i=new S().premultiply(ee).premultiply(new S().makeRotationX(n)).premultiply(new S().makeRotationZ(-r));t.elevation&&(i.elements[14]=t.cameraToCenterDistance*Math.cos(n)),this._camera.matrixWorld.copy(i);let s=t.scale*this._worldSizeRatio,o=new S().makeScale(s,s,s),c=t.x,h=t.y;if(!c||!h){let f=t.center,p=P.clamp(f.lat,-te,te);c=P.mercatorXFromLng(f.lng)*t.worldSize,h=P.mercatorYFromLat(p)*t.worldSize}let b=new S().makeTranslation(-c,h,0),_=new S().makeRotationZ(Math.PI);this._world.matrix=new S().premultiply(_).premultiply(this._translateCenter).premultiply(o).premultiply(b)}},re=Z;var F=class{_id;_mapScene;_cameraSync;constructor(e,t){this._id=e,this._mapScene=t,this._cameraSync=new re(this._mapScene.map,this._mapScene.world,this._mapScene.camera)}get id(){return this._id}get type(){return"custom"}get renderingMode(){return"3d"}onAdd(){this._cameraSync.syncCamera(!0)}render(){this._mapScene.render()}onRemove(){this._cameraSync=null,this._mapScene=null}},ne=F;import{Vector3 as Pe}from"three";var B=class{static projectedMercatorUnitsPerMeter(){return this.projectedUnitsPerMeter(0)}static projectedUnitsPerMeter(e){return Math.abs(1024e3/Math.cos(l*e)/R)}static lngLatToVector3(e,t,n){let r=[0,0,0];return Array.isArray(e)?(r=[-T*l*e[0]*C,-T*Math.log(Math.tan(Math.PI*.25+.5*l*e[1]))*C],e[2]?r.push(e[2]*this.projectedUnitsPerMeter(e[1])):r.push(0)):(r=[-T*l*e*C,-T*Math.log(Math.tan(Math.PI*.25+.5*l*(t||0)))*C],n?r.push(n*this.projectedUnitsPerMeter(t||0)):r.push(0)),new Pe(r[0],r[1],r[2])}static vector3ToLngLat(e){let t=[0,0,0];return e&&(t[0]=-e.x/(T*l*C),t[1]=2*(Math.atan(Math.exp(e.y/(C*-T)))-Math.PI/4)/l,t[2]=e.z/this.projectedUnitsPerMeter(t[1])),t}},L=B;var ae={name:"CustomOutputShader",uniforms:{tDiffuse:{value:null}},vertexShader:`
|
|
2
|
+
precision highp float;
|
|
3
|
+
varying vec2 vUv;
|
|
4
|
+
void main() {
|
|
5
|
+
vUv = uv;
|
|
6
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
7
|
+
|
|
8
|
+
}`,fragmentShader:`
|
|
9
|
+
precision highp float;
|
|
10
|
+
uniform sampler2D tDiffuse;
|
|
11
|
+
varying vec2 vUv;
|
|
12
|
+
void main() {
|
|
13
|
+
vec4 color = texture2D(tDiffuse, vUv);
|
|
14
|
+
color.rgb = pow(color.rgb, vec3(1.0/2.2));
|
|
15
|
+
color.rgb *= color.a;
|
|
16
|
+
gl_FragColor = color;
|
|
17
|
+
}`};var Ae={scene:null,camera:null,renderer:null,preserveDrawingBuffer:!1,renderLoop:null,enablePostProcessing:!1},V="map_scene_layer",k=class{_map;_options;_canvas;_scene;_camera;_renderer;_lights;_world;_composer;_renderPass;_customOutPass;_event;constructor(e,t={}){if(!e)throw"missing map";this._map=e,this._options={...Ae,...t},this._canvas=e.getCanvas(),this._scene=this._options.scene||new Ie,this._camera=this._options.camera||new Le(this._map.transform.fov,this._map.transform.width/this._map.transform.height,.001,1e21),this._camera.matrixAutoUpdate=!1,this._renderer=this._options.renderer||new De({alpha:!0,antialias:!0,preserveDrawingBuffer:this._options.preserveDrawingBuffer,canvas:this._canvas,context:this._canvas.getContext("webgl2")}),this._renderer.setPixelRatio(window.devicePixelRatio),this._renderer.setSize(this._canvas.clientWidth,this._canvas.clientHeight),this._renderer.autoClear=!1,this._lights=new se,this._lights.name="lights",this._scene.add(this._lights),this._world=new se,this._world.name="world",this._world.userData={isWorld:!0,name:"world"},this._world.position.set(1024e3/2,1024e3/2,0),this._world.matrixAutoUpdate=!1,this._scene.add(this._world),this._options.enablePostProcessing&&(this._composer=new Ee(this._renderer),this._composer.setSize(this._canvas.clientWidth,this._canvas.clientHeight),this._composer.renderTarget1.depthBuffer=!0,this._composer.renderTarget2.depthBuffer=!0,this._renderPass=new ze(this._scene,this._camera),this._renderer.setClearColor(0,0),this._composer.addPass(this._renderPass),this._customOutPass=new Oe(ae),this._customOutPass.renderToScreen=!0,this._customOutPass.material.transparent=!0,this._customOutPass.material.blending=Ce,this._customOutPass.clear=!1,this._composer.addPass(this._customOutPass)),this._map.on("render",this._onMapRender.bind(this)),this._event=new Te}get map(){return this._map}get canvas(){return this._canvas}get camera(){return this._camera}get scene(){return this._scene}get lights(){return this._lights}get world(){return this._world}get renderer(){return this._renderer}get composer(){return this._composer}get renderPass(){return this._renderPass}get customOutPass(){return this._customOutPass}_onMapRender(){this._map.getLayer(V)||this._map.addLayer(new ne(V,this))}render(){if(this._options.renderLoop)this._options.renderLoop(this);else{let e={center:this._map.getCenter(),scene:this._scene,camera:this._camera,renderer:this._renderer};this._event.dispatchEvent({type:"preReset",frameState:e}),this.renderer.resetState(),this._event.dispatchEvent({type:"postReset",frameState:e}),this._event.dispatchEvent({type:"preRender",frameState:e}),this._composer?this._composer.render():this._renderer.render(this._scene,this._camera),this._event.dispatchEvent({type:"postRender",frameState:e})}return this}addLight(e){return this._lights.add(e.delegate||e),this}removeLight(e){return this._lights.remove(e.delegate||e),this}addObject(e){let t="delegate"in e?e.delegate:e;return this._world.add(t),this}removeObject(e){let t="delegate"in e?e.delegate:e;return this._world.remove(t),t.traverse(n=>{n.geometry&&n.geometry.dispose(),n.material&&(Array.isArray(n.material)?n.material.forEach(r=>r.dispose()):n.material.dispose()),n.texture&&n.texture.dispose()}),this}getViewPosition(){let e=this._map.transform,t=e.center;return{position:[t.lng,t.lat,P.getHeightByZoom(e,e.zoom,t.lat,e.pitch)],heading:e.bearing,pitch:e.pitch}}flyTo(e,t,n){if(e&&e.position){n&&this._map.once("moveend",n);let r=e.size;r||(r=new Re,new xe().setFromObject(e.delegate||e,!0).getSize(r));let i=P.getViewInfo(this._map.transform,L.vector3ToLngLat(e.position),r);this._map.flyTo({center:i.center,zoom:i.zoom,duration:(t||3)*1e3})}return this}zoomTo(e,t){return this.flyTo(e,0,t)}flyToPosition(e,t=[0,0,0],n,r=3){return n&&this._map.once("moveend",n),this._map.flyTo({center:[e[0],e[1]],zoom:P.getZoomByHeight(this._map.transform,e[2],e[1],t[1]||0),bearing:t[0],pitch:t[1],duration:r*1e3}),this}zoomToPosition(e,t=[0,0,0],n){return this.flyToPosition(e,t,n,0)}on(e,t){return this._event.addEventListener(e,t),this}off(e,t){return this._event.removeEventListener(e,t),this}layerBeforeTo(e){return this._map.moveLayer(V,e),this}addPass(e){if(!this._options.enablePostProcessing||!e||!this._composer)return this;let t=this._customOutPass;if(this._composer.passes.includes(e))return this;let n=t?this._composer.passes.indexOf(t):-1;return n>=0?this._composer.insertPass(e,n):this._composer.addPass(e),this}removePass(e){return!this._options.enablePostProcessing||!e||!this._composer?this:(this._composer.removePass(e),this)}};import{Group as Fe,DirectionalLight as Be,HemisphereLight as Ve,Color as ye}from"three";var H=Math.PI,m=Math.sin,u=Math.cos,N=Math.tan,ie=Math.asin,O=Math.atan2,oe=Math.acos,d=H/180,X=1e3*60*60*24,me=2440588,ce=2451545;function Ue(a){return a.valueOf()/X-.5+me}function A(a){return new Date((a+.5-me)*X)}function j(a){return Ue(a)-ce}var G=d*23.4397;function ue(a,e){return O(m(a)*u(G)-N(e)*m(G),u(a))}function Y(a,e){return ie(m(e)*u(G)+u(e)*m(G)*m(a))}function he(a,e,t){return O(m(a),u(a)*m(e)-N(t)*u(e))}function le(a,e,t){return ie(m(e)*m(t)+u(e)*u(t)*u(a))}function pe(a,e){return d*(280.16+360.9856235*a)-e}function Ge(a){return a<0&&(a=0),2967e-7/Math.tan(a+.00312536/(a+.08901179))}function de(a){return d*(357.5291+.98560028*a)}function be(a){let e=d*(1.9148*m(a)+.02*m(2*a)+3e-4*m(3*a)),t=d*102.9372;return a+e+t+H}function fe(a){let e=de(a),t=be(e);return{dec:Y(t,0),ra:ue(t,0)}}var M={};M.getPosition=function(a,e,t){let n=d*-t,r=d*e,i=j(a),s=fe(i),o=pe(i,n)-s.ra;return{azimuth:he(o,r,s.dec),altitude:le(o,r,s.dec)}};var J=M.times=[[-.833,"sunrise","sunset"],[-.3,"sunriseEnd","sunsetStart"],[-6,"dawn","dusk"],[-12,"nauticalDawn","nauticalDusk"],[-18,"nightEnd","night"],[6,"goldenHourEnd","goldenHour"]];M.addTime=function(a,e,t){J.push([a,e,t])};var _e=9e-4;function He(a,e){return Math.round(a-_e-e/(2*H))}function ge(a,e,t){return _e+(a+e)/(2*H)+t}function Me(a,e,t){return ce+a+.0053*m(e)-.0069*m(2*t)}function je(a,e,t){return oe((m(a)-m(e)*m(t))/(u(e)*u(t)))}function We(a){return-2.076*Math.sqrt(a)/60}function Ze(a,e,t,n,r,i,s){let o=je(a,t,n),c=ge(o,e,r);return Me(c,i,s)}M.getTimes=function(a,e,t,n=0){let r=d*-t,i=d*e,s=We(n),o=j(a),c=He(o,r),h=ge(0,r,c),b=de(h),_=be(b),f=Y(_,0),p=Me(h,b,_),y,E,v,g,w,z,I={solarNoon:A(p),nadir:A(p-.5)};for(y=0,E=J.length;y<E;y+=1)v=J[y],g=(v[0]+s)*d,w=Ze(g,r,i,f,c,b,_),z=p-(w-p),I[v[1]]=A(z),I[v[2]]=A(w);return I};function ve(a){let e=d*(218.316+13.176396*a),t=d*(134.963+13.064993*a),n=d*(93.272+13.22935*a),r=e+d*6.289*m(t),i=d*5.128*m(n),s=385001-20905*u(t);return{ra:ue(r,i),dec:Y(r,i),dist:s}}M.getMoonPosition=function(a,e,t){let n=d*-t,r=d*e,i=j(a),s=ve(i),o=pe(i,n)-s.ra,c=le(o,r,s.dec),h=O(m(o),N(r)*u(s.dec)-m(s.dec)*u(o));return c=c+Ge(c),{azimuth:he(o,r,s.dec),altitude:c,distance:s.dist,parallacticAngle:h}};M.getMoonIllumination=function(a){let e=j(a||new Date),t=fe(e),n=ve(e),r=149598e3,i=oe(m(t.dec)*m(n.dec)+u(t.dec)*u(n.dec)*u(t.ra-n.ra)),s=O(r*m(i),n.dist-r*u(i)),o=O(u(t.dec)*m(t.ra-n.ra),m(t.dec)*u(n.dec)-u(t.dec)*m(n.dec)*u(t.ra-n.ra));return{fraction:(1+u(s))/2,phase:.5+.5*s*(o<0?-1:1)/Math.PI,angle:o}};function U(a,e){return new Date(a.valueOf()+e*X/24)}M.getMoonTimes=function(a,e,t,n=!1){let r=new Date(a);n?r.setUTCHours(0,0,0,0):r.setHours(0,0,0,0);let i=.133*d,s=M.getMoonPosition(r,e,t).altitude-i,o,c,h,b,_,f,p,y,E,v,g,w,z;for(let D=1;D<=24&&(o=M.getMoonPosition(U(r,D),e,t).altitude-i,c=M.getMoonPosition(U(r,D+1),e,t).altitude-i,_=(s+c)/2-o,f=(c-s)/2,p=-f/(2*_),y=(_*p+f)*p+o,E=f*f-4*_*o,v=0,E>=0&&(z=Math.sqrt(E)/(Math.abs(_)*2),g=p-z,w=p+z,Math.abs(g)<=1&&v++,Math.abs(w)<=1&&v++,g<-1&&(g=w)),v===1?s<0?h=D+g:b=D+g:v===2&&(h=D+(y<0?w:g),b=D+(y<0?g:w)),!(h&&b));D+=2)s=c;let I={};return h&&(I.rise=U(r,h)),b&&(I.set=U(r,b)),!h&&!b&&(I[y>0?"alwaysUp":"alwaysDown"]=!0),I};var Se=M;var q=class{_delegate;_sunLight;_hemiLight;_currentTime;constructor(){this._delegate=new Fe,this._delegate.name="Sun",this._sunLight=new Be(16777215,1),this._hemiLight=new Ve(new ye(16777215),new ye(16777215),.6),this._hemiLight.color.setHSL(.661,.96,.12),this._hemiLight.groundColor.setHSL(.11,.96,.14),this._hemiLight.position.set(0,0,50),this._delegate.add(this._sunLight),this._delegate.add(this._hemiLight),this._currentTime=new Date().getTime()}get delegate(){return this._delegate}set castShadow(e){this._sunLight.castShadow=e}get castShadow(){return this._sunLight.castShadow}set currentTime(e){this._currentTime=e}get currentTime(){return this._currentTime}get sunLight(){return this._sunLight}get hemiLight(){return this._hemiLight}setShadow(e={}){return this._sunLight.shadow.radius=e.radius||2,this._sunLight.shadow.mapSize.width=e.mapSize?e.mapSize[0]:8192,this._sunLight.shadow.mapSize.height=e.mapSize?e.mapSize[1]:8192,this._sunLight.shadow.camera.top=this._sunLight.shadow.camera.right=e.topRight||1e3,this._sunLight.shadow.camera.bottom=this._sunLight.shadow.camera.left=e.bottomLeft||-1e3,this._sunLight.shadow.camera.near=e.near||1,this._sunLight.shadow.camera.far=e.far||1e8,this._sunLight.shadow.camera.visible=!0,this}update(e){let n=new Date(this._currentTime||new Date().getTime()),r=e.center,i=Se.getPosition(n,r.lat,r.lng),s=i.altitude,o=Math.PI+i.azimuth,c=1024e3/2,h=Math.sin(s),b=Math.cos(s),_=Math.cos(o)*b,f=Math.sin(o)*b;this._sunLight.position.set(f,_,h),this._sunLight.position.multiplyScalar(c),this._sunLight.intensity=Math.max(h,0),this._hemiLight.intensity=Math.max(h*1,.1),this._sunLight.updateMatrixWorld()}},ke=q;import{Group as Je,Mesh as Ne,PlaneGeometry as Xe,ShadowMaterial as Ye}from"three";var K=class{static createRTCGroup(e,t,n){let r=new Je;if(r.name="rtc",r.position.copy(L.lngLatToVector3(e)),t?(r.rotateX(t[0]||0),r.rotateY(t[1]||0),r.rotateZ(t[2]||0)):(r.rotateX(Math.PI/2),r.rotateY(Math.PI)),n)r.scale.set(n[0]||1,n[1]||1,n[2]||1);else{let i=1;Array.isArray(e)&&(i=L.projectedUnitsPerMeter(e[1])),r.scale.set(i,i,i)}return r}static createMercatorRTCGroup(e,t,n){let r=this.createRTCGroup(e,t,n);if(!n){let i=1,s=L.projectedMercatorUnitsPerMeter();Array.isArray(e)&&(i=L.projectedUnitsPerMeter(e[1])),r.scale.set(s,s,i)}return r}static createShadowGround(e,t,n){let r=new Xe(t||100,n||100),i=new Ye({opacity:.5,transparent:!0}),s=new Ne(r,i);return s.position.copy(L.lngLatToVector3(e)),s.receiveShadow=!0,s.name="shadow-ground",s}},qe=K;export{qe as Creator,k as MapScene,L as SceneTransform,ke as Sun};
|
package/package.json
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dvt3d/maplibre-three-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"repository": "https://github.com/dvt3d/maplibre-three-plugin.git",
|
|
5
5
|
"author": "cavencj <cavencj@gmail.com>",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"maplibre",
|
|
10
|
+
"three",
|
|
11
|
+
"three.js",
|
|
12
|
+
"map",
|
|
13
|
+
"3D",
|
|
14
|
+
"gltf"
|
|
15
|
+
],
|
|
8
16
|
"exports": {
|
|
9
17
|
".": {
|
|
10
18
|
"types": "./dist/index.d.ts",
|
|
@@ -30,7 +38,6 @@
|
|
|
30
38
|
"@babel/preset-env": "^7.21.5",
|
|
31
39
|
"@types/three": "^0.179.0",
|
|
32
40
|
"chalk": "^5.2.0",
|
|
33
|
-
"esbuild-plugin-globals": "^0.2.0",
|
|
34
41
|
"eslint": "^8.40.0",
|
|
35
42
|
"eslint-config-prettier": "^8.8.0",
|
|
36
43
|
"eslint-plugin-import": "^2.27.5",
|
package/dist/mtp.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var MTP=(()=>{var Pe=Object.create;var W=Object.defineProperty;var Ee=Object.getOwnPropertyDescriptor;var ze=Object.getOwnPropertyNames;var Ae=Object.getPrototypeOf,Oe=Object.prototype.hasOwnProperty;var Ge=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),He=(n,e)=>{for(var t in e)W(n,t,{get:e[t],enumerable:!0})},se=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ze(e))!Oe.call(n,r)&&r!==t&&W(n,r,{get:()=>e[r],enumerable:!(a=Ee(e,r))||a.enumerable});return n};var j=(n,e,t)=>(t=n!=null?Pe(Ae(n)):{},se(e||!n||!n.__esModule?W(t,"default",{value:n,enumerable:!0}):t,n)),je=n=>se(W({},"__esModule",{value:!0}),n);var H=Ge((Xe,oe)=>{"use strict";oe.exports=THREE});var Be={};He(Be,{Creator:()=>ie,MapScene:()=>U,SceneTransform:()=>y,Sun:()=>re});var _=j(H(),1);var C=63710088e-1,z=2*Math.PI*C,l=Math.PI/180,Ye=180/Math.PI,A=1024e3/z,me=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)),f=h/c*b,g=Math.round(Math.log2(f/e.tileSize));return{center:[i.lng,i.lat],cameraHeight:c,zoom:Math.min(g,e.maxZoom)}}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),ce=new M.Matrix4,ue=new M.Matrix4,he=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=me/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 g=t.fov*l,p=t.centerOffset||new M.Vector3;this._camera.aspect=t.width/t.height,ce.elements=D.makePerspectiveMatrix(g,this._camera.aspect,t.height/50,t.farZ),this._camera.projectionMatrix=ce,this._camera.projectionMatrix.elements[8]=-p.x*2/t.width,this._camera.projectionMatrix.elements[9]=p.y*2/t.height}ue.makeTranslation(0,0,t.cameraToCenterDistance);let s=new M.Matrix4().premultiply(ue).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 g=t.center,p=D.clamp(g.lat,-he,he);c=D.mercatorXFromLng(g.lng)*t.worldSize,h=D.mercatorYFromLat(p)*t.worldSize}let b=new M.Matrix4().makeTranslation(-c,h,0),f=new M.Matrix4().makeRotationZ(Math.PI);this._world.matrix=new M.Matrix4().premultiply(f).premultiply(this._translateCenter).premultiply(o).premultiply(b)}},le=X;var Y=class{_id;_mapScene;_cameraSync;constructor(e,t){this._id=e,this._mapScene=t,this._cameraSync=new le(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}},pe=Y;var de=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 de.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 Ue={scene:null,camera:null,renderer:null,renderLoop:null,preserveDrawingBuffer:!1},K="map_scene_layer",U=class{_map;_options;_canvas;_scene;_camera;_renderer;_lights;_world;_event;constructor(e,t={}){if(!e)throw"missing map";this._map=e,this._options={...Ue,...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(K)||this._map.addLayer(new pe(K,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}layerBeforeTo(e){return this._map.moveLayer(K,e),this}};var T=j(H(),1);var V=Math.PI,m=Math.sin,u=Math.cos,$=Math.tan,be=Math.asin,Z=Math.atan2,ge=Math.acos,d=V/180,ee=1e3*60*60*24,fe=2440588,_e=2451545;function Ze(n){return n.valueOf()/ee-.5+fe}function F(n){return new Date((n+.5-fe)*ee)}function B(n){return Ze(n)-_e}var J=d*23.4397;function Me(n,e){return Z(m(n)*u(J)-$(e)*m(J),u(n))}function te(n,e){return be(m(e)*u(J)+u(e)*m(J)*m(n))}function Se(n,e,t){return Z(m(n),u(n)*m(e)-$(t)*u(e))}function ye(n,e,t){return be(m(e)*m(t)+u(e)*u(t)*u(n))}function we(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 ve(n){return d*(357.5291+.98560028*n)}function Le(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 Ie(n){let e=ve(n),t=Le(e);return{dec:te(t,0),ra:Me(t,0)}}var w={};w.getPosition=function(n,e,t){let a=d*-t,r=d*e,s=B(n),i=Ie(s),o=we(s,a)-i.ra;return{azimuth:Se(o,r,i.dec),altitude:ye(o,r,i.dec)}};var Q=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){Q.push([n,e,t])};var De=9e-4;function Fe(n,e){return Math.round(n-De-e/(2*V))}function Te(n,e,t){return De+(n+e)/(2*V)+t}function Re(n,e,t){return _e+n+.0053*m(e)-.0069*m(2*t)}function ke(n,e,t){return ge((m(n)-m(e)*m(t))/(u(e)*u(t)))}function Je(n){return-2.076*Math.sqrt(n)/60}function Ve(n,e,t,a,r,s,i){let o=ke(n,t,a),c=Te(o,e,r);return Re(c,s,i)}w.getTimes=function(n,e,t,a=0){let r=d*-t,s=d*e,i=Je(a),o=B(n),c=Fe(o,r),h=Te(0,r,c),b=ve(h),f=Le(b),g=te(f,0),p=Re(h,b,f),L,O,v,S,I,G,R={solarNoon:F(p),nadir:F(p-.5)};for(L=0,O=Q.length;L<O;L+=1)v=Q[L],S=(v[0]+i)*d,I=Ve(S,r,s,g,c,b,f),G=p-(I-p),R[v[1]]=F(G),R[v[2]]=F(I);return R};function xe(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:Me(r,s),dec:te(r,s),dist:i}}w.getMoonPosition=function(n,e,t){let a=d*-t,r=d*e,s=B(n),i=xe(s),o=we(s,a)-i.ra,c=ye(o,r,i.dec),h=Z(m(o),$(r)*u(i.dec)-m(i.dec)*u(o));return c=c+We(c),{azimuth:Se(o,r,i.dec),altitude:c,distance:i.dist,parallacticAngle:h}};w.getMoonIllumination=function(n){let e=B(n||new Date),t=Ie(e),a=xe(e),r=149598e3,s=ge(m(t.dec)*m(a.dec)+u(t.dec)*u(a.dec)*u(t.ra-a.ra)),i=Z(r*m(s),a.dist-r*u(s)),o=Z(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*ee/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,f,g,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,f=(i+c)/2-o,g=(c-i)/2,p=-g/(2*f),L=(f*p+g)*p+o,O=g*g-4*f*o,v=0,O>=0&&(G=Math.sqrt(O)/(Math.abs(f)*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 Ce=w;var ne=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=Ce.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),f=Math.cos(o)*b,g=Math.sin(o)*b;this._sunLight.position.set(g,f,h),this._sunLight.position.multiplyScalar(c),this._sunLight.intensity=Math.max(h,0),this._hemiLight.intensity=Math.max(h*1,.1),this._sunLight.updateMatrixWorld()}},re=ne;var E=j(H(),1);var ae=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}},ie=ae;return je(Be);})();
|