@maptiler/sdk 5.0.0-rc.1 → 5.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +178 -1
- package/dist/ImageViewer/monkeyPatchML.d.ts +1 -1
- package/dist/Map.d.ts +82 -1
- package/dist/Marker/Marker.d.ts +397 -0
- package/dist/Marker/MarkerManager.d.ts +137 -0
- package/dist/Marker/altitude-math.d.ts +24 -0
- package/dist/Marker/collision-helpers.d.ts +160 -0
- package/dist/Marker/index.d.ts +2 -0
- package/dist/Marker/marker-adaptive-colors.d.ts +35 -0
- package/dist/Marker/marker-animation-presets.d.ts +60 -0
- package/dist/Marker/marker-constants.d.ts +111 -0
- package/dist/Marker/marker-content-registry.d.ts +17 -0
- package/dist/Marker/marker-dom-utils.d.ts +66 -0
- package/dist/Marker/marker-icons.d.ts +31 -0
- package/dist/Marker/marker-state-helpers.d.ts +2 -0
- package/dist/Marker/marker-svg-config.d.ts +84 -0
- package/dist/Marker/marker-symbols.d.ts +12 -0
- package/dist/Marker/marker-text-fit.d.ts +20 -0
- package/dist/Marker/marker-transitions.d.ts +29 -0
- package/dist/Marker/types.d.ts +458 -0
- package/dist/index.d.ts +4 -1
- package/dist/mapstyle.d.ts +7 -0
- package/dist/maptiler-sdk.css +108 -1
- package/dist/maptiler-sdk.d.ts +1 -1
- package/dist/maptiler-sdk.mjs +16794 -14464
- package/dist/maptiler-sdk.mjs.map +1 -1
- package/dist/utils/object.d.ts +1 -0
- package/package.json +6 -5
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { Marker as MLMarker, CustomLayerProjectionData, LngLatLike, PointLike, Subscription } from 'maplibre-gl';
|
|
2
|
+
import { Map as SDKMap } from '../Map';
|
|
3
|
+
import { MapTilerMarkerElementOptions, MapTilerMarkerSVGOptions, PendingMarkerUpdates, Vector2, MapTilerMarkerOptions, MarkerCollisionEventData, MarkerCollisionDisplayState, MapTilerMarkerUIStateName, UIStateSpec, MarkerTransitionProperty, MapTilerMarkerTransitions, MarkerTransitionSpec, MarkerEventTypeSDK, GroundLineOptions, AltitudeReference, SetAltitudeOptions } from './types';
|
|
4
|
+
import { MarkerFootprint } from './collision-helpers';
|
|
5
|
+
import { PendingUpdatesSymbol, DetachFromDOMSymbol, FlushDOMUpdatesSymbol, MarkerElementSymbol, RefreshAdaptiveColorSymbol, CollisionFootprintSymbol, EmitCollisionDiffSymbol, ApplyCollisionDisplayStateSymbol, ApplyAltitudeFrameSymbol, MeasuredElementSizeSymbol, ClearFocusStateSymbol, AttachToMapSymbol } from './marker-symbols';
|
|
6
|
+
/** MapLibre's `Marker` extended with 2-D scale, named shapes, colour tokens, and batched DOM updates. */
|
|
7
|
+
export declare class Marker extends MLMarker {
|
|
8
|
+
/** Construction-time options snapshot — not updated by setters. */
|
|
9
|
+
readonly options: MapTilerMarkerOptions;
|
|
10
|
+
readonly _scale = 1;
|
|
11
|
+
/** Current values of all element-affecting properties. Written only via {@link setProp}. */
|
|
12
|
+
private readonly props;
|
|
13
|
+
/** Whether the shape anchor offset is auto-managed — `false` with an explicit `offset` or custom `element`. */
|
|
14
|
+
private readonly managesOffset;
|
|
15
|
+
/** The DOM element **/
|
|
16
|
+
[MarkerElementSymbol]: HTMLElement;
|
|
17
|
+
/** Property updates waiting to be flushed to the DOM on the next animation frame. */
|
|
18
|
+
[PendingUpdatesSymbol]: PendingMarkerUpdates;
|
|
19
|
+
/** Unscaled CSS pixel size of a custom `element`, measured once at registration. `null` until measured; unused for built-in SVG markers. */
|
|
20
|
+
[MeasuredElementSizeSymbol]: Vector2 | null;
|
|
21
|
+
/** UUID that uniquely identifies this marker instance. */
|
|
22
|
+
readonly id: string;
|
|
23
|
+
/**
|
|
24
|
+
* The `classList` of the marker's wrapper element — the inner transform
|
|
25
|
+
* wrapper of a built-in marker, or the custom `element` itself. Read-only
|
|
26
|
+
* reference; add and remove classes through the returned list.
|
|
27
|
+
*/
|
|
28
|
+
get classList(): DOMTokenList;
|
|
29
|
+
/** How the collision engine is currently displaying this marker. */
|
|
30
|
+
private collisionDisplayState;
|
|
31
|
+
/** Visual props overridden while minimized, restored from {@link props} on un-minimize. Empty when not minimized. */
|
|
32
|
+
private minimizedKeys;
|
|
33
|
+
/** Whether the minimized appearance is currently applied to the DOM. Lags {@link collisionDisplayState} during fades. */
|
|
34
|
+
private minimizedApplied;
|
|
35
|
+
/** Pending mid-fade appearance swap for minimize transitions. */
|
|
36
|
+
private minimizeSwapTimer;
|
|
37
|
+
/** Pending post-fade cull (`display: none`) while hidden. */
|
|
38
|
+
private cullTimer;
|
|
39
|
+
/** Pending release of the collision fade class once no fade/dip is in flight. */
|
|
40
|
+
private fadeClassReleaseTimer;
|
|
41
|
+
/** Registered property overrides per UI state, keyed by state name. */
|
|
42
|
+
private uiStates;
|
|
43
|
+
/** UI states currently active (interaction-driven). */
|
|
44
|
+
private readonly activeUIStates;
|
|
45
|
+
/** Keys owned by the flattened active UI state, masked out of DOM flushes like {@link minimizedKeys}. */
|
|
46
|
+
private appliedUIStateKeys;
|
|
47
|
+
/** Registered per-property transition config, keyed by property name. */
|
|
48
|
+
private transitions;
|
|
49
|
+
/** In-flight transitions, keyed by property — at most one each. `"opacity"` isn't a public {@link MarkerTransitionProperty}, reused for enter/exit fades. */
|
|
50
|
+
private readonly activeTransitions;
|
|
51
|
+
/** The currently-looping `idle` animation, if any — started after `enter` finishes (or immediately), stopped on `remove()`. */
|
|
52
|
+
private idleAnimation;
|
|
53
|
+
/** Configured enter/idle/exit lifecycle animations. */
|
|
54
|
+
private animations;
|
|
55
|
+
/** Set during `addTo()`'s call into the base `addTo()`, which calls `this.remove()` first to detach from any previous map. */
|
|
56
|
+
private suppressLifecycleAnimations;
|
|
57
|
+
/** Altitude in meters, faked via a per-frame pixel offset (MapLibre's Marker has no native Z). 0 by default — see {@link setAltitude}. */
|
|
58
|
+
private altitudeMeters;
|
|
59
|
+
/** What {@link altitudeMeters} is measured from — see {@link AltitudeReference}. */
|
|
60
|
+
private altitudeReference;
|
|
61
|
+
/** True once {@link setAltitude} has been called at least once — see {@link hasActiveAltitude}. */
|
|
62
|
+
private altitudeEngaged;
|
|
63
|
+
/** The offset MapLibre would show with no altitude applied. Only {@link writeOffset} should write the real offset — anything that calls `super.setOffset` directly clobbers altitude. */
|
|
64
|
+
private baseOffset;
|
|
65
|
+
/** Pixel delta from `groundBase` to `elevated`, added to {@link baseOffset}. Null when off-screen/behind camera. */
|
|
66
|
+
private altitudeDelta;
|
|
67
|
+
/** The `elevated` point in absolute canvas CSS pixels — the ground line's position. */
|
|
68
|
+
private groundLineOrigin;
|
|
69
|
+
/** True when off-screen/behind the camera. Not the below-ground case — see {@link altitudeOccluded}. */
|
|
70
|
+
private altitudeHidden;
|
|
71
|
+
/** True when below ground (`computeAltitudeProjection`'s `belowGround`). */
|
|
72
|
+
private altitudeOccluded;
|
|
73
|
+
private groundLineEnabled;
|
|
74
|
+
private groundLineOptions;
|
|
75
|
+
private groundLineEl;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a marker from a pre-built DOM or SVG element.
|
|
78
|
+
*
|
|
79
|
+
* `shape`/`size` don't apply. Color/shadow options still apply as CSS
|
|
80
|
+
* custom properties for the element's own styles to consume.
|
|
81
|
+
*/
|
|
82
|
+
constructor(options: MapTilerMarkerElementOptions);
|
|
83
|
+
/** Creates a marker styled via the built-in SVG system (`shape`, `size`, colour tokens, shadow). With no options, uses the default appearance. */
|
|
84
|
+
constructor(options?: MapTilerMarkerSVGOptions);
|
|
85
|
+
/**
|
|
86
|
+
* Adds a listener for events of a specified type.
|
|
87
|
+
* Accepts the MapLibre events as well as the SDK events (see {@link MaptilerMarkerEventType}).
|
|
88
|
+
*/
|
|
89
|
+
on<T extends keyof MarkerEventTypeSDK>(type: T, listener: (ev: MarkerEventTypeSDK[T]) => void): Subscription;
|
|
90
|
+
/**
|
|
91
|
+
* Adds a listener that will be called only once to a specified event type.
|
|
92
|
+
* Accepts the MapLibre events as well as the SDK events (see {@link MaptilerMarkerEventType}).
|
|
93
|
+
*/
|
|
94
|
+
once<T extends keyof MarkerEventTypeSDK>(type: T): Promise<MarkerEventTypeSDK[T]>;
|
|
95
|
+
once<T extends keyof MarkerEventTypeSDK>(type: T, listener: (ev: MarkerEventTypeSDK[T]) => void): this;
|
|
96
|
+
/**
|
|
97
|
+
* Removes an event listener previously added with {@link Marker.on} or {@link Marker.once}.
|
|
98
|
+
* Accepts the MapLibre events as well as the SDK events (see {@link MaptilerMarkerEventType}).
|
|
99
|
+
*/
|
|
100
|
+
off<T extends keyof MarkerEventTypeSDK>(type: T, listener: (ev: MarkerEventTypeSDK[T]) => void): this;
|
|
101
|
+
/**
|
|
102
|
+
* Adds the marker to a map. Equivalent to `map.addMarker(marker)`, which it delegates to.
|
|
103
|
+
* @deprecated Use `map.addMarker(marker)` instead. Kept for MapLibre-style call sites and will be removed in a future major version.
|
|
104
|
+
* @param map - Target map instance.
|
|
105
|
+
*/
|
|
106
|
+
addTo(map: SDKMap): this;
|
|
107
|
+
/**
|
|
108
|
+
* Attaches the marker to a map, and plays the configured `enter` animation (if any) once attached.
|
|
109
|
+
* Called only by `MarkerManager` during registration.
|
|
110
|
+
* @param map - Target map instance.
|
|
111
|
+
*/
|
|
112
|
+
[AttachToMapSymbol](map: SDKMap): this;
|
|
113
|
+
/** Recomputes the shape anchor offset so the shape's tip stays on the lngLat. No-op with an explicit `offset` or custom `element`. */
|
|
114
|
+
private applyShapeAnchorOffset;
|
|
115
|
+
/**
|
|
116
|
+
* Records a property's new value and schedules a DOM flush on the next
|
|
117
|
+
* animation frame via {@link MarkerManager}.
|
|
118
|
+
* @param prop - The element property to update.
|
|
119
|
+
* @param value - The new value for the property.
|
|
120
|
+
*/
|
|
121
|
+
private setProp;
|
|
122
|
+
/**
|
|
123
|
+
* Applies all pending property updates to the marker element and clears
|
|
124
|
+
* the batch. Called by {@link MarkerManager} on the next animation frame.
|
|
125
|
+
*/
|
|
126
|
+
[FlushDOMUpdatesSymbol](): void;
|
|
127
|
+
/** Returns the style id of the map this marker is on, or `undefined` when detached. */
|
|
128
|
+
private getCurrentStyleId;
|
|
129
|
+
/** Queues re-resolving every unset colour against the current map style. */
|
|
130
|
+
[RefreshAdaptiveColorSymbol](): void;
|
|
131
|
+
/** Sets one colour prop; `undefined` returns it to its map-style default (resolved at flush time, so nothing to transition to). */
|
|
132
|
+
private setColorProp;
|
|
133
|
+
/** A colour prop's value in effect — the explicit one, else the default for the map's style. */
|
|
134
|
+
private getEffectiveColor;
|
|
135
|
+
/** Resolves the marker's screen footprint for collision detection. Always full-size, even minimized. */
|
|
136
|
+
[CollisionFootprintSymbol](): MarkerFootprint;
|
|
137
|
+
/** Shape/size keys, or minimized substitutes. */
|
|
138
|
+
private effectiveShapeAndSize;
|
|
139
|
+
/** Screen offset for the collision footprint. */
|
|
140
|
+
private footprintOffset;
|
|
141
|
+
/** Fires the collision transition event (`markeroverlap`/`markerproximity`). */
|
|
142
|
+
[EmitCollisionDiffSymbol](data: MarkerCollisionEventData): void;
|
|
143
|
+
/**
|
|
144
|
+
* Applies the collision engine's display-state decision.
|
|
145
|
+
*
|
|
146
|
+
* Every transition fades. Hide/show fade in place; visible<->minimized
|
|
147
|
+
* fades *through* zero (dip out, swap at the invisible midpoint, fade back in).
|
|
148
|
+
*/
|
|
149
|
+
[ApplyCollisionDisplayStateSymbol](state: MarkerCollisionDisplayState): void;
|
|
150
|
+
/** Toggles the collision-hidden fade and reschedules releasing the fade class — see {@link fadeClassReleaseTimer}. */
|
|
151
|
+
private setCollisionHidden;
|
|
152
|
+
/** The fade duration (ms) configured for this marker's map, or the SDK default when off a map. */
|
|
153
|
+
private collisionTransitionMs;
|
|
154
|
+
/** Applies or restores the minimized appearance if it differs from what the DOM shows. */
|
|
155
|
+
private setMinimizedApplied;
|
|
156
|
+
/** Returns how the collision engine is currently displaying this marker. */
|
|
157
|
+
getCollisionDisplayState(): MarkerCollisionDisplayState;
|
|
158
|
+
/** The visual props the minimized appearance overrides for this marker. */
|
|
159
|
+
private minimizedOverrides;
|
|
160
|
+
/** Applies or restores the minimized appearance, straight to the DOM (never {@link setProp}). */
|
|
161
|
+
private applyMinimizedAppearance;
|
|
162
|
+
/** Builds the batch restoring `keys` to their prop values. */
|
|
163
|
+
private restoreUpdates;
|
|
164
|
+
/**
|
|
165
|
+
* Sets the marker's geographical position.
|
|
166
|
+
* @param lnglat - The new position.
|
|
167
|
+
*/
|
|
168
|
+
setLngLat(lnglat: LngLatLike): this;
|
|
169
|
+
/**
|
|
170
|
+
* Sets the marker's screen-space pixel offset. Composes with altitude (see {@link writeOffset}) rather than replacing it.
|
|
171
|
+
* @param offset - Offset in pixels (+y down).
|
|
172
|
+
*/
|
|
173
|
+
setOffset(offset: PointLike): this;
|
|
174
|
+
/** The only path that should write MapLibre's real offset: records `offset` as {@link baseOffset}, then writes `base + altitudeDelta`. Callers must never use `super.setOffset` directly, or altitude gets silently dropped. */
|
|
175
|
+
private writeOffset;
|
|
176
|
+
/**
|
|
177
|
+
* Sets the 2-D scale of the marker as `[x, y]`.
|
|
178
|
+
* @param scaleVector - Scale factors for the x and y axes.
|
|
179
|
+
*/
|
|
180
|
+
setScale(scaleVector: Vector2): void;
|
|
181
|
+
/** Returns the current 2-D scale. Defaults to `[1, 1]`. */
|
|
182
|
+
getScale(): Vector2 | undefined;
|
|
183
|
+
/**
|
|
184
|
+
* Sets the marker shape. Applies the new anchor offset (see {@link applyShapeAnchorOffset}).
|
|
185
|
+
* @param shape - Marker shape key.
|
|
186
|
+
*/
|
|
187
|
+
setShape(shape: MapTilerMarkerOptions["shape"]): void;
|
|
188
|
+
/** Returns the current shape, or `undefined` if never set. */
|
|
189
|
+
getShape(): import('./types').MapTilerMarkerShape | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* Sets the marker size.
|
|
192
|
+
* @param size - Marker size key.
|
|
193
|
+
*/
|
|
194
|
+
setSize(size: MapTilerMarkerOptions["size"]): void;
|
|
195
|
+
/** Returns the current size, or `undefined` if never explicitly set. */
|
|
196
|
+
getSize(): import('./types').MapTilerMarkerSize | undefined;
|
|
197
|
+
/**
|
|
198
|
+
* Sets the drop-shadow intensity.
|
|
199
|
+
* @param shadow - Shadow intensity preset, or `undefined` to reset to the default (`"medium"`). Use `"none"` to disable.
|
|
200
|
+
*/
|
|
201
|
+
setShadow(shadow: MapTilerMarkerOptions["shadow"]): void;
|
|
202
|
+
/** Returns the current shadow preset, or `undefined` if none is set. */
|
|
203
|
+
getShadow(): import('./types').MapTilerMarkerShadow | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* Sets the fill colour of the outer body of the marker.
|
|
206
|
+
* @param color - Any valid CSS colour string, or `undefined` to return to the map-style default.
|
|
207
|
+
*/
|
|
208
|
+
setOuterColor(color: MapTilerMarkerOptions["outerColor"]): void;
|
|
209
|
+
/** Returns the outer body colour currently in effect — the explicit `outerColor`, else the default for the map's style. */
|
|
210
|
+
getOuterColor(): string;
|
|
211
|
+
/**
|
|
212
|
+
* Sets an explicit fill colour for the inner area of the marker, replacing
|
|
213
|
+
* the map-style default.
|
|
214
|
+
* @param color - Any valid CSS colour string, or `undefined` to return to the map-style default.
|
|
215
|
+
*/
|
|
216
|
+
setInnerColor(color: MapTilerMarkerOptions["innerColor"]): void;
|
|
217
|
+
/** Returns the inner area colour currently in effect — the explicit `innerColor`, else the default for the map's style. */
|
|
218
|
+
getInnerColor(): string;
|
|
219
|
+
/**
|
|
220
|
+
* Sets the colour applied to the marker content (icon, text, etc.).
|
|
221
|
+
* @param color - Any valid CSS colour string, or `undefined` to return to the map-style default.
|
|
222
|
+
*/
|
|
223
|
+
setContentColor(color: MapTilerMarkerOptions["contentColor"]): void;
|
|
224
|
+
/** Returns the content colour currently in effect — the explicit `contentColor`, else the default for the map's style. */
|
|
225
|
+
getContentColor(): string;
|
|
226
|
+
/**
|
|
227
|
+
* Sets the stroke colour of the marker outline.
|
|
228
|
+
* Has no visible effect unless {@link setOutline} is also called.
|
|
229
|
+
* @param color - Any valid CSS colour string, or `undefined` to return to the map-style default.
|
|
230
|
+
*/
|
|
231
|
+
setOutlineColor(color: MapTilerMarkerOptions["outlineColor"]): void;
|
|
232
|
+
/** Returns the outline stroke colour currently in effect — the explicit `outlineColor`, else the default for the map's style. */
|
|
233
|
+
getOutlineColor(): string;
|
|
234
|
+
/**
|
|
235
|
+
* Sets the outline stroke width on the marker body.
|
|
236
|
+
* @param outline - `true` for the default width, a positive `number` for an
|
|
237
|
+
* explicit pixel width, or `undefined` to remove the outline.
|
|
238
|
+
*/
|
|
239
|
+
setOutline(outline: MapTilerMarkerOptions["outline"]): void;
|
|
240
|
+
/** Returns the current outline value (`true`, a pixel width, or `undefined`). */
|
|
241
|
+
getOutline(): number | true | undefined;
|
|
242
|
+
/**
|
|
243
|
+
* Sets the `title` attribute on the marker's root element (native tooltip).
|
|
244
|
+
* @param title - Tooltip string, or `undefined` to remove the attribute.
|
|
245
|
+
*/
|
|
246
|
+
setTitle(title: MapTilerMarkerOptions["title"]): void;
|
|
247
|
+
/** Returns the current title string. */
|
|
248
|
+
getTitle(): string | undefined;
|
|
249
|
+
/**
|
|
250
|
+
* Sets the text content displayed inside the marker body.
|
|
251
|
+
* @param content - Label string, or `undefined` to clear.
|
|
252
|
+
*/
|
|
253
|
+
setContent(content: MapTilerMarkerOptions["content"]): void;
|
|
254
|
+
/** Returns the current content string. */
|
|
255
|
+
getContent(): string | undefined;
|
|
256
|
+
/**
|
|
257
|
+
* Sets the rendering priority.
|
|
258
|
+
* @param priority - Numeric priority, a MapLibre-style expression, or
|
|
259
|
+
* `undefined` to restore DOM-order stacking.
|
|
260
|
+
*/
|
|
261
|
+
setPriority(priority: MapTilerMarkerOptions["priority"]): void;
|
|
262
|
+
/** Returns the current rendering priority, or `undefined` if never set. */
|
|
263
|
+
getPriority(): number | import('./types').MarkerPriorityExpression | undefined;
|
|
264
|
+
/**
|
|
265
|
+
* Shows or hides the debug overlay, which renders the marker's bounding
|
|
266
|
+
* box and center point on top of the marker element.
|
|
267
|
+
* @param debug - `true` to show the overlay, `false`/`undefined` to hide it.
|
|
268
|
+
*/
|
|
269
|
+
setDebug(debug: MapTilerMarkerOptions["debug"]): void;
|
|
270
|
+
/** Returns whether the debug overlay is currently enabled. */
|
|
271
|
+
getDebug(): boolean;
|
|
272
|
+
/**
|
|
273
|
+
* Rotates the marker's inner shell element in degrees, via the CSS
|
|
274
|
+
* `scale(x, y) rotate(deg)` transform on the inner wrapper — independent
|
|
275
|
+
* of MapLibre's own rotation on the outer container.
|
|
276
|
+
* @param rotation - Clockwise rotation in degrees.
|
|
277
|
+
*/
|
|
278
|
+
setRotation(rotation: number): this;
|
|
279
|
+
/**
|
|
280
|
+
* Returns the current inner-shell rotation in degrees.
|
|
281
|
+
* @returns Rotation in degrees; `0` if never set.
|
|
282
|
+
*/
|
|
283
|
+
getRotation(): number;
|
|
284
|
+
private attachUIStateListeners;
|
|
285
|
+
/** Blurs the marker's focusable element. Called by {@link MarkerManager} on map `click`. */
|
|
286
|
+
[ClearFocusStateSymbol](): void;
|
|
287
|
+
private setUIStateActive;
|
|
288
|
+
private applyUIStates;
|
|
289
|
+
/**
|
|
290
|
+
* Registers (or replaces) the property overrides applied while `name` is
|
|
291
|
+
* active. Applies immediately if that state is currently active.
|
|
292
|
+
* @param name - UI state to configure.
|
|
293
|
+
* @param spec - Property overrides to apply while the state is active.
|
|
294
|
+
*/
|
|
295
|
+
setUIState(name: MapTilerMarkerUIStateName, spec: UIStateSpec): void;
|
|
296
|
+
/**
|
|
297
|
+
* Configures (or clears) the easing used the next time `property` changes.
|
|
298
|
+
* @param property - Transitionable property to configure.
|
|
299
|
+
* @param transition - `[duration, easing?, delay?]` in milliseconds, or `null` to make future changes snap immediately again.
|
|
300
|
+
*/
|
|
301
|
+
setTransitionForProperty(property: MarkerTransitionProperty, transition: MarkerTransitionSpec | null): void;
|
|
302
|
+
/** Returns a copy of the currently configured per-property transitions. */
|
|
303
|
+
getTransitions(): MapTilerMarkerTransitions;
|
|
304
|
+
/**
|
|
305
|
+
* Applies `to` to `property`, either immediately or by easing from `from`
|
|
306
|
+
* when a transition is configured. Fires `transitionstart`/`transitionend`.
|
|
307
|
+
* @param property - Transitionable property being changed.
|
|
308
|
+
* @param from - Current value.
|
|
309
|
+
* @param to - Value being set.
|
|
310
|
+
* @param codec - Bridges `T` to/from the flat numeric props the underlying animation interpolates.
|
|
311
|
+
* @param apply - Writes an interpolated (or the immediate) value to the marker.
|
|
312
|
+
*/
|
|
313
|
+
private applyTransitionable;
|
|
314
|
+
/** Cancels any transition in flight for `property`, leaving its current (mid-transition) value as-is. */
|
|
315
|
+
private cancelTransition;
|
|
316
|
+
/** Cancels every transition in flight. Called on removal so a destroyed marker's props can't keep animating. */
|
|
317
|
+
private cancelAllTransitions;
|
|
318
|
+
/** Runs `preset`'s enter/exit motion (opacity + scale + lift) from `from` to `to`. */
|
|
319
|
+
private playLifecycleTransition;
|
|
320
|
+
/** Runs a `custom` enter/exit animation: an eased `0`→`1` alpha handed to `spec.custom` every frame. */
|
|
321
|
+
private playCustomLifecycleAnimation;
|
|
322
|
+
/** Clears the enter-mask opacity set at construction. Idempotent, safe to call unconditionally — each enter/exit path (preset or `custom`) is responsible for calling it on its own first frame, since the SDK can't know in advance whether a `custom` callback touches opacity. */
|
|
323
|
+
private clearEnterMask;
|
|
324
|
+
/** Plays the configured `enter` animation, easing from {@link enterPresetHiddenValue} up to the marker's own configured state. */
|
|
325
|
+
private playEnterAnimation;
|
|
326
|
+
/** Plays the configured `exit` animation, easing from the marker's own configured state down to {@link exitPresetHiddenValue}. */
|
|
327
|
+
private playExitAnimation;
|
|
328
|
+
/** Wires play/iteration/stop bookkeeping around a `value`-keyframed animation, and plays it. */
|
|
329
|
+
private runIdleAnimation;
|
|
330
|
+
/** Starts the configured `idle` loop — `preset`'s single channel (see {@link IDLE_PRESET_CONFIG}), or a `custom` callback fed a `0`→`1` alpha. */
|
|
331
|
+
private startIdleAnimation;
|
|
332
|
+
/** Stops the currently-looping `idle` animation, if any, leaving the marker at its current (mid-loop) state. */
|
|
333
|
+
private stopIdleAnimation;
|
|
334
|
+
/**
|
|
335
|
+
* Sets altitude in meters above the ground plane (negative is fine — below
|
|
336
|
+
* ground/sea level), faked via a per-frame pixel offset. `options.relativeTo`
|
|
337
|
+
* (default `"ground"`) picks what the meters are measured from. There is
|
|
338
|
+
* deliberately no fast path for `meters: 0`: MapLibre's native marker
|
|
339
|
+
* position is already terrain-elevated whenever the map has terrain, so
|
|
340
|
+
* doing nothing at `0` would leave the marker on the terrain, not at
|
|
341
|
+
* ground/sea level.
|
|
342
|
+
*
|
|
343
|
+
* Pass `false` to unset: deregisters and clamps to MapLibre's own native
|
|
344
|
+
* (terrain-aware) position, same as a marker that never called this.
|
|
345
|
+
* @param meters - Altitude in meters, measured per `options.relativeTo`, or `false` to unset altitude entirely.
|
|
346
|
+
* @param options - See {@link SetAltitudeOptions}. Ignored when `meters` is `false`.
|
|
347
|
+
* @experimental
|
|
348
|
+
*/
|
|
349
|
+
setAltitude(meters: false): this;
|
|
350
|
+
setAltitude(meters: number, options?: SetAltitudeOptions): this;
|
|
351
|
+
/**
|
|
352
|
+
* Returns the current altitude in meters, or 0 if never set.
|
|
353
|
+
* @experimental
|
|
354
|
+
*/
|
|
355
|
+
getAltitude(): number;
|
|
356
|
+
/**
|
|
357
|
+
* Returns what {@link getAltitude}'s meters are measured from. Defaults to `"ground"`.
|
|
358
|
+
* @experimental
|
|
359
|
+
*/
|
|
360
|
+
getAltitudeReference(): AltitudeReference;
|
|
361
|
+
/**
|
|
362
|
+
* True from the first {@link setAltitude} call onward.
|
|
363
|
+
* @experimental
|
|
364
|
+
*/
|
|
365
|
+
hasActiveAltitude(): boolean;
|
|
366
|
+
/** Stamps `altitude`/`altitudeReference`/`altitudeEngaged` onto every `dragstart`/`drag`/`dragend` event. */
|
|
367
|
+
fire(event: string | {
|
|
368
|
+
type: string;
|
|
369
|
+
}, properties?: Record<string, unknown>): this;
|
|
370
|
+
/**
|
|
371
|
+
* Toggles a dashed line from the marker down (or up) to its ground point.
|
|
372
|
+
* Off by default. See `.maptiler-marker-groundline` in
|
|
373
|
+
* the SDK stylesheet and {@link GroundLineOptions.className}.
|
|
374
|
+
* @param enabled - Whether to show the line.
|
|
375
|
+
* @param options - Optional extra CSS class for styling.
|
|
376
|
+
* @experimental
|
|
377
|
+
*/
|
|
378
|
+
setGroundLine(enabled: boolean, options?: GroundLineOptions): this;
|
|
379
|
+
/**
|
|
380
|
+
* Per-frame altitude hook, called by {@link MarkerManager} for every altitude-active marker. Returns the elevated point's camera depth (used to rank z-index among altitude-active markers), or `null` when off-screen/behind the camera.
|
|
381
|
+
*/
|
|
382
|
+
[ApplyAltitudeFrameSymbol](projectionData: CustomLayerProjectionData, map: SDKMap): number | null;
|
|
383
|
+
/** Idempotent toggle for {@link altitudeHidden} — cheap to call every frame regardless of whether the state actually changed. */
|
|
384
|
+
private setAltitudeHidden;
|
|
385
|
+
/** Idempotent toggle for {@link altitudeOccluded} — cheap to call every frame regardless of whether the state actually changed. */
|
|
386
|
+
private setAltitudeOccluded;
|
|
387
|
+
/**
|
|
388
|
+
* Creates/updates/removes the ground-line element. Geometry (position/width/rotation) comes from {@link altitudeDelta}/{@link groundLineOrigin}. Lives in a shared container at the map level ({@link MarkerManager.getGroundLineContainer}), not nested in this marker's own element — otherwise a long line would inherit its marker's camera-depth z-index and could paint over another marker's icon.
|
|
389
|
+
*/
|
|
390
|
+
private updateGroundLineElement;
|
|
391
|
+
/** Removes the marker from the DOM directly, bypassing {@link MarkerManager}. */
|
|
392
|
+
[DetachFromDOMSymbol](): void;
|
|
393
|
+
/** Removes the marker, playing the configured `exit` animation first (if any) before detaching from the DOM. */
|
|
394
|
+
remove(): this;
|
|
395
|
+
/** Deregisters (if registered) and detaches from the DOM immediately — no exit animation. */
|
|
396
|
+
private detachImmediately;
|
|
397
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Marker } from './Marker';
|
|
2
|
+
import { Map as SDKMap } from '../Map';
|
|
3
|
+
import { MarkerCollisionGroups, MarkerCollisionOptions } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* @class MarkerManagerImpl
|
|
6
|
+
* @description This singleton is used to batch marker updates and flush them to the DOM in a
|
|
7
|
+
* single animation frame to avoid multiple separate attribute writes
|
|
8
|
+
* It is not exposed as a public API and only used internally in the `Map` and `Marker` classes.
|
|
9
|
+
* It _may_ be used by multiple Maps.
|
|
10
|
+
*/
|
|
11
|
+
declare class MarkerManagerImpl {
|
|
12
|
+
private readonly dirty;
|
|
13
|
+
private animationFrameID;
|
|
14
|
+
private readonly markerMap;
|
|
15
|
+
private readonly mapIndex;
|
|
16
|
+
private readonly lastStyleId;
|
|
17
|
+
private readonly collisionState;
|
|
18
|
+
private readonly collisionPending;
|
|
19
|
+
private readonly dragEndHandlers;
|
|
20
|
+
private readonly altitudeState;
|
|
21
|
+
private altitudeLayerSequence;
|
|
22
|
+
private scheduleFlush;
|
|
23
|
+
private getOrCreateIndex;
|
|
24
|
+
private refreshAdaptiveColors;
|
|
25
|
+
register(marker: Marker, map: SDKMap): void;
|
|
26
|
+
deregister(marker: Marker, options?: {
|
|
27
|
+
deferDetach?: boolean;
|
|
28
|
+
}): void;
|
|
29
|
+
deregisterById(map: SDKMap, id: string): void;
|
|
30
|
+
deregisterAll(map: SDKMap, ids?: string[]): void;
|
|
31
|
+
getMap(marker: Marker): SDKMap | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the id of the map's current style (e.g. `"streets-v4-dark"`), or
|
|
34
|
+
* `undefined` when it cannot be determined (custom style spec / URL).
|
|
35
|
+
* Falls back to the raw stylesheet's `id` field, since the id is not part
|
|
36
|
+
* of the serialized `StyleSpecification` returned by `map.getStyle()`.
|
|
37
|
+
*/
|
|
38
|
+
getMapStyleId(map: SDKMap): string | undefined;
|
|
39
|
+
getMarkers(map: SDKMap): Marker[];
|
|
40
|
+
getMarker(map: SDKMap, id: string): Marker | undefined;
|
|
41
|
+
flushUpdates(): void;
|
|
42
|
+
addMarkerUpdateToQueue(marker: Marker): void;
|
|
43
|
+
cancelCuedUpdatesForMarker(marker: Marker): void;
|
|
44
|
+
/**
|
|
45
|
+
* Requests a full collision detection pass for a map's markers.
|
|
46
|
+
*
|
|
47
|
+
* The single entry point for everything that can change collisions —
|
|
48
|
+
* marker add / remove / move / drag, footprint changes, and camera
|
|
49
|
+
* `moveend`. Requests coalesce onto one animation frame, so a bulk add
|
|
50
|
+
* runs the pass once. During camera movement markers track their positions
|
|
51
|
+
* via MapLibre's own per-frame update; the pass itself only runs when
|
|
52
|
+
* movement settles (dense fields make it quadratic in overlapping pairs).
|
|
53
|
+
*/
|
|
54
|
+
invalidateCollisions(map: SDKMap): void;
|
|
55
|
+
/**
|
|
56
|
+
* Collision groups from the latest detection pass: the full sets of
|
|
57
|
+
* mutually-colliding markers, with no priority or winner/loser resolution.
|
|
58
|
+
* The behaviour layer consumes these to decide what to do about collisions.
|
|
59
|
+
*/
|
|
60
|
+
getCollisionGroups(map: SDKMap): MarkerCollisionGroups;
|
|
61
|
+
/**
|
|
62
|
+
* Configures collision detection for a map.
|
|
63
|
+
* @param options.proximityPadding - Distance in CSS px within which two
|
|
64
|
+
* markers count as "in proximity". Overlap always uses 0.
|
|
65
|
+
* @param options.accuracy - `high` (default) tests rotated markers with
|
|
66
|
+
* their actual rotated box; `low` uses the enclosing upright box, which
|
|
67
|
+
* is cheaper but over-reports collisions for rotated markers.
|
|
68
|
+
* @param options.behaviour - Default collision behaviour for every marker
|
|
69
|
+
* on the map; a marker's own `collisionBehaviour` option overrides it.
|
|
70
|
+
* Defaults to `always-show`.
|
|
71
|
+
* @param options.transitionDuration - Duration in ms of the hide/show/minimize fade. Defaults to `150`.
|
|
72
|
+
* @param options.transitionEasing - CSS easing function for the fade. Defaults to `"ease"`.
|
|
73
|
+
*/
|
|
74
|
+
setCollisionOptions(map: SDKMap, options: MarkerCollisionOptions): void;
|
|
75
|
+
/** Returns the fade-transition duration (ms) configured for `map`, or the SDK default if never configured. */
|
|
76
|
+
getCollisionTransitionDuration(map: SDKMap): number;
|
|
77
|
+
private applyCollisionTransitionVars;
|
|
78
|
+
private getOrCreateCollisionState;
|
|
79
|
+
/**
|
|
80
|
+
* The full detection pass. Builds each marker's screen box from its stored
|
|
81
|
+
* footprint and projected position (no DOM reads), finds intersecting
|
|
82
|
+
* pairs, derives collision groups, then diffs against the previous pass so
|
|
83
|
+
* markers only emit enter/exit transitions.
|
|
84
|
+
*
|
|
85
|
+
* Markers outside the (margin-padded) viewport never enter the pass: they
|
|
86
|
+
* are hidden outright — off screen there is nothing to show, and skipping
|
|
87
|
+
* them keeps the pair scan and placement proportional to what is actually
|
|
88
|
+
* visible. They rejoin (and fade back in) on the first pass that finds
|
|
89
|
+
* them near the viewport again. Consequence: collision events and
|
|
90
|
+
* `getCollisionGroups` only cover on-screen markers.
|
|
91
|
+
*/
|
|
92
|
+
private runCollisionPass;
|
|
93
|
+
/**
|
|
94
|
+
* The behaviour layer: turns the pass's geometry into display states via
|
|
95
|
+
* greedy priority placement — `hide-by-priority` losers hide (and stop
|
|
96
|
+
* blocking), `minimize-by-priority` losers minimize (and keep reserving
|
|
97
|
+
* their full-size box, so priority order is strict). See
|
|
98
|
+
* {@link resolveDisplayStates}.
|
|
99
|
+
*
|
|
100
|
+
* Hide/minimize act on *overlap* only — the proximity padding stays an
|
|
101
|
+
* events-only concern; `collisionRadius` is the per-marker way to act at a
|
|
102
|
+
* distance.
|
|
103
|
+
*/
|
|
104
|
+
private applyCollisionBehaviours;
|
|
105
|
+
/** Resolves a marker's collision behaviour against the map default. */
|
|
106
|
+
private effectiveBehaviour;
|
|
107
|
+
private getOrCreateCollisionSet;
|
|
108
|
+
private linkCollision;
|
|
109
|
+
/** Allocation-free set equality — dense passes must not allocate for unchanged collisions. */
|
|
110
|
+
private collisionSetsEqual;
|
|
111
|
+
private emitCollisionDiffs;
|
|
112
|
+
/**
|
|
113
|
+
* Starts driving `marker`'s per-frame altitude projection on `map`. Shared
|
|
114
|
+
* across every altitude-active marker on the map — several markers here
|
|
115
|
+
* still cost one no-op custom layer and one `render` listener, not one
|
|
116
|
+
* each. Called by {@link Marker.setAltitude} (and by {@link register} for
|
|
117
|
+
* a marker whose altitude was set before it had a map).
|
|
118
|
+
*/
|
|
119
|
+
registerAltitudeParticipant(marker: Marker, map: SDKMap): void;
|
|
120
|
+
/** Stops driving `marker`'s altitude projection. Tears down the shared layer/listener once the last participant on `map` leaves. */
|
|
121
|
+
deregisterAltitudeParticipant(marker: Marker, map: SDKMap): void;
|
|
122
|
+
/**
|
|
123
|
+
* The shared, always-behind-markers container every marker's ground-line
|
|
124
|
+
* element gets appended to on this map — a sibling of the marker elements
|
|
125
|
+
* (both live in `map.getCanvasContainer()`), not a descendant of any one
|
|
126
|
+
* marker, so a long line can never inherit a marker's camera-depth
|
|
127
|
+
* z-index and paint over some *other* marker's icon. Created together
|
|
128
|
+
* with the rest of the per-map altitude state.
|
|
129
|
+
*/
|
|
130
|
+
getGroundLineContainer(map: SDKMap): HTMLDivElement;
|
|
131
|
+
private getOrCreateAltitudeState;
|
|
132
|
+
private ensureAltitudeLayerInstalled;
|
|
133
|
+
private installAltitudeLayer;
|
|
134
|
+
private teardownAltitudeLayer;
|
|
135
|
+
}
|
|
136
|
+
export declare const MarkerManager: MarkerManagerImpl;
|
|
137
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CustomLayerProjectionData, LngLat, Map as MLMap } from 'maplibre-gl';
|
|
2
|
+
import { AltitudeReference } from './types';
|
|
3
|
+
/** A screen-space position in CSS pixels, DOM convention (+y down). */
|
|
4
|
+
export interface ScreenPoint {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
/** Clip-space W — proportional to camera distance. For ordering points against each other, not a real distance. */
|
|
8
|
+
depth: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Projects `lngLat`/`altitudeMeters` to a screen point using the projection data MapLibre hands to custom layers each frame.
|
|
12
|
+
* A JS port of MapLibre's `projectTileFor3D` shader function, so it works under mercator, globe, and mid-morph between the two.
|
|
13
|
+
*/
|
|
14
|
+
export declare function projectLngLatAltitude(lngLat: LngLat, altitudeMeters: number, projectionData: CustomLayerProjectionData, map: MLMap): ScreenPoint | null;
|
|
15
|
+
/**
|
|
16
|
+
* `groundBase` — MapLibre's own native marker position (terrain height, or 0 without terrain).
|
|
17
|
+
* `elevated` — the target: `nativeElevation + altitudeMeters` under `"ground"`, or plain `altitudeMeters` under `"sea"`.
|
|
18
|
+
* `belowGround` — `elevated` under `groundBase`, for fading markers DOM can't depth-test against terrain.
|
|
19
|
+
*/
|
|
20
|
+
export declare function computeAltitudeProjection(lngLat: LngLat, altitudeMeters: number, projectionData: CustomLayerProjectionData, map: MLMap, relativeTo: AltitudeReference): {
|
|
21
|
+
groundBase: ScreenPoint;
|
|
22
|
+
elevated: ScreenPoint;
|
|
23
|
+
belowGround: boolean;
|
|
24
|
+
} | null;
|