@maptiler/sdk 5.0.0-beta.m-r.1 → 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.
package/dist/Map.d.ts CHANGED
@@ -2,6 +2,7 @@ import { Map as MapMLGL, StyleSpecification, MapOptions as MapOptionsML, Control
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';
@@ -406,6 +407,18 @@ export declare class Map extends MapMLGL {
406
407
  * doesn't follow the MapTiler Cloud `/maps/<id>/style.json` shape.
407
408
  */
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;
409
422
  /**
410
423
  * Adds a [MapLibre style layer](https://maplibre.org/maplibre-style-spec/layers)
411
424
  * to the map's style.
@@ -1,6 +1,6 @@
1
1
  import { Marker as MLMarker, CustomLayerProjectionData, LngLatLike, PointLike, Subscription } from 'maplibre-gl';
2
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';
3
+ import { MapTilerMarkerElementOptions, MapTilerMarkerSVGOptions, PendingMarkerUpdates, Vector2, MapTilerMarkerOptions, MarkerCollisionEventData, MarkerCollisionDisplayState, MapTilerMarkerUIStateName, UIStateSpec, MarkerTransitionProperty, MapTilerMarkerTransitions, MarkerTransitionSpec, MarkerEventTypeSDK, GroundLineOptions, AltitudeReference, SetAltitudeOptions, MarkerStyle } from './types';
4
4
  import { MarkerFootprint } from './collision-helpers';
5
5
  import { PendingUpdatesSymbol, DetachFromDOMSymbol, FlushDOMUpdatesSymbol, MarkerElementSymbol, RefreshAdaptiveColorSymbol, CollisionFootprintSymbol, EmitCollisionDiffSymbol, ApplyCollisionDisplayStateSymbol, ApplyAltitudeFrameSymbol, MeasuredElementSizeSymbol, ClearFocusStateSymbol, AttachToMapSymbol } from './marker-symbols';
6
6
  /** MapLibre's `Marker` extended with 2-D scale, named shapes, colour tokens, and batched DOM updates. */
@@ -281,6 +281,12 @@ export declare class Marker extends MLMarker {
281
281
  * @returns Rotation in degrees; `0` if never set.
282
282
  */
283
283
  getRotation(): number;
284
+ /**
285
+ * Returns the marker's visual style. Colours are only included when set
286
+ * explicitly — unlike {@link getOuterColor} and friends, map-style defaults
287
+ * are not resolved, so the result stays adaptive wherever it's reused.
288
+ */
289
+ getStyle(): MarkerStyle;
284
290
  private attachUIStateListeners;
285
291
  /** Blurs the marker's focusable element. Called by {@link MarkerManager} on map `click`. */
286
292
  [ClearFocusStateSymbol](): void;
@@ -1,32 +1,8 @@
1
- import { defaultReferenceStyleMap } from '@maptiler/client';
2
- /**
3
- * Unversioned reference-style key, matching the reference styles of
4
- * `MapStyle` from `@maptiler/client` (e.g. `MapStyle.STREETS` → `"streets"`).
5
- */
6
- export type ReferenceStyleKey = Lowercase<keyof typeof defaultReferenceStyleMap>;
7
- /**
8
- * Style key the marker colours can target: an unversioned reference-style id,
9
- * optionally with a variant suffix (e.g. `"streets"`, `"streets-dark"`).
10
- * Versioned style ids (`"streets-v4-dark"`) are normalised to this form by
11
- * {@link getAdaptiveColors}.
12
- */
13
- export type AdaptiveStyleKey = ReferenceStyleKey | `${ReferenceStyleKey}-${string}`;
14
- /** The colours of each marker part for one map style. */
15
- export type AdaptiveColorSet = {
16
- /** Fill of the inner area. */
17
- innerColor: string;
18
- /** Fill of the outer body / border. */
19
- outerColor: string;
20
- /** Colour of the content (text, glyph). */
21
- contentColor: string;
22
- /** Stroke of the outline (only visible when an outline width is set). */
23
- outlineColor: string;
24
- };
1
+ import { AdaptiveColorSet } from '../adaptive-colors';
25
2
  /**
26
3
  * Resolves the default marker colours for a given map style and shape.
27
4
  *
28
- * Lookup order: exact style key (version stripped, variant kept) → reference
29
- * style without variant → `base`, so an unknown style id resolves to `base`.
5
+ * The style's colours come from {@link getAdaptiveColorsForStyle}.
30
6
  * Shapes in {@link INVERTED_COLOR_SHAPES} get the style's colours swapped: the
31
7
  * accent colour on the body and the mark, the body colour on the inner fill.
32
8
  * @param styleId - Style id, versioned (`"streets-v4-dark"`) or not (`"streets-dark"`).
@@ -0,0 +1,31 @@
1
+ import { MarkerStyle } from './types';
2
+ export type MarkerCanvasOptions = {
3
+ /** Device pixels per CSS pixel. Defaults to `window.devicePixelRatio`. */
4
+ pixelRatio?: number;
5
+ /** Map style id used to resolve unset colours to their adaptive defaults. Defaults to the `base` colours. */
6
+ styleId?: string;
7
+ };
8
+ export type MarkerCanvas = {
9
+ /** The drawn marker, `pixelRatio` device pixels per CSS pixel. */
10
+ canvas: HTMLCanvasElement;
11
+ pixelRatio: number;
12
+ /**
13
+ * Transparent margin in CSS px on every side of the marker's nominal
14
+ * `SIZE_PX` box, leaving room for the outline and shadow. Equal on all
15
+ * sides, so the image centre is the box centre and `getShapeAnchorOffset`
16
+ * applies unchanged.
17
+ */
18
+ padding: number;
19
+ };
20
+ /**
21
+ * Draws a marker to a canvas, matching the DOM marker built from the same
22
+ * style. Opacity is not baked in — apply it at display time, as the DOM path
23
+ * does on its wrapper.
24
+ *
25
+ * Text content is drawn with whatever font is available at call time —
26
+ * await `document.fonts.load()` for the marker font first, or the text falls
27
+ * back to the next family in {@link MARKER_FONT_FAMILY}.
28
+ * @param style - Visual style of the marker.
29
+ * @param options - Pixel ratio and style id for adaptive colours.
30
+ */
31
+ export declare function drawMarkerCanvas(style: MarkerStyle, options?: MarkerCanvasOptions): MarkerCanvas;
@@ -1,7 +1,6 @@
1
1
  import { MarkerOptions } from 'maplibre-gl';
2
2
  import { EasingFunctionName } from '../MaptilerAnimation/types';
3
3
  import { EnterAnimationPreset, ExitAnimationPreset, IdleAnimationPreset, MapTilerMarkerUIStateName, MapTilerMarkerShape, MapTilerMarkerSize, MapTilerMarkerShadow } from './types';
4
- import { AdaptiveColorSet, AdaptiveStyleKey } from './marker-adaptive-colors';
5
4
  import { ContentMetrics, ShapeSize } from './marker-svg-config';
6
5
  export declare const DEFAULT_SHAPE: MapTilerMarkerShape;
7
6
  export declare const DEFAULT_SIZE: MapTilerMarkerSize;
@@ -22,16 +21,18 @@ export declare const DEFAULT_PROXIMITY_PADDING = 4;
22
21
  /** Matches the fade duration in the SDK stylesheet (`.maptiler-marker-collision-fade`). */
23
22
  export declare const COLLISION_FADE_DURATION_MS = 150;
24
23
  export declare const SIZE_PX: Record<MapTilerMarkerSize, number>;
24
+ /** Drop-shadow geometry in CSS px. `blur` follows the CSS `drop-shadow()` / canvas `shadowBlur` convention (twice the Gaussian standard deviation). */
25
+ export type MarkerShadowParams = {
26
+ offsetX: number;
27
+ offsetY: number;
28
+ blur: number;
29
+ color: string;
30
+ };
31
+ /** Single source of truth for marker shadows — the DOM path's CSS filter and the canvas path's `shadow*` settings are both derived from it. */
32
+ export declare const SHADOW_PARAMS: Record<MapTilerMarkerShadow, MarkerShadowParams | null>;
25
33
  export declare const SHADOW_FILTER: Record<MapTilerMarkerShadow, string>;
26
34
  /** Content sizing per marker size, shared by every shape (px). */
27
35
  export declare const CONTENT_METRICS: Record<ShapeSize, ContentMetrics>;
28
- /**
29
- * Default marker colours per map style. `base` doubles as the fallback for
30
- * styles without a dedicated entry.
31
- */
32
- export declare const ADAPTIVE_COLORS: {
33
- base: AdaptiveColorSet;
34
- } & Partial<Record<AdaptiveStyleKey, AdaptiveColorSet>>;
35
36
  /**
36
37
  * Shapes whose default colours are the map style's, swapped: a blue body with a white inner fill and
37
38
  * a blue mark. Colours set explicitly aren't touched.
@@ -415,6 +415,13 @@ export type MapTilerMarkerSVGOptions = MapTilerMarkerBaseOptions & Exclude<Marke
415
415
  type MapTilerMarkerElementPropKeys = "shape" | "outerColor" | "innerColor" | "contentColor" | "outline" | "outlineColor" | "shadow" | "opacity" | "title" | "content" | "htmlAttributes" | "rotation" | "scale" | "size" | "debug" | "priority";
416
416
  export type MapTilerMarkerElementProps = Pick<MapTilerMarkerBaseOptions, MapTilerMarkerElementPropKeys>;
417
417
  export type MapTilerMarkerOptions = MapTilerMarkerBaseOptions & MarkerContent;
418
+ /**
419
+ * Visual subset of {@link MapTilerMarkerBaseOptions} — everything that
420
+ * determines how a marker looks, and nothing about how it behaves or where
421
+ * it sits. Unset fields fall back to the marker defaults; unset colours
422
+ * fall back to the current map style's adaptive colours.
423
+ */
424
+ export type MarkerStyle = Pick<MapTilerMarkerBaseOptions, "shape" | "size" | "outerColor" | "innerColor" | "contentColor" | "outline" | "outlineColor" | "shadow" | "opacity" | "content">;
418
425
  /**
419
426
  * Batch of property updates waiting to be flushed to the DOM.
420
427
  * A key being present (even with an `undefined` value) means "apply this
@@ -0,0 +1,48 @@
1
+ import { defaultReferenceStyleMap } from '@maptiler/client';
2
+ /**
3
+ * Unversioned reference-style key, matching the reference styles of
4
+ * `MapStyle` from `@maptiler/client` (e.g. `MapStyle.STREETS` → `"streets"`).
5
+ */
6
+ export type ReferenceStyleKey = Lowercase<keyof typeof defaultReferenceStyleMap>;
7
+ /**
8
+ * Style key the adaptive colours can target: an unversioned reference-style id,
9
+ * optionally with a variant suffix (e.g. `"streets"`, `"streets-dark"`).
10
+ * Versioned style ids (`"streets-v4-dark"`) are normalised to this form by
11
+ * {@link getAdaptiveColorsForStyle}.
12
+ */
13
+ export type AdaptiveStyleKey = ReferenceStyleKey | `${ReferenceStyleKey}-${string}`;
14
+ /** The default colours of each marker part for one map style. */
15
+ export type AdaptiveColorSet = {
16
+ /** Fill of the inner area. */
17
+ innerColor: string;
18
+ /** Fill of the outer body / border. */
19
+ outerColor: string;
20
+ /** Colour of the content (text, glyph). */
21
+ contentColor: string;
22
+ /** Stroke of the outline (only visible when an outline width is set). */
23
+ outlineColor: string;
24
+ };
25
+ /**
26
+ * Default colours per map style. `base` doubles as the fallback for styles
27
+ * without a dedicated entry. Frozen, as lookups hand out these objects as is.
28
+ */
29
+ export declare const ADAPTIVE_COLORS: {
30
+ base: AdaptiveColorSet;
31
+ } & Partial<Record<AdaptiveStyleKey, AdaptiveColorSet>>;
32
+ /**
33
+ * Resolves the default (adaptive) colours for a given map style.
34
+ *
35
+ * Lookup order: exact style key (version stripped, variant kept) → reference
36
+ * style without variant → `base`, so an unknown style id resolves to `base`.
37
+ * @param styleId - Style id, versioned (`"streets-v4-dark"`) or not (`"streets-dark"`).
38
+ * @returns The style's colour set. The object is frozen and shared, so spread it to modify a copy.
39
+ * @example
40
+ * ```ts
41
+ * getAdaptiveColorsForStyle("streets-v4-dark").innerColor; // "#4D97FF"
42
+ * ```
43
+ * @example
44
+ * ```ts
45
+ * getAdaptiveColorsForStyle("my-custom-style"); // falls back to the `base` colours
46
+ * ```
47
+ */
48
+ export declare function getAdaptiveColorsForStyle(styleId: string): AdaptiveColorSet;
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export { setRTLTextPlugin, getRTLTextPluginStatus, LngLat, LngLatBounds, Mercato
9
9
  export { getVersion as getMapLibreVersion, Map as MapMLGL, Marker as MarkerMLGL, Popup as PopupMLGL, Style as StyleMLGL, CanvasSource as CanvasSourceMLGL, GeoJSONSource as GeoJSONSourceMLGL, ImageSource as ImageSourceMLGL, RasterTileSource as RasterTileSourceMLGL, RasterDEMTileSource as RasterDEMTileSourceMLGL, VectorTileSource as VectorTileSourceMLGL, VideoSource as VideoSourceMLGL, NavigationControl as NavigationControMLGL, GeolocateControl as GeolocateControlMLGL, AttributionControl as AttributionControlMLGL, LogoControl as LogoControlMLGL, ScaleControl as ScaleControlMLGL, FullscreenControl as FullscreenControlMLGL, TerrainControl as TerrainControMLGL, BoxZoomHandler as BoxZoomHandlerMLGL, ScrollZoomHandler as ScrollZoomHandlerMLGL, CooperativeGesturesHandler as CooperativeGesturesHandlerMLGL, KeyboardHandler as KeyboardHandlerMLGL, TwoFingersTouchPitchHandler as TwoFingersTouchPitchHandlerMLGL, MapWheelEvent as MapWheelEventMLGL, MapTouchEvent as MapTouchEventMLGL, MapMouseEvent as MapMouseEventMLGL, config as configMLGL, } from 'maplibre-gl';
10
10
  export * from './Marker';
11
11
  export { Marker } from './Marker';
12
+ export { getAdaptiveColorsForStyle, type AdaptiveColorSet, type AdaptiveStyleKey, type ReferenceStyleKey } from './adaptive-colors';
12
13
  export { Popup, Style, CanvasSource, GeoJSONSource, ImageSource, RasterTileSource, RasterDEMTileSource, VectorTileSource, VideoSource, NavigationControl, GeolocateControl, AttributionControl, LogoControl, ScaleControl, FullscreenControl, TerrainControl, BoxZoomHandler, ScrollZoomHandler, CooperativeGesturesHandler, KeyboardHandler, TwoFingersTouchPitchHandler, MapWheelEvent, MapTouchEvent, MapMouseEvent, } from 'maplibre-gl';
13
14
  export { Map, GeolocationType, type AttributionControlOptions, type MapOptions, type LoadWithTerrainEvent, type MaptilerMapEventType, type MapEventTypeSDK } from './Map';
14
15
  export type { CameraPosition, TilePreloadOptions, WithTilePreload, PreloadTilesForBoundsOptions, PreloadTilesForCameraPositionsOptions, PreloadTilesOptions, TilePreloadErrorCallback, TilePreloadProgressCallback, } from './tile-preloading';