@maptiler/sdk 4.2.0 → 5.0.0-beta.m-r.2

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.
Files changed (75) hide show
  1. package/README.md +276 -30
  2. package/dist/ImageViewer/ImageViewer.d.ts +6 -8
  3. package/dist/ImageViewer/ImageViewerMarker.d.ts +9 -9
  4. package/dist/ImageViewer/monkeyPatchML.d.ts +1 -1
  5. package/dist/Map.d.ts +168 -11
  6. package/dist/Marker/Marker.d.ts +403 -0
  7. package/dist/Marker/MarkerManager.d.ts +137 -0
  8. package/dist/Marker/altitude-math.d.ts +24 -0
  9. package/dist/Marker/collision-helpers.d.ts +160 -0
  10. package/dist/Marker/index.d.ts +2 -0
  11. package/dist/Marker/marker-adaptive-colors.d.ts +11 -0
  12. package/dist/Marker/marker-animation-presets.d.ts +60 -0
  13. package/dist/Marker/marker-canvas.d.ts +31 -0
  14. package/dist/Marker/marker-constants.d.ts +112 -0
  15. package/dist/Marker/marker-content-registry.d.ts +17 -0
  16. package/dist/Marker/marker-dom-utils.d.ts +66 -0
  17. package/dist/Marker/marker-icons.d.ts +31 -0
  18. package/dist/Marker/marker-state-helpers.d.ts +2 -0
  19. package/dist/Marker/marker-svg-config.d.ts +84 -0
  20. package/dist/Marker/marker-symbols.d.ts +12 -0
  21. package/dist/Marker/marker-text-fit.d.ts +20 -0
  22. package/dist/Marker/marker-transitions.d.ts +29 -0
  23. package/dist/Marker/types.d.ts +465 -0
  24. package/dist/adaptive-colors.d.ts +48 -0
  25. package/dist/bundler/maplibre-gl-worker.mjs +13839 -0
  26. package/dist/bundler/next-worker.mjs +16 -0
  27. package/dist/bundler/next.cjs +42 -0
  28. package/dist/bundler/next.d.ts +6 -0
  29. package/dist/bundler/next.mjs +48 -0
  30. package/dist/bundler/side-effect.d.ts +2 -0
  31. package/dist/bundler/vite-worker.mjs +11 -0
  32. package/dist/bundler/webpack-worker.mjs +11 -0
  33. package/dist/constants/defaults.d.ts +0 -1
  34. package/dist/controls/MaptilerGeolocateControl.d.ts +1 -1
  35. package/dist/controls/MaptilerLogoControl.d.ts +1 -2
  36. package/dist/controls/MaptilerNavigationControl.d.ts +3 -4
  37. package/dist/controls/Minimap.d.ts +3 -3
  38. package/dist/eslint.mjs +4 -4
  39. package/dist/index.d.ts +11 -81
  40. package/dist/mapstyle.d.ts +11 -3
  41. package/dist/maptiler-sdk.css +108 -1
  42. package/dist/maptiler-sdk.d.ts +1 -1
  43. package/dist/maptiler-sdk.mjs +16816 -14372
  44. package/dist/maptiler-sdk.mjs.map +1 -1
  45. package/dist/routing.d.ts +18 -0
  46. package/dist/tools.d.ts +6 -7
  47. package/dist/utils/defaultWorkerUrl.d.ts +17 -0
  48. package/dist/utils/object.d.ts +1 -0
  49. package/package.json +26 -8
  50. package/dist/MLAdapters/AttributionControl.d.ts +0 -5
  51. package/dist/MLAdapters/BoxZoomHandler.d.ts +0 -7
  52. package/dist/MLAdapters/CanvasSource.d.ts +0 -5
  53. package/dist/MLAdapters/CooperativeGesturesHandler.d.ts +0 -5
  54. package/dist/MLAdapters/FullscreenControl.d.ts +0 -5
  55. package/dist/MLAdapters/GeoJSONSource.d.ts +0 -5
  56. package/dist/MLAdapters/GeolocateControl.d.ts +0 -5
  57. package/dist/MLAdapters/ImageSource.d.ts +0 -5
  58. package/dist/MLAdapters/KeyboardHandler.d.ts +0 -5
  59. package/dist/MLAdapters/LogoControl.d.ts +0 -5
  60. package/dist/MLAdapters/MapMouseEvent.d.ts +0 -5
  61. package/dist/MLAdapters/MapTouchEvent.d.ts +0 -5
  62. package/dist/MLAdapters/MapWheelEvent.d.ts +0 -5
  63. package/dist/MLAdapters/Marker.d.ts +0 -5
  64. package/dist/MLAdapters/NavigationControl.d.ts +0 -5
  65. package/dist/MLAdapters/Popup.d.ts +0 -5
  66. package/dist/MLAdapters/RasterDEMTileSource.d.ts +0 -5
  67. package/dist/MLAdapters/RasterTileSource.d.ts +0 -5
  68. package/dist/MLAdapters/ScaleControl.d.ts +0 -5
  69. package/dist/MLAdapters/ScrollZoomHandler.d.ts +0 -5
  70. package/dist/MLAdapters/Style.d.ts +0 -5
  71. package/dist/MLAdapters/TerrainControl.d.ts +0 -5
  72. package/dist/MLAdapters/TwoFingersTouchPitchHandler.d.ts +0 -5
  73. package/dist/MLAdapters/VectorTileSource.d.ts +0 -5
  74. package/dist/MLAdapters/VideoSource.d.ts +0 -5
  75. package/dist/ml-types.d.ts +0 -638
