@superrouteca/smap 1.0.2 → 1.0.5

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.2",
3
+ "version": "1.0.5",
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",
package/types/smap.d.cts CHANGED
@@ -30,8 +30,38 @@ export interface PointInput {
30
30
  [property: string]: unknown;
31
31
  }
32
32
 
33
- /** Layer data: GeoJSON (a FeatureCollection or a Feature) or an array of points or features. */
34
- export type LayerData = GeoJSONFeatureCollection | GeoJSONFeature | Array<PointInput | GeoJSONFeature> | null | undefined;
33
+ /** Layer data: GeoJSON (a FeatureCollection, a Feature or a bare geometry) or an array of points or features. */
34
+ export type LayerData = GeoJSONFeatureCollection | GeoJSONFeature | GeoJSONGeometry | Array<PointInput | GeoJSONFeature> | null | undefined;
35
+
36
+ /**
37
+ * What a popup shows: an HTML string (inserted as it is and never sanitized, so it must be trusted: escape any feature
38
+ * data you put in it, or use `popupTemplate`), a DOM node, or a promise of either (the loading state shows meanwhile;
39
+ * a rejection closes the popup and is reported as the map's `error` event). Nothing (null, undefined, false, '')
40
+ * opens no popup.
41
+ */
42
+ export type PopupContent = string | Node | null | undefined | false;
43
+
44
+ /** How a popup looks and behaves. Layer options are merged over the map's `popup` defaults. */
45
+ export interface PopupOptions {
46
+ /** Classes added to the popup's element, beside `smap-popup`. */
47
+ className?: string;
48
+ /** Largest width: pixels or a CSS length (default 240px). */
49
+ maxWidth?: number | string;
50
+ /** Smallest width: pixels or a CSS length. */
51
+ minWidth?: number | string;
52
+ /** Distance from the anchor in pixels, or per anchor (default 12). */
53
+ offset?: number | [number, number] | Record<string, [number, number]>;
54
+ /** Which side of the popup points at the position; chosen to fit by default. */
55
+ anchor?: 'center' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
56
+ /** A close button in the corner (default true). */
57
+ closeButton?: boolean;
58
+ /** A click on the map closes it (default true). */
59
+ closeOnClick?: boolean;
60
+ /** Focus moves into the popup when it opens (default true). */
61
+ focusAfterOpen?: boolean;
62
+ /** Pan the map so the popup is fully visible (default true). */
63
+ autoPan?: boolean;
64
+ }
35
65
 
36
66
  /** The event of a click on a layer's feature (the engine's map mouse event). */
