@superrouteca/smap 1.0.6 → 1.1.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superrouteca/smap",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
4
4
  "description": "sMap for the web: maps from Superroute's sMap service, the Web SDK (map view) and the JS client (tokens, nearest node, styles, tiles).",
5
5
  "license": "MIT",
6
6
  "author": "Goodneo Solutions",
@@ -62,6 +62,14 @@
62
62
  "prepack": "cp ../LICENSE LICENSE",
63
63
  "test": "node --test test/*.test.mjs test/*.test.cjs"
64
64
  },
65
+ "peerDependencies": {
66
+ "@deck.gl/mapbox": "^9.0.0"
67
+ },
68
+ "peerDependenciesMeta": {
69
+ "@deck.gl/mapbox": {
70
+ "optional": true
71
+ }
72
+ },
65
73
  "devDependencies": {
66
74
  "esbuild": "0.28.2",
67
75
  "maplibre-gl": "6.16.0"
package/types/smap.d.cts CHANGED
@@ -2,6 +2,74 @@
2
2
  // smap.d.cts hold the same text (test/types.test.mjs checks).
3
3
 
4
4
  export type StyleFlavor = 'light' | 'white' | 'grayscale' | 'dark' | 'black';
5
+ /** A saved custom style of sMap (`custom:sms_…`), served in every label language. */
6
+ export type CustomStyleName = `custom:${string}`;
7
+
8
+ /**
9
+ * Where a layer is drawn relative to the basemap: `bottom` (over land and water, under everything else), `roads`
10
+ * (under roads), `labels` (under labels), `top`. Without a slot (or `before`) a layer draws as in 1.0: on top, in the
11
+ * order added.
12
+ */
13
+ export type Slot = 'bottom' | 'roads' | 'labels' | 'top';
14
+
15
+ /** Where a layer goes: a slot, or under one named layer (yours or the basemap's), and its order inside. */
16
+ export interface Placement {
17
+ slot?: Slot;
18
+ /** A layer id to draw under, instead of a slot. */
19
+ before?: string;
20
+ /** Higher draws on top inside the same slot; equal values keep the order added. */
21
+ zIndex?: number;
22
+ }
23
+
24
+ /** A source of the Style Specification v8 (geojson, vector, raster, raster-dem, image, video). */
25
+ export interface StyleSource { type: string; attribution?: string; [key: string]: unknown }
26
+ /** A layer of the Style Specification v8, passed to the engine as it is. */
27
+ export interface StyleLayer { id: string; type: string; source?: string | StyleSource; 'source-layer'?: string; paint?: Record<string, unknown>; layout?: Record<string, unknown>; filter?: unknown; minzoom?: number; maxzoom?: number; [key: string]: unknown }
28
+
29
+ /** One basemap class's override (contract §1): every field optional. */
30
+ export interface BasemapOverride {
31
+ visible?: boolean;
32
+ /** Fill, line or background colour; text colour for labels (never casings). */
33
+ color?: string;
34
+ /** Casing colour (roads). */
35
+ casing?: string;
36
+ /** Text halo colour (labels). */
37
+ halo?: string;
38
+ /** 0 to 1. */
39
+ opacity?: number;
40
+ /** Line width factor, 0.25 to 4. */
41
+ width?: number;
42
+ }
43
+ export type BasemapClass = 'land' | 'landcover' | 'parks' | 'landuse' | 'airports' | 'water' | 'roads' | 'roads.paths' | 'roads.minor' | 'roads.major' |
44
+ 'roads.highway' | 'buildings' | 'rail' | 'boundaries' | 'labels' | 'labels.addresses' | 'labels.water' | 'labels.roads' | 'labels.places' | 'pois';
45
+ /** Basemap overrides by class; `roads` and `labels` apply to every `roads.*` / `labels.*` class (the class itself wins). */
46
+ export type BasemapOverrides = Partial<Record<BasemapClass, BasemapOverride>>;
47
+ /** The class table (shared/basemap-classes.json). */
48
+ export interface BasemapClassTable {
49
+ paint: Record<string, Record<string, string>>;
50
+ classes: Record<string, Array<{ layer: string; role: 'background' | 'fill' | 'line' | 'casing' | 'label' }>>;
51
+ }
52
+
53
+ /** File formats read on the device and by sMap's converting endpoint. */
54
+ export type FileFormat = 'kml' | 'kmz' | 'gpx' | 'polyline' | 'polyline6' | 'wkt' | 'wkb' | 'csv' | 'topojson' | 'geojson';
55
+ /** What a file is read from: text, bytes, or a parsed JSON object (GeoJSON, TopoJSON). */
56
+ export type FileInput = string | ArrayBuffer | Uint8Array | Record<string, unknown>;
57
+ export interface ReadOptions {
58
+ /** Guessed from `name`'s extension or the content when omitted (polylines are never guessed). */
59
+ format?: FileFormat;
60
+ /** CSV latitude column (guessed from common headings when omitted). */
61
+ lat?: string;
62
+ /** CSV longitude column. */
63
+ lng?: string;
64
+ /** A file name, for its extension. */
65
+ name?: string;
66
+ }
67
+ export interface ConvertOptions extends ReadOptions {
68
+ /** The map service (default https://tile.srsr.ca; a map's own address for map.convert). */
69
+ baseUrl?: string;
70
+ apiKey?: string;
71
+ token?: string;
72
+ }
5
73
 
6
74
  /** A position as [longitude, latitude]. */
7
75
  export type LngLatLike = [number, number] | { lng: number; lat: number } | { lon: number; lat: number };
@@ -79,11 +147,16 @@ interface CommonLayerOptions {
79
147
  maxzoom?: number;
80
148
  /** A feature property used as the feature id. */
81
149
  idProperty?: string;
150
+ /** A slot (`bottom`, `roads`, `labels`, `top`); without one (or `before`) the layer draws on top, as in 1.0. */
151
+ slot?: Slot;
152
+ /** A layer id to draw under, instead of a slot. */
153
+ before?: string;
82
154
  /**
83
155
  * The popup opened when the top feature at a click is this layer's; called only then. A point's popup opens at the
84
- * point, a line's or area's where it was clicked. `popupTemplate('<b>{name}</b>')` gives a fast, escaped one.
156
+ * point, a line's or area's where it was clicked. A string is a template (`'<b>{name}</b>'`, as popupTemplate:
157
+ * every {name} the feature's property, HTML-escaped), and the one form written by toJSON.
85
158
  */
86
- popup?: (properties: Record<string, unknown>, feature: GeoJSONFeature) => PopupContent | Promise<PopupContent>;
159
+ popup?: string | ((properties: Record<string, unknown>, feature: GeoJSONFeature) => PopupContent | Promise<PopupContent>);
87
160
  /** This layer's popup options, over the map's `popup` defaults. */
88
161
  popupOptions?: PopupOptions;
89
162
  /** Shown while this layer's popup content is a pending promise (HTML string or DOM node; default pulsing dots). */
@@ -198,8 +271,8 @@ export interface MapOptions {
198
271
  getToken?: () => string | Promise<string>;
199
272
  /** A map key (`smk_…`) whose allowlist names this site; with a token both are sent and the token is checked first. */
200
273
  apiKey?: string;
201
- /** A colour scheme, or a style URL or object of your own. */
202
- style?: StyleFlavor | string | Record<string, unknown>;
274
+ /** A colour scheme, a saved custom style (`custom:<id>`), or a style URL or object of your own. */
275
+ style?: StyleFlavor | CustomStyleName | string | Record<string, unknown>;
203
276
  /** Label language as a BCP-47 tag (`en`, `fr`, `zh-Hans`, …); the browser language by default. */
204
277
  language?: string;
205
278
  /** The map service, `https://tile.srsr.ca` by default. */
@@ -223,6 +296,115 @@ export interface MapOptions {
223
296
  [engineOption: string]: unknown;
224
297
  }
225
298
 
299
+ /** addData: how the file is read, then the options of addPoints / addLines / addPolygons for its parts. */
300
+ export type DataOptions = ReadOptions & PointOptions & LineOptions & PolygonOptions;
301
+
302
+ export interface RasterLayerOptions extends Placement {
303
+ /** XYZ templates ({z}/{x}/{y}). */
304
+ tiles?: string | string[];
305
+ /** An XYZ template, or a TileJSON address. */
306
+ url?: string;
307
+ /** Default 256. */
308
+ tileSize?: number;
309
+ /** Shown beside the map's credit. */
310
+ attribution?: string;
311
+ opacity?: number;
312
+ minzoom?: number;
313
+ maxzoom?: number;
314
+ bounds?: [number, number, number, number];
315
+ scheme?: 'xyz' | 'tms';
316
+ }
317
+ export interface WmsLayerOptions extends Placement {
318
+ url: string;
319
+ layers: string | string[];
320
+ styles?: string | string[];
321
+ /** Default image/png. */
322
+ format?: string;
323
+ /** Default true. */
324
+ transparent?: boolean;
325
+ /** Default 1.3.0 (CRS=EPSG:3857); 1.1.1 sends SRS. */
326
+ version?: '1.3.0' | '1.1.1';
327
+ /** More GetMap parameters. */
328
+ params?: Record<string, string | number>;
329
+ tileSize?: number;
330
+ attribution?: string;
331
+ opacity?: number;
332
+ minzoom?: number;
333
+ maxzoom?: number;
334
+ }
335
+ export interface WmtsLayerOptions extends Placement {
336
+ /** The GetCapabilities address (or the service address), or a REST template with {TileMatrix}, {TileRow}, {TileCol}. */
337
+ url?: string;
338
+ /** The capabilities document as text, instead of fetching `url`. */
339
+ capabilities?: string;
340
+ layer?: string;
341
+ /** A Web Mercator matrix set (found from the capabilities when omitted). */
342
+ tileMatrixSet?: string;
343
+ style?: string;
344
+ format?: string;
345
+ /** REST (the layer's resource template) or KVP (GetTile); REST when the capabilities offer it. */
346
+ encoding?: 'rest' | 'kvp';
347
+ attribution?: string;
348
+ opacity?: number;
349
+ minzoom?: number;
350
+ maxzoom?: number;
351
+ }
352
+ export interface VectorTilesOptions extends Placement {
353
+ /** Mapbox Vector Tile templates. */
354
+ tiles?: string | string[];
355
+ /** A TileJSON address, or a PMTiles archive (ending in .pmtiles or pmtiles://…). */
356
+ url?: string;
357
+ /** A PMTiles archive address. */
358
+ pmtiles?: string;
359
+ /** Style layers drawing the tiles; their `source` is this id when they name none. */
360
+ layers?: StyleLayer[];
361
+ attribution?: string;
362
+ minzoom?: number;
363
+ maxzoom?: number;
364
+ bounds?: [number, number, number, number];
365
+ promoteId?: string | Record<string, string>;
366
+ }
367
+ export interface ArcGisLayerOptions extends Placement {
368
+ /** A MapServer / ImageServer (raster tiles) or VectorTileServer address. */
369
+ url: string;
370
+ /** VectorTileServer: style layers (the service's own root style when omitted). */
371
+ layers?: StyleLayer[];
372
+ /** The service's copyright text when omitted. */
373
+ attribution?: string;
374
+ opacity?: number;
375
+ minzoom?: number;
376
+ maxzoom?: number;
377
+ }
378
+
379
+ /** The shared layer description (shared/LAYER-JSON.md). */
380
+ export interface LayerDescription {
381
+ type: 'smap.layers';
382
+ version: 1;
383
+ basemap?: { style?: StyleFlavor | CustomStyleName; language?: string; overrides?: BasemapOverrides };
384
+ sources?: Record<string, StyleSource>;
385
+ layers: Array<{
386
+ id: string;
387
+ kind: 'points' | 'lines' | 'polygons' | 'style';
388
+ slot?: Slot;
389
+ before?: string;
390
+ zIndex?: number;
391
+ visible?: boolean;
392
+ group?: string;
393
+ data?: GeoJSONFeatureCollection;
394
+ options?: Record<string, unknown>;
395
+ layer?: StyleLayer;
396
+ }>;
397
+ }
398
+
399
+ export interface RasterUrlOptions {
400
+ /** Label language. */
401
+ lang?: string;
402
+ /** 512 px tiles (@2x). */
403
+ retina?: boolean;
404
+ baseUrl?: string;
405
+ apiKey?: string;
406
+ }
407
+
226
408
  export interface FlyToOptions {
227
409
  center?: LngLatLike;
228
410
  zoom?: number;
@@ -246,7 +428,7 @@ export declare class Map {
246
428
  readonly ready: Promise<Map>;
247
429
  /** The rendering engine's map, for anything the SDK does not wrap (set once `ready` resolves). */
248
430
  readonly engine: any;
249
- setStyle(style: StyleFlavor | string | Record<string, unknown>): this;
431
+ setStyle(style: StyleFlavor | CustomStyleName | string | Record<string, unknown>): this;
250
432
  setLanguage(language: string): this;
251
433
  setProjection(projection: 'mercator' | 'globe'): this;
252
434
  setBuildings3D(on: boolean, options?: BuildingsOptions): this;
@@ -255,9 +437,58 @@ export declare class Map {
255
437
  addPolygons(id: string, data: LayerData, options?: PolygonOptions): this;
256
438
  setData(id: string, data: LayerData): this;
257
439
  setVisible(id: string, visible: boolean): this;
440
+ /** Removes a layer of any kind (an addData group whole, a helper layer with its source), or a source of addSource. */
258
441
  removeLayer(id: string): this;
259
442
  /** Layer ids in draw order, bottom first. */
260
443
  layers(): string[];
444
+ /** Adds a Style Specification v8 source, kept across style and language changes. */
445
+ addSource(id: string, source: StyleSource): this;
446
+ /** Removes a source and the style layers that read it. */
447
+ removeSource(id: string): this;
448
+ /** The sources added with addSource. */
449
+ sources(): Record<string, StyleSource>;
450
+ /** Adds a Style Specification v8 layer as it is; without a slot or `before` it draws on top. */
451
+ addStyleLayer(layer: StyleLayer, placement?: Placement): this;
452
+ setPaint(layerId: string, name: string, value: unknown): this;
453
+ setLayout(layerId: string, name: string, value: unknown): this;
454
+ /** null clears the filter. */
455
+ setFilter(layerId: string, filter: unknown[] | null): this;
456
+ /** A style layer (yours or the basemap's) as a Style Specification object; null when there is none. */
457
+ getStyleLayer(layerId: string): StyleLayer | null;
458
+ /** Where each slot begins in the current basemap (layer ids; `top` is undefined). */
459
+ slots(): Record<Slot, string | undefined>;
460
+ /** Shows, hides and recolours the basemap by class; replaces the previous overrides ({} clears them). */
461
+ setBasemap(overrides: BasemapOverrides): this;
462
+ /** The basemap overrides in force. */
463
+ basemap(): BasemapOverrides;
464
+ /** Reads a file and draws it as `<id>` (points), `<id>:lines` and `<id>:areas`. */
465
+ addData(id: string, input: FileInput | Blob, options?: DataOptions): Promise<this>;
466
+ /** A layer's features (an addData group together) as GeoJSON. */
467
+ toGeoJSON(layerId: string): GeoJSONFeatureCollection;
468
+ /** A layer's features as a KML document. */
469
+ toKML(layerId: string): string;
470
+ /** Converts a file on sMap (POST /v1/convert) with this map's address, key and token. */
471
+ convert(input: FileInput | Blob, options?: ConvertOptions): Promise<GeoJSONFeatureCollection>;
472
+ /** sMap's raster tiles of a style (default the map's own) as a {z}/{x}/{y} template on this map's node and key. */
473
+ rasterUrl(style?: StyleFlavor | CustomStyleName, options?: Pick<RasterUrlOptions, 'lang' | 'retina'>): string;
474
+ addRasterLayer(id: string, options: RasterLayerOptions): this;
475
+ addWmsLayer(id: string, options: WmsLayerOptions): this;
476
+ addWmtsLayer(id: string, options: WmtsLayerOptions): Promise<this>;
477
+ addVectorTiles(id: string, options: VectorTilesOptions): this;
478
+ addArcGisLayer(id: string, options: ArcGisLayerOptions): Promise<this>;
479
+ /** The map's layers as the shared layer description. */
480
+ toJSON(): LayerDescription;
481
+ /** Loads a layer description (an object or its text). */
482
+ loadLayers(json: LayerDescription | string): this;
483
+ /** A deck.gl layer drawn interleaved with the basemap (load deck.gl first with useDeck). */
484
+ addDeckLayer(layer: any, placement?: Pick<Placement, 'slot' | 'before'>): this;
485
+ removeDeckLayer(id: string): this;
486
+ deckLayers(): any[];
487
+ /**
488
+ * The map's deck.gl overlay (MapboxOverlay), made on first use; `props` are other deck.gl props (getTooltip,
489
+ * onClick, pickingRadius, …). Null before the map is ready or when deck.gl is not loaded.
490
+ */
491
+ deckOverlay(props?: Record<string, unknown>): any | null;
261
492
  fitLayer(id: string, options?: FitOptions): this;
262
493
  flyTo(options: FlyToOptions): this;
263
494
  /** Opens the map's popup at a position, closing the one open before (one popup per map). */
@@ -284,11 +515,74 @@ export declare function getEngine(): any;
284
515
  */
285
516
  export declare function popupTemplate(template: string): (properties: Record<string, unknown> | null | undefined, feature?: GeoJSONFeature) => string;
286
517
 
518
+ /** The slot names. */
519
+ export declare const slots: Slot[];
520
+
521
+ export interface Formats {
522
+ list: FileFormat[];
523
+ /** Reads a file into a FeatureCollection, on the device. */
524
+ read(input: FileInput, options?: ReadOptions): GeoJSONFeatureCollection;
525
+ /** Reads a Blob or File (the format from its name when not given). */
526
+ readFile(file: Blob & { name?: string }, options?: ReadOptions): Promise<GeoJSONFeatureCollection>;
527
+ /** Writes GeoJSON text or a KML document. */
528
+ write(data: LayerData, format: 'geojson' | 'kml', options?: { name?: string }): string;
529
+ toKML(data: LayerData, options?: { name?: string }): string;
530
+ sniff(input: FileInput): FileFormat | null;
531
+ formatOfName(name: string): FileFormat | null;
532
+ decodePolyline(text: string, precision?: number): Array<[number, number]>;
533
+ encodePolyline(coordinates: Array<[number, number] | number[]>, precision?: number): string;
534
+ }
535
+ /** File formats read on the device (KML, KMZ, GPX, polylines, WKT, WKB, CSV, TopoJSON, GeoJSON). */
536
+ export declare const formats: Formats;
537
+ /** Converts a file on sMap (POST /v1/convert). */
538
+ export declare function convert(input: FileInput | Blob, options?: ConvertOptions): Promise<GeoJSONFeatureCollection>;
539
+ /** sMap's raster tiles of a style as an XYZ template, for tools without vector tiles. */
540
+ export declare function rasterUrl(style: StyleFlavor | CustomStyleName, options?: RasterUrlOptions): string;
541
+ /** The TileJSON address of sMap's raster tiles of a style. */
542
+ export declare function rasterTileJsonUrl(style: StyleFlavor | CustomStyleName, options?: RasterUrlOptions): string;
543
+ /** The style URL of a scheme or a custom style. */
544
+ export declare function styleUrl(style: StyleFlavor | CustomStyleName, options?: { lang?: string; baseUrl?: string; apiKey?: string }): string;
545
+ /** A style with basemap overrides applied (a copy); throws on an unknown class or field. */
546
+ export declare function applyBasemapOverrides<S extends { layers?: StyleLayer[] }>(style: S, overrides: BasemapOverrides | null | undefined, table?: BasemapClassTable): S;
547
+ /** The basemap class table. */
548
+ export declare function basemapClasses(): BasemapClassTable;
549
+ /** Where each slot begins in a list of basemap layer ids. */
550
+ export declare function slotAnchors(layerIds: string[], table?: BasemapClassTable): Record<Slot, string | undefined>;
551
+ export interface WmtsCapabilities {
552
+ layers: Array<{ id: string; title: string; styles: Array<{ id: string; isDefault: boolean }>; formats: string[]; tileMatrixSets: string[]; resourceUrls: Array<{ format: string; template: string }>; bounds: [number, number, number, number] | null }>;
553
+ tileMatrixSets: Record<string, { id: string; crs: string; wellKnown: string; matrices: Array<{ id: string; zoom: number; tileWidth: number }> }>;
554
+ getTile: string | null;
555
+ }
556
+ /** Reads WMTS 1.0.0 capabilities. */
557
+ export declare function parseWmtsCapabilities(xml: string): WmtsCapabilities;
558
+ /** A PMTiles v3 archive read by HTTP range requests. */
559
+ export declare class PMTilesArchive {
560
+ constructor(url: string, fetchRange?: (url: string, offset: number, length: number) => Promise<Uint8Array | ArrayBuffer> | Uint8Array);
561
+ header(): Promise<Record<string, unknown>>;
562
+ metadata(): Promise<Record<string, unknown>>;
563
+ tile(z: number, x: number, y: number): Promise<Uint8Array | null>;
564
+ tileJSON(): Promise<Record<string, unknown>>;
565
+ }
566
+ /** Registers deck.gl's map overlay module (`@deck.gl/mapbox`) for addDeckLayer. */
567
+ export declare function useDeck(module: { MapboxOverlay: any } | { default: { MapboxOverlay: any } }): any;
568
+
287
569
  declare const sMap: {
288
570
  Map: typeof Map;
289
571
  version: string;
290
572
  styles: StyleFlavor[];
291
573
  getEngine: typeof getEngine;
292
574
  popupTemplate: typeof popupTemplate;
575
+ slots: Slot[];
576
+ formats: Formats;
577
+ convert: typeof convert;
578
+ rasterUrl: typeof rasterUrl;
579
+ rasterTileJsonUrl: typeof rasterTileJsonUrl;
580
+ styleUrl: typeof styleUrl;
581
+ applyBasemapOverrides: typeof applyBasemapOverrides;
582
+ basemapClasses: typeof basemapClasses;
583
+ slotAnchors: typeof slotAnchors;
584
+ parseWmtsCapabilities: typeof parseWmtsCapabilities;
585
+ PMTilesArchive: typeof PMTilesArchive;
586
+ useDeck: typeof useDeck;
293
587
  };
294
588
  export default sMap;