package/dist/Map.d.ts CHANGED
@@ -1,13 +1,15 @@
1
- import { default as maplibregl, StyleSpecification, MapOptions as MapOptionsML, ControlPosition, StyleSwapOptions, StyleOptions, RequestTransformFunction, LayerSpecification, SourceSpecification, CustomLayerInterface, FilterSpecification, StyleSetterOptions, ProjectionSpecification, FlyToOptions, EaseToOptions, FitBoundsOptions, AnimationOptions, LngLatBoundsLike, LngLatLike } from 'maplibre-gl';
1
+ import { Map as MapMLGL, StyleSpecification, MapOptions as MapOptionsML, ControlPosition, StyleSwapOptions, StyleOptions, RequestTransformFunction, LayerSpecification, SourceSpecification, CustomLayerInterface, FilterSpecification, StyleSetterOptions, ProjectionSpecification, FlyToOptions, EaseToOptions, FitBoundsOptions, AnimationOptions, LngLatBoundsLike, LngLatLike, AllPaintProperties, AllLayoutProperties, MapEventType, MapLayerEventType, Listener, Subscription, TerrainSpecification, Event as EventML } from 'maplibre-gl';
2
2
  import { ReferenceMapStyle, MapStyleVariant } from '@maptiler/client';
3
3
  import { SdkConfig } from './config';
4
4
  import { LanguageInfo } from './language';
5
+ import { AdaptiveColorSet } from './adaptive-colors';
5
6
  import { MinimapOptionsInput } from './controls/Minimap';
6
7
  import { PreloadTilesForBoundsOptions, PreloadTilesForCameraPositionsOptions, PreloadTilesOptions, WithTilePreload } from './tile-preloading/types';
7
8
  import { Telemetry } from './Telemetry';
8
9
  import { CubemapDefinition, CubemapLayer, CubemapLayerConstructorOptions } from './custom-layers/CubemapLayer';
9
10
  import { GradientDefinition, RadialGradientLayer, RadialGradientLayerConstructorOptions } from './custom-layers/RadialGradientLayer';
10
11
  import { StyleSpecificationWithMetaData } from './custom-layers/extractCustomLayerStyle';
12
+ import { MapTilerMarkerOptions, Marker, MarkerCollisionOptions, RemoveMarkerOptions } from '.';
11
13
  export type LoadWithTerrainEvent = {
12
14
  type: "loadWithTerrain";
13
15
  target: Map;
@@ -16,6 +18,45 @@ export type LoadWithTerrainEvent = {
16
18
  exaggeration: number;
17
19
  };
18
20
  };