37
67
  export interface LayerClickEvent {
@@ -50,14 +80,66 @@ interface CommonLayerOptions {
50
80
  /** A feature property used as the feature id. */
51
81
  idProperty?: string;
52
82
  /**
53
- * A popup opened on click, from the clicked feature's properties: an HTML string, inserted as it is and never
54
- * sanitized (so it must be trusted; escape any feature data you put in it), or a DOM node.
83
+ * 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.
55
85
  */
56
- popup?: (properties: Record<string, unknown>, feature: GeoJSONFeature) => string | Node | null | undefined | false;
86
+ popup?: (properties: Record<string, unknown>, feature: GeoJSONFeature) => PopupContent | Promise<PopupContent>;
87
+ /** This layer's popup options, over the map's `popup` defaults. */
88
+ popupOptions?: PopupOptions;
89
+ /** Shown while this layer's popup content is a pending promise (HTML string or DOM node; default pulsing dots). */
90
+ popupLoading?: string | Node;
91
+ /** Auto Zoom: a click on pins piled up zooms in around it, or lists them close up (default true). */
92
+ autoZoom?: boolean;
93
+ /** In 3D, W / S tilt and A / D turn the view while the map has focus (default true). */
94
+ keyboard3D?: boolean;
57
95
  onClick?: (feature: GeoJSONFeature, event: LayerClickEvent) => void;
58
96
  }
59
97
 
98
+ /**
99
+ * A value drawn per feature: a constant (`'#e6194b'`, `3`), a feature property (`{ property: 'status_color' }`, with
100
+ * `default` for features without it), or an engine expression (an array, e.g. `['get', 'color']`).
101
+ */
102
+ export type StyleValue<T = string> = T | { property: string; default?: T } | unknown[];
103
+
104
+ /** Pins like Superroute's route map, drawn on the GPU (one image per colour pair, made when first shown). */
105
+ export interface MarkerOptions {
106
+ /** `pin` (default: a teardrop whose tip is at the position) or `circle` (centred on it). */
107
+ shape?: 'pin' | 'circle';
108
+ /** Inside colour (default white). */
109
+ fill?: StyleValue;
110
+ /** Border colour (default the layer's `color`). */
111
+ border?: StyleValue;
112
+ /** Border width in pixels (default 3). */
113
+ borderWidth?: number;
114
+ /** Width of the pin in pixels (default 32). */
115
+ size?: number;
116
+ /** The text in the pin, e.g. the stop number; none when empty. */
117
+ text?: StyleValue<string | number>;
118
+ /** Text colour (default white). */
119
+ textColor?: StyleValue;
120
+ /** A red count badge at the pin's upper right, shown when the value is more than 1. */
121
+ badge?: StyleValue<number>;
122
+ /** Numbers from this zoom on (pins without numbers below it, so a crowded overview stays readable). */
123
+ /** Size factor of the pin, its number and its badge together: a number or an engine expression, e.g. of the zoom. Default 1. */
124
+ scale?: number | unknown[];
125
+ /** The pin under the pointer comes to the front (default true). */
126
+ hoverRaise?: boolean;
127
+ /**
128
+ * Pins piled up under a click (default on): with `threshold` (4) or more within `radius` (12 px) the map zooms in by
129
+ * `zoomBy` (2) up to `maxZoom` (17); close up, or for pins at one spot, a chooser lists them (`label(properties)`).
130
+ * `false` turns it off.
131
+ */
132
+ overlap?: false | { threshold?: number; radius?: number; zoomBy?: number; maxZoom?: number; label?: (properties: Record<string, unknown>, feature: GeoJSONFeature) => string };
133
+ /** Opacity of the pin, its number and its badge (default 1). */
134
+ opacity?: StyleValue<number>;
135
+ textMinzoom?: number;
136
+ /** Badges from this zoom on. */
137
+ badgeMinzoom?: number;
138
+ }
139
+
60
140
  export interface PointOptions extends CommonLayerOptions {
141
+ /** Route-map pins instead of circles or an icon. */
142
+ marker?: MarkerOptions;
61
143
  /** Groups nearby points into circles sized by their count; a click zooms in to split them. */
62
144
  cluster?: boolean | { radius?: number; maxZoom?: number };
63
145
  clusterColor?: string;
@@ -74,11 +156,18 @@ export interface PointOptions extends CommonLayerOptions {
74
156
  }
75
157
 
76
158
  export interface LineOptions extends CommonLayerOptions {
77
- color?: string;
159
+ /** A colour, or one per feature (`{ property: 'color' }` or an expression): one layer for many routes. */
160
+ color?: StyleValue;
78
161
  width?: number;
79
162
  /** Dash and gap lengths in line widths, e.g. [2, 2]. */
80
163
  dash?: number[];
81
164
  opacity?: number;
165
+ /** A wider line under the line (true: white, 9 px). */
166
+ casing?: boolean | { color?: StyleValue; width?: number; opacity?: number };
167
+ /** A shadow line between the casing and the line (true: black, 7 px, opacity 0.3). */
168
+ shadow?: boolean | { color?: StyleValue; width?: number; opacity?: number };
169
+ /** Arrowheads along the line in its direction (true: every 80 px, 14 px, the line's colour, opacity 0.8). */
170
+ arrows?: boolean | { spacing?: number; size?: number; color?: StyleValue; opacity?: number };
82
171
  }
83
172
 
84
173
  export interface PolygonOptions extends CommonLayerOptions {
@@ -122,6 +211,10 @@ export interface MapOptions {
122
211
  pitch?: number;
123
212
  minZoom?: number;
124
213
  maxZoom?: number;
214
+ /** Default popup options of every layer and of `openPopup`. */
215
+ popup?: PopupOptions;
216
+ /** Shown while a popup's content is a pending promise (HTML string or DOM node; default pulsing dots). */
217
+ popupLoading?: string | Node;
125
218
  /** Every other option goes to the rendering engine. */
126
219
  [engineOption: string]: unknown;
127
220
  }
@@ -163,6 +256,12 @@ export declare class Map {
163
256
  layers(): string[];
164
257
  fitLayer(id: string, options?: FitOptions): this;
165
258
  flyTo(options: FlyToOptions): this;
259
+ /** Opens the map's popup at a position, closing the one open before (one popup per map). */
260
+ openPopup(lngLat: LngLatLike, content: PopupContent | Promise<PopupContent>, options?: PopupOptions & { loading?: string | Node }): this;
261
+ /** Closes the map's popup, if one is open. */
262
+ closePopup(): this;
263
+ setAutoZoom(on: boolean): this;
264
+ autoZoom(): boolean;
166
265
  on(type: string, ...args: any[]): this;
167
266
  off(type: string, ...args: any[]): this;
168
267
  once(type: string, ...args: any[]): any;
@@ -175,11 +274,17 @@ export declare const version: string;
175
274
  export declare const styles: StyleFlavor[];
176
275
  /** The bundled rendering engine, for anything the SDK does not wrap (loaded on the first call). */
177
276
  export declare function getEngine(): any;
277
+ /**
278
+ * A popup function from a template: every `{name}` becomes the feature's property of that name, HTML-escaped (empty
279
+ * when missing). The template itself is trusted HTML. Compiled once; it runs only when a popup opens.
280
+ */
281
+ export declare function popupTemplate(template: string): (properties: Record<string, unknown> | null | undefined, feature?: GeoJSONFeature) => string;
178
282
 
179
283
  declare const sMap: {
180
284
  Map: typeof Map;
181
285
  version: string;
182
286
  styles: StyleFlavor[];
183
287
  getEngine: typeof getEngine;
288
+ popupTemplate: typeof popupTemplate;
184
289
  };
185
290
  export default sMap;
package/types/smap.d.mts CHANGED
@@ -30,8 +30,38 @@ export interface PointInput {
30
30
  [property: string]: unknown;
31
31
  }
32
32
 
33
- /** Layer data: GeoJSON (a FeatureCollection or a Feature) or an array of points or features. */
34
- export type LayerData = GeoJSONFeatureCollection | GeoJSONFeature | Array<PointInput | GeoJSONFeature> | null | undefined;
33
+ /** Layer data: GeoJSON (a FeatureCollection, a Feature or a bare geometry) or an array of points or features. */
34
+ export type LayerData = GeoJSONFeatureCollection | GeoJSONFeature | GeoJSONGeometry | Array<PointInput | GeoJSONFeature> | null | undefined;
35
+
36
+ /**
37
+ * What a popup shows: an HTML string (inserted as it is and never sanitized, so it must be trusted: escape any feature
38
+ * data you put in it, or use `popupTemplate`), a DOM node, or a promise of either (the loading state shows meanwhile;
39
+ * a rejection closes the popup and is reported as the map's `error` event). Nothing (null, undefined, false, '')
40
+ * opens no popup.
41
+ */
42
+ export type PopupContent = string | Node | null | undefined | false;
43
+
44
+ /** How a popup looks and behaves. Layer options are merged over the map's `popup` defaults. */
45
+ export interface PopupOptions {
46
+ /** Classes added to the popup's element, beside `smap-popup`. */
47
+ className?: string;
48
+ /** Largest width: pixels or a CSS length (default 240px). */
49
+ maxWidth?: number | string;
50
+ /** Smallest width: pixels or a CSS length. */
51
+ minWidth?: number | string;
52
+ /** Distance from the anchor in pixels, or per anchor (default 12). */
53
+ offset?: number | [number, number] | Record<string, [number, number]>;
54
+ /** Which side of the popup points at the position; chosen to fit by default. */
55
+ anchor?: 'center' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
56
+ /** A close button in the corner (default true). */
57
+ closeButton?: boolean;
58
+ /** A click on the map closes it (default true). */
59
+ closeOnClick?: boolean;
60
+ /** Focus moves into the popup when it opens (default true). */
61
+ focusAfterOpen?: boolean;
62
+ /** Pan the map so the popup is fully visible (default true). */
63
+ autoPan?: boolean;
64
+ }
35
65
 
36
66
  /** The event of a click on a layer's feature (the engine's map mouse event). */
37
67
  export interface LayerClickEvent {
@@ -50,14 +80,66 @@ interface CommonLayerOptions {
50
80
  /** A feature property used as the feature id. */
51
81
  idProperty?: string;
52
82
  /**
53
- * A popup opened on click, from the clicked feature's properties: an HTML string, inserted as it is and never
54
- * sanitized (so it must be trusted; escape any feature data you put in it), or a DOM node.
83
+ * 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.
55
85
  */
56
- popup?: (properties: Record<string, unknown>, feature: GeoJSONFeature) => string | Node | null | undefined | false;
86
+ popup?: (properties: Record<string, unknown>, feature: GeoJSONFeature) => PopupContent | Promise<PopupContent>;
87
+ /** This layer's popup options, over the map's `popup` defaults. */
88
+ popupOptions?: PopupOptions;
89
+ /** Shown while this layer's popup content is a pending promise (HTML string or DOM node; default pulsing dots). */
90
+ popupLoading?: string | Node;
91
+ /** Auto Zoom: a click on pins piled up zooms in around it, or lists them close up (default true). */
92
+ autoZoom?: boolean;
93
+ /** In 3D, W / S tilt and A / D turn the view while the map has focus (default true). */
94
+ keyboard3D?: boolean;
57
95
  onClick?: (feature: GeoJSONFeature, event: LayerClickEvent) => void;
58
96
  }
59
97
 
98
+ /**
99
+ * A value drawn per feature: a constant (`'#e6194b'`, `3`), a feature property (`{ property: 'status_color' }`, with
100
+ * `default` for features without it), or an engine expression (an array, e.g. `['get', 'color']`).
101
+ */
102
+ export type StyleValue<T = string> = T | { property: string; default?: T } | unknown[];
103
+
104
+ /** Pins like Superroute's route map, drawn on the GPU (one image per colour pair, made when first shown). */
105
+ export interface MarkerOptions {
106
+ /** `pin` (default: a teardrop whose tip is at the position) or `circle` (centred on it). */
107
+ shape?: 'pin' | 'circle';
108
+ /** Inside colour (default white). */
109
+ fill?: StyleValue;
110
+ /** Border colour (default the layer's `color`). */
111
+ border?: StyleValue;
112
+ /** Border width in pixels (default 3). */
113
+ borderWidth?: number;
114
+ /** Width of the pin in pixels (default 32). */
115
+ size?: number;
116
+ /** The text in the pin, e.g. the stop number; none when empty. */
117
+ text?: StyleValue<string | number>;
118
+ /** Text colour (default white). */
119
+ textColor?: StyleValue;
120
+ /** A red count badge at the pin's upper right, shown when the value is more than 1. */
121
+ badge?: StyleValue<number>;
122
+ /** Numbers from this zoom on (pins without numbers below it, so a crowded overview stays readable). */
123
+ /** Size factor of the pin, its number and its badge together: a number or an engine expression, e.g. of the zoom. Default 1. */
124
+ scale?: number | unknown[];
125
+ /** The pin under the pointer comes to the front (default true). */
126
+ hoverRaise?: boolean;
127
+ /**
128
+ * Pins piled up under a click (default on): with `threshold` (4) or more within `radius` (12 px) the map zooms in by
129
+ * `zoomBy` (2) up to `maxZoom` (17); close up, or for pins at one spot, a chooser lists them (`label(properties)`).
130
+ * `false` turns it off.
131
+ */
132
+ overlap?: false | { threshold?: number; radius?: number; zoomBy?: number; maxZoom?: number; label?: (properties: Record<string, unknown>, feature: GeoJSONFeature) => string };
133
+ /** Opacity of the pin, its number and its badge (default 1). */
134
+ opacity?: StyleValue<number>;
135
+ textMinzoom?: number;
136
+ /** Badges from this zoom on. */
137
+ badgeMinzoom?: number;
138
+ }
139
+
60
140
  export interface PointOptions extends CommonLayerOptions {
141
+ /** Route-map pins instead of circles or an icon. */
142
+ marker?: MarkerOptions;
61
143
  /** Groups nearby points into circles sized by their count; a click zooms in to split them. */
62
144
  cluster?: boolean | { radius?: number; maxZoom?: number };
63
145
  clusterColor?: string;
@@ -74,11 +156,18 @@ export interface PointOptions extends CommonLayerOptions {
74
156
  }
75
157
 
76
158
  export interface LineOptions extends CommonLayerOptions {
77
- color?: string;
159
+ /** A colour, or one per feature (`{ property: 'color' }` or an expression): one layer for many routes. */
160
+ color?: StyleValue;
78
161
  width?: number;
79
162
  /** Dash and gap lengths in line widths, e.g. [2, 2]. */
80
163
  dash?: number[];
81
164
  opacity?: number;
165
+ /** A wider line under the line (true: white, 9 px). */
166
+ casing?: boolean | { color?: StyleValue; width?: number; opacity?: number };
167
+ /** A shadow line between the casing and the line (true: black, 7 px, opacity 0.3). */
168
+ shadow?: boolean | { color?: StyleValue; width?: number; opacity?: number };
169
+ /** Arrowheads along the line in its direction (true: every 80 px, 14 px, the line's colour, opacity 0.8). */
170
+ arrows?: boolean | { spacing?: number; size?: number; color?: StyleValue; opacity?: number };
82
171
  }
83
172
 
84
173
  export interface PolygonOptions extends CommonLayerOptions {
@@ -122,6 +211,10 @@ export interface MapOptions {
122
211
  pitch?: number;
123
212
  minZoom?: number;
124
213
  maxZoom?: number;
214
+ /** Default popup options of every layer and of `openPopup`. */
215
+ popup?: PopupOptions;
216
+ /** Shown while a popup's content is a pending promise (HTML string or DOM node; default pulsing dots). */
217
+ popupLoading?: string | Node;
125
218
  /** Every other option goes to the rendering engine. */
126
219
  [engineOption: string]: unknown;
127
220
  }
@@ -163,6 +256,12 @@ export declare class Map {
163
256
  layers(): string[];
164
257
  fitLayer(id: string, options?: FitOptions): this;
165
258
  flyTo(options: FlyToOptions): this;
259
+ /** Opens the map's popup at a position, closing the one open before (one popup per map). */
260
+ openPopup(lngLat: LngLatLike, content: PopupContent | Promise<PopupContent>, options?: PopupOptions & { loading?: string | Node }): this;
261
+ /** Closes the map's popup, if one is open. */
262
+ closePopup(): this;
263
+ setAutoZoom(on: boolean): this;
264
+ autoZoom(): boolean;
166
265
  on(type: string, ...args: any[]): this;
167
266
  off(type: string, ...args: any[]): this;
168
267
  once(type: string, ...args: any[]): any;
@@ -175,11 +274,17 @@ export declare const version: string;
175
274
  export declare const styles: StyleFlavor[];
176
275
  /** The bundled rendering engine, for anything the SDK does not wrap (loaded on the first call). */
177
276
  export declare function getEngine(): any;
277
+ /**
278
+ * A popup function from a template: every `{name}` becomes the feature's property of that name, HTML-escaped (empty
279
+ * when missing). The template itself is trusted HTML. Compiled once; it runs only when a popup opens.
280
+ */
281
+ export declare function popupTemplate(template: string): (properties: Record<string, unknown> | null | undefined, feature?: GeoJSONFeature) => string;
178
282
 
179
283
  declare const sMap: {
180
284
  Map: typeof Map;
181
285
  version: string;
182
286
  styles: StyleFlavor[];
183
287
  getEngine: typeof getEngine;
288
+ popupTemplate: typeof popupTemplate;
184
289
  };
185
290
  export default sMap;