@antv/l7-map 2.25.7 → 2.25.9
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/es/index.d.ts +5 -0
- package/es/index.js +4 -0
- package/es/map/camera.d.ts +690 -0
- package/es/map/camera.js +1138 -0
- package/es/map/css/l7.css +171 -0
- package/es/map/events.d.ts +384 -0
- package/es/map/events.js +231 -0
- package/es/map/geo/edge_insets.d.ts +97 -0
- package/es/map/geo/edge_insets.js +115 -0
- package/es/map/geo/lng_lat.d.ts +116 -0
- package/es/map/geo/lng_lat.js +159 -0
- package/es/map/geo/lng_lat_bounds.d.ts +217 -0
- package/es/map/geo/lng_lat_bounds.js +334 -0
- package/es/map/geo/mercator_coordinate.d.ts +113 -0
- package/es/map/geo/mercator_coordinate.js +142 -0
- package/es/map/geo/transform.d.ts +262 -0
- package/es/map/geo/transform.js +736 -0
- package/es/map/handler/box_zoom.d.ts +65 -0
- package/es/map/handler/box_zoom.js +145 -0
- package/es/map/handler/click_zoom.d.ts +24 -0
- package/es/map/handler/click_zoom.js +47 -0
- package/es/map/handler/cooperative_gestures.d.ts +40 -0
- package/es/map/handler/cooperative_gestures.js +94 -0
- package/es/map/handler/drag_handler.d.ts +88 -0
- package/es/map/handler/drag_handler.js +89 -0
- package/es/map/handler/drag_move_state_manager.d.ts +30 -0
- package/es/map/handler/drag_move_state_manager.js +94 -0
- package/es/map/handler/handler_util.d.ts +3 -0
- package/es/map/handler/handler_util.js +8 -0
- package/es/map/handler/keyboard.d.ts +88 -0
- package/es/map/handler/keyboard.js +197 -0
- package/es/map/handler/map_event.d.ts +46 -0
- package/es/map/handler/map_event.js +131 -0
- package/es/map/handler/mouse.d.ts +30 -0
- package/es/map/handler/mouse.js +85 -0
- package/es/map/handler/one_finger_touch_drag.d.ts +15 -0
- package/es/map/handler/one_finger_touch_drag.js +39 -0
- package/es/map/handler/scroll_zoom.d.ts +102 -0
- package/es/map/handler/scroll_zoom.js +312 -0
- package/es/map/handler/shim/dblclick_zoom.d.ts +44 -0
- package/es/map/handler/shim/dblclick_zoom.js +60 -0
- package/es/map/handler/shim/drag_pan.d.ts +79 -0
- package/es/map/handler/shim/drag_pan.js +77 -0
- package/es/map/handler/shim/drag_rotate.d.ts +54 -0
- package/es/map/handler/shim/drag_rotate.js +66 -0
- package/es/map/handler/shim/two_fingers_touch.d.ts +74 -0
- package/es/map/handler/shim/two_fingers_touch.js +106 -0
- package/es/map/handler/tap_drag_zoom.d.ts +28 -0
- package/es/map/handler/tap_drag_zoom.js +92 -0
- package/es/map/handler/tap_recognizer.d.ts +35 -0
- package/es/map/handler/tap_recognizer.js +107 -0
- package/es/map/handler/tap_zoom.d.ts +28 -0
- package/es/map/handler/tap_zoom.js +87 -0
- package/es/map/handler/touch_pan.d.ts +40 -0
- package/es/map/handler/touch_pan.js +85 -0
- package/es/map/handler/transform-provider.d.ts +23 -0
- package/es/map/handler/transform-provider.js +35 -0
- package/es/map/handler/two_fingers_touch.d.ts +107 -0
- package/es/map/handler/two_fingers_touch.js +289 -0
- package/es/map/handler_inertia.d.ts +20 -0
- package/es/map/handler_inertia.js +128 -0
- package/es/map/handler_manager.d.ts +154 -0
- package/es/map/handler_manager.js +466 -0
- package/es/map/map.d.ts +637 -0
- package/es/map/map.js +984 -0
- package/es/map/util/abort_error.d.ts +15 -0
- package/es/map/util/abort_error.js +21 -0
- package/es/map/util/browser.d.ts +10 -0
- package/es/map/util/browser.js +30 -0
- package/es/map/util/dom.d.ts +30 -0
- package/es/map/util/dom.js +105 -0
- package/es/map/util/evented.d.ts +75 -0
- package/es/map/util/evented.js +158 -0
- package/es/map/util/simpleMapCoord.d.ts +31 -0
- package/es/map/util/simpleMapCoord.js +54 -0
- package/es/map/util/task_queue.d.ts +18 -0
- package/es/map/util/task_queue.js +54 -0
- package/es/map/util/util.d.ts +104 -0
- package/es/map/util/util.js +155 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +33 -0
- package/lib/map/camera.d.ts +690 -0
- package/lib/map/camera.js +1145 -0
- package/lib/map/css/l7.css +171 -0
- package/lib/map/events.d.ts +384 -0
- package/lib/map/events.js +240 -0
- package/lib/map/geo/edge_insets.d.ts +97 -0
- package/lib/map/geo/edge_insets.js +122 -0
- package/lib/map/geo/lng_lat.d.ts +116 -0
- package/lib/map/geo/lng_lat.js +166 -0
- package/lib/map/geo/lng_lat_bounds.d.ts +217 -0
- package/lib/map/geo/lng_lat_bounds.js +341 -0
- package/lib/map/geo/mercator_coordinate.d.ts +113 -0
- package/lib/map/geo/mercator_coordinate.js +157 -0
- package/lib/map/geo/transform.d.ts +262 -0
- package/lib/map/geo/transform.js +744 -0
- package/lib/map/handler/box_zoom.d.ts +65 -0
- package/lib/map/handler/box_zoom.js +153 -0
- package/lib/map/handler/click_zoom.d.ts +24 -0
- package/lib/map/handler/click_zoom.js +54 -0
- package/lib/map/handler/cooperative_gestures.d.ts +40 -0
- package/lib/map/handler/cooperative_gestures.js +101 -0
- package/lib/map/handler/drag_handler.d.ts +88 -0
- package/lib/map/handler/drag_handler.js +97 -0
- package/lib/map/handler/drag_move_state_manager.d.ts +30 -0
- package/lib/map/handler/drag_move_state_manager.js +103 -0
- package/lib/map/handler/handler_util.d.ts +3 -0
- package/lib/map/handler/handler_util.js +14 -0
- package/lib/map/handler/keyboard.d.ts +88 -0
- package/lib/map/handler/keyboard.js +205 -0
- package/lib/map/handler/map_event.d.ts +46 -0
- package/lib/map/handler/map_event.js +140 -0
- package/lib/map/handler/mouse.d.ts +30 -0
- package/lib/map/handler/mouse.js +93 -0
- package/lib/map/handler/one_finger_touch_drag.d.ts +15 -0
- package/lib/map/handler/one_finger_touch_drag.js +47 -0
- package/lib/map/handler/scroll_zoom.d.ts +102 -0
- package/lib/map/handler/scroll_zoom.js +320 -0
- package/lib/map/handler/shim/dblclick_zoom.d.ts +44 -0
- package/lib/map/handler/shim/dblclick_zoom.js +68 -0
- package/lib/map/handler/shim/drag_pan.d.ts +79 -0
- package/lib/map/handler/shim/drag_pan.js +85 -0
- package/lib/map/handler/shim/drag_rotate.d.ts +54 -0
- package/lib/map/handler/shim/drag_rotate.js +74 -0
- package/lib/map/handler/shim/two_fingers_touch.d.ts +74 -0
- package/lib/map/handler/shim/two_fingers_touch.js +114 -0
- package/lib/map/handler/tap_drag_zoom.d.ts +28 -0
- package/lib/map/handler/tap_drag_zoom.js +99 -0
- package/lib/map/handler/tap_recognizer.d.ts +35 -0
- package/lib/map/handler/tap_recognizer.js +116 -0
- package/lib/map/handler/tap_zoom.d.ts +28 -0
- package/lib/map/handler/tap_zoom.js +94 -0
- package/lib/map/handler/touch_pan.d.ts +40 -0
- package/lib/map/handler/touch_pan.js +92 -0
- package/lib/map/handler/transform-provider.d.ts +23 -0
- package/lib/map/handler/transform-provider.js +43 -0
- package/lib/map/handler/two_fingers_touch.d.ts +107 -0
- package/lib/map/handler/two_fingers_touch.js +296 -0
- package/lib/map/handler_inertia.d.ts +20 -0
- package/lib/map/handler_inertia.js +136 -0
- package/lib/map/handler_manager.d.ts +154 -0
- package/lib/map/handler_manager.js +474 -0
- package/lib/map/map.d.ts +637 -0
- package/lib/map/map.js +991 -0
- package/lib/map/util/abort_error.d.ts +15 -0
- package/lib/map/util/abort_error.js +29 -0
- package/lib/map/util/browser.d.ts +10 -0
- package/lib/map/util/browser.js +36 -0
- package/lib/map/util/dom.d.ts +30 -0
- package/lib/map/util/dom.js +113 -0
- package/lib/map/util/evented.d.ts +75 -0
- package/lib/map/util/evented.js +167 -0
- package/lib/map/util/simpleMapCoord.d.ts +31 -0
- package/lib/map/util/simpleMapCoord.js +62 -0
- package/lib/map/util/task_queue.d.ts +18 -0
- package/lib/map/util/task_queue.js +62 -0
- package/lib/map/util/util.d.ts +104 -0
- package/lib/map/util/util.js +171 -0
- package/package.json +2 -2
package/es/map/map.js
ADDED
|
@@ -0,0 +1,984 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
+
import Point from '@mapbox/point-geometry';
|
|
4
|
+
import { Camera } from "./camera";
|
|
5
|
+
import { LngLat } from "./geo/lng_lat";
|
|
6
|
+
import { LngLatBounds } from "./geo/lng_lat_bounds";
|
|
7
|
+
import { Transform } from "./geo/transform";
|
|
8
|
+
import { HandlerManager } from "./handler_manager";
|
|
9
|
+
import { browser } from "./util/browser";
|
|
10
|
+
import { DOM } from "./util/dom";
|
|
11
|
+
import { Event } from "./util/evented";
|
|
12
|
+
import { TaskQueue } from "./util/task_queue";
|
|
13
|
+
import { extend, uniqueId } from "./util/util";
|
|
14
|
+
function loadStyles(css, doc) {
|
|
15
|
+
var isMiniAli = typeof my !== 'undefined' && !!my && typeof my.showToast === 'function' && my.isFRM !== true;
|
|
16
|
+
var isWeChatMiniProgram = typeof wx !== 'undefined' && wx !== null && (typeof wx.request !== 'undefined' || typeof wx.miniProgram !== 'undefined');
|
|
17
|
+
if (isMiniAli || isWeChatMiniProgram) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (!doc) doc = document;
|
|
21
|
+
if (!doc) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
var head = doc.head || doc.getElementsByTagName('head')[0];
|
|
25
|
+
if (!head) {
|
|
26
|
+
head = doc.createElement('head');
|
|
27
|
+
var body = doc.body || doc.getElementsByTagName('body')[0];
|
|
28
|
+
if (body) {
|
|
29
|
+
body.parentNode.insertBefore(head, body);
|
|
30
|
+
} else {
|
|
31
|
+
doc.documentElement.appendChild(head);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
var style = doc.createElement('style');
|
|
35
|
+
style.type = 'text/css';
|
|
36
|
+
if (style.styleSheet) {
|
|
37
|
+
style.styleSheet.cssText = css;
|
|
38
|
+
} else {
|
|
39
|
+
style.appendChild(doc.createTextNode(css));
|
|
40
|
+
}
|
|
41
|
+
head.appendChild(style);
|
|
42
|
+
return style;
|
|
43
|
+
}
|
|
44
|
+
loadStyles(`.l7-map {
|
|
45
|
+
font:
|
|
46
|
+
12px/20px 'Helvetica Neue',
|
|
47
|
+
Arial,
|
|
48
|
+
Helvetica,
|
|
49
|
+
sans-serif;
|
|
50
|
+
overflow: hidden;
|
|
51
|
+
position: relative;
|
|
52
|
+
-webkit-tap-highlight-color: rgb(0 0 0 / 0%);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.l7-canvas {
|
|
56
|
+
position: absolute;
|
|
57
|
+
left: 0;
|
|
58
|
+
top: 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.l7-map:full-screen {
|
|
62
|
+
width: 100%;
|
|
63
|
+
height: 100%;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.l7-canary {
|
|
67
|
+
background-color: salmon;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.l7-canvas-container.l7-interactive,
|
|
71
|
+
.l7-ctrl-group button.l7-ctrl-compass {
|
|
72
|
+
cursor: grab;
|
|
73
|
+
-webkit-user-select: none;
|
|
74
|
+
-moz-user-select: none;
|
|
75
|
+
-ms-user-select: none;
|
|
76
|
+
user-select: none;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.l7-canvas-container.l7-interactive.l7-track-pointer {
|
|
80
|
+
cursor: pointer;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.l7-canvas-container.l7-interactive:active,
|
|
84
|
+
.l7-ctrl-group button.l7-ctrl-compass:active {
|
|
85
|
+
cursor: grabbing;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.l7-canvas-container.l7-touch-zoom-rotate,
|
|
89
|
+
.l7-canvas-container.l7-touch-zoom-rotate .l7-canvas {
|
|
90
|
+
touch-action: pan-x pan-y;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.l7-canvas-container.l7-touch-drag-pan,
|
|
94
|
+
.l7-canvas-container.l7-touch-drag-pan .l7-canvas {
|
|
95
|
+
touch-action: pinch-zoom;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.l7-canvas-container.l7-touch-zoom-rotate.l7-touch-drag-pan,
|
|
99
|
+
.l7-canvas-container.l7-touch-zoom-rotate.l7-touch-drag-pan .l7-canvas {
|
|
100
|
+
touch-action: none;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.l7-canvas-container.l7-touch-drag-pan.l7-cooperative-gestures,
|
|
104
|
+
.l7-canvas-container.l7-touch-drag-pan.l7-cooperative-gestures .l7-canvas {
|
|
105
|
+
touch-action: pan-x pan-y;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.l7-cooperative-gesture-screen {
|
|
109
|
+
background: rgba(0 0 0 / 40%);
|
|
110
|
+
position: absolute;
|
|
111
|
+
inset: 0;
|
|
112
|
+
display: flex;
|
|
113
|
+
justify-content: center;
|
|
114
|
+
align-items: center;
|
|
115
|
+
color: white;
|
|
116
|
+
padding: 1rem;
|
|
117
|
+
font-size: 1.4em;
|
|
118
|
+
line-height: 1.2;
|
|
119
|
+
opacity: 0;
|
|
120
|
+
pointer-events: none;
|
|
121
|
+
transition: opacity 1s ease 1s;
|
|
122
|
+
z-index: 99999;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.l7-cooperative-gesture-screen.l7-show {
|
|
126
|
+
opacity: 1;
|
|
127
|
+
transition: opacity 0.05s;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.l7-cooperative-gesture-screen .l7-mobile-message {
|
|
131
|
+
display: none;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@media (hover: none), (width <= 480px) {
|
|
135
|
+
.l7-cooperative-gesture-screen .l7-desktop-message {
|
|
136
|
+
display: none;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.l7-cooperative-gesture-screen .l7-mobile-message {
|
|
140
|
+
display: block;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.l7-ctrl-top-left,
|
|
145
|
+
.l7-ctrl-top-right,
|
|
146
|
+
.l7-ctrl-bottom-left,
|
|
147
|
+
.l7-ctrl-bottom-right {
|
|
148
|
+
position: absolute;
|
|
149
|
+
pointer-events: none;
|
|
150
|
+
z-index: 2;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.l7-ctrl-top-left {
|
|
154
|
+
top: 0;
|
|
155
|
+
left: 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.l7-ctrl-top-right {
|
|
159
|
+
top: 0;
|
|
160
|
+
right: 0;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.l7-ctrl-bottom-left {
|
|
164
|
+
bottom: 0;
|
|
165
|
+
left: 0;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.l7-ctrl-bottom-right {
|
|
169
|
+
right: 0;
|
|
170
|
+
bottom: 0;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.l7-ctrl {
|
|
174
|
+
clear: both;
|
|
175
|
+
pointer-events: auto;
|
|
176
|
+
|
|
177
|
+
/* workaround for a Safari bug https://github.com/mapbox/mapbox-gl-js/issues/8185 */
|
|
178
|
+
-webkit-transform: translate(0, 0);
|
|
179
|
+
transform: translate(0, 0);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.l7-ctrl-top-left .l7-ctrl {
|
|
183
|
+
margin: 10px 0 0 10px;
|
|
184
|
+
float: left;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.l7-ctrl-top-right .l7-ctrl {
|
|
188
|
+
margin: 10px 10px 0 0;
|
|
189
|
+
float: right;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.l7-ctrl-bottom-left .l7-ctrl {
|
|
193
|
+
margin: 0 0 10px 10px;
|
|
194
|
+
float: left;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.l7-ctrl-bottom-right .l7-ctrl {
|
|
198
|
+
margin: 0 10px 10px 0;
|
|
199
|
+
float: right;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.l7-crosshair,
|
|
203
|
+
.l7-crosshair .l7-interactive,
|
|
204
|
+
.l7-crosshair .l7-interactive:active {
|
|
205
|
+
cursor: crosshair;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.l7-boxzoom {
|
|
209
|
+
position: absolute;
|
|
210
|
+
top: 0;
|
|
211
|
+
left: 0;
|
|
212
|
+
width: 0;
|
|
213
|
+
height: 0;
|
|
214
|
+
background: #fff;
|
|
215
|
+
border: 2px dotted #202020;
|
|
216
|
+
opacity: 0.5;
|
|
217
|
+
z-index: 10;
|
|
218
|
+
}
|
|
219
|
+
`);
|
|
220
|
+
import { lodashUtil } from '@antv/l7-utils';
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* The {@link Map} options object.
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
// This type is used inside map since all properties are assigned a default value.
|
|
227
|
+
|
|
228
|
+
const defaultMinZoom = -2;
|
|
229
|
+
const defaultMaxZoom = 22;
|
|
230
|
+
|
|
231
|
+
// the default values, but also the valid range
|
|
232
|
+
const defaultMinPitch = 0;
|
|
233
|
+
const defaultMaxPitch = 60;
|
|
234
|
+
|
|
235
|
+
// use this variable to check maxPitch for validity
|
|
236
|
+
const maxPitchThreshold = 85;
|
|
237
|
+
const defaultOptions = {
|
|
238
|
+
interactive: true,
|
|
239
|
+
bearingSnap: 7,
|
|
240
|
+
scrollZoom: true,
|
|
241
|
+
minZoom: defaultMinZoom,
|
|
242
|
+
maxZoom: defaultMaxZoom,
|
|
243
|
+
minPitch: defaultMinPitch,
|
|
244
|
+
maxPitch: defaultMaxPitch,
|
|
245
|
+
boxZoom: true,
|
|
246
|
+
dragRotate: true,
|
|
247
|
+
dragPan: true,
|
|
248
|
+
keyboard: true,
|
|
249
|
+
doubleClickZoom: true,
|
|
250
|
+
touchZoomRotate: true,
|
|
251
|
+
touchPitch: true,
|
|
252
|
+
cooperativeGestures: false,
|
|
253
|
+
trackResize: true,
|
|
254
|
+
center: [0, 0],
|
|
255
|
+
zoom: 0,
|
|
256
|
+
bearing: 0,
|
|
257
|
+
pitch: 0,
|
|
258
|
+
renderWorldCopies: true,
|
|
259
|
+
fadeDuration: 300,
|
|
260
|
+
clickTolerance: 3,
|
|
261
|
+
pitchWithRotate: true
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The `Map` object represents the map on your page. It exposes methods
|
|
266
|
+
* and properties that enable you to programmatically change the map,
|
|
267
|
+
* and fires events as users interact with it.
|
|
268
|
+
*
|
|
269
|
+
* You create a `Map` by specifying a `container` and other options, see {@link MapOptions} for the full list.
|
|
270
|
+
* Then MapLibre GL JS initializes the map on the page and returns your `Map` object.
|
|
271
|
+
*
|
|
272
|
+
* @group Main
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```ts
|
|
276
|
+
* let map = new Map({
|
|
277
|
+
* container: 'map',
|
|
278
|
+
* center: [-122.420679, 37.772537],
|
|
279
|
+
* zoom: 13,
|
|
280
|
+
* });
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
export class Map extends Camera {
|
|
284
|
+
constructor(options) {
|
|
285
|
+
const resolvedOptions = _objectSpread(_objectSpread({}, defaultOptions), options);
|
|
286
|
+
if (resolvedOptions.minZoom != null && resolvedOptions.maxZoom != null && resolvedOptions.minZoom > resolvedOptions.maxZoom) {
|
|
287
|
+
throw new Error('maxZoom must be greater than or equal to minZoom');
|
|
288
|
+
}
|
|
289
|
+
if (resolvedOptions.minPitch != null && resolvedOptions.maxPitch != null && resolvedOptions.minPitch > resolvedOptions.maxPitch) {
|
|
290
|
+
throw new Error('maxPitch must be greater than or equal to minPitch');
|
|
291
|
+
}
|
|
292
|
+
if (resolvedOptions.minPitch != null && resolvedOptions.minPitch < defaultMinPitch) {
|
|
293
|
+
throw new Error(`minPitch must be greater than or equal to ${defaultMinPitch}`);
|
|
294
|
+
}
|
|
295
|
+
if (resolvedOptions.maxPitch != null && resolvedOptions.maxPitch > maxPitchThreshold) {
|
|
296
|
+
throw new Error(`maxPitch must be less than or equal to ${maxPitchThreshold}`);
|
|
297
|
+
}
|
|
298
|
+
const transform = new Transform(resolvedOptions.minZoom, resolvedOptions.maxZoom, resolvedOptions.minPitch, resolvedOptions.maxPitch, resolvedOptions.renderWorldCopies);
|
|
299
|
+
super(transform, {
|
|
300
|
+
bearingSnap: resolvedOptions.bearingSnap
|
|
301
|
+
});
|
|
302
|
+
_defineProperty(this, "_container", void 0);
|
|
303
|
+
_defineProperty(this, "_canvasContainer", void 0);
|
|
304
|
+
_defineProperty(this, "_interactive", void 0);
|
|
305
|
+
_defineProperty(this, "_frameRequest", void 0);
|
|
306
|
+
_defineProperty(this, "_loaded", void 0);
|
|
307
|
+
_defineProperty(this, "_idleTriggered", false);
|
|
308
|
+
// accounts for placement finishing as well
|
|
309
|
+
_defineProperty(this, "_fullyLoaded", void 0);
|
|
310
|
+
_defineProperty(this, "_trackResize", void 0);
|
|
311
|
+
_defineProperty(this, "_resizeObserver", void 0);
|
|
312
|
+
_defineProperty(this, "_preserveDrawingBuffer", void 0);
|
|
313
|
+
_defineProperty(this, "_failIfMajorPerformanceCaveat", void 0);
|
|
314
|
+
_defineProperty(this, "_fadeDuration", void 0);
|
|
315
|
+
_defineProperty(this, "_crossSourceCollisions", void 0);
|
|
316
|
+
_defineProperty(this, "_crossFadingFactor", 1);
|
|
317
|
+
_defineProperty(this, "_collectResourceTiming", void 0);
|
|
318
|
+
_defineProperty(this, "_renderTaskQueue", new TaskQueue());
|
|
319
|
+
_defineProperty(this, "_mapId", uniqueId());
|
|
320
|
+
_defineProperty(this, "_removed", void 0);
|
|
321
|
+
_defineProperty(this, "_clickTolerance", void 0);
|
|
322
|
+
_defineProperty(this, "version", void 0);
|
|
323
|
+
_defineProperty(this, "mapSize", void 0);
|
|
324
|
+
/**
|
|
325
|
+
* The map's {@link ScrollZoomHandler}, which implements zooming in and out with a scroll wheel or trackpad.
|
|
326
|
+
* Find more details and examples using `scrollZoom` in the {@link ScrollZoomHandler} section.
|
|
327
|
+
*/
|
|
328
|
+
_defineProperty(this, "scrollZoom", void 0);
|
|
329
|
+
/**
|
|
330
|
+
* The map's {@link BoxZoomHandler}, which implements zooming using a drag gesture with the Shift key pressed.
|
|
331
|
+
* Find more details and examples using `boxZoom` in the {@link BoxZoomHandler} section.
|
|
332
|
+
*/
|
|
333
|
+
_defineProperty(this, "boxZoom", void 0);
|
|
334
|
+
/**
|
|
335
|
+
* The map's {@link DragRotateHandler}, which implements rotating the map while dragging with the right
|
|
336
|
+
* mouse button or with the Control key pressed. Find more details and examples using `dragRotate`
|
|
337
|
+
* in the {@link DragRotateHandler} section.
|
|
338
|
+
*/
|
|
339
|
+
_defineProperty(this, "dragRotate", void 0);
|
|
340
|
+
/**
|
|
341
|
+
* The map's {@link DragPanHandler}, which implements dragging the map with a mouse or touch gesture.
|
|
342
|
+
* Find more details and examples using `dragPan` in the {@link DragPanHandler} section.
|
|
343
|
+
*/
|
|
344
|
+
_defineProperty(this, "dragPan", void 0);
|
|
345
|
+
/**
|
|
346
|
+
* The map's {@link KeyboardHandler}, which allows the user to zoom, rotate, and pan the map using keyboard
|
|
347
|
+
* shortcuts. Find more details and examples using `keyboard` in the {@link KeyboardHandler} section.
|
|
348
|
+
*/
|
|
349
|
+
_defineProperty(this, "keyboard", void 0);
|
|
350
|
+
/**
|
|
351
|
+
* The map's {@link DoubleClickZoomHandler}, which allows the user to zoom by double clicking.
|
|
352
|
+
* Find more details and examples using `doubleClickZoom` in the {@link DoubleClickZoomHandler} section.
|
|
353
|
+
*/
|
|
354
|
+
_defineProperty(this, "doubleClickZoom", void 0);
|
|
355
|
+
/**
|
|
356
|
+
* The map's {@link TwoFingersTouchZoomRotateHandler}, which allows the user to zoom or rotate the map with touch gestures.
|
|
357
|
+
* Find more details and examples using `touchZoomRotate` in the {@link TwoFingersTouchZoomRotateHandler} section.
|
|
358
|
+
*/
|
|
359
|
+
_defineProperty(this, "touchZoomRotate", void 0);
|
|
360
|
+
/**
|
|
361
|
+
* The map's {@link TwoFingersTouchPitchHandler}, which allows the user to pitch the map with touch gestures.
|
|
362
|
+
* Find more details and examples using `touchPitch` in the {@link TwoFingersTouchPitchHandler} section.
|
|
363
|
+
*/
|
|
364
|
+
_defineProperty(this, "touchPitch", void 0);
|
|
365
|
+
/**
|
|
366
|
+
* The map's {@link CooperativeGesturesHandler}, which allows the user to see cooperative gesture info when user tries to zoom in/out.
|
|
367
|
+
* Find more details and examples using `cooperativeGestures` in the {@link CooperativeGesturesHandler} section.
|
|
368
|
+
*/
|
|
369
|
+
_defineProperty(this, "cooperativeGestures", void 0);
|
|
370
|
+
_defineProperty(this, "_onMapScroll", event => {
|
|
371
|
+
if (event.target !== this._container) return;
|
|
372
|
+
|
|
373
|
+
// Revert any scroll which would move the canvas outside of the view
|
|
374
|
+
this._container.scrollTop = 0;
|
|
375
|
+
this._container.scrollLeft = 0;
|
|
376
|
+
return false;
|
|
377
|
+
});
|
|
378
|
+
this._interactive = resolvedOptions.interactive;
|
|
379
|
+
this._trackResize = resolvedOptions.trackResize === true;
|
|
380
|
+
this._bearingSnap = resolvedOptions.bearingSnap;
|
|
381
|
+
this._fadeDuration = resolvedOptions.fadeDuration;
|
|
382
|
+
this._clickTolerance = resolvedOptions.clickTolerance;
|
|
383
|
+
this.version = options.version;
|
|
384
|
+
this.mapSize = options.mapSize;
|
|
385
|
+
if (typeof resolvedOptions.container === 'string') {
|
|
386
|
+
this._container = document.getElementById(resolvedOptions.container);
|
|
387
|
+
if (!this._container) {
|
|
388
|
+
throw new Error(`Container '${resolvedOptions.container}' not found.`);
|
|
389
|
+
}
|
|
390
|
+
} else if (resolvedOptions.container instanceof HTMLElement) {
|
|
391
|
+
this._container = resolvedOptions.container;
|
|
392
|
+
} else {
|
|
393
|
+
throw new Error("Invalid type: 'container' must be a String or HTMLElement.");
|
|
394
|
+
}
|
|
395
|
+
if (resolvedOptions.maxBounds) {
|
|
396
|
+
this.setMaxBounds(resolvedOptions.maxBounds);
|
|
397
|
+
}
|
|
398
|
+
this._setupContainer();
|
|
399
|
+
this.on('move', () => this._update()).on('moveend', () => this._update()).on('zoom', () => this._update()).once('idle', () => {
|
|
400
|
+
this._idleTriggered = true;
|
|
401
|
+
});
|
|
402
|
+
if (typeof window !== 'undefined') {
|
|
403
|
+
let initialResizeEventCaptured = false;
|
|
404
|
+
const throttledResizeCallback = lodashUtil.throttle(entries => {
|
|
405
|
+
if (this._trackResize && !this._removed) {
|
|
406
|
+
this.resize(entries)._update();
|
|
407
|
+
}
|
|
408
|
+
}, 50);
|
|
409
|
+
this._resizeObserver = new ResizeObserver(entries => {
|
|
410
|
+
if (!initialResizeEventCaptured) {
|
|
411
|
+
initialResizeEventCaptured = true;
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
throttledResizeCallback(entries);
|
|
415
|
+
});
|
|
416
|
+
this._resizeObserver.observe(this._container);
|
|
417
|
+
}
|
|
418
|
+
this.handlers = new HandlerManager(this, resolvedOptions);
|
|
419
|
+
this.jumpTo({
|
|
420
|
+
center: resolvedOptions.center,
|
|
421
|
+
zoom: resolvedOptions.zoom,
|
|
422
|
+
bearing: resolvedOptions.bearing,
|
|
423
|
+
pitch: resolvedOptions.pitch
|
|
424
|
+
});
|
|
425
|
+
if (resolvedOptions.bounds) {
|
|
426
|
+
this.resize();
|
|
427
|
+
this.fitBounds(resolvedOptions.bounds, extend({}, resolvedOptions.fitBoundsOptions, {
|
|
428
|
+
duration: 0
|
|
429
|
+
}));
|
|
430
|
+
}
|
|
431
|
+
this.resize();
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* @internal
|
|
436
|
+
* Returns a unique number for this map instance which is used for the MapLoadEvent
|
|
437
|
+
* to make sure we only fire one event per instantiated map object.
|
|
438
|
+
* @returns the uniq map ID
|
|
439
|
+
*/
|
|
440
|
+
_getMapId() {
|
|
441
|
+
return this._mapId;
|
|
442
|
+
}
|
|
443
|
+
calculateCameraOptionsFromTo(from, altitudeFrom, to, altitudeTo) {
|
|
444
|
+
return super.calculateCameraOptionsFromTo(from, altitudeFrom, to, altitudeTo);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Resizes the map according to the dimensions of its
|
|
449
|
+
* `container` element.
|
|
450
|
+
*
|
|
451
|
+
* Checks if the map container size changed and updates the map if it has changed.
|
|
452
|
+
* This method must be called after the map's `container` is resized programmatically
|
|
453
|
+
* or when the map is shown after being initially hidden with CSS.
|
|
454
|
+
*
|
|
455
|
+
* Triggers the following events: `movestart`, `move`, `moveend`, and `resize`.
|
|
456
|
+
*
|
|
457
|
+
* @param eventData - Additional properties to be passed to `movestart`, `move`, `resize`, and `moveend`
|
|
458
|
+
* events that get triggered as a result of resize. This can be useful for differentiating the
|
|
459
|
+
* source of an event (for example, user-initiated or programmatically-triggered events).
|
|
460
|
+
* @example
|
|
461
|
+
* Resize the map when the map container is shown after being initially hidden with CSS.
|
|
462
|
+
* ```ts
|
|
463
|
+
* let mapDiv = document.getElementById('map');
|
|
464
|
+
* if (mapDiv.style.visibility === true) map.resize();
|
|
465
|
+
* ```
|
|
466
|
+
*/
|
|
467
|
+
resize(eventData) {
|
|
468
|
+
var _this$_requestedCamer;
|
|
469
|
+
const dimensions = this._containerDimensions();
|
|
470
|
+
const width = dimensions[0];
|
|
471
|
+
const height = dimensions[1];
|
|
472
|
+
this.transform.resize(width, height);
|
|
473
|
+
(_this$_requestedCamer = this._requestedCameraState) === null || _this$_requestedCamer === void 0 || _this$_requestedCamer.resize(width, height);
|
|
474
|
+
const fireMoving = !this._moving;
|
|
475
|
+
if (fireMoving) {
|
|
476
|
+
this.stop();
|
|
477
|
+
this.fire(new Event('movestart', eventData)).fire(new Event('move', eventData));
|
|
478
|
+
}
|
|
479
|
+
this.fire(new Event('resize', eventData));
|
|
480
|
+
if (fireMoving) this.fire(new Event('moveend', eventData));
|
|
481
|
+
return this;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Returns the map's geographical bounds. When the bearing or pitch is non-zero, the visible region is not
|
|
486
|
+
* an axis-aligned rectangle, and the result is the smallest bounds that encompasses the visible region.
|
|
487
|
+
* @returns The geographical bounds of the map as {@link LngLatBounds}.
|
|
488
|
+
* @example
|
|
489
|
+
* ```ts
|
|
490
|
+
* let bounds = map.getBounds();
|
|
491
|
+
* ```
|
|
492
|
+
*/
|
|
493
|
+
getBounds() {
|
|
494
|
+
return this.transform.getBounds();
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Returns the maximum geographical bounds the map is constrained to, or `null` if none set.
|
|
499
|
+
* @returns The map object.
|
|
500
|
+
* @example
|
|
501
|
+
* ```ts
|
|
502
|
+
* let maxBounds = map.getMaxBounds();
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
505
|
+
getMaxBounds() {
|
|
506
|
+
return this.transform.getMaxBounds();
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Sets or clears the map's geographical bounds.
|
|
511
|
+
*
|
|
512
|
+
* Pan and zoom operations are constrained within these bounds.
|
|
513
|
+
* If a pan or zoom is performed that would
|
|
514
|
+
* display regions outside these bounds, the map will
|
|
515
|
+
* instead display a position and zoom level
|
|
516
|
+
* as close as possible to the operation's request while still
|
|
517
|
+
* remaining within the bounds.
|
|
518
|
+
*
|
|
519
|
+
* @param bounds - The maximum bounds to set. If `null` or `undefined` is provided, the function removes the map's maximum bounds.
|
|
520
|
+
* @example
|
|
521
|
+
* Define bounds that conform to the `LngLatBoundsLike` object as set the max bounds.
|
|
522
|
+
* ```ts
|
|
523
|
+
* let bounds = [
|
|
524
|
+
* [-74.04728, 40.68392], // [west, south]
|
|
525
|
+
* [-73.91058, 40.87764] // [east, north]
|
|
526
|
+
* ];
|
|
527
|
+
* map.setMaxBounds(bounds);
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
setMaxBounds(bounds) {
|
|
531
|
+
this.transform.setMaxBounds(bounds && LngLatBounds.convert(bounds));
|
|
532
|
+
return this._update();
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Sets or clears the map's minimum zoom level.
|
|
537
|
+
* If the map's current zoom level is lower than the new minimum,
|
|
538
|
+
* the map will zoom to the new minimum.
|
|
539
|
+
*
|
|
540
|
+
* It is not always possible to zoom out and reach the set `minZoom`.
|
|
541
|
+
* Other factors such as map height may restrict zooming. For example,
|
|
542
|
+
* if the map is 512px tall it will not be possible to zoom below zoom 0
|
|
543
|
+
* no matter what the `minZoom` is set to.
|
|
544
|
+
*
|
|
545
|
+
* A {@link ErrorEvent} event will be fired if minZoom is out of bounds.
|
|
546
|
+
*
|
|
547
|
+
* @param minZoom - The minimum zoom level to set (-2 - 24).
|
|
548
|
+
* If `null` or `undefined` is provided, the function removes the current minimum zoom (i.e. sets it to -2).
|
|
549
|
+
* @example
|
|
550
|
+
* ```ts
|
|
551
|
+
* map.setMinZoom(12.25);
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
setMinZoom(minZoom) {
|
|
555
|
+
minZoom = minZoom === null || minZoom === undefined ? defaultMinZoom : minZoom;
|
|
556
|
+
if (minZoom >= defaultMinZoom && minZoom <= this.transform.maxZoom) {
|
|
557
|
+
this.transform.minZoom = minZoom;
|
|
558
|
+
this._update();
|
|
559
|
+
if (this.getZoom() < minZoom) this.setZoom(minZoom);
|
|
560
|
+
return this;
|
|
561
|
+
} else throw new Error(`minZoom must be between ${defaultMinZoom} and the current maxZoom, inclusive`);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Returns the map's minimum allowable zoom level.
|
|
566
|
+
*
|
|
567
|
+
* @returns minZoom
|
|
568
|
+
* @example
|
|
569
|
+
* ```ts
|
|
570
|
+
* let minZoom = map.getMinZoom();
|
|
571
|
+
* ```
|
|
572
|
+
*/
|
|
573
|
+
getMinZoom() {
|
|
574
|
+
return this.transform.minZoom;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Sets or clears the map's maximum zoom level.
|
|
579
|
+
* If the map's current zoom level is higher than the new maximum,
|
|
580
|
+
* the map will zoom to the new maximum.
|
|
581
|
+
*
|
|
582
|
+
* A {@link ErrorEvent} event will be fired if minZoom is out of bounds.
|
|
583
|
+
*
|
|
584
|
+
* @param maxZoom - The maximum zoom level to set.
|
|
585
|
+
* If `null` or `undefined` is provided, the function removes the current maximum zoom (sets it to 22).
|
|
586
|
+
* @example
|
|
587
|
+
* ```ts
|
|
588
|
+
* map.setMaxZoom(18.75);
|
|
589
|
+
* ```
|
|
590
|
+
*/
|
|
591
|
+
setMaxZoom(maxZoom) {
|
|
592
|
+
maxZoom = maxZoom === null || maxZoom === undefined ? defaultMaxZoom : maxZoom;
|
|
593
|
+
if (maxZoom >= this.transform.minZoom) {
|
|
594
|
+
this.transform.maxZoom = maxZoom;
|
|
595
|
+
if (this.getZoom() > maxZoom) this.setZoom(maxZoom);
|
|
596
|
+
return this;
|
|
597
|
+
} else throw new Error('maxZoom must be greater than the current minZoom');
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Returns the map's maximum allowable zoom level.
|
|
602
|
+
*
|
|
603
|
+
* @returns The maxZoom
|
|
604
|
+
* @example
|
|
605
|
+
* ```ts
|
|
606
|
+
* let maxZoom = map.getMaxZoom();
|
|
607
|
+
* ```
|
|
608
|
+
*/
|
|
609
|
+
getMaxZoom() {
|
|
610
|
+
return this.transform.maxZoom;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Sets or clears the map's minimum pitch.
|
|
615
|
+
* If the map's current pitch is lower than the new minimum,
|
|
616
|
+
* the map will pitch to the new minimum.
|
|
617
|
+
*
|
|
618
|
+
* A {@link ErrorEvent} event will be fired if minPitch is out of bounds.
|
|
619
|
+
*
|
|
620
|
+
* @param minPitch - The minimum pitch to set (0-85). Values greater than 60 degrees are experimental and may result in rendering issues. If you encounter any, please raise an issue with details in the MapLibre project.
|
|
621
|
+
* If `null` or `undefined` is provided, the function removes the current minimum pitch (i.e. sets it to 0).
|
|
622
|
+
*/
|
|
623
|
+
setMinPitch(minPitch) {
|
|
624
|
+
minPitch = minPitch === null || minPitch === undefined ? defaultMinPitch : minPitch;
|
|
625
|
+
if (minPitch < defaultMinPitch) {
|
|
626
|
+
throw new Error(`minPitch must be greater than or equal to ${defaultMinPitch}`);
|
|
627
|
+
}
|
|
628
|
+
if (minPitch >= defaultMinPitch && minPitch <= this.transform.maxPitch) {
|
|
629
|
+
this.transform.minPitch = minPitch;
|
|
630
|
+
if (this.getPitch() < minPitch) this.setPitch(minPitch);
|
|
631
|
+
return this;
|
|
632
|
+
} else throw new Error(`minPitch must be between ${defaultMinPitch} and the current maxPitch, inclusive`);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Returns the map's minimum allowable pitch.
|
|
637
|
+
*
|
|
638
|
+
* @returns The minPitch
|
|
639
|
+
*/
|
|
640
|
+
getMinPitch() {
|
|
641
|
+
return this.transform.minPitch;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Sets or clears the map's maximum pitch.
|
|
646
|
+
* If the map's current pitch is higher than the new maximum,
|
|
647
|
+
* the map will pitch to the new maximum.
|
|
648
|
+
*
|
|
649
|
+
* A {@link ErrorEvent} event will be fired if maxPitch is out of bounds.
|
|
650
|
+
*
|
|
651
|
+
* @param maxPitch - The maximum pitch to set (0-85). Values greater than 60 degrees are experimental and may result in rendering issues. If you encounter any, please raise an issue with details in the MapLibre project.
|
|
652
|
+
* If `null` or `undefined` is provided, the function removes the current maximum pitch (sets it to 60).
|
|
653
|
+
*/
|
|
654
|
+
setMaxPitch(maxPitch) {
|
|
655
|
+
maxPitch = maxPitch === null || maxPitch === undefined ? defaultMaxPitch : maxPitch;
|
|
656
|
+
if (maxPitch > maxPitchThreshold) {
|
|
657
|
+
throw new Error(`maxPitch must be less than or equal to ${maxPitchThreshold}`);
|
|
658
|
+
}
|
|
659
|
+
if (maxPitch >= this.transform.minPitch) {
|
|
660
|
+
this.transform.maxPitch = maxPitch;
|
|
661
|
+
if (this.getPitch() > maxPitch) this.setPitch(maxPitch);
|
|
662
|
+
return this;
|
|
663
|
+
} else throw new Error('maxPitch must be greater than the current minPitch');
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Returns the map's maximum allowable pitch.
|
|
668
|
+
*
|
|
669
|
+
* @returns The maxPitch
|
|
670
|
+
*/
|
|
671
|
+
getMaxPitch() {
|
|
672
|
+
return this.transform.maxPitch;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Returns the state of `renderWorldCopies`. If `true`, multiple copies of the world will be rendered side by side beyond -180 and 180 degrees longitude. If set to `false`:
|
|
677
|
+
*
|
|
678
|
+
* - When the map is zoomed out far enough that a single representation of the world does not fill the map's entire
|
|
679
|
+
* container, there will be blank space beyond 180 and -180 degrees longitude.
|
|
680
|
+
* - Features that cross 180 and -180 degrees longitude will be cut in two (with one portion on the right edge of the
|
|
681
|
+
* map and the other on the left edge of the map) at every zoom level.
|
|
682
|
+
* @returns The renderWorldCopies
|
|
683
|
+
* @example
|
|
684
|
+
* ```ts
|
|
685
|
+
* let worldCopiesRendered = map.getRenderWorldCopies();
|
|
686
|
+
* ```
|
|
687
|
+
* @see [Render world copies](https://maplibre.org/maplibre-gl-js/docs/examples/render-world-copies/)
|
|
688
|
+
*/
|
|
689
|
+
getRenderWorldCopies() {
|
|
690
|
+
return this.transform.renderWorldCopies;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Sets the state of `renderWorldCopies`.
|
|
695
|
+
*
|
|
696
|
+
* @param renderWorldCopies - If `true`, multiple copies of the world will be rendered side by side beyond -180 and 180 degrees longitude. If set to `false`:
|
|
697
|
+
*
|
|
698
|
+
* - When the map is zoomed out far enough that a single representation of the world does not fill the map's entire
|
|
699
|
+
* container, there will be blank space beyond 180 and -180 degrees longitude.
|
|
700
|
+
* - Features that cross 180 and -180 degrees longitude will be cut in two (with one portion on the right edge of the
|
|
701
|
+
* map and the other on the left edge of the map) at every zoom level.
|
|
702
|
+
*
|
|
703
|
+
* `undefined` is treated as `true`, `null` is treated as `false`.
|
|
704
|
+
* @example
|
|
705
|
+
* ```ts
|
|
706
|
+
* map.setRenderWorldCopies(true);
|
|
707
|
+
* ```
|
|
708
|
+
*/
|
|
709
|
+
setRenderWorldCopies(renderWorldCopies) {
|
|
710
|
+
this.transform.renderWorldCopies = renderWorldCopies;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Returns a [Point](https://github.com/mapbox/point-geometry) representing pixel coordinates, relative to the map's `container`,
|
|
715
|
+
* that correspond to the specified geographical location.
|
|
716
|
+
*
|
|
717
|
+
* @param lnglat - The geographical location to project.
|
|
718
|
+
* @returns The [Point](https://github.com/mapbox/point-geometry) corresponding to `lnglat`, relative to the map's `container`.
|
|
719
|
+
* @example
|
|
720
|
+
* ```ts
|
|
721
|
+
* let coordinate = [-122.420679, 37.772537];
|
|
722
|
+
* let point = map.project(coordinate);
|
|
723
|
+
* ```
|
|
724
|
+
*/
|
|
725
|
+
project(lnglat) {
|
|
726
|
+
return this.transform.locationPoint(LngLat.convert(lnglat));
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* Returns a {@link LngLat} representing geographical coordinates that correspond
|
|
731
|
+
* to the specified pixel coordinates.
|
|
732
|
+
*
|
|
733
|
+
* @param point - The pixel coordinates to unproject.
|
|
734
|
+
* @returns The {@link LngLat} corresponding to `point`.
|
|
735
|
+
* @example
|
|
736
|
+
* ```ts
|
|
737
|
+
* map.on('click', (e) => {
|
|
738
|
+
* // When the map is clicked, get the geographic coordinate.
|
|
739
|
+
* let coordinate = map.unproject(e.point);
|
|
740
|
+
* });
|
|
741
|
+
* ```
|
|
742
|
+
*/
|
|
743
|
+
unproject(point) {
|
|
744
|
+
return this.transform.pointLocation(Point.convert(point));
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* Returns true if the map is panning, zooming, rotating, or pitching due to a camera animation or user gesture.
|
|
749
|
+
* @returns true if the map is moving.
|
|
750
|
+
* @example
|
|
751
|
+
* ```ts
|
|
752
|
+
* let isMoving = map.isMoving();
|
|
753
|
+
* ```
|
|
754
|
+
*/
|
|
755
|
+
isMoving() {
|
|
756
|
+
var _this$handlers;
|
|
757
|
+
return this._moving || ((_this$handlers = this.handlers) === null || _this$handlers === void 0 ? void 0 : _this$handlers.isMoving());
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* Returns true if the map is zooming due to a camera animation or user gesture.
|
|
762
|
+
* @returns true if the map is zooming.
|
|
763
|
+
* @example
|
|
764
|
+
* ```ts
|
|
765
|
+
* let isZooming = map.isZooming();
|
|
766
|
+
* ```
|
|
767
|
+
*/
|
|
768
|
+
isZooming() {
|
|
769
|
+
var _this$handlers2;
|
|
770
|
+
return this._zooming || ((_this$handlers2 = this.handlers) === null || _this$handlers2 === void 0 ? void 0 : _this$handlers2.isZooming());
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Returns true if the map is rotating due to a camera animation or user gesture.
|
|
775
|
+
* @returns true if the map is rotating.
|
|
776
|
+
* @example
|
|
777
|
+
* ```ts
|
|
778
|
+
* map.isRotating();
|
|
779
|
+
* ```
|
|
780
|
+
*/
|
|
781
|
+
isRotating() {
|
|
782
|
+
var _this$handlers3;
|
|
783
|
+
return this._rotating || ((_this$handlers3 = this.handlers) === null || _this$handlers3 === void 0 ? void 0 : _this$handlers3.isRotating());
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* Overload of the `on` method that allows to listen to events without specifying a layer.
|
|
788
|
+
* @event
|
|
789
|
+
* @param type - The type of the event.
|
|
790
|
+
* @param listener - The listener callback.
|
|
791
|
+
*/
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Overload of the `on` method that allows to listen to events without specifying a layer.
|
|
795
|
+
* @event
|
|
796
|
+
* @param type - The type of the event.
|
|
797
|
+
* @param listener - The listener callback.
|
|
798
|
+
*/
|
|
799
|
+
|
|
800
|
+
on(type, listener) {
|
|
801
|
+
return super.on(type, listener);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* Overload of the `once` method that allows to listen to events without specifying a layer.
|
|
806
|
+
* @event
|
|
807
|
+
* @param type - The type of the event.
|
|
808
|
+
* @param listener - The listener callback.
|
|
809
|
+
*/
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* Overload of the `once` method that allows to listen to events without specifying a layer.
|
|
813
|
+
* @event
|
|
814
|
+
* @param type - The type of the event.
|
|
815
|
+
* @param listener - The listener callback.
|
|
816
|
+
*/
|
|
817
|
+
|
|
818
|
+
once(type, listener) {
|
|
819
|
+
return super.once(type, listener);
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Overload of the `off` method that allows to listen to events without specifying a layer.
|
|
824
|
+
* @event
|
|
825
|
+
* @param type - The type of the event.
|
|
826
|
+
* @param listener - The function previously installed as a listener.
|
|
827
|
+
*/
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Overload of the `off` method that allows to listen to events without specifying a layer.
|
|
831
|
+
* @event
|
|
832
|
+
* @param type - The type of the event.
|
|
833
|
+
* @param listener - The function previously installed as a listener.
|
|
834
|
+
*/
|
|
835
|
+
|
|
836
|
+
off(type, listener) {
|
|
837
|
+
return super.off(type, listener);
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Returns the map's containing HTML element.
|
|
842
|
+
*
|
|
843
|
+
* @returns The map's container.
|
|
844
|
+
*/
|
|
845
|
+
getContainer() {
|
|
846
|
+
return this._container;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* Returns the HTML element containing the map's `<canvas>` element.
|
|
851
|
+
*
|
|
852
|
+
* If you want to add non-GL overlays to the map, you should append them to this element.
|
|
853
|
+
*
|
|
854
|
+
* This is the element to which event bindings for map interactivity (such as panning and zooming) are
|
|
855
|
+
* attached. It will receive bubbled events from child elements such as the `<canvas>`, but not from
|
|
856
|
+
* map controls.
|
|
857
|
+
*
|
|
858
|
+
* @returns The container of the map's `<canvas>`.
|
|
859
|
+
* @see [Create a draggable point](https://maplibre.org/maplibre-gl-js/docs/examples/drag-a-point/)
|
|
860
|
+
*/
|
|
861
|
+
getCanvasContainer() {
|
|
862
|
+
return this._canvasContainer;
|
|
863
|
+
}
|
|
864
|
+
_containerDimensions() {
|
|
865
|
+
let width = 0;
|
|
866
|
+
let height = 0;
|
|
867
|
+
if (this._container) {
|
|
868
|
+
width = this._container.clientWidth || 400;
|
|
869
|
+
height = this._container.clientHeight || 300;
|
|
870
|
+
}
|
|
871
|
+
return [width, height];
|
|
872
|
+
}
|
|
873
|
+
_setupContainer() {
|
|
874
|
+
const container = this._container;
|
|
875
|
+
container.classList.add('l7-map');
|
|
876
|
+
const canvasContainer = this._canvasContainer = DOM.create('div', 'l7-canvas-container', container);
|
|
877
|
+
if (this._interactive) {
|
|
878
|
+
canvasContainer.classList.add('l7-interactive');
|
|
879
|
+
}
|
|
880
|
+
this._container.addEventListener('scroll', this._onMapScroll, false);
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* @internal
|
|
884
|
+
* Update this map's style and sources, and re-render the map.
|
|
885
|
+
*
|
|
886
|
+
* @param updateStyle - mark the map's style for reprocessing as
|
|
887
|
+
* well as its sources
|
|
888
|
+
*/
|
|
889
|
+
_update() {
|
|
890
|
+
this.triggerRepaint();
|
|
891
|
+
return this;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* @internal
|
|
896
|
+
* Request that the given callback be executed during the next render
|
|
897
|
+
* frame. Schedule a render frame if one is not already scheduled.
|
|
898
|
+
*
|
|
899
|
+
* @returns An id that can be used to cancel the callback
|
|
900
|
+
*/
|
|
901
|
+
_requestRenderFrame(callback) {
|
|
902
|
+
this._update();
|
|
903
|
+
return this._renderTaskQueue.add(callback);
|
|
904
|
+
}
|
|
905
|
+
_cancelRenderFrame(id) {
|
|
906
|
+
this._renderTaskQueue.remove(id);
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* @internal
|
|
911
|
+
* Call when a (re-)render of the map is required:
|
|
912
|
+
*
|
|
913
|
+
* - The style has changed (`setPaintProperty()`, etc.)
|
|
914
|
+
* - Source data has changed (e.g. tiles have finished loading)
|
|
915
|
+
* - The map has is moving (or just finished moving)
|
|
916
|
+
* - A transition is in progress
|
|
917
|
+
*
|
|
918
|
+
* @param paintStartTimeStamp - The time when the animation frame began executing.
|
|
919
|
+
*/
|
|
920
|
+
_render(paintStartTimeStamp) {
|
|
921
|
+
this._renderTaskQueue.run(paintStartTimeStamp);
|
|
922
|
+
// A task queue callback may have fired a user event which may have removed the map
|
|
923
|
+
if (this._removed) return;
|
|
924
|
+
this.fire(new Event('render'));
|
|
925
|
+
if (!this.isMoving()) {
|
|
926
|
+
this.fire(new Event('idle'));
|
|
927
|
+
}
|
|
928
|
+
return this;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* Clean up and release all internal resources associated with this map.
|
|
933
|
+
*
|
|
934
|
+
* This includes DOM elements, event bindings, web workers, and WebGL resources.
|
|
935
|
+
*
|
|
936
|
+
* Use this method when you are done using the map and wish to ensure that it no
|
|
937
|
+
* longer consumes browser resources. Afterwards, you must not call any other
|
|
938
|
+
* methods on the map.
|
|
939
|
+
*/
|
|
940
|
+
remove() {
|
|
941
|
+
var _this$_resizeObserver;
|
|
942
|
+
if (this._frameRequest) {
|
|
943
|
+
this._frameRequest.abort();
|
|
944
|
+
this._frameRequest = null;
|
|
945
|
+
}
|
|
946
|
+
this._renderTaskQueue.clear();
|
|
947
|
+
this.handlers.destroy();
|
|
948
|
+
delete this.handlers;
|
|
949
|
+
(_this$_resizeObserver = this._resizeObserver) === null || _this$_resizeObserver === void 0 || _this$_resizeObserver.disconnect();
|
|
950
|
+
DOM.remove(this._canvasContainer);
|
|
951
|
+
this._container.classList.remove('l7-map');
|
|
952
|
+
this._removed = true;
|
|
953
|
+
this.fire(new Event('remove'));
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* Trigger the rendering of a single frame. Use this method with custom layers to
|
|
958
|
+
* repaint the map when the layer changes. Calling this multiple times before the
|
|
959
|
+
* next frame is rendered will still result in only a single frame being rendered.
|
|
960
|
+
* @example
|
|
961
|
+
* ```ts
|
|
962
|
+
* map.triggerRepaint();
|
|
963
|
+
* ```
|
|
964
|
+
*/
|
|
965
|
+
triggerRepaint() {
|
|
966
|
+
if (!this._frameRequest) {
|
|
967
|
+
this._frameRequest = new AbortController();
|
|
968
|
+
browser.frameAsync(this._frameRequest).then(paintStartTimeStamp => {
|
|
969
|
+
this._frameRequest = null;
|
|
970
|
+
this._render(paintStartTimeStamp);
|
|
971
|
+
}).catch(() => {}); // ignore abort error
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* Returns the elevation for the point where the camera is looking.
|
|
977
|
+
* This value corresponds to:
|
|
978
|
+
* "meters above sea level" * "exaggeration"
|
|
979
|
+
* @returns The elevation.
|
|
980
|
+
*/
|
|
981
|
+
getCameraTargetElevation() {
|
|
982
|
+
return this.transform.elevation;
|
|
983
|
+
}
|
|
984
|
+
}
|