@dvt3d/maplibre-three-plugin 1.3.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +293 -272
- package/dist/index.d.ts +9 -3
- package/dist/index.js +1 -1
- package/dist/mtp.min.js +1 -1
- package/package.json +10 -2
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
|
@@ -1,272 +1,293 @@
|
|
|
1
|
-
# maplibre-three-plugin
|
|
2
|
-
|
|
3
|
-
`maplibre-three-plugin` is a bridge plugin that cleverly
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
import
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
//
|
|
42
|
-
mapScene
|
|
43
|
-
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
- `
|
|
99
|
-
- `
|
|
100
|
-
- `
|
|
101
|
-
- `
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
- **
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
- params
|
|
120
|
-
|
|
121
|
-
- returns
|
|
122
|
-
- `this`
|
|
123
|
-
|
|
124
|
-
- **
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
- params
|
|
129
|
-
- `{THREE.Object3D |
|
|
130
|
-
- returns
|
|
131
|
-
- `this`
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
-
|
|
139
|
-
- `
|
|
140
|
-
|
|
141
|
-
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
- params
|
|
157
|
-
- `{
|
|
158
|
-
- `{Function} completed `:
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
-
|
|
170
|
-
-
|
|
171
|
-
- `
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
- params
|
|
193
|
-
|
|
194
|
-
- returns
|
|
195
|
-
- `
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
-
|
|
227
|
-
-
|
|
228
|
-
- `{
|
|
229
|
-
-
|
|
230
|
-
- `{
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
1
|
+
# maplibre-three-plugin
|
|
2
|
+
|
|
3
|
+
`maplibre-three-plugin` is a bridge plugin that cleverly
|
|
4
|
+
connects [MapLibre GL JS](https://maplibre.org/maplibre-gl-js/docs/) with [Three.js](https://threejs.org/), enabling
|
|
5
|
+
developers to implement 3D rendering and animation on maps.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
npm install @dvt3d/maplibre-three-plugin
|
|
11
|
+
----------------------------------------
|
|
12
|
+
yarn add @dvt3d/maplibre-three-plugin
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quickly Start
|
|
16
|
+
|
|
17
|
+
`maplibre-three-plugin` depends on three, please make sure three is installed before using it.
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
|
|
21
|
+
<div id="map-container"></div>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
|
|
26
|
+
import maplibregl from 'maplibre-gl'
|
|
27
|
+
import * as THREE from 'three'
|
|
28
|
+
import { GLTFLoader } from 'three/addons'
|
|
29
|
+
import * as MTP from '@dvt3d/maplibre-three-plugin'
|
|
30
|
+
|
|
31
|
+
const map = new maplibregl.Map({
|
|
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
|
+
})
|
|
40
|
+
|
|
41
|
+
//init three scene
|
|
42
|
+
const mapScene = new MTP.MapScene(map)
|
|
43
|
+
|
|
44
|
+
//add light
|
|
45
|
+
mapScene.addLight(new THREE.AmbientLight())
|
|
46
|
+
|
|
47
|
+
// add model
|
|
48
|
+
const glTFLoader = new GLTFLoader()
|
|
49
|
+
|
|
50
|
+
glTFLoader.load('./assets/34M_17/34M_17.gltf', (gltf) => {
|
|
51
|
+
let rtcGroup = MTP.Creator.createRTCGroup([148.9819, -35.39847])
|
|
52
|
+
rtcGroup.add(gltf.scene)
|
|
53
|
+
mapScene.addObject(rtcGroup)
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Examples
|
|
58
|
+
|
|
59
|
+
|  |  |  |  |
|
|
60
|
+
|:------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------:|
|
|
61
|
+
| [model](https://dvt3d.github.io/maplibre-three-plugin/examples/index.html) | [sun-light](https://dvt3d.github.io/maplibre-three-plugin/examples/sun-light.html) | [point](https://dvt3d.github.io/maplibre-three-plugin/examples/point.html) | [point-collection](https://dvt3d.github.io/maplibre-three-plugin/examples/point-collection.html) |
|
|
62
|
+
|  |  |  |  |
|
|
63
|
+
| [billboard](https://dvt3d.github.io/maplibre-three-plugin/examples/billboard.html) | [div-icon](https://dvt3d.github.io/maplibre-three-plugin/examples/div-icon.html) | [3d-tiles](https://dvt3d.github.io/maplibre-three-plugin/examples/3d-tiles.html) | [3d-tiles-osgb](https://dvt3d.github.io/maplibre-three-plugin/examples/3d-tiles-osgb.html) |
|
|
64
|
+
|  |  |  |  |
|
|
65
|
+
| [3d-tiles-cesium-ion](https://dvt3d.github.io/maplibre-three-plugin/examples/3d-tiles-cesium-ion.html) | [3d-gs-cesium-ion](https://dvt3d.github.io/maplibre-three-plugin/examples/3d-gs-cesium-ion.html) | [3d-gs-splat](https://dvt3d.github.io/maplibre-three-plugin/examples/3d-gs-splat.html) | [heat-map](https://dvt3d.github.io/maplibre-three-plugin/examples/heat-map.html) |
|
|
66
|
+
|
|
67
|
+
## Docs
|
|
68
|
+
|
|
69
|
+
### MapScene
|
|
70
|
+
|
|
71
|
+
#### examples
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
const mapScene = new MapScene(map)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### creation
|
|
78
|
+
|
|
79
|
+
- constructor(map,[options])
|
|
80
|
+
- params
|
|
81
|
+
- `{Map} map ` : map instance
|
|
82
|
+
- `{Object} options ` : config
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
// config
|
|
86
|
+
Object({
|
|
87
|
+
scene: null, //THREE.Scene,if not passed in, the default scene will be used
|
|
88
|
+
camera: null, //THREE.Camera, if not passed in, the default camera will be used
|
|
89
|
+
renderer: null, //THREE.WebGLRenderer if not passed in, the default renderer will be used
|
|
90
|
+
preserveDrawingBuffer: false,
|
|
91
|
+
renderLoop: (ins) => {
|
|
92
|
+
} //Frame animation rendering function, if not passed in, the default function will be used,the params is an instance for MapScene
|
|
93
|
+
})
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### event hooks
|
|
97
|
+
|
|
98
|
+
- `preReset` : A hook that calls `renderer.resetState` before each animation frame
|
|
99
|
+
- `postReset`: A hook that calls `renderer.resetState` after each animation frame
|
|
100
|
+
- `preRender`: A hook that calls `renderer.render` before each animation frame
|
|
101
|
+
- `postRender`: A hook that calls `renderer.render` after each animation frame
|
|
102
|
+
|
|
103
|
+
#### properties
|
|
104
|
+
|
|
105
|
+
- `{maplibregl.Map} map ` : `readonly`
|
|
106
|
+
- `{HTMLCanvasElement} canvas ` : `readonly`
|
|
107
|
+
- `{THREE.Camera} camera `: `readonly`
|
|
108
|
+
- `{THREE.Sence} scene` : `readonly`
|
|
109
|
+
- `{THREE.Group} lights`: `readonly`
|
|
110
|
+
- `{THREE.Group} world` : `readonly`
|
|
111
|
+
- `{THREE.WebGLRenderer} renderer` : `readonly`
|
|
112
|
+
|
|
113
|
+
#### methods
|
|
114
|
+
|
|
115
|
+
- **_addLight(light)_**
|
|
116
|
+
|
|
117
|
+
Add light to the scene, support custom light objects, but the custom light objects need to support the `delegate`
|
|
118
|
+
property, and the `delegate` type is `THREE.Object3D`
|
|
119
|
+
- params
|
|
120
|
+
- `{THREE.Object3D | Sun | CustomLight } light `
|
|
121
|
+
- returns
|
|
122
|
+
- `this`
|
|
123
|
+
|
|
124
|
+
- **_removeLight(light)_**
|
|
125
|
+
|
|
126
|
+
Remove light from the scene
|
|
127
|
+
|
|
128
|
+
- params
|
|
129
|
+
- `{THREE.Object3D | Sun | CustomLight } light `
|
|
130
|
+
- returns
|
|
131
|
+
- `this`
|
|
132
|
+
|
|
133
|
+
- **_addObject(object)_**
|
|
134
|
+
|
|
135
|
+
Add an object to world,support custom object, but the custom object need to support the `delegate` property, and the
|
|
136
|
+
`delegate` type is `THREE.Object3D`
|
|
137
|
+
|
|
138
|
+
- params
|
|
139
|
+
- `{THREE.Object3D | CustomObject} object `
|
|
140
|
+
- returns
|
|
141
|
+
- `this`
|
|
142
|
+
- **_removeObject(object)_**
|
|
143
|
+
|
|
144
|
+
Remove an object from world
|
|
145
|
+
|
|
146
|
+
- params
|
|
147
|
+
- `{THREE.Object3D | CustomObject} object `
|
|
148
|
+
- returns
|
|
149
|
+
- `this`
|
|
150
|
+
|
|
151
|
+
- **_flyTo(target,[completed],[duration])_**
|
|
152
|
+
|
|
153
|
+
Fly the map to the provided target over a period of time, the completion callback will be triggered when the flight is
|
|
154
|
+
complete, the target needs to contain the `position` property
|
|
155
|
+
|
|
156
|
+
- params
|
|
157
|
+
- `{THREE.Object3D | CustomObject} target `
|
|
158
|
+
- `{Function} completed `:
|
|
159
|
+
- `{Number} duration `:
|
|
160
|
+
- returns
|
|
161
|
+
- `this`
|
|
162
|
+
|
|
163
|
+
- **_zoomTo(target,[completed])_**
|
|
164
|
+
|
|
165
|
+
Zoom the map to the provided target
|
|
166
|
+
|
|
167
|
+
- params
|
|
168
|
+
- `{Ojbect} target `
|
|
169
|
+
- `{Function} completed `:
|
|
170
|
+
- returns
|
|
171
|
+
- `this`
|
|
172
|
+
|
|
173
|
+
- **_on(type,callback)_**
|
|
174
|
+
- params
|
|
175
|
+
- `{String} type `
|
|
176
|
+
- `{Function} callback `:
|
|
177
|
+
- returns
|
|
178
|
+
- `this`
|
|
179
|
+
|
|
180
|
+
- **_off(type,callback)_**
|
|
181
|
+
- params
|
|
182
|
+
- `{String} type `
|
|
183
|
+
- `{Function} callback `:
|
|
184
|
+
- returns
|
|
185
|
+
- `this`
|
|
186
|
+
|
|
187
|
+
- **_layerBeforeTo([beforeId])_**
|
|
188
|
+
|
|
189
|
+
Moves the three to a different z-position, If beforeId is omitted, the layer will be appended to the end of the layers
|
|
190
|
+
array and appear above all other layers on the map.
|
|
191
|
+
|
|
192
|
+
- params
|
|
193
|
+
- `{String} beforeId `
|
|
194
|
+
- returns
|
|
195
|
+
- `this`
|
|
196
|
+
|
|
197
|
+
### SceneTransform
|
|
198
|
+
|
|
199
|
+
#### examples
|
|
200
|
+
|
|
201
|
+
```js
|
|
202
|
+
const scale = new SceneTransform.projectedUnitsPerMeter(24)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
#### static methods
|
|
206
|
+
|
|
207
|
+
- **_projectedMercatorUnitsPerMeter()_**
|
|
208
|
+
- params
|
|
209
|
+
- returns
|
|
210
|
+
- `{Number} value`
|
|
211
|
+
|
|
212
|
+
- **_projectedUnitsPerMeter(lat)_**
|
|
213
|
+
- params
|
|
214
|
+
- `{Number} lat `
|
|
215
|
+
- returns
|
|
216
|
+
- `{Number} value`
|
|
217
|
+
|
|
218
|
+
- **_lngLatToVector3(lng, [lat], [alt] )_**
|
|
219
|
+
- params
|
|
220
|
+
- `{Array | Number} lng `
|
|
221
|
+
- `{Number} lat `
|
|
222
|
+
- `{Number} alt `
|
|
223
|
+
- returns
|
|
224
|
+
- `{THREE.Vector3} v`
|
|
225
|
+
|
|
226
|
+
- **_vector3ToLngLat(v)_**
|
|
227
|
+
- params
|
|
228
|
+
- `{THREE.Vector3} v`
|
|
229
|
+
- returns
|
|
230
|
+
- `{Array} value`
|
|
231
|
+
|
|
232
|
+
### Sun
|
|
233
|
+
|
|
234
|
+
#### examples
|
|
235
|
+
|
|
236
|
+
```js
|
|
237
|
+
const sun = new Sun()
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
#### creation
|
|
241
|
+
|
|
242
|
+
- constructor()
|
|
243
|
+
- params
|
|
244
|
+
|
|
245
|
+
#### properties
|
|
246
|
+
|
|
247
|
+
- `{THREE.Group} delegate ` : `readonly`
|
|
248
|
+
- `{Boolean} castShadow `
|
|
249
|
+
- `{Date || String} currentTime `
|
|
250
|
+
- `{THREE.DirectionalLight} sunLight` : `readonly`
|
|
251
|
+
- `{THREE.HemisphereLight} hemiLight`: `readonly`
|
|
252
|
+
|
|
253
|
+
#### methods
|
|
254
|
+
|
|
255
|
+
- **_update(frameState)_**
|
|
256
|
+
- params
|
|
257
|
+
- `{Object} frameState`:
|
|
258
|
+
- returns
|
|
259
|
+
- `this`
|
|
260
|
+
|
|
261
|
+
### Creator
|
|
262
|
+
|
|
263
|
+
#### examples
|
|
264
|
+
|
|
265
|
+
```js
|
|
266
|
+
const rtcGroup = Creator.createRTCGroup([-1000, 0, 0])
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
#### static methods
|
|
270
|
+
|
|
271
|
+
- **_createRTCGroup(center, [rotation], [scale])_**
|
|
272
|
+
- params
|
|
273
|
+
- `{Array} center`
|
|
274
|
+
- `{Array} rotation`: default value is [0,0,0]
|
|
275
|
+
- `{Array} scale`: scale corresponding to the current latitude
|
|
276
|
+
- returns
|
|
277
|
+
- `{THREE.Group} rtc`
|
|
278
|
+
|
|
279
|
+
- **_createMercatorRTCGroup(center, [rotation], [scale])_**
|
|
280
|
+
- params
|
|
281
|
+
- `{Array} center`
|
|
282
|
+
- `{Array} rotation`: default value is [0,0,0]
|
|
283
|
+
- `{Array} scale`: scale corresponding to the current latitude
|
|
284
|
+
- returns
|
|
285
|
+
- `{THREE.Group} rtc`
|
|
286
|
+
|
|
287
|
+
- **_createShadowGround(center, [width], [height])_**
|
|
288
|
+
- params
|
|
289
|
+
- `{THREE.Vector3} center`
|
|
290
|
+
- `{Number} width`: default value is 100
|
|
291
|
+
- `{Number} height` : default value is 100
|
|
292
|
+
- returns
|
|
293
|
+
- `{Object} rtc`
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ interface IMap {
|
|
|
19
19
|
pitch: number;
|
|
20
20
|
duration: number;
|
|
21
21
|
}): void;
|
|
22
|
+
moveLayer(id: String, beforeId?: String): void;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* Configuration options for initializing a MapScene
|
|
@@ -184,6 +185,11 @@ declare class MapScene {
|
|
|
184
185
|
* @returns {MapScene}
|
|
185
186
|
*/
|
|
186
187
|
off(type: string, callback: () => void): MapScene;
|
|
188
|
+
/**
|
|
189
|
+
*
|
|
190
|
+
* @param beforeId
|
|
191
|
+
*/
|
|
192
|
+
layerBeforeTo(beforeId?: String): MapScene;
|
|
187
193
|
}
|
|
188
194
|
|
|
189
195
|
declare class SceneTransform {
|
|
@@ -272,14 +278,14 @@ declare class Creator {
|
|
|
272
278
|
* @param rotation
|
|
273
279
|
* @param scale
|
|
274
280
|
*/
|
|
275
|
-
static createRTCGroup(center: number
|
|
281
|
+
static createRTCGroup(center: number[], rotation: number[], scale: number[]): Group;
|
|
276
282
|
/**
|
|
277
283
|
*
|
|
278
284
|
* @param center
|
|
279
285
|
* @param rotation
|
|
280
286
|
* @param scale
|
|
281
287
|
*/
|
|
282
|
-
static createMercatorRTCGroup(center: number
|
|
288
|
+
static createMercatorRTCGroup(center: number[], rotation: number[], scale: number[]): Group;
|
|
283
289
|
/**
|
|
284
290
|
*
|
|
285
291
|
* @param center
|
|
@@ -287,7 +293,7 @@ declare class Creator {
|
|
|
287
293
|
* @param height
|
|
288
294
|
* @returns {Mesh}
|
|
289
295
|
*/
|
|
290
|
-
static createShadowGround(center: number
|
|
296
|
+
static createShadowGround(center: number[], width?: number, height?: number): Mesh;
|
|
291
297
|
}
|
|
292
298
|
|
|
293
299
|
export { Creator, MapScene, SceneTransform, Sun };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Group as re,PerspectiveCamera as Ie,Scene as De,WebGLRenderer as Te,EventDispatcher as Re,Box3 as xe,Vector3 as Ce}from"three";var R=63710088e-1,C=2*Math.PI*R,l=Math.PI/180,Ve=180/Math.PI,P=1024e3/C,K=512;var Z=class{static clamp(e,t,r){return Math.min(r,Math.max(t,e))}static makePerspectiveMatrix(e,t,r,n){let s=1/Math.tan(e/2),i=1/(r-n);return[s/t,0,0,0,0,s,0,0,0,0,(n+r)*i,-1,0,0,2*n*r*i,0]}static mercatorXFromLng(e){return(180+e)/360}static mercatorYFromLat(e){return(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+e*Math.PI/360)))/360}static getViewInfo(e,t,r){let n=e.fov*l,s=e.pitch*l,i=null;if(Array.isArray(t)&&(i={lng:t[0],lat:t[1],alt:t[2]||0}),typeof t=="string"){let p=t.split(",");i={lng:+p[0],lat:+p[1],alt:+p[2]||0}}let c=Math.max(r.x,r.y,r.z)/(2*Math.tan(n/2))*Math.cos(s)+i.alt,h=Math.abs(Math.cos(s)*e.cameraToCenterDistance),b=C*Math.abs(Math.cos(i.lat*l)),g=h/c*b,f=Math.round(Math.log2(g/e.tileSize));return{center:[i.lng,i.lat],cameraHeight:c,zoom:f}}static getHeightByZoom(e,t,r,n){let s=Math.abs(Math.cos(n*l)*e.cameraToCenterDistance),i=C*Math.abs(Math.cos(r*l)),o=Math.pow(2,t)*e.tileSize;return s*i/o}static getZoomByHeight(e,t,r,n){let s=Math.abs(Math.cos(n*l)*e.cameraToCenterDistance),i=C*Math.abs(Math.cos(r*l)),o=s/t*i;return Math.round(Math.log2(o/e.tileSize))}},I=Z;import{Matrix4 as y,Vector3 as ve}from"three";var Q=new y,$=new y,ee=85.051129,F=class{_map;_world;_camera;_translateCenter;_worldSizeRatio;constructor(e,t,r){this._map=e,this._world=t,this._camera=r,this._translateCenter=new y().makeTranslation(1024e3/2,-1024e3/2,0),this._worldSizeRatio=K/1024e3,this._map.on("move",()=>{this.syncCamera(!1)}),this._map.on("resize",()=>{this.syncCamera(!0)})}syncCamera(e){let t=this._map.transform,r=t.pitch*l,n=t.bearing*l;if(e){let f=t.fov*l,p=t.centerOffset||new ve;this._camera.aspect=t.width/t.height,Q.elements=I.makePerspectiveMatrix(f,this._camera.aspect,t.height/50,t.farZ),this._camera.projectionMatrix=Q,this._camera.projectionMatrix.elements[8]=-p.x*2/t.width,this._camera.projectionMatrix.elements[9]=p.y*2/t.height}$.makeTranslation(0,0,t.cameraToCenterDistance);let s=new y().premultiply($).premultiply(new y().makeRotationX(r)).premultiply(new y().makeRotationZ(-n));t.elevation&&(s.elements[14]=t.cameraToCenterDistance*Math.cos(r)),this._camera.matrixWorld.copy(s);let i=t.scale*this._worldSizeRatio,o=new y().makeScale(i,i,i),c=t.x,h=t.y;if(!c||!h){let f=t.center,p=I.clamp(f.lat,-ee,ee);c=I.mercatorXFromLng(f.lng)*t.worldSize,h=I.mercatorYFromLat(p)*t.worldSize}let b=new y().makeTranslation(-c,h,0),g=new y().makeRotationZ(Math.PI);this._world.matrix=new y().premultiply(g).premultiply(this._translateCenter).premultiply(o).premultiply(b)}},te=F;var k=class{_id;_mapScene;_cameraSync;constructor(e,t){this._id=e,this._mapScene=t,this._cameraSync=new te(this._mapScene.map,this._mapScene.world,this._mapScene.camera)}get id(){return this._id}get type(){return"custom"}get renderingMode(){return"3d"}onAdd(){this._cameraSync.syncCamera(!0)}render(){this._mapScene.render()}onRemove(){this._cameraSync=null,this._mapScene=null}},ne=k;import{Vector3 as Le}from"three";var J=class{static projectedMercatorUnitsPerMeter(){return this.projectedUnitsPerMeter(0)}static projectedUnitsPerMeter(e){return Math.abs(1024e3/Math.cos(l*e)/C)}static lngLatToVector3(e,t,r){let n=[0,0,0];return Array.isArray(e)?(n=[-R*l*e[0]*P,-R*Math.log(Math.tan(Math.PI*.25+.5*l*e[1]))*P],e[2]?n.push(e[2]*this.projectedUnitsPerMeter(e[1])):n.push(0)):(n=[-R*l*e*P,-R*Math.log(Math.tan(Math.PI*.25+.5*l*(t||0)))*P],r?n.push(r*this.projectedUnitsPerMeter(t||0)):n.push(0)),new Le(n[0],n[1],n[2])}static vector3ToLngLat(e){let t=[0,0,0];return e&&(t[0]=-e.x/(R*l*P),t[1]=2*(Math.atan(Math.exp(e.y/(P*-R)))-Math.PI/4)/l,t[2]=e.z/this.projectedUnitsPerMeter(t[1])),t}},w=J;var Pe={scene:null,camera:null,renderer:null,renderLoop:null,preserveDrawingBuffer:!1},O=class{_map;_options;_canvas;_scene;_camera;_renderer;_lights;_world;_event;constructor(e,t={}){if(!e)throw"missing map";this._map=e,this._options={...Pe,...t},this._canvas=e.getCanvas(),this._scene=this._options.scene||new De,this._camera=this._options.camera||new Ie(this._map.transform.fov,this._map.transform.width/this._map.transform.height,.001,1e21),this._camera.matrixAutoUpdate=!1,this._renderer=this._options.renderer||new Te({alpha:!0,antialias:!0,preserveDrawingBuffer:this._options.preserveDrawingBuffer,canvas:this._canvas,context:this._canvas.getContext("webgl2")}),this._renderer.setPixelRatio(window.devicePixelRatio),this._renderer.setSize(this._canvas.clientWidth,this._canvas.clientHeight),this._renderer.autoClear=!1,this._lights=new re,this._lights.name="lights",this._scene.add(this._lights),this._world=new re,this._world.name="world",this._world.userData={isWorld:!0,name:"world"},this._world.position.set(1024e3/2,1024e3/2,0),this._world.matrixAutoUpdate=!1,this._scene.add(this._world),this._map.on("render",this._onMapRender.bind(this)),this._event=new Re}get map(){return this._map}get canvas(){return this._canvas}get camera(){return this._camera}get scene(){return this._scene}get lights(){return this._lights}get world(){return this._world}get renderer(){return this._renderer}_onMapRender(){this._map.getLayer("map_scene_layer")||this._map.addLayer(new ne("map_scene_layer",this))}render(){if(this._options.renderLoop)this._options.renderLoop(this);else{let e={center:this._map.getCenter(),scene:this._scene,camera:this._camera,renderer:this._renderer};this._event.dispatchEvent({type:"preReset",frameState:e}),this.renderer.resetState(),this._event.dispatchEvent({type:"postReset",frameState:e}),this._event.dispatchEvent({type:"preRender",frameState:e}),this.renderer.render(this._scene,this._camera),this._event.dispatchEvent({type:"postRender",frameState:e})}return this}addLight(e){return this._lights.add(e.delegate||e),this}removeLight(e){return this._lights.remove(e.delegate||e),this}addObject(e){let t="delegate"in e?e.delegate:e;return this._world.add(t),this}removeObject(e){let t="delegate"in e?e.delegate:e;return this._world.remove(t),t.traverse(r=>{r.geometry&&r.geometry.dispose(),r.material&&(Array.isArray(r.material)?r.material.forEach(n=>n.dispose()):r.material.dispose()),r.texture&&r.texture.dispose()}),this}getViewPosition(){let e=this._map.transform,t=e.center;return{position:[t.lng,t.lat,I.getHeightByZoom(e,e.zoom,t.lat,e.pitch)],heading:e.bearing,pitch:e.pitch}}flyTo(e,t,r){if(e&&e.position){r&&this._map.once("moveend",r);let n=e.size;n||(n=new Ce,new xe().setFromObject(e.delegate||e,!0).getSize(n));let s=I.getViewInfo(this._map.transform,w.vector3ToLngLat(e.position),n);this._map.flyTo({center:s.center,zoom:s.zoom,duration:(t||3)*1e3})}return this}zoomTo(e,t){return this.flyTo(e,0,t)}flyToPosition(e,t=[0,0,0],r,n=3){return r&&this._map.once("moveend",r),this._map.flyTo({center:[e[0],e[1]],zoom:I.getZoomByHeight(this._map.transform,e[2],e[1],t[1]||0),bearing:t[0],pitch:t[1],duration:n*1e3}),this}zoomToPosition(e,t=[0,0,0],r){return this.flyToPosition(e,t,r,0)}on(e,t){return this._event.addEventListener(e,t),this}off(e,t){return this._event.removeEventListener(e,t),this}};import{Group as je,DirectionalLight as Ue,HemisphereLight as We,Color as Se}from"three";var U=Math.PI,m=Math.sin,u=Math.cos,B=Math.tan,ae=Math.asin,A=Math.atan2,ie=Math.acos,d=U/180,N=1e3*60*60*24,se=2440588,oe=2451545;function ze(a){return a.valueOf()/N-.5+se}function G(a){return new Date((a+.5-se)*N)}function W(a){return ze(a)-oe}var j=d*23.4397;function me(a,e){return A(m(a)*u(j)-B(e)*m(j),u(a))}function X(a,e){return ae(m(e)*u(j)+u(e)*m(j)*m(a))}function ce(a,e,t){return A(m(a),u(a)*m(e)-B(t)*u(e))}function ue(a,e,t){return ae(m(e)*m(t)+u(e)*u(t)*u(a))}function he(a,e){return d*(280.16+360.9856235*a)-e}function Ee(a){return a<0&&(a=0),2967e-7/Math.tan(a+.00312536/(a+.08901179))}function le(a){return d*(357.5291+.98560028*a)}function pe(a){let e=d*(1.9148*m(a)+.02*m(2*a)+3e-4*m(3*a)),t=d*102.9372;return a+e+t+U}function de(a){let e=le(a),t=pe(e);return{dec:X(t,0),ra:me(t,0)}}var M={};M.getPosition=function(a,e,t){let r=d*-t,n=d*e,s=W(a),i=de(s),o=he(s,r)-i.ra;return{azimuth:ce(o,n,i.dec),altitude:ue(o,n,i.dec)}};var V=M.times=[[-.833,"sunrise","sunset"],[-.3,"sunriseEnd","sunsetStart"],[-6,"dawn","dusk"],[-12,"nauticalDawn","nauticalDusk"],[-18,"nightEnd","night"],[6,"goldenHourEnd","goldenHour"]];M.addTime=function(a,e,t){V.push([a,e,t])};var be=9e-4;function Ae(a,e){return Math.round(a-be-e/(2*U))}function fe(a,e,t){return be+(a+e)/(2*U)+t}function ge(a,e,t){return oe+a+.0053*m(e)-.0069*m(2*t)}function Oe(a,e,t){return ie((m(a)-m(e)*m(t))/(u(e)*u(t)))}function Ge(a){return-2.076*Math.sqrt(a)/60}function He(a,e,t,r,n,s,i){let o=Oe(a,t,r),c=fe(o,e,n);return ge(c,s,i)}M.getTimes=function(a,e,t,r=0){let n=d*-t,s=d*e,i=Ge(r),o=W(a),c=Ae(o,n),h=fe(0,n,c),b=le(h),g=pe(b),f=X(g,0),p=ge(h,b,g),v,z,S,_,L,E,D={solarNoon:G(p),nadir:G(p-.5)};for(v=0,z=V.length;v<z;v+=1)S=V[v],_=(S[0]+i)*d,L=He(_,n,s,f,c,b,g),E=p-(L-p),D[S[1]]=G(E),D[S[2]]=G(L);return D};function _e(a){let e=d*(218.316+13.176396*a),t=d*(134.963+13.064993*a),r=d*(93.272+13.22935*a),n=e+d*6.289*m(t),s=d*5.128*m(r),i=385001-20905*u(t);return{ra:me(n,s),dec:X(n,s),dist:i}}M.getMoonPosition=function(a,e,t){let r=d*-t,n=d*e,s=W(a),i=_e(s),o=he(s,r)-i.ra,c=ue(o,n,i.dec),h=A(m(o),B(n)*u(i.dec)-m(i.dec)*u(o));return c=c+Ee(c),{azimuth:ce(o,n,i.dec),altitude:c,distance:i.dist,parallacticAngle:h}};M.getMoonIllumination=function(a){let e=W(a||new Date),t=de(e),r=_e(e),n=149598e3,s=ie(m(t.dec)*m(r.dec)+u(t.dec)*u(r.dec)*u(t.ra-r.ra)),i=A(n*m(s),r.dist-n*u(s)),o=A(u(t.dec)*m(t.ra-r.ra),m(t.dec)*u(r.dec)-u(t.dec)*m(r.dec)*u(t.ra-r.ra));return{fraction:(1+u(i))/2,phase:.5+.5*i*(o<0?-1:1)/Math.PI,angle:o}};function H(a,e){return new Date(a.valueOf()+e*N/24)}M.getMoonTimes=function(a,e,t,r=!1){let n=new Date(a);r?n.setUTCHours(0,0,0,0):n.setHours(0,0,0,0);let s=.133*d,i=M.getMoonPosition(n,e,t).altitude-s,o,c,h,b,g,f,p,v,z,S,_,L,E;for(let T=1;T<=24&&(o=M.getMoonPosition(H(n,T),e,t).altitude-s,c=M.getMoonPosition(H(n,T+1),e,t).altitude-s,g=(i+c)/2-o,f=(c-i)/2,p=-f/(2*g),v=(g*p+f)*p+o,z=f*f-4*g*o,S=0,z>=0&&(E=Math.sqrt(z)/(Math.abs(g)*2),_=p-E,L=p+E,Math.abs(_)<=1&&S++,Math.abs(L)<=1&&S++,_<-1&&(_=L)),S===1?i<0?h=T+_:b=T+_:S===2&&(h=T+(v<0?L:_),b=T+(v<0?_:L)),!(h&&b));T+=2)i=c;let D={};return h&&(D.rise=H(n,h)),b&&(D.set=H(n,b)),!h&&!b&&(D[v>0?"alwaysUp":"alwaysDown"]=!0),D};var Me=M;var Y=class{_delegate;_sunLight;_hemiLight;_currentTime;constructor(){this._delegate=new je,this._delegate.name="Sun",this._sunLight=new Ue(16777215,1),this._hemiLight=new We(new Se(16777215),new Se(16777215),.6),this._hemiLight.color.setHSL(.661,.96,.12),this._hemiLight.groundColor.setHSL(.11,.96,.14),this._hemiLight.position.set(0,0,50),this._delegate.add(this._sunLight),this._delegate.add(this._hemiLight),this._currentTime=new Date().getTime()}get delegate(){return this._delegate}set castShadow(e){this._sunLight.castShadow=e}get castShadow(){return this._sunLight.castShadow}set currentTime(e){this._currentTime=e}get currentTime(){return this._currentTime}get sunLight(){return this._sunLight}get hemiLight(){return this._hemiLight}setShadow(e={}){return this._sunLight.shadow.radius=e.radius||2,this._sunLight.shadow.mapSize.width=e.mapSize?e.mapSize[0]:8192,this._sunLight.shadow.mapSize.height=e.mapSize?e.mapSize[1]:8192,this._sunLight.shadow.camera.top=this._sunLight.shadow.camera.right=e.topRight||1e3,this._sunLight.shadow.camera.bottom=this._sunLight.shadow.camera.left=e.bottomLeft||-1e3,this._sunLight.shadow.camera.near=e.near||1,this._sunLight.shadow.camera.far=e.far||1e8,this._sunLight.shadow.camera.visible=!0,this}update(e){let r=new Date(this._currentTime||new Date().getTime()),n=e.center,s=Me.getPosition(r,n.lat,n.lng),i=s.altitude,o=Math.PI+s.azimuth,c=1024e3/2,h=Math.sin(i),b=Math.cos(i),g=Math.cos(o)*b,f=Math.sin(o)*b;this._sunLight.position.set(f,g,h),this._sunLight.position.multiplyScalar(c),this._sunLight.intensity=Math.max(h,0),this._hemiLight.intensity=Math.max(h*1,.1),this._sunLight.updateMatrixWorld()}},ye=Y;import{Group as Ze,Mesh as Fe,PlaneGeometry as ke,ShadowMaterial as Je}from"three";var q=class{static createRTCGroup(e,t,r){let n=new Ze;if(n.name="rtc",n.position.copy(w.lngLatToVector3(e)),t?(n.rotateX(t[0]||0),n.rotateY(t[1]||0),n.rotateZ(t[2]||0)):(n.rotateX(Math.PI/2),n.rotateY(Math.PI)),r)n.scale.set(r[0]||1,r[1]||1,r[2]||1);else{let s=1;Array.isArray(e)&&(s=w.projectedUnitsPerMeter(e[1])),n.scale.set(s,s,s)}return n}static createMercatorRTCGroup(e,t,r){let n=this.createRTCGroup(e,t,r);if(!r){let s=1,i=w.projectedMercatorUnitsPerMeter();Array.isArray(e)&&(s=w.projectedUnitsPerMeter(e[1])),n.scale.set(i,i,s)}return n}static createShadowGround(e,t,r){let n=new ke(t||100,r||100),s=new Je({opacity:.5,transparent:!0}),i=new Fe(n,s);return i.position.copy(w.lngLatToVector3(e)),i.receiveShadow=!0,i.name="shadow-ground",i}},we=q;export{we as Creator,O as MapScene,w as SceneTransform,ye as Sun};
|
|
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};
|
package/dist/mtp.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var MTP=(()=>{var Ce=Object.create;var Z=Object.defineProperty;var Pe=Object.getOwnPropertyDescriptor;var Ee=Object.getOwnPropertyNames;var ze=Object.getPrototypeOf,Ae=Object.prototype.hasOwnProperty;var Oe=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Ge=(n,e)=>{for(var t in e)Z(n,t,{get:e[t],enumerable:!0})},ie=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ee(e))!Ae.call(n,r)&&r!==t&&Z(n,r,{get:()=>e[r],enumerable:!(a=Pe(e,r))||a.enumerable});return n};var j=(n,e,t)=>(t=n!=null?Ce(ze(n)):{},ie(e||!n||!n.__esModule?Z(t,"default",{value:n,enumerable:!0}):t,n)),He=n=>ie(Z({},"__esModule",{value:!0}),n);var H=Oe((Ne,se)=>{"use strict";se.exports=THREE});var Ve={};Ge(Ve,{Creator:()=>ae,MapScene:()=>U,SceneTransform:()=>y,Sun:()=>ne});var _=j(H(),1);var C=63710088e-1,z=2*Math.PI*C,l=Math.PI/180,Xe=180/Math.PI,A=1024e3/z,oe=512;var N=class{static clamp(e,t,a){return Math.min(a,Math.max(t,e))}static makePerspectiveMatrix(e,t,a,r){let s=1/Math.tan(e/2),i=1/(a-r);return[s/t,0,0,0,0,s,0,0,0,0,(r+a)*i,-1,0,0,2*r*a*i,0]}static mercatorXFromLng(e){return(180+e)/360}static mercatorYFromLat(e){return(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+e*Math.PI/360)))/360}static getViewInfo(e,t,a){let r=e.fov*l,s=e.pitch*l,i=null;if(Array.isArray(t)&&(i={lng:t[0],lat:t[1],alt:t[2]||0}),typeof t=="string"){let p=t.split(",");i={lng:+p[0],lat:+p[1],alt:+p[2]||0}}let c=Math.max(a.x,a.y,a.z)/(2*Math.tan(r/2))*Math.cos(s)+i.alt,h=Math.abs(Math.cos(s)*e.cameraToCenterDistance),b=z*Math.abs(Math.cos(i.lat*l)),g=h/c*b,f=Math.round(Math.log2(g/e.tileSize));return{center:[i.lng,i.lat],cameraHeight:c,zoom:f}}static getHeightByZoom(e,t,a,r){let s=Math.abs(Math.cos(r*l)*e.cameraToCenterDistance),i=z*Math.abs(Math.cos(a*l)),o=Math.pow(2,t)*e.tileSize;return s*i/o}static getZoomByHeight(e,t,a,r){let s=Math.abs(Math.cos(r*l)*e.cameraToCenterDistance),i=z*Math.abs(Math.cos(a*l)),o=s/t*i;return Math.round(Math.log2(o/e.tileSize))}},D=N;var M=j(H(),1),me=new M.Matrix4,ce=new M.Matrix4,ue=85.051129,X=class{_map;_world;_camera;_translateCenter;_worldSizeRatio;constructor(e,t,a){this._map=e,this._world=t,this._camera=a,this._translateCenter=new M.Matrix4().makeTranslation(1024e3/2,-1024e3/2,0),this._worldSizeRatio=oe/1024e3,this._map.on("move",()=>{this.syncCamera(!1)}),this._map.on("resize",()=>{this.syncCamera(!0)})}syncCamera(e){let t=this._map.transform,a=t.pitch*l,r=t.bearing*l;if(e){let f=t.fov*l,p=t.centerOffset||new M.Vector3;this._camera.aspect=t.width/t.height,me.elements=D.makePerspectiveMatrix(f,this._camera.aspect,t.height/50,t.farZ),this._camera.projectionMatrix=me,this._camera.projectionMatrix.elements[8]=-p.x*2/t.width,this._camera.projectionMatrix.elements[9]=p.y*2/t.height}ce.makeTranslation(0,0,t.cameraToCenterDistance);let s=new M.Matrix4().premultiply(ce).premultiply(new M.Matrix4().makeRotationX(a)).premultiply(new M.Matrix4().makeRotationZ(-r));t.elevation&&(s.elements[14]=t.cameraToCenterDistance*Math.cos(a)),this._camera.matrixWorld.copy(s);let i=t.scale*this._worldSizeRatio,o=new M.Matrix4().makeScale(i,i,i),c=t.x,h=t.y;if(!c||!h){let f=t.center,p=D.clamp(f.lat,-ue,ue);c=D.mercatorXFromLng(f.lng)*t.worldSize,h=D.mercatorYFromLat(p)*t.worldSize}let b=new M.Matrix4().makeTranslation(-c,h,0),g=new M.Matrix4().makeRotationZ(Math.PI);this._world.matrix=new M.Matrix4().premultiply(g).premultiply(this._translateCenter).premultiply(o).premultiply(b)}},he=X;var Y=class{_id;_mapScene;_cameraSync;constructor(e,t){this._id=e,this._mapScene=t,this._cameraSync=new he(this._mapScene.map,this._mapScene.world,this._mapScene.camera)}get id(){return this._id}get type(){return"custom"}get renderingMode(){return"3d"}onAdd(){this._cameraSync.syncCamera(!0)}render(){this._mapScene.render()}onRemove(){this._cameraSync=null,this._mapScene=null}},le=Y;var pe=j(H(),1);var q=class{static projectedMercatorUnitsPerMeter(){return this.projectedUnitsPerMeter(0)}static projectedUnitsPerMeter(e){return Math.abs(1024e3/Math.cos(l*e)/z)}static lngLatToVector3(e,t,a){let r=[0,0,0];return Array.isArray(e)?(r=[-C*l*e[0]*A,-C*Math.log(Math.tan(Math.PI*.25+.5*l*e[1]))*A],e[2]?r.push(e[2]*this.projectedUnitsPerMeter(e[1])):r.push(0)):(r=[-C*l*e*A,-C*Math.log(Math.tan(Math.PI*.25+.5*l*(t||0)))*A],a?r.push(a*this.projectedUnitsPerMeter(t||0)):r.push(0)),new pe.Vector3(r[0],r[1],r[2])}static vector3ToLngLat(e){let t=[0,0,0];return e&&(t[0]=-e.x/(C*l*A),t[1]=2*(Math.atan(Math.exp(e.y/(A*-C)))-Math.PI/4)/l,t[2]=e.z/this.projectedUnitsPerMeter(t[1])),t}},y=q;var je={scene:null,camera:null,renderer:null,renderLoop:null,preserveDrawingBuffer:!1},U=class{_map;_options;_canvas;_scene;_camera;_renderer;_lights;_world;_event;constructor(e,t={}){if(!e)throw"missing map";this._map=e,this._options={...je,...t},this._canvas=e.getCanvas(),this._scene=this._options.scene||new _.Scene,this._camera=this._options.camera||new _.PerspectiveCamera(this._map.transform.fov,this._map.transform.width/this._map.transform.height,.001,1e21),this._camera.matrixAutoUpdate=!1,this._renderer=this._options.renderer||new _.WebGLRenderer({alpha:!0,antialias:!0,preserveDrawingBuffer:this._options.preserveDrawingBuffer,canvas:this._canvas,context:this._canvas.getContext("webgl2")}),this._renderer.setPixelRatio(window.devicePixelRatio),this._renderer.setSize(this._canvas.clientWidth,this._canvas.clientHeight),this._renderer.autoClear=!1,this._lights=new _.Group,this._lights.name="lights",this._scene.add(this._lights),this._world=new _.Group,this._world.name="world",this._world.userData={isWorld:!0,name:"world"},this._world.position.set(1024e3/2,1024e3/2,0),this._world.matrixAutoUpdate=!1,this._scene.add(this._world),this._map.on("render",this._onMapRender.bind(this)),this._event=new _.EventDispatcher}get map(){return this._map}get canvas(){return this._canvas}get camera(){return this._camera}get scene(){return this._scene}get lights(){return this._lights}get world(){return this._world}get renderer(){return this._renderer}_onMapRender(){this._map.getLayer("map_scene_layer")||this._map.addLayer(new le("map_scene_layer",this))}render(){if(this._options.renderLoop)this._options.renderLoop(this);else{let e={center:this._map.getCenter(),scene:this._scene,camera:this._camera,renderer:this._renderer};this._event.dispatchEvent({type:"preReset",frameState:e}),this.renderer.resetState(),this._event.dispatchEvent({type:"postReset",frameState:e}),this._event.dispatchEvent({type:"preRender",frameState:e}),this.renderer.render(this._scene,this._camera),this._event.dispatchEvent({type:"postRender",frameState:e})}return this}addLight(e){return this._lights.add(e.delegate||e),this}removeLight(e){return this._lights.remove(e.delegate||e),this}addObject(e){let t="delegate"in e?e.delegate:e;return this._world.add(t),this}removeObject(e){let t="delegate"in e?e.delegate:e;return this._world.remove(t),t.traverse(a=>{a.geometry&&a.geometry.dispose(),a.material&&(Array.isArray(a.material)?a.material.forEach(r=>r.dispose()):a.material.dispose()),a.texture&&a.texture.dispose()}),this}getViewPosition(){let e=this._map.transform,t=e.center;return{position:[t.lng,t.lat,D.getHeightByZoom(e,e.zoom,t.lat,e.pitch)],heading:e.bearing,pitch:e.pitch}}flyTo(e,t,a){if(e&&e.position){a&&this._map.once("moveend",a);let r=e.size;r||(r=new _.Vector3,new _.Box3().setFromObject(e.delegate||e,!0).getSize(r));let s=D.getViewInfo(this._map.transform,y.vector3ToLngLat(e.position),r);this._map.flyTo({center:s.center,zoom:s.zoom,duration:(t||3)*1e3})}return this}zoomTo(e,t){return this.flyTo(e,0,t)}flyToPosition(e,t=[0,0,0],a,r=3){return a&&this._map.once("moveend",a),this._map.flyTo({center:[e[0],e[1]],zoom:D.getZoomByHeight(this._map.transform,e[2],e[1],t[1]||0),bearing:t[0],pitch:t[1],duration:r*1e3}),this}zoomToPosition(e,t=[0,0,0],a){return this.flyToPosition(e,t,a,0)}on(e,t){return this._event.addEventListener(e,t),this}off(e,t){return this._event.removeEventListener(e,t),this}};var T=j(H(),1);var V=Math.PI,m=Math.sin,u=Math.cos,Q=Math.tan,de=Math.asin,W=Math.atan2,be=Math.acos,d=V/180,$=1e3*60*60*24,fe=2440588,ge=2451545;function Ue(n){return n.valueOf()/$-.5+fe}function F(n){return new Date((n+.5-fe)*$)}function B(n){return Ue(n)-ge}var J=d*23.4397;function _e(n,e){return W(m(n)*u(J)-Q(e)*m(J),u(n))}function ee(n,e){return de(m(e)*u(J)+u(e)*m(J)*m(n))}function Me(n,e,t){return W(m(n),u(n)*m(e)-Q(t)*u(e))}function Se(n,e,t){return de(m(e)*m(t)+u(e)*u(t)*u(n))}function ye(n,e){return d*(280.16+360.9856235*n)-e}function We(n){return n<0&&(n=0),2967e-7/Math.tan(n+.00312536/(n+.08901179))}function we(n){return d*(357.5291+.98560028*n)}function ve(n){let e=d*(1.9148*m(n)+.02*m(2*n)+3e-4*m(3*n)),t=d*102.9372;return n+e+t+V}function Le(n){let e=we(n),t=ve(e);return{dec:ee(t,0),ra:_e(t,0)}}var w={};w.getPosition=function(n,e,t){let a=d*-t,r=d*e,s=B(n),i=Le(s),o=ye(s,a)-i.ra;return{azimuth:Me(o,r,i.dec),altitude:Se(o,r,i.dec)}};var K=w.times=[[-.833,"sunrise","sunset"],[-.3,"sunriseEnd","sunsetStart"],[-6,"dawn","dusk"],[-12,"nauticalDawn","nauticalDusk"],[-18,"nightEnd","night"],[6,"goldenHourEnd","goldenHour"]];w.addTime=function(n,e,t){K.push([n,e,t])};var Ie=9e-4;function Ze(n,e){return Math.round(n-Ie-e/(2*V))}function De(n,e,t){return Ie+(n+e)/(2*V)+t}function Te(n,e,t){return ge+n+.0053*m(e)-.0069*m(2*t)}function Fe(n,e,t){return be((m(n)-m(e)*m(t))/(u(e)*u(t)))}function ke(n){return-2.076*Math.sqrt(n)/60}function Je(n,e,t,a,r,s,i){let o=Fe(n,t,a),c=De(o,e,r);return Te(c,s,i)}w.getTimes=function(n,e,t,a=0){let r=d*-t,s=d*e,i=ke(a),o=B(n),c=Ze(o,r),h=De(0,r,c),b=we(h),g=ve(b),f=ee(g,0),p=Te(h,b,g),L,O,v,S,I,G,R={solarNoon:F(p),nadir:F(p-.5)};for(L=0,O=K.length;L<O;L+=1)v=K[L],S=(v[0]+i)*d,I=Je(S,r,s,f,c,b,g),G=p-(I-p),R[v[1]]=F(G),R[v[2]]=F(I);return R};function Re(n){let e=d*(218.316+13.176396*n),t=d*(134.963+13.064993*n),a=d*(93.272+13.22935*n),r=e+d*6.289*m(t),s=d*5.128*m(a),i=385001-20905*u(t);return{ra:_e(r,s),dec:ee(r,s),dist:i}}w.getMoonPosition=function(n,e,t){let a=d*-t,r=d*e,s=B(n),i=Re(s),o=ye(s,a)-i.ra,c=Se(o,r,i.dec),h=W(m(o),Q(r)*u(i.dec)-m(i.dec)*u(o));return c=c+We(c),{azimuth:Me(o,r,i.dec),altitude:c,distance:i.dist,parallacticAngle:h}};w.getMoonIllumination=function(n){let e=B(n||new Date),t=Le(e),a=Re(e),r=149598e3,s=be(m(t.dec)*m(a.dec)+u(t.dec)*u(a.dec)*u(t.ra-a.ra)),i=W(r*m(s),a.dist-r*u(s)),o=W(u(t.dec)*m(t.ra-a.ra),m(t.dec)*u(a.dec)-u(t.dec)*m(a.dec)*u(t.ra-a.ra));return{fraction:(1+u(i))/2,phase:.5+.5*i*(o<0?-1:1)/Math.PI,angle:o}};function k(n,e){return new Date(n.valueOf()+e*$/24)}w.getMoonTimes=function(n,e,t,a=!1){let r=new Date(n);a?r.setUTCHours(0,0,0,0):r.setHours(0,0,0,0);let s=.133*d,i=w.getMoonPosition(r,e,t).altitude-s,o,c,h,b,g,f,p,L,O,v,S,I,G;for(let x=1;x<=24&&(o=w.getMoonPosition(k(r,x),e,t).altitude-s,c=w.getMoonPosition(k(r,x+1),e,t).altitude-s,g=(i+c)/2-o,f=(c-i)/2,p=-f/(2*g),L=(g*p+f)*p+o,O=f*f-4*g*o,v=0,O>=0&&(G=Math.sqrt(O)/(Math.abs(g)*2),S=p-G,I=p+G,Math.abs(S)<=1&&v++,Math.abs(I)<=1&&v++,S<-1&&(S=I)),v===1?i<0?h=x+S:b=x+S:v===2&&(h=x+(L<0?I:S),b=x+(L<0?S:I)),!(h&&b));x+=2)i=c;let R={};return h&&(R.rise=k(r,h)),b&&(R.set=k(r,b)),!h&&!b&&(R[L>0?"alwaysUp":"alwaysDown"]=!0),R};var xe=w;var te=class{_delegate;_sunLight;_hemiLight;_currentTime;constructor(){this._delegate=new T.Group,this._delegate.name="Sun",this._sunLight=new T.DirectionalLight(16777215,1),this._hemiLight=new T.HemisphereLight(new T.Color(16777215),new T.Color(16777215),.6),this._hemiLight.color.setHSL(.661,.96,.12),this._hemiLight.groundColor.setHSL(.11,.96,.14),this._hemiLight.position.set(0,0,50),this._delegate.add(this._sunLight),this._delegate.add(this._hemiLight),this._currentTime=new Date().getTime()}get delegate(){return this._delegate}set castShadow(e){this._sunLight.castShadow=e}get castShadow(){return this._sunLight.castShadow}set currentTime(e){this._currentTime=e}get currentTime(){return this._currentTime}get sunLight(){return this._sunLight}get hemiLight(){return this._hemiLight}setShadow(e={}){return this._sunLight.shadow.radius=e.radius||2,this._sunLight.shadow.mapSize.width=e.mapSize?e.mapSize[0]:8192,this._sunLight.shadow.mapSize.height=e.mapSize?e.mapSize[1]:8192,this._sunLight.shadow.camera.top=this._sunLight.shadow.camera.right=e.topRight||1e3,this._sunLight.shadow.camera.bottom=this._sunLight.shadow.camera.left=e.bottomLeft||-1e3,this._sunLight.shadow.camera.near=e.near||1,this._sunLight.shadow.camera.far=e.far||1e8,this._sunLight.shadow.camera.visible=!0,this}update(e){let a=new Date(this._currentTime||new Date().getTime()),r=e.center,s=xe.getPosition(a,r.lat,r.lng),i=s.altitude,o=Math.PI+s.azimuth,c=1024e3/2,h=Math.sin(i),b=Math.cos(i),g=Math.cos(o)*b,f=Math.sin(o)*b;this._sunLight.position.set(f,g,h),this._sunLight.position.multiplyScalar(c),this._sunLight.intensity=Math.max(h,0),this._hemiLight.intensity=Math.max(h*1,.1),this._sunLight.updateMatrixWorld()}},ne=te;var E=j(H(),1);var re=class{static createRTCGroup(e,t,a){let r=new E.Group;if(r.name="rtc",r.position.copy(y.lngLatToVector3(e)),t?(r.rotateX(t[0]||0),r.rotateY(t[1]||0),r.rotateZ(t[2]||0)):(r.rotateX(Math.PI/2),r.rotateY(Math.PI)),a)r.scale.set(a[0]||1,a[1]||1,a[2]||1);else{let s=1;Array.isArray(e)&&(s=y.projectedUnitsPerMeter(e[1])),r.scale.set(s,s,s)}return r}static createMercatorRTCGroup(e,t,a){let r=this.createRTCGroup(e,t,a);if(!a){let s=1,i=y.projectedMercatorUnitsPerMeter();Array.isArray(e)&&(s=y.projectedUnitsPerMeter(e[1])),r.scale.set(i,i,s)}return r}static createShadowGround(e,t,a){let r=new E.PlaneGeometry(t||100,a||100),s=new E.ShadowMaterial({opacity:.5,transparent:!0}),i=new E.Mesh(r,s);return i.position.copy(y.lngLatToVector3(e)),i.receiveShadow=!0,i.name="shadow-ground",i}},ae=re;return He(Ve);})();
|
|
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);})();
|
package/package.json
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dvt3d/maplibre-three-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
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",
|