21
+ /**
22
+ * Shape of an event fired by the SDK on top of the MapLibre events,
23
+ * with the properties passed to `fire(type, properties)` merged in.
24
+ */
25
+ type SDKMapEvent<TType extends string, TProps extends object = object> = EventML<TType> & {
26
+ target: Map;
27
+ } & TProps;
28
+ /**
29
+ * Events fired by the MapTiler SDK `Map` in addition to the MapLibre ones.
30
+ */
31
+ export type MaptilerMapEventType = {
32
+ /** Fired once the map style and the SDK controls are ready */
33
+ ready: SDKMapEvent<"ready">;
34
+ /** Fired once the map is loaded and the terrain (if any) is ready */
35
+ loadWithTerrain: LoadWithTerrainEvent;
36
+ /** Fired when the WebGL context is lost unexpectedly (i.e. not after `map.remove()`) */
37
+ webglContextLost: SDKMapEvent<"webglContextLost">;
38
+ terrainAnimationStart: SDKMapEvent<"terrainAnimationStart", {
39
+ terrain: TerrainSpecification | null;
40
+ }>;
41
+ terrainAnimationStop: SDKMapEvent<"terrainAnimationStop", {
42
+ terrain: TerrainSpecification | null;
43
+ }>;
44
+ "projection.change": SDKMapEvent<"projection.change", {
45
+ projection: ProjectionSpecification;
46
+ }>;
47
+ "cubemaplayer:animateindone": SDKMapEvent<"cubemaplayer:animateindone", Partial<CubemapLayer>>;
48
+ "cubemaplayer:animateoutdone": SDKMapEvent<"cubemaplayer:animateoutdone", Partial<CubemapLayer>>;
49
+ "cubemaplayer:onremove": SDKMapEvent<"cubemaplayer:onremove", Partial<CubemapLayer>>;
50
+ "radialgradientlayer:animateindone": SDKMapEvent<"radialgradientlayer:animateindone", Partial<RadialGradientLayer>>;
51
+ "radialgradientlayer:animateoutdone": SDKMapEvent<"radialgradientlayer:animateoutdone", Partial<RadialGradientLayer>>;
52
+ "radialgradientlayer:onremove": SDKMapEvent<"radialgradientlayer:onremove", Partial<RadialGradientLayer>>;
53
+ };
54
+ /**
55
+ * All the events that can be listened to on a MapTiler SDK `Map`: the MapLibre ones plus the SDK ones.
56
+ * Since MapLibre v6.3, `on`/`once`/`off`/`fire` only accept the keys of `MapEventType`,
57
+ * so the SDK `Map` overrides them to accept its own events as well.
58
+ */
59
+ export type MapEventTypeSDK = MapEventType & MaptilerMapEventType;
19
60
  export declare const GeolocationType: {
20
61
  POINT: "POINT";
21
62
  COUNTRY: "COUNTRY";
@@ -25,6 +66,11 @@ export declare const GeolocationType: {
25
66
  * if falls back to the default Mercator
26
67
  */
27
68
  export type ProjectionTypes = "mercator" | "globe" | undefined;
69
+ /**
70
+ * Default zoom at/above which a `"globe"` projection request switches to flat mercator — see
71
+ * {@link MapOptions.globeMercatorSwitchZoom}.
72
+ */
73
+ export declare const DEFAULT_GLOBE_MERCATOR_SWITCH_ZOOM = 11;
28
74
  /**
29
75
  * The {@link AttributionControl} options object
30
76
  */
@@ -157,6 +203,26 @@ export type MapOptions = Omit<MapOptionsML, "style" | "maplibreLogo" | "attribut
157
203
  * If not provided, the style takes precedence. If provided, overwrite the style.
158
204
  */
159
205
  projection?: ProjectionTypes;
206
+ /**
207
+ * MapLibre's plain `type: "globe"` already resolves to
208
+ * `["interpolate", ["linear"], ["zoom"], 11, "vertical-perspective", 12, "mercator"]` —
209
+ * vertical-perspective below zoom 11, linearly blended into flat mercator between 11 and 12.
210
+ * That blend is a MapLibre bug for anything that places objects via its per-projection model
211
+ * matrix (marker altitude, `maptiler-3d-js`): the matrix isn't well-defined mid-blend, only
212
+ * once it's settled fully at one end, so objects placed while zooming through 11-12 jump
213
+ * around.
214
+ *
215
+ * Whenever a projection change resolves to `"globe"` (constructor option, `setProjection`, or
216
+ * the {@link MaptilerProjectionControl}), the SDK requests
217
+ * `{ type: ["step", ["zoom"], "vertical-perspective", globeMercatorSwitchZoom, "mercator"] }`
218
+ * instead of the literal string — spherical below this zoom, flat mercator at and above it,
219
+ * snapping instantly at the threshold instead of blending across that zoom band.
220
+ *
221
+ * Set to `false` to request MapLibre's own `"globe"` literally instead, blend bug and all.
222
+ *
223
+ * Default: `11`
224
+ */
225
+ globeMercatorSwitchZoom?: number | false;
160
226
  /**
161
227
  * Turn on/off spacebox.
162
228
  *
@@ -169,11 +235,6 @@ export type MapOptions = Omit<MapOptionsML, "style" | "maplibreLogo" | "attribut
169
235
  * Default: Unless this is set explicitly to false, the SDK version will be logged to the console.
170
236
  */
171
237
  logSDKVersion?: boolean;
172
- /**
173
- * Whether to enable the RTL plugin or import a different one.
174
- * Default is undefined, which means the plugin is enabled by default.
175
- */
176
- rtlTextPlugin?: boolean | string;
177
238
  /**
178
239
  * Whether to enable the experimental tile preloading feature.
179
240
  * Default is false.
@@ -202,8 +263,36 @@ export interface ProjectionChangeOptions {
202
263
  /**
203
264
  * The Map class can be instanciated to display a map in a `<div>`
204
265
  */
205
- export declare class Map extends maplibregl.Map {
266
+ export declare class Map extends MapMLGL {
206
267
  readonly telemetry: Telemetry;
268
+ /**
269
+ * Adds a listener for events of a specified type, optionally limited to features in one or more layers.
270
+ * Accepts the MapLibre events as well as the SDK events (see {@link MaptilerMapEventType}).
271
+ */
272
+ on<T extends keyof MapLayerEventType>(type: T, layerIds: string | string[], listener: (ev: MapLayerEventType[T] & object) => void): Subscription;
273
+ on<T extends keyof MapEventTypeSDK>(type: T, listener: (ev: MapEventTypeSDK[T] & object) => void): Subscription;
274
+ on(type: keyof MapEventTypeSDK, listener: Listener): Subscription;
275
+ /**
276
+ * Adds a listener that will be called only once to a specified event type, optionally limited to features in one or more layers.
277
+ * Accepts the MapLibre events as well as the SDK events (see {@link MaptilerMapEventType}).
278
+ */
279
+ once<T extends keyof MapLayerEventType>(type: T, layerIds: string | string[], listener: (ev: MapLayerEventType[T] & object) => void): this;
280
+ once<T extends keyof MapLayerEventType>(type: T, layerIds: string | string[]): Promise<MapLayerEventType[T] & object>;
281
+ once<T extends keyof MapEventTypeSDK>(type: T, listener: (ev: MapEventTypeSDK[T] & object) => void): this;
282
+ once<T extends keyof MapEventTypeSDK>(type: T): Promise<MapEventTypeSDK[T] & object>;
283
+ once(type: keyof MapEventTypeSDK, listener?: Listener): this | Promise<any>;
284
+ /**
285
+ * Removes an event listener previously added with {@link Map.on} or {@link Map.once}.
286
+ * Accepts the MapLibre events as well as the SDK events (see {@link MaptilerMapEventType}).
287
+ */
288
+ off<T extends keyof MapLayerEventType>(type: T, layerIds: string | string[], listener: (ev: MapLayerEventType[T] & object) => void): this;
289
+ off<T extends keyof MapEventTypeSDK>(type: T, listener: (ev: MapEventTypeSDK[T] & object) => void): this;
290
+ off(type: keyof MapEventTypeSDK, listener: Listener): this;
291
+ /**
292
+ * Fires an event. Accepts the MapLibre events as well as the SDK events (see {@link MaptilerMapEventType}).
293
+ */
294
+ fire(event: MapEventTypeSDK[keyof MapEventTypeSDK]): this;
295
+ fire(type: keyof MapEventTypeSDK, properties?: object): this;
207
296
  private space?;
208
297
  private halo?;
209
298
  getSpace(): CubemapLayer | undefined;
@@ -261,6 +350,7 @@ export declare class Map extends maplibregl.Map {
261
350
  private terrainAnimationDuration;
262
351
  private monitoredStyleUrls;
263
352
  private styleInProcess;
353
+ private currentStyleId?;
264
354
  private curentProjection;
265
355
  private originalLabelStyle;
266
356
  private isStyleLocalized;
@@ -310,6 +400,25 @@ export declare class Map extends maplibregl.Map {
310
400
  */
311
401
  setStyle(style: null | ReferenceMapStyle | MapStyleVariant | StyleSpecification | StyleSpecificationWithMetaData | string, options?: StyleSwapOptions & StyleOptions): this;
312
402
  private spaceboxLoadingState;
403
+ /**
404
+ * Returns the id of the current MapTiler style (e.g. `"streets-v4-dark"`),
405
+ * derived from the value passed to the constructor or `setStyle`.
406
+ * `undefined` when the style is a custom `StyleSpecification` or a URL that
407
+ * doesn't follow the MapTiler Cloud `/maps/<id>/style.json` shape.
408
+ */
409
+ getStyleId(): string | undefined;
410
+ /**
411
+ * Returns the default (adaptive) colours for the current style — the colours
412
+ * markers fall back to when none are set. Resolved from {@link getStyleId},
413
+ * or the stylesheet's `id` when that's `undefined`; unknown styles resolve to
414
+ * the `base` colours.
415
+ * @returns The current style's colour set. The object is frozen and shared, so spread it to modify a copy.
416
+ * @example
417
+ * ```ts
418
+ * const { innerColor, outerColor } = map.getAdaptiveColorsForCurrentStyle();
419
+ * ```
420
+ */
421
+ getAdaptiveColorsForCurrentStyle(): AdaptiveColorSet;
313
422
  /**
314
423
  * Adds a [MapLibre style layer](https://maplibre.org/maplibre-style-spec/layers)
315
424
  * to the map's style.
@@ -361,6 +470,49 @@ export declare class Map extends maplibregl.Map {
361
470
  * ```
362
471
  */
363
472
  removeLayer(id: string): this;
473
+ /**
474
+ * Adds a marker to the map, registering it for collision handling and style-aware colours.
475
+ * Plays the marker's `enter` animation, if it has one.
476
+ * @param markerOrMarkerConfig - A `Marker`, or the options to create one from.
477
+ */
478
+ addMarker(markerOrMarkerConfig: Marker | MapTilerMarkerOptions): this;
479
+ /**
480
+ * Removes a marker from the map, playing its `exit` animation first, if it has one.
481
+ * @param id - Id of the marker to remove.
482
+ * @param options.immediate - Removes the marker straight away, without its `exit` animation.
483
+ */
484
+ removeMarker(id: string, options?: RemoveMarkerOptions): this;
485
+ /**
486
+ * Adds several markers to the map. See {@link Map.addMarker}.
487
+ * @param markers - `Marker`s, or the options to create them from.
488
+ */
489
+ addMarkers(markers: (Marker | MapTilerMarkerOptions)[]): this;
490
+ /**
491
+ * Removes several markers from the map, playing their `exit` animations first, if they have them.
492
+ * @param markerIds - Ids of the markers to remove. Removes every marker when omitted.
493
+ * @param options.immediate - Removes the markers straight away, without their `exit` animations.
494
+ */
495
+ removeMarkers(markerIds?: string[], options?: RemoveMarkerOptions): this;
496
+ /** Returns every marker added to the map. */
497
+ getMarkers(): Marker[];
498
+ /** Returns the marker with the given id, or `undefined` if it isn't on the map. */
499
+ getMarker(id: string): Marker | undefined;
500
+ /**
501
+ * Configures marker collision detection for this map.
502
+ * @param options.proximityPadding - Distance in CSS px within which two
503
+ * markers count as "in proximity". Overlap always uses 0.
504
+ * @param options.accuracy - `high` (default) tests rotated markers with
505
+ * their actual rotated box; `low` uses the upright box enclosing it,
506
+ * which is cheaper per pair but over-reports collisions for rotated
507
+ * markers (it never misses a real one).
508
+ * @param options.behaviour - Default collision behaviour applied to every
509
+ * marker on this map (`always-show` | `hide-by-priority` |
510
+ * `minimize-by-priority`). A marker's own `collisionBehaviour` option
511
+ * overrides it. Defaults to `always-show`.
512
+ * @param options.transitionDuration - Duration in ms of the hide/show/minimize fade. Defaults to `150`.
513
+ * @param options.transitionEasing - CSS easing function for the fade. Defaults to `"ease"`.
514
+ */
515
+ setMarkerCollisionOptions(options: MarkerCollisionOptions): this;
364
516
  /**
365
517
  * Sets the zoom extent for the specified style layer. The zoom extent includes the
366
518
  * [minimum zoom level](https://maplibre.org/maplibre-style-spec/layers/#minzoom)
@@ -399,7 +551,7 @@ export declare class Map extends maplibregl.Map {
399
551
  * map.setPaintProperty('my-layer', 'fill-color', '#faafee');
400
552
  * ```
401
553
  */
402
- setPaintProperty(layerId: string, name: string, value: any, options?: StyleSetterOptions): this;
554
+ setPaintProperty<K extends keyof AllPaintProperties>(layerId: string, name: K, value: AllPaintProperties[K], options?: StyleSetterOptions): this;
403
555
  /**
404
556
  * Sets the value of a layout property in the specified style layer.
405
557
  * Layout properties define how the layer is styled.
@@ -413,7 +565,7 @@ export declare class Map extends maplibregl.Map {
413
565
  * @param options - Options object.
414
566
  * @returns `this`
415
567
  */
416
- setLayoutProperty(layerId: string, name: string, value: any, options?: StyleSetterOptions): this;
568
+ setLayoutProperty<K extends keyof AllLayoutProperties>(layerId: string, name: K, value: AllLayoutProperties[K], options?: StyleSetterOptions): this;
417
569
  /**
418
570
  * Sets the value of the style's glyphs property.
419
571
  *
@@ -509,7 +661,11 @@ export declare class Map extends maplibregl.Map {
509
661
  */
510
662
  getProjection(): ProjectionSpecification;
511
663
  /**
512
- * Returns whether a globe projection is currently being used
664
+ * Returns whether a globe-family projection is currently configured — `"globe"`,
665
+ * `"vertical-perspective"`, or the `globeMercatorSwitchZoom` step expression this class
666
+ * requests for `"globe"` (see {@link MapOptions.globeMercatorSwitchZoom}). This reflects the
667
+ * configured projection, not the instantaneous rendered state — under the step expression it
668
+ * stays `true` even after zooming past the switch threshold into flat mercator rendering.
513
669
  */
514
670
  isGlobeProjection(): boolean;
515
671
  /**
@@ -530,7 +686,7 @@ export declare class Map extends maplibregl.Map {
530
686
  * Sets the projection to a {@linkcode ProjectionSpecification}.
531
687
  * @param projection - the projection specification to set
532
688
  */
533
- setProjection(projection: maplibregl.ProjectionSpecification): this;
689
+ setProjection(projection: ProjectionSpecification): this;
534
690
  /**
535
691
  * Forget the persisted projection - from both constructor option and result of any `map.setProjection(..., { persist: true })` calls.
536
692
  */
@@ -684,3 +840,4 @@ export declare class Map extends maplibregl.Map {
684
840
  */
685
841
  private resolveCameraPosition;
686
842
  }
843
+ export {};