@superrouteca/smap 1.0.1 → 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/CHANGELOG.md +32 -0
- package/README.md +136 -4
- package/dist/SOURCE.json +8 -8
- package/dist/smap-client.cjs +2 -2
- package/dist/smap-client.js +2 -2
- package/dist/smap-client.mjs +2 -2
- package/dist/smap.cjs +643 -31
- package/dist/smap.css +54 -0
- package/dist/smap.js +634 -29
- package/dist/smap.mjs +643 -32
- package/package.json +1 -1
- package/types/smap.d.cts +111 -6
- package/types/smap.d.mts +111 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.5 — 2026-10-27
|
|
4
|
+
|
|
5
|
+
- Auto Zoom has a switch: the map option `autoZoom` and `map.setAutoZoom(on)`. In 3D, W / S tilt and A / D turn the view (`keyboard3D`).
|
|
6
|
+
- Auto Zoom, pins piled up under a click: the map zooms in around it so they come apart; close up, or for pins at one spot, a chooser lists them and opens the one picked (`overlap`). Marker `opacity`; a clicked pin stays in front while its popup is open.
|
|
7
|
+
- A pin's popup opens just above the pin at its current size, and the map pans to show it whole (`autoPan`). Overlapping pins: the one under the pointer comes to the front, as on Superroute's route map (`hoverRaise`, on by default).
|
|
8
|
+
- Markers take `scale`: the pin, its number and its badge are sized together, for example smaller at a low zoom.
|
|
9
|
+
- Markers take `textMinzoom` and `badgeMinzoom`: numbers and badges appear only from that zoom on, so an overview of
|
|
10
|
+
thousands of stops stays readable.
|
|
11
|
+
- Popups made for many markers: one popup per map (opening another closes the one before), a point's popup opens at
|
|
12
|
+
the point, and only the top feature under a click opens. Nothing runs for a feature until its popup opens.
|
|
13
|
+
- `popupTemplate('<b>{name}</b><br>{address}')` builds a popup from feature properties, HTML-escaped; the fast and
|
|
14
|
+
safe choice for large layers.
|
|
15
|
+
- A popup may be a promise of HTML or a DOM node: a loading state shows meanwhile (`popupLoading`), an answer that
|
|
16
|
+
arrives after another popup opened is dropped, and a failure closes the popup and is reported as the map's `error`
|
|
17
|
+
event.
|
|
18
|
+
- Popup options per layer (`popupOptions`) over map defaults (`popup` when creating the map): `className`, `maxWidth`,
|
|
19
|
+
`minWidth`, `offset`, `anchor`, `closeButton`, `closeOnClick`, `focusAfterOpen`.
|
|
20
|
+
- Popups are styled with CSS variables (`--smap-popup-bg`, `--smap-popup-color`, `--smap-popup-radius`,
|
|
21
|
+
`--smap-popup-padding`, `--smap-popup-shadow`, `--smap-popup-font-size`, `--smap-popup-width`); dark colours on the
|
|
22
|
+
dark and black schemes.
|
|
23
|
+
- `map.openPopup(position, content, options)` and `map.closePopup()`.
|
|
24
|
+
- Route-map pins on the GPU (`marker` on `addPoints`): the pin of Superroute's route map (or a circle) with a fill and
|
|
25
|
+
a border colour, a number and a red count badge, each set per feature from a property, a constant or an expression.
|
|
26
|
+
Each distinct pin, number and badge is drawn once, when a feature first shows it, so tens of thousands of stops stay
|
|
27
|
+
smooth.
|
|
28
|
+
- Route lines like Superroute's route map: a colour per feature, `casing`, `shadow` and direction `arrows`.
|
|
29
|
+
|
|
30
|
+
## 1.0.2 — 2026-10-27
|
|
31
|
+
|
|
32
|
+
- A layer takes a bare GeoJSON geometry as well (`addLines('route', { type: 'LineString', coordinates })`, a Polygon, a
|
|
33
|
+
Point, …): it is drawn as one feature. Before, such a layer stayed empty.
|
|
34
|
+
|
|
3
35
|
## 1.0.1 — 2026-10-27
|
|
4
36
|
|
|
5
37
|
- Every map shows a small sMap badge (the sMap icon and name on a semi-transparent pill that reads on all five colour
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ areas drawn on the GPU (hundreds of thousands of points, clustered or not), 3D b
|
|
|
10
10
|
renew themselves. Also the JS client (no map view) for servers and workers: tokens, the nearest node, styles, tiles
|
|
11
11
|
and raw reads.
|
|
12
12
|
|
|
13
|
-
- Version 1.0.
|
|
13
|
+
- Version 1.0.5, MIT licence (see `LICENSE` at the repository root)
|
|
14
14
|
- Works with bundlers (Vite, webpack, Next.js and others): ES module and CommonJS entry points with types
|
|
15
15
|
- Nothing else to install: the map renderer is bundled in the package
|
|
16
16
|
- Importing is safe on a server; a map is created in the browser only
|
|
@@ -57,9 +57,6 @@ map.setBuildings3D(true);
|
|
|
57
57
|
map.fitLayer('stops');
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
A `popup` option returns an HTML string, which is inserted as it is and never sanitized (escape any feature data you
|
|
61
|
-
put in it), or a DOM node.
|
|
62
|
-
|
|
63
60
|
`setStyle()` and `setLanguage()` keep your layers. Other calls: `setData`, `setVisible`, `removeLayer`, `layers`,
|
|
64
61
|
`flyTo`, `setProjection`, `on` / `off` / `once`, `remove`. `map.engine` is the renderer's own map for anything the
|
|
65
62
|
SDK does not wrap, and `getEngine()` gives the renderer itself.
|
|
@@ -67,6 +64,141 @@ SDK does not wrap, and `getEngine()` gives the renderer itself.
|
|
|
67
64
|
In a server-rendered page (for example Next.js), create the map in an effect or event handler, never while rendering
|
|
68
65
|
on the server: `new Map()` throws outside a browser. Importing the package is fine anywhere.
|
|
69
66
|
|
|
67
|
+
## Popups
|
|
68
|
+
|
|
69
|
+
Give a layer a `popup` and a click on one of its features opens it. A map has one popup: opening another closes the
|
|
70
|
+
one before. A point's popup opens at the point, a line's or area's where it was clicked, and only the top feature
|
|
71
|
+
under the click opens.
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
import { Map, popupTemplate } from '@superrouteca/smap'; // browser build: sMap.popupTemplate
|
|
75
|
+
|
|
76
|
+
map.addPoints('stops', stops, {
|
|
77
|
+
icon: '/img/stop.png',
|
|
78
|
+
popup: popupTemplate('<b>{name}</b><br>{address}'),
|
|
79
|
+
popupOptions: { className: 'stop-popup', maxWidth: 280 },
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Templates.** `popupTemplate(template)` replaces every `{name}` with the feature's property of that name,
|
|
84
|
+
HTML-escaped (empty when the feature has none). The template is compiled once, and nothing runs for a feature until
|
|
85
|
+
its popup opens, so a layer of tens of thousands of markers costs nothing extra. It is the recommended popup for
|
|
86
|
+
large layers.
|
|
87
|
+
|
|
88
|
+
**Your own function.** `popup(properties, feature)` may return:
|
|
89
|
+
|
|
90
|
+
- an HTML string: inserted as it is and never sanitized, so it must be trusted (escape any feature data you put in
|
|
91
|
+
it, or use `popupTemplate`);
|
|
92
|
+
- a DOM node, inserted as it is;
|
|
93
|
+
- a promise of either, for content fetched when the popup opens. The loading state shows meanwhile (`popupLoading`,
|
|
94
|
+
an HTML string or a DOM node; three pulsing dots by default). An answer that arrives after another popup opened is
|
|
95
|
+
dropped; a failure closes the popup and is reported as the map's `error` event (`map.on('error', …)`);
|
|
96
|
+
- nothing (`null`, `false`, `''`): no popup.
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
map.addPoints('orders', orders, {
|
|
100
|
+
popup: async (p) => {
|
|
101
|
+
const order = await (await fetch(`/api/orders/${p.id}`)).json();
|
|
102
|
+
return popupTemplate('<b>{number}</b><br>{status}')(order);
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Options.** `popupOptions` on a layer is merged over the map's defaults, given as `popup` when the map is created:
|
|
108
|
+
|
|
109
|
+
| Option | Meaning |
|
|
110
|
+
|---|---|
|
|
111
|
+
| `className` | classes added beside `smap-popup` |
|
|
112
|
+
| `maxWidth`, `minWidth` | pixels or a CSS length (`maxWidth` is 240px by default) |
|
|
113
|
+
| `offset` | distance from the position in pixels (default 12) |
|
|
114
|
+
| `anchor` | the side that points at the position (`top`, `bottom-left`, …); chosen to fit by default |
|
|
115
|
+
| `closeButton` | the close button (default true) |
|
|
116
|
+
| `closeOnClick` | a click on the map closes the popup (default true) |
|
|
117
|
+
| `focusAfterOpen` | focus moves into the popup (default true) |
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
const map = new Map({ container: 'map', popup: { maxWidth: 320, closeButton: false }, popupLoading: '<span>…</span>' });
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Styling.** The popup's element has the class `smap-popup` (plus your `className`). Set these CSS variables on the
|
|
124
|
+
popup's class, on the map's element or on the page; nothing else needs overriding:
|
|
125
|
+
|
|
126
|
+
```css
|
|
127
|
+
.stop-popup {
|
|
128
|
+
--smap-popup-bg: #0f172a;
|
|
129
|
+
--smap-popup-color: #f8fafc;
|
|
130
|
+
--smap-popup-radius: 12px;
|
|
131
|
+
--smap-popup-padding: 12px 14px;
|
|
132
|
+
--smap-popup-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
|
|
133
|
+
--smap-popup-font-size: 14px;
|
|
134
|
+
--smap-popup-width: 260px;
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The tip follows the background. On the `dark` and `black` schemes the defaults are dark (the map's element carries
|
|
139
|
+
`smap-style-<scheme>`).
|
|
140
|
+
|
|
141
|
+
**From code.** `map.openPopup([lng, lat], content, options)` opens the map's popup with the same kinds of content
|
|
142
|
+
(and `options.loading`); `map.closePopup()` closes it.
|
|
143
|
+
|
|
144
|
+
## 3D view from the keyboard
|
|
145
|
+
|
|
146
|
+
In 3D (3D buildings on, or the map tilted) W / S tilt the view and A / D turn it while the map has focus; Shift
|
|
147
|
+
takes bigger steps. `keyboard3D: false` turns it off.
|
|
148
|
+
|
|
149
|
+
## Route maps: pins, numbers and route lines
|
|
150
|
+
|
|
151
|
+
Points can be drawn as the pins of Superroute's route map (`marker`), and lines with a casing, a shadow and direction
|
|
152
|
+
arrows. Everything is drawn on the GPU, so tens of thousands of stops stay smooth: each distinct pin (a colour pair),
|
|
153
|
+
number and badge is drawn once, the first time a feature shows it.
|
|
154
|
+
|
|
155
|
+
A value that can differ per feature is a constant (`'#e6194b'`), a feature property (`{ property: 'status_color' }`,
|
|
156
|
+
with `default` for features without it) or an engine expression (an array such as `['get', 'color']`).
|
|
157
|
+
|
|
158
|
+
**`marker`** on `addPoints`:
|
|
159
|
+
|
|
160
|
+
| Option | Meaning |
|
|
161
|
+
|---|---|
|
|
162
|
+
| `shape` | `'pin'` (default; the tip is at the position) or `'circle'` |
|
|
163
|
+
| `fill` | inside colour (default white) |
|
|
164
|
+
| `border` | border colour (default the layer's `color`) |
|
|
165
|
+
| `borderWidth` | pixels (default 3) |
|
|
166
|
+
| `size` | width in pixels (default 32) |
|
|
167
|
+
| `text` | the text in the pin, e.g. the stop number (none when empty) |
|
|
168
|
+
| `textColor` | default white |
|
|
169
|
+
| `badge` | a red count at the upper right, shown when more than 1 |
|
|
170
|
+
| `opacity` | of the pin, its number and its badge together (e.g. settled stops paler) |
|
|
171
|
+
| `overlap` | Auto Zoom for this layer (map option `autoZoom`, `map.setAutoZoom(on)`, on by default): pins piled up under a click: 4 or more within 12 px zoom the map in by 2; close up (zoom 17) or at one spot a chooser lists them, `label(properties)` names each row; `false` turns it off |
|
|
172
|
+
| `hoverRaise` | the pin under the pointer comes to the front, so overlapping pins can be read and clicked (default `true`) |
|
|
173
|
+
| `scale` | size factor of the pin, its number and its badge together; a number or an expression of the zoom, e.g. `['interpolate', ['linear'], ['zoom'], 9, 0.5, 14, 1]` |
|
|
174
|
+
| `textMinzoom`, `badgeMinzoom` | show numbers / badges only from this zoom on, so an overview of many stops stays readable |
|
|
175
|
+
|
|
176
|
+
**Lines** on `addLines`: `color` may be per feature; `casing` (`true`: white, 9 px), `shadow` (`true`: black, 7 px,
|
|
177
|
+
opacity 0.3) and `arrows` (`true`: every 80 px, 14 px, in the line's colour; or `{ spacing, size, color, opacity }`)
|
|
178
|
+
are drawn under, between and over the line.
|
|
179
|
+
|
|
180
|
+
**The route map, as on Superroute** (one layer for all routes, one for all stops):
|
|
181
|
+
|
|
182
|
+
```js
|
|
183
|
+
map.addLines('routes', routes, { // features with properties.color
|
|
184
|
+
color: { property: 'color' }, width: 5, opacity: 0.9,
|
|
185
|
+
casing: true, shadow: true, arrows: true,
|
|
186
|
+
});
|
|
187
|
+
map.addPoints('stops', stops, { // {lng, lat, stop_number, status_color, route_color, orders, …}
|
|
188
|
+
marker: {
|
|
189
|
+
fill: { property: 'status_color' },
|
|
190
|
+
border: { property: 'route_color' },
|
|
191
|
+
text: { property: 'stop_number' },
|
|
192
|
+
badge: { property: 'orders' },
|
|
193
|
+
},
|
|
194
|
+
popup: popupTemplate('<b>{stop_number}</b> {address}'),
|
|
195
|
+
zIndex: 1, // stops over the routes
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Numbers and badges are drawn over all pins of the layer, so where pins overlap a lower pin's number can show through
|
|
200
|
+
an upper pin.
|
|
201
|
+
|
|
70
202
|
## Map keys and tokens
|
|
71
203
|
|
|
72
204
|
- **Map key** (`apiKey: 'smk_…'`): created in the Superroute developer center, with the sites (and apps) it may be
|
package/dist/SOURCE.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
-
"sdkVersion": "1.0.
|
|
2
|
+
"sdkVersion": "1.0.5",
|
|
3
3
|
"engine": "maplibre-gl 6.16.0",
|
|
4
4
|
"files": {
|
|
5
|
-
"smap.js": "
|
|
6
|
-
"smap.css": "
|
|
7
|
-
"smap-client.js": "
|
|
5
|
+
"smap.js": "3b8d6eaa6a2ddd6fb14b1465a9c6ef46a09d550093bb567b613fda3b26fa1fe5",
|
|
6
|
+
"smap.css": "5e3bdcb00b8fc8805f545b76cdeea5e783c89984f48ec2fee66c4319af4ada0b",
|
|
7
|
+
"smap-client.js": "1ae5f49b4be515efa69570a110b862ac8f325a6b45a9438a5c8011fa9278f598",
|
|
8
8
|
"smap-client.d.ts": "ad701612630a290b2dc0e49250ae25cea965ecb3a145c016bb462cd30f108cf7",
|
|
9
|
-
"smap.mjs": "
|
|
10
|
-
"smap.cjs": "
|
|
11
|
-
"smap-client.cjs": "
|
|
12
|
-
"smap-client.mjs": "
|
|
9
|
+
"smap.mjs": "7ea12152fa21a7d3e2c235646998cd8e36fded1db808945289123dc19c11424e",
|
|
10
|
+
"smap.cjs": "668b85f95674a22b7072566ec91f499de3623cddb10afb28aa32c528a39313da",
|
|
11
|
+
"smap-client.cjs": "6c54aa4a7676c26e7c4569203afb19f6c20233dc96f3e1400087b035f4e7d4f0",
|
|
12
|
+
"smap-client.mjs": "207bcb78118603359d73aecbea3f422d101b729f5e8462c1bb05225ad886d1f5",
|
|
13
13
|
"smap-client.d.cts": "80b96f5a907caf6295ca073816dc526e8d285f22670c809adaab5242a018e686",
|
|
14
14
|
"smap-client.d.mts": "a66834cab868a6a0eaf943c1b185a236916cb00ecf32a871f972ab3213eddeba",
|
|
15
15
|
"vendor-licenses.txt": "ee5fc05a0677eaf69601d2c7db0d9ecd6cc27c3abc1d0733bc9ed34707cf8ef2"
|
package/dist/smap-client.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* Generated by js/build.mjs from js/src (see SOURCE.json). Do not edit. */
|
|
2
|
-
/*! sMap JS client 1.0.
|
|
2
|
+
/*! sMap JS client 1.0.5 — tokens, the nearest node, styles, tiles and raw reads, without a map view. */
|
|
3
3
|
/*
|
|
4
4
|
* Runs wherever `fetch` exists: browsers, Node.js 18+, workers; elsewhere (mini programs, older runtimes) pass your
|
|
5
5
|
* own `fetch`. UMD: `window.SMapClient`, `require('smap-client')`, or an AMD module.
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
}(typeof self !== 'undefined' ? self : this, function () {
|
|
20
20
|
'use strict';
|
|
21
21
|
|
|
22
|
-
var VERSION = '1.0.
|
|
22
|
+
var VERSION = '1.0.5';
|
|
23
23
|
var NODE_TTL = 3600 * 1000; // the measured order
|
|
24
24
|
var KNOWN_TTL = 30 * 86400 * 1000; // the last node list received, used when none can be read
|
|
25
25
|
|
package/dist/smap-client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! sMap JS client 1.0.
|
|
1
|
+
/*! sMap JS client 1.0.5 — tokens, the nearest node, styles, tiles and raw reads, without a map view. */
|
|
2
2
|
/*
|
|
3
3
|
* Runs wherever `fetch` exists: browsers, Node.js 18+, workers; elsewhere (mini programs, older runtimes) pass your
|
|
4
4
|
* own `fetch`. UMD: `window.SMapClient`, `require('smap-client')`, or an AMD module.
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
}(typeof self !== 'undefined' ? self : this, function () {
|
|
19
19
|
'use strict';
|
|
20
20
|
|
|
21
|
-
var VERSION = '1.0.
|
|
21
|
+
var VERSION = '1.0.5';
|
|
22
22
|
var NODE_TTL = 3600 * 1000; // the measured order
|
|
23
23
|
var KNOWN_TTL = 30 * 86400 * 1000; // the last node list received, used when none can be read
|
|
24
24
|
|
package/dist/smap-client.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Generated by js/build.mjs from js/src (see SOURCE.json). Do not edit. */
|
|
2
2
|
var smapClientModule = { exports: {} };
|
|
3
3
|
(function (module, exports, define) {
|
|
4
|
-
/*! sMap JS client 1.0.
|
|
4
|
+
/*! sMap JS client 1.0.5 — tokens, the nearest node, styles, tiles and raw reads, without a map view. */
|
|
5
5
|
/*
|
|
6
6
|
* Runs wherever `fetch` exists: browsers, Node.js 18+, workers; elsewhere (mini programs, older runtimes) pass your
|
|
7
7
|
* own `fetch`. UMD: `window.SMapClient`, `require('smap-client')`, or an AMD module.
|
|
@@ -21,7 +21,7 @@ var smapClientModule = { exports: {} };
|
|
|
21
21
|
}(typeof self !== 'undefined' ? self : this, function () {
|
|
22
22
|
'use strict';
|
|
23
23
|
|
|
24
|
-
var VERSION = '1.0.
|
|
24
|
+
var VERSION = '1.0.5';
|
|
25
25
|
var NODE_TTL = 3600 * 1000; // the measured order
|
|
26
26
|
var KNOWN_TTL = 30 * 86400 * 1000; // the last node list received, used when none can be read
|
|
27
27
|
|