@superrouteca/smap-react 0.0.0-stage → 1.0.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/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +92 -2
- package/dist/index.cjs +270 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +80 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.js +248 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0.0 (unreleased)
|
|
4
|
+
|
|
5
|
+
- `<SMap>` with access, style, language, camera and 3D building props; the ref and `useSMap()` give the map.
|
|
6
|
+
- `<Points>`, `<Lines>` and `<Polygons>` added, updated and removed with the components, with `onTap`.
|
|
7
|
+
- Client components, safe to render on a server.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Goodneo Solutions
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,93 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @superrouteca/smap-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React components for maps from Superroute's sMap service: `<SMap>`, `<Points>`, `<Lines>`, `<Polygons>` and the
|
|
4
|
+
`useSMap()` hook, over [`@superrouteca/smap`](../js).
|
|
5
|
+
|
|
6
|
+
- Version 1.0.0, MIT licence (see `LICENSE` at the repository root)
|
|
7
|
+
- React 18 or later; TypeScript types included
|
|
8
|
+
- Server rendering (Next.js App Router included): the components are client components and the map is created only
|
|
9
|
+
in the browser, after mounting
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @superrouteca/smap-react @superrouteca/smap
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Import the stylesheet once, for example in your app's entry file:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import '@superrouteca/smap/smap.css';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## A minimal map
|
|
24
|
+
|
|
25
|
+
```jsx
|
|
26
|
+
import { useRef } from 'react';
|
|
27
|
+
import { SMap, Points, Lines, Polygons } from '@superrouteca/smap-react';
|
|
28
|
+
|
|
29
|
+
export function Deliveries({ stops, route, zones }) {
|
|
30
|
+
const map = useRef(null);
|
|
31
|
+
return (
|
|
32
|
+
<div style={{ height: 480 }}>
|
|
33
|
+
<SMap ref={map} apiKey="smk_…" style="light" language="en" center={[-79.38, 43.65]} zoom={11}
|
|
34
|
+
onReady={(m) => m.fitLayer('stops')}>
|
|
35
|
+
<Points id="stops" data={stops} options={{ cluster: true, label: 'name' }}
|
|
36
|
+
onTap={(properties) => console.log(properties.name)} />
|
|
37
|
+
<Lines id="route" data={route} options={{ color: '#16a34a', width: 5 }} />
|
|
38
|
+
<Polygons id="zones" data={zones} options={{ fill: '#f97316', extrude: { height: 'height' } }} />
|
|
39
|
+
</SMap>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`<SMap>` fills its parent (`className` and `containerStyle` style the element that holds it).
|
|
46
|
+
|
|
47
|
+
### `<SMap>` props
|
|
48
|
+
|
|
49
|
+
| Prop | |
|
|
50
|
+
|---|---|
|
|
51
|
+
| `apiKey`, `token`, `getToken` | access, see below |
|
|
52
|
+
| `style` | `light`, `white`, `grayscale`, `dark`, `black` (or a style URL); a change keeps the layers |
|
|
53
|
+
| `language` | label language (`en`, `fr`, `zh-Hans`, …); a change keeps the layers |
|
|
54
|
+
| `center`, `zoom`, `bearing`, `pitch` | the camera; it follows a change |
|
|
55
|
+
| `buildings3D` | buildings in 3D |
|
|
56
|
+
| `nodes`, `baseUrl`, `nearest` | the service (default `https://tile.srsr.ca`) |
|
|
57
|
+
| `projection`, `mapOptions` | `mercator` or `globe`; further options when the map is created |
|
|
58
|
+
| `onReady(map)`, `onError(error)` | |
|
|
59
|
+
|
|
60
|
+
The ref is the SDK map once it is ready (null before): `fitLayer`, `flyTo`, `setVisible`, `layers()`, `engine` and
|
|
61
|
+
everything else of `@superrouteca/smap`. `useSMap()` gives the same map to components inside `<SMap>`.
|
|
62
|
+
|
|
63
|
+
`apiKey`, `token`, `baseUrl`, `nodes` and `nearest` are read when the map is created; changing one creates the map
|
|
64
|
+
again (its layers are added again).
|
|
65
|
+
|
|
66
|
+
### Layers
|
|
67
|
+
|
|
68
|
+
`<Points>`, `<Lines>` and `<Polygons>` take `id`, `data` (GeoJSON, or an array of `{lng, lat, …properties}`),
|
|
69
|
+
`options` (as `addPoints` / `addLines` / `addPolygons` of `@superrouteca/smap`), `onTap(properties, {lat, lng},
|
|
70
|
+
feature)` and `visible`. A layer is added when the map is ready and removed when the component unmounts; new `data`
|
|
71
|
+
replaces the data and keeps the look, new `options` draw the layer again. Higher `zIndex` draws on top.
|
|
72
|
+
|
|
73
|
+
## Map keys and tokens
|
|
74
|
+
|
|
75
|
+
- **Map key** (`apiKey="smk_…"`): created in the Superroute developer center with the sites it may be used from.
|
|
76
|
+
Safe to put in a page.
|
|
77
|
+
- **Token** (`token`, or `getToken={async () => …}`): signed by your own server for a limited time; with `getToken` a
|
|
78
|
+
new token is asked for two minutes before the current one expires.
|
|
79
|
+
- With both, both are sent and the token is checked first.
|
|
80
|
+
|
|
81
|
+
## Data attribution
|
|
82
|
+
|
|
83
|
+
The map data credit stays visible on every map, as the data licence requires.
|
|
84
|
+
|
|
85
|
+
## Example and tests
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
npm install # at the repository root (workspaces)
|
|
89
|
+
npm run dev --workspace react/example
|
|
90
|
+
npm test --workspace react
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The example reads a map key from `VITE_SMAP_KEY` (or a token from `VITE_SMAP_TOKEN`).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key2 of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key2) && key2 !== except)
|
|
15
|
+
__defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
Lines: () => Lines,
|
|
25
|
+
Points: () => Points,
|
|
26
|
+
Polygons: () => Polygons,
|
|
27
|
+
SMap: () => SMap,
|
|
28
|
+
useSMap: () => useSMap
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
31
|
+
|
|
32
|
+
// src/SMap.tsx
|
|
33
|
+
var import_react = require("react");
|
|
34
|
+
var import_smap = require("@superrouteca/smap");
|
|
35
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
+
var MapContext = (0, import_react.createContext)(null);
|
|
37
|
+
var removedMaps = /* @__PURE__ */ new WeakSet();
|
|
38
|
+
function useSMap() {
|
|
39
|
+
return (0, import_react.useContext)(MapContext);
|
|
40
|
+
}
|
|
41
|
+
var key = (v) => JSON.stringify(v ?? null);
|
|
42
|
+
function cameraChanges(prev, next) {
|
|
43
|
+
const out = {};
|
|
44
|
+
let changed = false;
|
|
45
|
+
if (next.center !== void 0 && key(next.center) !== key(prev.center)) {
|
|
46
|
+
out.center = next.center;
|
|
47
|
+
changed = true;
|
|
48
|
+
}
|
|
49
|
+
for (const k of ["zoom", "bearing", "pitch"]) {
|
|
50
|
+
if (next[k] !== void 0 && next[k] !== prev[k]) {
|
|
51
|
+
out[k] = next[k];
|
|
52
|
+
changed = true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return changed ? out : null;
|
|
56
|
+
}
|
|
57
|
+
var SMap = (0, import_react.forwardRef)(function SMap2(props, ref) {
|
|
58
|
+
const containerRef = (0, import_react.useRef)(null);
|
|
59
|
+
const [map, setMap] = (0, import_react.useState)(null);
|
|
60
|
+
const latest = (0, import_react.useRef)(props);
|
|
61
|
+
latest.current = props;
|
|
62
|
+
const applied = (0, import_react.useRef)(
|
|
63
|
+
{ style: "", language: "", camera: {}, projection: "", buildings: false }
|
|
64
|
+
);
|
|
65
|
+
(0, import_react.useImperativeHandle)(ref, () => map, [map]);
|
|
66
|
+
const nodesKey = key(props.nodes);
|
|
67
|
+
const mapOptionsKey = key(props.mapOptions);
|
|
68
|
+
const hasGetToken = !!props.getToken;
|
|
69
|
+
(0, import_react.useEffect)(() => {
|
|
70
|
+
const container = containerRef.current;
|
|
71
|
+
if (!container) {
|
|
72
|
+
return void 0;
|
|
73
|
+
}
|
|
74
|
+
const p = latest.current;
|
|
75
|
+
const options = {
|
|
76
|
+
...p.mapOptions || {},
|
|
77
|
+
container,
|
|
78
|
+
apiKey: p.apiKey,
|
|
79
|
+
token: p.token,
|
|
80
|
+
getToken: p.getToken ? () => latest.current.getToken() : void 0,
|
|
81
|
+
style: p.style,
|
|
82
|
+
language: p.language,
|
|
83
|
+
center: p.center,
|
|
84
|
+
zoom: p.zoom,
|
|
85
|
+
bearing: p.bearing,
|
|
86
|
+
pitch: p.pitch,
|
|
87
|
+
nodes: p.nodes,
|
|
88
|
+
baseUrl: p.baseUrl,
|
|
89
|
+
nearest: p.nearest,
|
|
90
|
+
projection: p.projection
|
|
91
|
+
};
|
|
92
|
+
for (const k of Object.keys(options)) {
|
|
93
|
+
if (options[k] === void 0) {
|
|
94
|
+
delete options[k];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
let alive = true;
|
|
98
|
+
let ready = false;
|
|
99
|
+
let created;
|
|
100
|
+
try {
|
|
101
|
+
created = new import_smap.Map(options);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
latest.current.onError?.(e);
|
|
104
|
+
return void 0;
|
|
105
|
+
}
|
|
106
|
+
applied.current = {
|
|
107
|
+
style: key(p.style ?? "light"),
|
|
108
|
+
language: key(p.language ?? null),
|
|
109
|
+
camera: { center: p.center, zoom: p.zoom, bearing: p.bearing, pitch: p.pitch },
|
|
110
|
+
projection: p.projection ?? "mercator",
|
|
111
|
+
buildings: false
|
|
112
|
+
};
|
|
113
|
+
created.ready.then(() => {
|
|
114
|
+
ready = true;
|
|
115
|
+
if (!alive) {
|
|
116
|
+
created.remove();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
setMap(created);
|
|
120
|
+
latest.current.onReady?.(created);
|
|
121
|
+
}, (e) => {
|
|
122
|
+
if (alive) {
|
|
123
|
+
latest.current.onError?.(e);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return () => {
|
|
127
|
+
alive = false;
|
|
128
|
+
removedMaps.add(created);
|
|
129
|
+
setMap(null);
|
|
130
|
+
if (ready) {
|
|
131
|
+
created.remove();
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}, [props.apiKey, props.token, props.baseUrl, nodesKey, props.nearest, mapOptionsKey, hasGetToken]);
|
|
135
|
+
const styleKey = key(props.style ?? "light");
|
|
136
|
+
(0, import_react.useEffect)(() => {
|
|
137
|
+
if (!map || applied.current.style === styleKey) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
applied.current.style = styleKey;
|
|
141
|
+
map.setStyle(latest.current.style ?? "light");
|
|
142
|
+
}, [map, styleKey]);
|
|
143
|
+
const languageKey = key(props.language ?? null);
|
|
144
|
+
(0, import_react.useEffect)(() => {
|
|
145
|
+
if (!map || applied.current.language === languageKey || props.language === void 0) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
applied.current.language = languageKey;
|
|
149
|
+
map.setLanguage(props.language);
|
|
150
|
+
}, [map, languageKey]);
|
|
151
|
+
const centerKey = key(props.center);
|
|
152
|
+
(0, import_react.useEffect)(() => {
|
|
153
|
+
if (!map) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const next = { center: props.center, zoom: props.zoom, bearing: props.bearing, pitch: props.pitch };
|
|
157
|
+
const change = cameraChanges(applied.current.camera, next);
|
|
158
|
+
applied.current.camera = next;
|
|
159
|
+
if (change && map.engine) {
|
|
160
|
+
map.engine.jumpTo(change);
|
|
161
|
+
}
|
|
162
|
+
}, [map, centerKey, props.zoom, props.bearing, props.pitch]);
|
|
163
|
+
(0, import_react.useEffect)(() => {
|
|
164
|
+
const projection = props.projection ?? "mercator";
|
|
165
|
+
if (!map || applied.current.projection === projection) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
applied.current.projection = projection;
|
|
169
|
+
map.setProjection(projection);
|
|
170
|
+
}, [map, props.projection]);
|
|
171
|
+
(0, import_react.useEffect)(() => {
|
|
172
|
+
const on = !!props.buildings3D;
|
|
173
|
+
if (!map || applied.current.buildings === on) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
applied.current.buildings = on;
|
|
177
|
+
map.setBuildings3D(on);
|
|
178
|
+
}, [map, props.buildings3D]);
|
|
179
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
180
|
+
"div",
|
|
181
|
+
{
|
|
182
|
+
id: props.id,
|
|
183
|
+
className: props.className,
|
|
184
|
+
style: { position: "relative", width: "100%", height: "100%", ...props.containerStyle },
|
|
185
|
+
children: [
|
|
186
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: containerRef, style: { position: "absolute", inset: 0 } }),
|
|
187
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(MapContext.Provider, { value: map, children: props.children })
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// src/layers.tsx
|
|
194
|
+
var import_react2 = require("react");
|
|
195
|
+
function optionsKey(options) {
|
|
196
|
+
return JSON.stringify(options ?? {}, (_k, v) => typeof v === "function" ? "[fn]" : v);
|
|
197
|
+
}
|
|
198
|
+
function useLayer(kind, props) {
|
|
199
|
+
const map = useSMap();
|
|
200
|
+
const { id, data, options, onTap, visible = true } = props;
|
|
201
|
+
const latest = (0, import_react2.useRef)(props);
|
|
202
|
+
latest.current = props;
|
|
203
|
+
const shown = (0, import_react2.useRef)(null);
|
|
204
|
+
const shownVisible = (0, import_react2.useRef)(true);
|
|
205
|
+
const hasTap = !!onTap || typeof options?.onClick === "function";
|
|
206
|
+
const looks = optionsKey(options);
|
|
207
|
+
(0, import_react2.useEffect)(() => {
|
|
208
|
+
if (!map) {
|
|
209
|
+
return void 0;
|
|
210
|
+
}
|
|
211
|
+
const o = { ...latest.current.options || {} };
|
|
212
|
+
if (hasTap) {
|
|
213
|
+
o.onClick = (feature, event) => {
|
|
214
|
+
const p = latest.current;
|
|
215
|
+
p.options?.onClick?.(feature, event);
|
|
216
|
+
p.onTap?.(feature.properties || {}, { lat: event.lngLat.lat, lng: event.lngLat.lng }, feature);
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
if (typeof o.popup === "function") {
|
|
220
|
+
o.popup = (properties, feature) => latest.current.options?.popup?.(properties, feature);
|
|
221
|
+
}
|
|
222
|
+
const d = latest.current.data;
|
|
223
|
+
map[kind](id, d, o);
|
|
224
|
+
if (latest.current.visible === false) {
|
|
225
|
+
map.setVisible(id, false);
|
|
226
|
+
}
|
|
227
|
+
shownVisible.current = latest.current.visible !== false;
|
|
228
|
+
shown.current = { map, data: d };
|
|
229
|
+
return () => {
|
|
230
|
+
shown.current = null;
|
|
231
|
+
if (!removedMaps.has(map)) {
|
|
232
|
+
map.removeLayer(id);
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
}, [map, id, looks, hasTap]);
|
|
236
|
+
(0, import_react2.useEffect)(() => {
|
|
237
|
+
const s = shown.current;
|
|
238
|
+
if (!map || !s || s.map !== map || s.data === data) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
s.data = data;
|
|
242
|
+
map.setData(id, data);
|
|
243
|
+
}, [map, id, data]);
|
|
244
|
+
(0, import_react2.useEffect)(() => {
|
|
245
|
+
if (!map || shownVisible.current === visible) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
shownVisible.current = visible;
|
|
249
|
+
map.setVisible(id, visible);
|
|
250
|
+
}, [map, id, visible]);
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
function Points(props) {
|
|
254
|
+
return useLayer("addPoints", props);
|
|
255
|
+
}
|
|
256
|
+
function Lines(props) {
|
|
257
|
+
return useLayer("addLines", props);
|
|
258
|
+
}
|
|
259
|
+
function Polygons(props) {
|
|
260
|
+
return useLayer("addPolygons", props);
|
|
261
|
+
}
|
|
262
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
263
|
+
0 && (module.exports = {
|
|
264
|
+
Lines,
|
|
265
|
+
Points,
|
|
266
|
+
Polygons,
|
|
267
|
+
SMap,
|
|
268
|
+
useSMap
|
|
269
|
+
});
|
|
270
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/SMap.tsx","../src/layers.tsx"],"sourcesContent":["export { SMap, useSMap } from './SMap';\nexport type { SMapProps, SMapMap } from './SMap';\nexport { Points, Lines, Polygons } from './layers';\nexport type { LayerProps, PointsProps, LinesProps, PolygonsProps, TapHandler } from './layers';\nexport type {\n LayerData,\n LngLatLike,\n PointOptions,\n LineOptions,\n PolygonOptions,\n StyleFlavor,\n GeoJSONFeature,\n GeoJSONFeatureCollection,\n} from '@superrouteca/smap';\n","import {\n createContext,\n forwardRef,\n useContext,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n} from 'react';\nimport { Map as SMapMap, type LngLatLike, type StyleFlavor } from '@superrouteca/smap';\n\nexport type { SMapMap };\n\nconst MapContext = createContext<SMapMap | null>(null);\n\n/** Maps that were removed: their layers must not be touched any more. */\nexport const removedMaps = new WeakSet<SMapMap>();\n\n/** The map of the nearest `<SMap>` above, once it is ready (null before). */\nexport function useSMap(): SMapMap | null {\n return useContext(MapContext);\n}\n\nexport interface SMapProps {\n /** A map key (`smk_…`) whose allowlist names this site. Read when the map is created. */\n apiKey?: string;\n /** A map token. Read when the map is created; changing it creates the map again (use `getToken` to renew). */\n token?: string;\n /** Called at start and again two minutes before each token expires. */\n getToken?: () => string | Promise<string>;\n /** A colour scheme, or a style URL or object of your own. Changing it keeps the layers. */\n style?: StyleFlavor | string | Record<string, unknown>;\n /** Label language (`en`, `fr`, `zh-Hans`, …). Changing it keeps the layers. */\n language?: string;\n /** [longitude, latitude] or `{lng, lat}`; the camera follows a change. */\n center?: LngLatLike;\n zoom?: number;\n bearing?: number;\n pitch?: number;\n /** Node URLs known in advance, used while `baseUrl` is down. */\n nodes?: string[];\n /** The map service, `https://tile.srsr.ca` by default. */\n baseUrl?: string;\n /** Read from the nearest service node (default true). */\n nearest?: boolean;\n projection?: 'mercator' | 'globe';\n /** Buildings in 3D. */\n buildings3D?: boolean;\n /** Further options handed to the map when it is created (minZoom, maxZoom, maxBounds, hash, …). */\n mapOptions?: Record<string, unknown>;\n /** Called once the first style has loaded, with the map. */\n onReady?: (map: SMapMap) => void;\n /** Called when the map cannot start. */\n onError?: (error: unknown) => void;\n /** Class and style of the element holding the map (it fills the element). */\n className?: string;\n containerStyle?: CSSProperties;\n id?: string;\n /** `<Points>`, `<Lines>`, `<Polygons>`, or anything to draw over the map. */\n children?: ReactNode;\n}\n\ntype Camera = { center?: LngLatLike; zoom?: number; bearing?: number; pitch?: number };\n\nconst key = (v: unknown) => JSON.stringify(v ?? null);\n\nfunction cameraChanges(prev: Camera, next: Camera): Camera | null {\n const out: Camera = {};\n let changed = false;\n if (next.center !== undefined && key(next.center) !== key(prev.center)) { out.center = next.center; changed = true; }\n for (const k of ['zoom', 'bearing', 'pitch'] as const) {\n if (next[k] !== undefined && next[k] !== prev[k]) { out[k] = next[k]; changed = true; }\n }\n return changed ? out : null;\n}\n\n/**\n * A map. Created in the browser only (after the component mounts), so it can be rendered on a server. The ref is\n * the SDK map once it is ready (null before).\n */\nexport const SMap = forwardRef<SMapMap | null, SMapProps>(function SMap(props, ref) {\n const containerRef = useRef<HTMLDivElement | null>(null);\n const [map, setMap] = useState<SMapMap | null>(null);\n const latest = useRef(props);\n latest.current = props;\n // What the map shows now, so a prop that did not change is not applied again.\n const applied = useRef<{ style: string; language: string; camera: Camera; projection: string; buildings: boolean }>(\n { style: '', language: '', camera: {}, projection: '', buildings: false });\n\n useImperativeHandle(ref, () => map as SMapMap, [map]);\n\n const nodesKey = key(props.nodes);\n const mapOptionsKey = key(props.mapOptions);\n const hasGetToken = !!props.getToken;\n\n useEffect(() => {\n const container = containerRef.current;\n if (!container) { return undefined; }\n const p = latest.current;\n const options: Record<string, unknown> = {\n ...(p.mapOptions || {}),\n container,\n apiKey: p.apiKey,\n token: p.token,\n getToken: p.getToken ? () => latest.current.getToken!() : undefined,\n style: p.style,\n language: p.language,\n center: p.center,\n zoom: p.zoom,\n bearing: p.bearing,\n pitch: p.pitch,\n nodes: p.nodes,\n baseUrl: p.baseUrl,\n nearest: p.nearest,\n projection: p.projection,\n };\n for (const k of Object.keys(options)) { if (options[k] === undefined) { delete options[k]; } }\n let alive = true;\n let ready = false;\n let created: SMapMap;\n try {\n created = new SMapMap(options as unknown as ConstructorParameters<typeof SMapMap>[0]);\n } catch (e) {\n latest.current.onError?.(e);\n return undefined;\n }\n applied.current = {\n style: key(p.style ?? 'light'),\n language: key(p.language ?? null),\n camera: { center: p.center, zoom: p.zoom, bearing: p.bearing, pitch: p.pitch },\n projection: p.projection ?? 'mercator',\n buildings: false,\n };\n created.ready.then(() => {\n ready = true;\n if (!alive) { created.remove(); return; }\n setMap(created);\n latest.current.onReady?.(created);\n }, (e: unknown) => {\n if (alive) { latest.current.onError?.(e); }\n });\n return () => {\n alive = false;\n removedMaps.add(created);\n setMap(null);\n // Before it is ready the map has nothing to remove yet; it is removed as soon as it is.\n if (ready) { created.remove(); }\n };\n }, [props.apiKey, props.token, props.baseUrl, nodesKey, props.nearest, mapOptionsKey, hasGetToken]);\n\n const styleKey = key(props.style ?? 'light');\n useEffect(() => {\n if (!map || applied.current.style === styleKey) { return; }\n applied.current.style = styleKey;\n map.setStyle(latest.current.style ?? 'light');\n }, [map, styleKey]);\n\n const languageKey = key(props.language ?? null);\n useEffect(() => {\n if (!map || applied.current.language === languageKey || props.language === undefined) { return; }\n applied.current.language = languageKey;\n map.setLanguage(props.language);\n }, [map, languageKey]);\n\n const centerKey = key(props.center);\n useEffect(() => {\n if (!map) { return; }\n const next: Camera = { center: props.center, zoom: props.zoom, bearing: props.bearing, pitch: props.pitch };\n const change = cameraChanges(applied.current.camera, next);\n applied.current.camera = next;\n if (change && map.engine) { map.engine.jumpTo(change); }\n }, [map, centerKey, props.zoom, props.bearing, props.pitch]);\n\n useEffect(() => {\n const projection = props.projection ?? 'mercator';\n if (!map || applied.current.projection === projection) { return; }\n applied.current.projection = projection;\n map.setProjection(projection);\n }, [map, props.projection]);\n\n useEffect(() => {\n const on = !!props.buildings3D;\n if (!map || applied.current.buildings === on) { return; }\n applied.current.buildings = on;\n map.setBuildings3D(on);\n }, [map, props.buildings3D]);\n\n return (\n <div\n id={props.id}\n className={props.className}\n style={{ position: 'relative', width: '100%', height: '100%', ...props.containerStyle }}\n >\n <div ref={containerRef} style={{ position: 'absolute', inset: 0 }} />\n <MapContext.Provider value={map}>{props.children}</MapContext.Provider>\n </div>\n );\n});\n","import { useEffect, useRef } from 'react';\nimport type {\n GeoJSONFeature,\n LayerClickEvent,\n LayerData,\n LineOptions,\n PointOptions,\n PolygonOptions,\n} from '@superrouteca/smap';\nimport { removedMaps, useSMap, type SMapMap } from './SMap';\n\n/** Called with the tapped feature's properties, its position and the feature itself. */\nexport type TapHandler = (\n properties: Record<string, unknown>,\n position: { lat: number; lng: number },\n feature: GeoJSONFeature,\n) => void;\n\nexport interface LayerProps<O> {\n /** The layer id, unique on the map. */\n id: string;\n /** GeoJSON, or an array of points `{lng, lat, …properties}`. A new value replaces the data and keeps the look. */\n data: LayerData;\n /** How the layer is drawn; a change draws the layer again. */\n options?: O;\n /** Called when a feature of this layer is tapped or clicked. */\n onTap?: TapHandler;\n /** Shows or hides the layer (default true). */\n visible?: boolean;\n}\n\nexport type PointsProps = LayerProps<PointOptions>;\nexport type LinesProps = LayerProps<LineOptions>;\nexport type PolygonsProps = LayerProps<PolygonOptions>;\n\ntype Kind = 'addPoints' | 'addLines' | 'addPolygons';\n\n// Options compared by value; functions (popup, onClick) are read when called, so a new function is no change.\nfunction optionsKey(options: unknown): string {\n return JSON.stringify(options ?? {}, (_k, v) => (typeof v === 'function' ? '[fn]' : v));\n}\n\nfunction useLayer(kind: Kind, props: LayerProps<PointOptions | LineOptions | PolygonOptions>): null {\n const map = useSMap();\n const { id, data, options, onTap, visible = true } = props;\n const latest = useRef(props);\n latest.current = props;\n const shown = useRef<{ map: SMapMap; data: LayerData } | null>(null);\n const shownVisible = useRef(true);\n const hasTap = !!onTap || typeof options?.onClick === 'function';\n const looks = optionsKey(options);\n\n useEffect(() => {\n if (!map) { return undefined; }\n const o: Record<string, unknown> = { ...(latest.current.options || {}) };\n if (hasTap) {\n o.onClick = (feature: GeoJSONFeature, event: LayerClickEvent) => {\n const p = latest.current;\n p.options?.onClick?.(feature, event);\n p.onTap?.(feature.properties || {}, { lat: event.lngLat.lat, lng: event.lngLat.lng }, feature);\n };\n }\n if (typeof o.popup === 'function') {\n o.popup = (properties: Record<string, unknown>, feature: GeoJSONFeature) => latest.current.options?.popup?.(properties, feature);\n }\n const d = latest.current.data;\n (map[kind] as (id: string, data: LayerData, o: unknown) => SMapMap)(id, d, o);\n if (latest.current.visible === false) { map.setVisible(id, false); }\n shownVisible.current = latest.current.visible !== false;\n shown.current = { map, data: d };\n return () => {\n shown.current = null;\n if (!removedMaps.has(map)) { map.removeLayer(id); }\n };\n }, [map, id, looks, hasTap]);\n\n useEffect(() => {\n const s = shown.current;\n if (!map || !s || s.map !== map || s.data === data) { return; }\n s.data = data;\n map.setData(id, data);\n }, [map, id, data]);\n\n useEffect(() => {\n if (!map || shownVisible.current === visible) { return; }\n shownVisible.current = visible;\n map.setVisible(id, visible);\n }, [map, id, visible]);\n\n return null;\n}\n\n/** Points at any scale, clustered or not. Must be inside `<SMap>`. */\nexport function Points(props: PointsProps): null {\n return useLayer('addPoints', props);\n}\n\n/** Lines (routes, tracks). Must be inside `<SMap>`. */\nexport function Lines(props: LinesProps): null {\n return useLayer('addLines', props);\n}\n\n/** Areas, flat or in 3D (`options.extrude`). Must be inside `<SMap>`. */\nexport function Polygons(props: PolygonsProps): null {\n return useLayer('addPolygons', props);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAUO;AACP,kBAAkE;AAmL9D;AA/KJ,IAAM,iBAAa,4BAA8B,IAAI;AAG9C,IAAM,cAAc,oBAAI,QAAiB;AAGzC,SAAS,UAA0B;AACxC,aAAO,yBAAW,UAAU;AAC9B;AA2CA,IAAM,MAAM,CAAC,MAAe,KAAK,UAAU,KAAK,IAAI;AAEpD,SAAS,cAAc,MAAc,MAA6B;AAChE,QAAM,MAAc,CAAC;AACrB,MAAI,UAAU;AACd,MAAI,KAAK,WAAW,UAAa,IAAI,KAAK,MAAM,MAAM,IAAI,KAAK,MAAM,GAAG;AAAE,QAAI,SAAS,KAAK;AAAQ,cAAU;AAAA,EAAM;AACpH,aAAW,KAAK,CAAC,QAAQ,WAAW,OAAO,GAAY;AACrD,QAAI,KAAK,CAAC,MAAM,UAAa,KAAK,CAAC,MAAM,KAAK,CAAC,GAAG;AAAE,UAAI,CAAC,IAAI,KAAK,CAAC;AAAG,gBAAU;AAAA,IAAM;AAAA,EACxF;AACA,SAAO,UAAU,MAAM;AACzB;AAMO,IAAM,WAAO,yBAAsC,SAASA,MAAK,OAAO,KAAK;AAClF,Q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,KAAK,MAAM,EAAE;AAC/B,WAAO,MAAM;AACX,YAAM,UAAU;AAChB,UAAI,CAAC,YAAY,IAAI,GAAG,GAAG;AAAE,YAAI,YAAY,EAAE;AAAA,MAAG;AAAA,IACpD;AAAA,EACF,GAAG,CAAC,KAAK,IAAI,OAAO,MAAM,CAAC;AAE3B,+BAAU,MAAM;AACd,UAAM,IAAI,MAAM;AAChB,QAAI,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,OAAO,EAAE,SAAS,MAAM;AAAE;AAAA,IAAQ;AAC9D,MAAE,OAAO;AACT,QAAI,QAAQ,IAAI,IAAI;AAAA,EACtB,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC;AAElB,+BAAU,MAAM;AACd,QAAI,CAAC,OAAO,aAAa,YAAY,SAAS;AAAE;AAAA,IAAQ;AACxD,iBAAa,UAAU;AACvB,QAAI,WAAW,IAAI,OAAO;AAAA,EAC5B,GAAG,CAAC,KAAK,IAAI,OAAO,CAAC;AAErB,SAAO;AACT;AAGO,SAAS,OAAO,OAA0B;AAC/C,SAAO,SAAS,aAAa,KAAK;AACpC;AAGO,SAAS,MAAM,OAAyB;AAC7C,SAAO,SAAS,YAAY,KAAK;AACnC;AAGO,SAAS,SAAS,OAA4B;AACnD,SAAO,SAAS,eAAe,KAAK;AACtC;","names":["SMap","SMapMap","import_react"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { CSSProperties, ReactNode } from 'react';
|
|
3
|
+
import { StyleFlavor, LngLatLike, Map, LayerData, GeoJSONFeature, LineOptions, PointOptions, PolygonOptions } from '@superrouteca/smap';
|
|
4
|
+
export { GeoJSONFeature, GeoJSONFeatureCollection, LayerData, LineOptions, LngLatLike, PointOptions, PolygonOptions, Map as SMapMap, StyleFlavor } from '@superrouteca/smap';
|
|
5
|
+
|
|
6
|
+
/** The map of the nearest `<SMap>` above, once it is ready (null before). */
|
|
7
|
+
declare function useSMap(): Map | null;
|
|
8
|
+
interface SMapProps {
|
|
9
|
+
/** A map key (`smk_…`) whose allowlist names this site. Read when the map is created. */
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
/** A map token. Read when the map is created; changing it creates the map again (use `getToken` to renew). */
|
|
12
|
+
token?: string;
|
|
13
|
+
/** Called at start and again two minutes before each token expires. */
|
|
14
|
+
getToken?: () => string | Promise<string>;
|
|
15
|
+
/** A colour scheme, or a style URL or object of your own. Changing it keeps the layers. */
|
|
16
|
+
style?: StyleFlavor | string | Record<string, unknown>;
|
|
17
|
+
/** Label language (`en`, `fr`, `zh-Hans`, …). Changing it keeps the layers. */
|
|
18
|
+
language?: string;
|
|
19
|
+
/** [longitude, latitude] or `{lng, lat}`; the camera follows a change. */
|
|
20
|
+
center?: LngLatLike;
|
|
21
|
+
zoom?: number;
|
|
22
|
+
bearing?: number;
|
|
23
|
+
pitch?: number;
|
|
24
|
+
/** Node URLs known in advance, used while `baseUrl` is down. */
|
|
25
|
+
nodes?: string[];
|
|
26
|
+
/** The map service, `https://tile.srsr.ca` by default. */
|
|
27
|
+
baseUrl?: string;
|
|
28
|
+
/** Read from the nearest service node (default true). */
|
|
29
|
+
nearest?: boolean;
|
|
30
|
+
projection?: 'mercator' | 'globe';
|
|
31
|
+
/** Buildings in 3D. */
|
|
32
|
+
buildings3D?: boolean;
|
|
33
|
+
/** Further options handed to the map when it is created (minZoom, maxZoom, maxBounds, hash, …). */
|
|
34
|
+
mapOptions?: Record<string, unknown>;
|
|
35
|
+
/** Called once the first style has loaded, with the map. */
|
|
36
|
+
onReady?: (map: Map) => void;
|
|
37
|
+
/** Called when the map cannot start. */
|
|
38
|
+
onError?: (error: unknown) => void;
|
|
39
|
+
/** Class and style of the element holding the map (it fills the element). */
|
|
40
|
+
className?: string;
|
|
41
|
+
containerStyle?: CSSProperties;
|
|
42
|
+
id?: string;
|
|
43
|
+
/** `<Points>`, `<Lines>`, `<Polygons>`, or anything to draw over the map. */
|
|
44
|
+
children?: ReactNode;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A map. Created in the browser only (after the component mounts), so it can be rendered on a server. The ref is
|
|
48
|
+
* the SDK map once it is ready (null before).
|
|
49
|
+
*/
|
|
50
|
+
declare const SMap: react.ForwardRefExoticComponent<SMapProps & react.RefAttributes<Map | null>>;
|
|
51
|
+
|
|
52
|
+
/** Called with the tapped feature's properties, its position and the feature itself. */
|
|
53
|
+
type TapHandler = (properties: Record<string, unknown>, position: {
|
|
54
|
+
lat: number;
|
|
55
|
+
lng: number;
|
|
56
|
+
}, feature: GeoJSONFeature) => void;
|
|
57
|
+
interface LayerProps<O> {
|
|
58
|
+
/** The layer id, unique on the map. */
|
|
59
|
+
id: string;
|
|
60
|
+
/** GeoJSON, or an array of points `{lng, lat, …properties}`. A new value replaces the data and keeps the look. */
|
|
61
|
+
data: LayerData;
|
|
62
|
+
/** How the layer is drawn; a change draws the layer again. */
|
|
63
|
+
options?: O;
|
|
64
|
+
/** Called when a feature of this layer is tapped or clicked. */
|
|
65
|
+
onTap?: TapHandler;
|
|
66
|
+
/** Shows or hides the layer (default true). */
|
|
67
|
+
visible?: boolean;
|
|
68
|
+
}
|
|
69
|
+
type PointsProps = LayerProps<PointOptions>;
|
|
70
|
+
type LinesProps = LayerProps<LineOptions>;
|
|
71
|
+
type PolygonsProps = LayerProps<PolygonOptions>;
|
|
72
|
+
/** Points at any scale, clustered or not. Must be inside `<SMap>`. */
|
|
73
|
+
declare function Points(props: PointsProps): null;
|
|
74
|
+
/** Lines (routes, tracks). Must be inside `<SMap>`. */
|
|
75
|
+
declare function Lines(props: LinesProps): null;
|
|
76
|
+
/** Areas, flat or in 3D (`options.extrude`). Must be inside `<SMap>`. */
|
|
77
|
+
declare function Polygons(props: PolygonsProps): null;
|
|
78
|
+
|
|
79
|
+
export { Lines, Points, Polygons, SMap, useSMap };
|
|
80
|
+
export type { LayerProps, LinesProps, PointsProps, PolygonsProps, SMapProps, TapHandler };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { CSSProperties, ReactNode } from 'react';
|
|
3
|
+
import { StyleFlavor, LngLatLike, Map, LayerData, GeoJSONFeature, LineOptions, PointOptions, PolygonOptions } from '@superrouteca/smap';
|
|
4
|
+
export { GeoJSONFeature, GeoJSONFeatureCollection, LayerData, LineOptions, LngLatLike, PointOptions, PolygonOptions, Map as SMapMap, StyleFlavor } from '@superrouteca/smap';
|
|
5
|
+
|
|
6
|
+
/** The map of the nearest `<SMap>` above, once it is ready (null before). */
|
|
7
|
+
declare function useSMap(): Map | null;
|
|
8
|
+
interface SMapProps {
|
|
9
|
+
/** A map key (`smk_…`) whose allowlist names this site. Read when the map is created. */
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
/** A map token. Read when the map is created; changing it creates the map again (use `getToken` to renew). */
|
|
12
|
+
token?: string;
|
|
13
|
+
/** Called at start and again two minutes before each token expires. */
|
|
14
|
+
getToken?: () => string | Promise<string>;
|
|
15
|
+
/** A colour scheme, or a style URL or object of your own. Changing it keeps the layers. */
|
|
16
|
+
style?: StyleFlavor | string | Record<string, unknown>;
|
|
17
|
+
/** Label language (`en`, `fr`, `zh-Hans`, …). Changing it keeps the layers. */
|
|
18
|
+
language?: string;
|
|
19
|
+
/** [longitude, latitude] or `{lng, lat}`; the camera follows a change. */
|
|
20
|
+
center?: LngLatLike;
|
|
21
|
+
zoom?: number;
|
|
22
|
+
bearing?: number;
|
|
23
|
+
pitch?: number;
|
|
24
|
+
/** Node URLs known in advance, used while `baseUrl` is down. */
|
|
25
|
+
nodes?: string[];
|
|
26
|
+
/** The map service, `https://tile.srsr.ca` by default. */
|
|
27
|
+
baseUrl?: string;
|
|
28
|
+
/** Read from the nearest service node (default true). */
|
|
29
|
+
nearest?: boolean;
|
|
30
|
+
projection?: 'mercator' | 'globe';
|
|
31
|
+
/** Buildings in 3D. */
|
|
32
|
+
buildings3D?: boolean;
|
|
33
|
+
/** Further options handed to the map when it is created (minZoom, maxZoom, maxBounds, hash, …). */
|
|
34
|
+
mapOptions?: Record<string, unknown>;
|
|
35
|
+
/** Called once the first style has loaded, with the map. */
|
|
36
|
+
onReady?: (map: Map) => void;
|
|
37
|
+
/** Called when the map cannot start. */
|
|
38
|
+
onError?: (error: unknown) => void;
|
|
39
|
+
/** Class and style of the element holding the map (it fills the element). */
|
|
40
|
+
className?: string;
|
|
41
|
+
containerStyle?: CSSProperties;
|
|
42
|
+
id?: string;
|
|
43
|
+
/** `<Points>`, `<Lines>`, `<Polygons>`, or anything to draw over the map. */
|
|
44
|
+
children?: ReactNode;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A map. Created in the browser only (after the component mounts), so it can be rendered on a server. The ref is
|
|
48
|
+
* the SDK map once it is ready (null before).
|
|
49
|
+
*/
|
|
50
|
+
declare const SMap: react.ForwardRefExoticComponent<SMapProps & react.RefAttributes<Map | null>>;
|
|
51
|
+
|
|
52
|
+
/** Called with the tapped feature's properties, its position and the feature itself. */
|
|
53
|
+
type TapHandler = (properties: Record<string, unknown>, position: {
|
|
54
|
+
lat: number;
|
|
55
|
+
lng: number;
|
|
56
|
+
}, feature: GeoJSONFeature) => void;
|
|
57
|
+
interface LayerProps<O> {
|
|
58
|
+
/** The layer id, unique on the map. */
|
|
59
|
+
id: string;
|
|
60
|
+
/** GeoJSON, or an array of points `{lng, lat, …properties}`. A new value replaces the data and keeps the look. */
|
|
61
|
+
data: LayerData;
|
|
62
|
+
/** How the layer is drawn; a change draws the layer again. */
|
|
63
|
+
options?: O;
|
|
64
|
+
/** Called when a feature of this layer is tapped or clicked. */
|
|
65
|
+
onTap?: TapHandler;
|
|
66
|
+
/** Shows or hides the layer (default true). */
|
|
67
|
+
visible?: boolean;
|
|
68
|
+
}
|
|
69
|
+
type PointsProps = LayerProps<PointOptions>;
|
|
70
|
+
type LinesProps = LayerProps<LineOptions>;
|
|
71
|
+
type PolygonsProps = LayerProps<PolygonOptions>;
|
|
72
|
+
/** Points at any scale, clustered or not. Must be inside `<SMap>`. */
|
|
73
|
+
declare function Points(props: PointsProps): null;
|
|
74
|
+
/** Lines (routes, tracks). Must be inside `<SMap>`. */
|
|
75
|
+
declare function Lines(props: LinesProps): null;
|
|
76
|
+
/** Areas, flat or in 3D (`options.extrude`). Must be inside `<SMap>`. */
|
|
77
|
+
declare function Polygons(props: PolygonsProps): null;
|
|
78
|
+
|
|
79
|
+
export { Lines, Points, Polygons, SMap, useSMap };
|
|
80
|
+
export type { LayerProps, LinesProps, PointsProps, PolygonsProps, SMapProps, TapHandler };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// src/SMap.tsx
|
|
4
|
+
import {
|
|
5
|
+
createContext,
|
|
6
|
+
forwardRef,
|
|
7
|
+
useContext,
|
|
8
|
+
useEffect,
|
|
9
|
+
useImperativeHandle,
|
|
10
|
+
useRef,
|
|
11
|
+
useState
|
|
12
|
+
} from "react";
|
|
13
|
+
import { Map as SMapMap } from "@superrouteca/smap";
|
|
14
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
var MapContext = createContext(null);
|
|
16
|
+
var removedMaps = /* @__PURE__ */ new WeakSet();
|
|
17
|
+
function useSMap() {
|
|
18
|
+
return useContext(MapContext);
|
|
19
|
+
}
|
|
20
|
+
var key = (v) => JSON.stringify(v ?? null);
|
|
21
|
+
function cameraChanges(prev, next) {
|
|
22
|
+
const out = {};
|
|
23
|
+
let changed = false;
|
|
24
|
+
if (next.center !== void 0 && key(next.center) !== key(prev.center)) {
|
|
25
|
+
out.center = next.center;
|
|
26
|
+
changed = true;
|
|
27
|
+
}
|
|
28
|
+
for (const k of ["zoom", "bearing", "pitch"]) {
|
|
29
|
+
if (next[k] !== void 0 && next[k] !== prev[k]) {
|
|
30
|
+
out[k] = next[k];
|
|
31
|
+
changed = true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return changed ? out : null;
|
|
35
|
+
}
|
|
36
|
+
var SMap = forwardRef(function SMap2(props, ref) {
|
|
37
|
+
const containerRef = useRef(null);
|
|
38
|
+
const [map, setMap] = useState(null);
|
|
39
|
+
const latest = useRef(props);
|
|
40
|
+
latest.current = props;
|
|
41
|
+
const applied = useRef(
|
|
42
|
+
{ style: "", language: "", camera: {}, projection: "", buildings: false }
|
|
43
|
+
);
|
|
44
|
+
useImperativeHandle(ref, () => map, [map]);
|
|
45
|
+
const nodesKey = key(props.nodes);
|
|
46
|
+
const mapOptionsKey = key(props.mapOptions);
|
|
47
|
+
const hasGetToken = !!props.getToken;
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
const container = containerRef.current;
|
|
50
|
+
if (!container) {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
const p = latest.current;
|
|
54
|
+
const options = {
|
|
55
|
+
...p.mapOptions || {},
|
|
56
|
+
container,
|
|
57
|
+
apiKey: p.apiKey,
|
|
58
|
+
token: p.token,
|
|
59
|
+
getToken: p.getToken ? () => latest.current.getToken() : void 0,
|
|
60
|
+
style: p.style,
|
|
61
|
+
language: p.language,
|
|
62
|
+
center: p.center,
|
|
63
|
+
zoom: p.zoom,
|
|
64
|
+
bearing: p.bearing,
|
|
65
|
+
pitch: p.pitch,
|
|
66
|
+
nodes: p.nodes,
|
|
67
|
+
baseUrl: p.baseUrl,
|
|
68
|
+
nearest: p.nearest,
|
|
69
|
+
projection: p.projection
|
|
70
|
+
};
|
|
71
|
+
for (const k of Object.keys(options)) {
|
|
72
|
+
if (options[k] === void 0) {
|
|
73
|
+
delete options[k];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
let alive = true;
|
|
77
|
+
let ready = false;
|
|
78
|
+
let created;
|
|
79
|
+
try {
|
|
80
|
+
created = new SMapMap(options);
|
|
81
|
+
} catch (e) {
|
|
82
|
+
latest.current.onError?.(e);
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
applied.current = {
|
|
86
|
+
style: key(p.style ?? "light"),
|
|
87
|
+
language: key(p.language ?? null),
|
|
88
|
+
camera: { center: p.center, zoom: p.zoom, bearing: p.bearing, pitch: p.pitch },
|
|
89
|
+
projection: p.projection ?? "mercator",
|
|
90
|
+
buildings: false
|
|
91
|
+
};
|
|
92
|
+
created.ready.then(() => {
|
|
93
|
+
ready = true;
|
|
94
|
+
if (!alive) {
|
|
95
|
+
created.remove();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
setMap(created);
|
|
99
|
+
latest.current.onReady?.(created);
|
|
100
|
+
}, (e) => {
|
|
101
|
+
if (alive) {
|
|
102
|
+
latest.current.onError?.(e);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
return () => {
|
|
106
|
+
alive = false;
|
|
107
|
+
removedMaps.add(created);
|
|
108
|
+
setMap(null);
|
|
109
|
+
if (ready) {
|
|
110
|
+
created.remove();
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}, [props.apiKey, props.token, props.baseUrl, nodesKey, props.nearest, mapOptionsKey, hasGetToken]);
|
|
114
|
+
const styleKey = key(props.style ?? "light");
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
if (!map || applied.current.style === styleKey) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
applied.current.style = styleKey;
|
|
120
|
+
map.setStyle(latest.current.style ?? "light");
|
|
121
|
+
}, [map, styleKey]);
|
|
122
|
+
const languageKey = key(props.language ?? null);
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (!map || applied.current.language === languageKey || props.language === void 0) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
applied.current.language = languageKey;
|
|
128
|
+
map.setLanguage(props.language);
|
|
129
|
+
}, [map, languageKey]);
|
|
130
|
+
const centerKey = key(props.center);
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
if (!map) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const next = { center: props.center, zoom: props.zoom, bearing: props.bearing, pitch: props.pitch };
|
|
136
|
+
const change = cameraChanges(applied.current.camera, next);
|
|
137
|
+
applied.current.camera = next;
|
|
138
|
+
if (change && map.engine) {
|
|
139
|
+
map.engine.jumpTo(change);
|
|
140
|
+
}
|
|
141
|
+
}, [map, centerKey, props.zoom, props.bearing, props.pitch]);
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
const projection = props.projection ?? "mercator";
|
|
144
|
+
if (!map || applied.current.projection === projection) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
applied.current.projection = projection;
|
|
148
|
+
map.setProjection(projection);
|
|
149
|
+
}, [map, props.projection]);
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
const on = !!props.buildings3D;
|
|
152
|
+
if (!map || applied.current.buildings === on) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
applied.current.buildings = on;
|
|
156
|
+
map.setBuildings3D(on);
|
|
157
|
+
}, [map, props.buildings3D]);
|
|
158
|
+
return /* @__PURE__ */ jsxs(
|
|
159
|
+
"div",
|
|
160
|
+
{
|
|
161
|
+
id: props.id,
|
|
162
|
+
className: props.className,
|
|
163
|
+
style: { position: "relative", width: "100%", height: "100%", ...props.containerStyle },
|
|
164
|
+
children: [
|
|
165
|
+
/* @__PURE__ */ jsx("div", { ref: containerRef, style: { position: "absolute", inset: 0 } }),
|
|
166
|
+
/* @__PURE__ */ jsx(MapContext.Provider, { value: map, children: props.children })
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// src/layers.tsx
|
|
173
|
+
import { useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
174
|
+
function optionsKey(options) {
|
|
175
|
+
return JSON.stringify(options ?? {}, (_k, v) => typeof v === "function" ? "[fn]" : v);
|
|
176
|
+
}
|
|
177
|
+
function useLayer(kind, props) {
|
|
178
|
+
const map = useSMap();
|
|
179
|
+
const { id, data, options, onTap, visible = true } = props;
|
|
180
|
+
const latest = useRef2(props);
|
|
181
|
+
latest.current = props;
|
|
182
|
+
const shown = useRef2(null);
|
|
183
|
+
const shownVisible = useRef2(true);
|
|
184
|
+
const hasTap = !!onTap || typeof options?.onClick === "function";
|
|
185
|
+
const looks = optionsKey(options);
|
|
186
|
+
useEffect2(() => {
|
|
187
|
+
if (!map) {
|
|
188
|
+
return void 0;
|
|
189
|
+
}
|
|
190
|
+
const o = { ...latest.current.options || {} };
|
|
191
|
+
if (hasTap) {
|
|
192
|
+
o.onClick = (feature, event) => {
|
|
193
|
+
const p = latest.current;
|
|
194
|
+
p.options?.onClick?.(feature, event);
|
|
195
|
+
p.onTap?.(feature.properties || {}, { lat: event.lngLat.lat, lng: event.lngLat.lng }, feature);
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
if (typeof o.popup === "function") {
|
|
199
|
+
o.popup = (properties, feature) => latest.current.options?.popup?.(properties, feature);
|
|
200
|
+
}
|
|
201
|
+
const d = latest.current.data;
|
|
202
|
+
map[kind](id, d, o);
|
|
203
|
+
if (latest.current.visible === false) {
|
|
204
|
+
map.setVisible(id, false);
|
|
205
|
+
}
|
|
206
|
+
shownVisible.current = latest.current.visible !== false;
|
|
207
|
+
shown.current = { map, data: d };
|
|
208
|
+
return () => {
|
|
209
|
+
shown.current = null;
|
|
210
|
+
if (!removedMaps.has(map)) {
|
|
211
|
+
map.removeLayer(id);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}, [map, id, looks, hasTap]);
|
|
215
|
+
useEffect2(() => {
|
|
216
|
+
const s = shown.current;
|
|
217
|
+
if (!map || !s || s.map !== map || s.data === data) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
s.data = data;
|
|
221
|
+
map.setData(id, data);
|
|
222
|
+
}, [map, id, data]);
|
|
223
|
+
useEffect2(() => {
|
|
224
|
+
if (!map || shownVisible.current === visible) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
shownVisible.current = visible;
|
|
228
|
+
map.setVisible(id, visible);
|
|
229
|
+
}, [map, id, visible]);
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
function Points(props) {
|
|
233
|
+
return useLayer("addPoints", props);
|
|
234
|
+
}
|
|
235
|
+
function Lines(props) {
|
|
236
|
+
return useLayer("addLines", props);
|
|
237
|
+
}
|
|
238
|
+
function Polygons(props) {
|
|
239
|
+
return useLayer("addPolygons", props);
|
|
240
|
+
}
|
|
241
|
+
export {
|
|
242
|
+
Lines,
|
|
243
|
+
Points,
|
|
244
|
+
Polygons,
|
|
245
|
+
SMap,
|
|
246
|
+
useSMap
|
|
247
|
+
};
|
|
248
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/SMap.tsx","../src/layers.tsx"],"sourcesContent":["import {\n createContext,\n forwardRef,\n useContext,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n} from 'react';\nimport { Map as SMapMap, type LngLatLike, type StyleFlavor } from '@superrouteca/smap';\n\nexport type { SMapMap };\n\nconst MapContext = createContext<SMapMap | null>(null);\n\n/** Maps that were removed: their layers must not be touched any more. */\nexport const removedMaps = new WeakSet<SMapMap>();\n\n/** The map of the nearest `<SMap>` above, once it is ready (null before). */\nexport function useSMap(): SMapMap | null {\n return useContext(MapContext);\n}\n\nexport interface SMapProps {\n /** A map key (`smk_…`) whose allowlist names this site. Read when the map is created. */\n apiKey?: string;\n /** A map token. Read when the map is created; changing it creates the map again (use `getToken` to renew). */\n token?: string;\n /** Called at start and again two minutes before each token expires. */\n getToken?: () => string | Promise<string>;\n /** A colour scheme, or a style URL or object of your own. Changing it keeps the layers. */\n style?: StyleFlavor | string | Record<string, unknown>;\n /** Label language (`en`, `fr`, `zh-Hans`, …). Changing it keeps the layers. */\n language?: string;\n /** [longitude, latitude] or `{lng, lat}`; the camera follows a change. */\n center?: LngLatLike;\n zoom?: number;\n bearing?: number;\n pitch?: number;\n /** Node URLs known in advance, used while `baseUrl` is down. */\n nodes?: string[];\n /** The map service, `https://tile.srsr.ca` by default. */\n baseUrl?: string;\n /** Read from the nearest service node (default true). */\n nearest?: boolean;\n projection?: 'mercator' | 'globe';\n /** Buildings in 3D. */\n buildings3D?: boolean;\n /** Further options handed to the map when it is created (minZoom, maxZoom, maxBounds, hash, …). */\n mapOptions?: Record<string, unknown>;\n /** Called once the first style has loaded, with the map. */\n onReady?: (map: SMapMap) => void;\n /** Called when the map cannot start. */\n onError?: (error: unknown) => void;\n /** Class and style of the element holding the map (it fills the element). */\n className?: string;\n containerStyle?: CSSProperties;\n id?: string;\n /** `<Points>`, `<Lines>`, `<Polygons>`, or anything to draw over the map. */\n children?: ReactNode;\n}\n\ntype Camera = { center?: LngLatLike; zoom?: number; bearing?: number; pitch?: number };\n\nconst key = (v: unknown) => JSON.stringify(v ?? null);\n\nfunction cameraChanges(prev: Camera, next: Camera): Camera | null {\n const out: Camera = {};\n let changed = false;\n if (next.center !== undefined && key(next.center) !== key(prev.center)) { out.center = next.center; changed = true; }\n for (const k of ['zoom', 'bearing', 'pitch'] as const) {\n if (next[k] !== undefined && next[k] !== prev[k]) { out[k] = next[k]; changed = true; }\n }\n return changed ? out : null;\n}\n\n/**\n * A map. Created in the browser only (after the component mounts), so it can be rendered on a server. The ref is\n * the SDK map once it is ready (null before).\n */\nexport const SMap = forwardRef<SMapMap | null, SMapProps>(function SMap(props, ref) {\n const containerRef = useRef<HTMLDivElement | null>(null);\n const [map, setMap] = useState<SMapMap | null>(null);\n const latest = useRef(props);\n latest.current = props;\n // What the map shows now, so a prop that did not change is not applied again.\n const applied = useRef<{ style: string; language: string; camera: Camera; projection: string; buildings: boolean }>(\n { style: '', language: '', camera: {}, projection: '', buildings: false });\n\n useImperativeHandle(ref, () => map as SMapMap, [map]);\n\n const nodesKey = key(props.nodes);\n const mapOptionsKey = key(props.mapOptions);\n const hasGetToken = !!props.getToken;\n\n useEffect(() => {\n const container = containerRef.current;\n if (!container) { return undefined; }\n const p = latest.current;\n const options: Record<string, unknown> = {\n ...(p.mapOptions || {}),\n container,\n apiKey: p.apiKey,\n token: p.token,\n getToken: p.getToken ? () => latest.current.getToken!() : undefined,\n style: p.style,\n language: p.language,\n center: p.center,\n zoom: p.zoom,\n bearing: p.bearing,\n pitch: p.pitch,\n nodes: p.nodes,\n baseUrl: p.baseUrl,\n nearest: p.nearest,\n projection: p.projection,\n };\n for (const k of Object.keys(options)) { if (options[k] === undefined) { delete options[k]; } }\n let alive = true;\n let ready = false;\n let created: SMapMap;\n try {\n created = new SMapMap(options as unknown as ConstructorParameters<typeof SMapMap>[0]);\n } catch (e) {\n latest.current.onError?.(e);\n return undefined;\n }\n applied.current = {\n style: key(p.style ?? 'light'),\n language: key(p.language ?? null),\n camera: { center: p.center, zoom: p.zoom, bearing: p.bearing, pitch: p.pitch },\n projection: p.projection ?? 'mercator',\n buildings: false,\n };\n created.ready.then(() => {\n ready = true;\n if (!alive) { created.remove(); return; }\n setMap(created);\n latest.current.onReady?.(created);\n }, (e: unknown) => {\n if (alive) { latest.current.onError?.(e); }\n });\n return () => {\n alive = false;\n removedMaps.add(created);\n setMap(null);\n // Before it is ready the map has nothing to remove yet; it is removed as soon as it is.\n if (ready) { created.remove(); }\n };\n }, [props.apiKey, props.token, props.baseUrl, nodesKey, props.nearest, mapOptionsKey, hasGetToken]);\n\n const styleKey = key(props.style ?? 'light');\n useEffect(() => {\n if (!map || applied.current.style === styleKey) { return; }\n applied.current.style = styleKey;\n map.setStyle(latest.current.style ?? 'light');\n }, [map, styleKey]);\n\n const languageKey = key(props.language ?? null);\n useEffect(() => {\n if (!map || applied.current.language === languageKey || props.language === undefined) { return; }\n applied.current.language = languageKey;\n map.setLanguage(props.language);\n }, [map, languageKey]);\n\n const centerKey = key(props.center);\n useEffect(() => {\n if (!map) { return; }\n const next: Camera = { center: props.center, zoom: props.zoom, bearing: props.bearing, pitch: props.pitch };\n const change = cameraChanges(applied.current.camera, next);\n applied.current.camera = next;\n if (change && map.engine) { map.engine.jumpTo(change); }\n }, [map, centerKey, props.zoom, props.bearing, props.pitch]);\n\n useEffect(() => {\n const projection = props.projection ?? 'mercator';\n if (!map || applied.current.projection === projection) { return; }\n applied.current.projection = projection;\n map.setProjection(projection);\n }, [map, props.projection]);\n\n useEffect(() => {\n const on = !!props.buildings3D;\n if (!map || applied.current.buildings === on) { return; }\n applied.current.buildings = on;\n map.setBuildings3D(on);\n }, [map, props.buildings3D]);\n\n return (\n <div\n id={props.id}\n className={props.className}\n style={{ position: 'relative', width: '100%', height: '100%', ...props.containerStyle }}\n >\n <div ref={containerRef} style={{ position: 'absolute', inset: 0 }} />\n <MapContext.Provider value={map}>{props.children}</MapContext.Provider>\n </div>\n );\n});\n","import { useEffect, useRef } from 'react';\nimport type {\n GeoJSONFeature,\n LayerClickEvent,\n LayerData,\n LineOptions,\n PointOptions,\n PolygonOptions,\n} from '@superrouteca/smap';\nimport { removedMaps, useSMap, type SMapMap } from './SMap';\n\n/** Called with the tapped feature's properties, its position and the feature itself. */\nexport type TapHandler = (\n properties: Record<string, unknown>,\n position: { lat: number; lng: number },\n feature: GeoJSONFeature,\n) => void;\n\nexport interface LayerProps<O> {\n /** The layer id, unique on the map. */\n id: string;\n /** GeoJSON, or an array of points `{lng, lat, …properties}`. A new value replaces the data and keeps the look. */\n data: LayerData;\n /** How the layer is drawn; a change draws the layer again. */\n options?: O;\n /** Called when a feature of this layer is tapped or clicked. */\n onTap?: TapHandler;\n /** Shows or hides the layer (default true). */\n visible?: boolean;\n}\n\nexport type PointsProps = LayerProps<PointOptions>;\nexport type LinesProps = LayerProps<LineOptions>;\nexport type PolygonsProps = LayerProps<PolygonOptions>;\n\ntype Kind = 'addPoints' | 'addLines' | 'addPolygons';\n\n// Options compared by value; functions (popup, onClick) are read when called, so a new function is no change.\nfunction optionsKey(options: unknown): string {\n return JSON.stringify(options ?? {}, (_k, v) => (typeof v === 'function' ? '[fn]' : v));\n}\n\nfunction useLayer(kind: Kind, props: LayerProps<PointOptions | LineOptions | PolygonOptions>): null {\n const map = useSMap();\n const { id, data, options, onTap, visible = true } = props;\n const latest = useRef(props);\n latest.current = props;\n const shown = useRef<{ map: SMapMap; data: LayerData } | null>(null);\n const shownVisible = useRef(true);\n const hasTap = !!onTap || typeof options?.onClick === 'function';\n const looks = optionsKey(options);\n\n useEffect(() => {\n if (!map) { return undefined; }\n const o: Record<string, unknown> = { ...(latest.current.options || {}) };\n if (hasTap) {\n o.onClick = (feature: GeoJSONFeature, event: LayerClickEvent) => {\n const p = latest.current;\n p.options?.onClick?.(feature, event);\n p.onTap?.(feature.properties || {}, { lat: event.lngLat.lat, lng: event.lngLat.lng }, feature);\n };\n }\n if (typeof o.popup === 'function') {\n o.popup = (properties: Record<string, unknown>, feature: GeoJSONFeature) => latest.current.options?.popup?.(properties, feature);\n }\n const d = latest.current.data;\n (map[kind] as (id: string, data: LayerData, o: unknown) => SMapMap)(id, d, o);\n if (latest.current.visible === false) { map.setVisible(id, false); }\n shownVisible.current = latest.current.visible !== false;\n shown.current = { map, data: d };\n return () => {\n shown.current = null;\n if (!removedMaps.has(map)) { map.removeLayer(id); }\n };\n }, [map, id, looks, hasTap]);\n\n useEffect(() => {\n const s = shown.current;\n if (!map || !s || s.map !== map || s.data === data) { return; }\n s.data = data;\n map.setData(id, data);\n }, [map, id, data]);\n\n useEffect(() => {\n if (!map || shownVisible.current === visible) { return; }\n shownVisible.current = visible;\n map.setVisible(id, visible);\n }, [map, id, visible]);\n\n return null;\n}\n\n/** Points at any scale, clustered or not. Must be inside `<SMap>`. */\nexport function Points(props: PointsProps): null {\n return useLayer('addPoints', props);\n}\n\n/** Lines (routes, tracks). Must be inside `<SMap>`. */\nexport function Lines(props: LinesProps): null {\n return useLayer('addLines', props);\n}\n\n/** Areas, flat or in 3D (`options.extrude`). Must be inside `<SMap>`. */\nexport function Polygons(props: PolygonsProps): null {\n return useLayer('addPolygons', props);\n}\n"],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I,CAAC;AAElB,EAAAA,WAAU,MAAM;AACd,QAAI,CAAC,OAAO,aAAa,YAAY,SAAS;AAAE;AAAA,IAAQ;AACxD,iBAAa,UAAU;AACvB,QAAI,WAAW,IAAI,OAAO;AAAA,EAC5B,GAAG,CAAC,KAAK,IAAI,OAAO,CAAC;AAErB,SAAO;AACT;AAGO,SAAS,OAAO,OAA0B;AAC/C,SAAO,SAAS,aAAa,KAAK;AACpC;AAGO,SAAS,MAAM,OAAyB;AAC7C,SAAO,SAAS,YAAY,KAAK;AACnC;AAGO,SAAS,SAAS,OAA4B;AACnD,SAAO,SAAS,eAAe,KAAK;AACtC;","names":["SMap","useEffect","useRef","useRef","useEffect"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superrouteca/smap-react",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "React components for maps from Superroute's sMap service.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Goodneo Solutions",
|
|
7
|
+
"homepage": "https://github.com/Goodneo-Solutions/smap-sdk/tree/main/react#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/Goodneo-Solutions/smap-sdk.git",
|
|
11
|
+
"directory": "react"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"map",
|
|
15
|
+
"maps",
|
|
16
|
+
"react",
|
|
17
|
+
"smap",
|
|
18
|
+
"superroute"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"main": "./dist/index.cjs",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.cts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./dist/index.d.cts",
|
|
33
|
+
"default": "./dist/index.cjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"README.md",
|
|
41
|
+
"CHANGELOG.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"prepack": "cp ../LICENSE LICENSE && npm run build"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"react": ">=18"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@superrouteca/smap": "1.0.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@testing-library/react": "16.3.3",
|
|
58
|
+
"@types/react": "19.3.0",
|
|
59
|
+
"@types/react-dom": "19.3.0",
|
|
60
|
+
"jsdom": "30.1.3",
|
|
61
|
+
"react": "19.3.1",
|
|
62
|
+
"react-dom": "19.3.1",
|
|
63
|
+
"tsup": "9.0.0",
|
|
64
|
+
"typescript": "6.0.3",
|
|
65
|
+
"vitest": "5.0.5"
|
|
66
|
+
}
|
|
67
|
+
}
|