@swisper.ai/web-map 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +134 -0
- package/dist/base-map.d.ts +28 -0
- package/dist/base-map.d.ts.map +1 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/index.css +2 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.es.js +283 -0
- package/dist/index.es.js.map +1 -0
- package/dist/load-map-lib.d.ts +13 -0
- package/dist/load-map-lib.d.ts.map +1 -0
- package/dist/map-context.d.ts +14 -0
- package/dist/map-context.d.ts.map +1 -0
- package/dist/map-marker.d.ts +26 -0
- package/dist/map-marker.d.ts.map +1 -0
- package/dist/map-pin.d.ts +28 -0
- package/dist/map-pin.d.ts.map +1 -0
- package/dist/map-user-location.d.ts +11 -0
- package/dist/map-user-location.d.ts.map +1 -0
- package/dist/map-view.d.ts +30 -0
- package/dist/map-view.d.ts.map +1 -0
- package/dist/maplibre-worker-source-DgoyX01U.js +4 -0
- package/dist/user-location-pin.d.ts +8 -0
- package/dist/user-location-pin.d.ts.map +1 -0
- package/dist/utils/get-bounds-from-points.d.ts +10 -0
- package/dist/utils/get-bounds-from-points.d.ts.map +1 -0
- package/dist/worker/maplibre-worker-source.d.ts +2 -0
- package/dist/worker/maplibre-worker-source.d.ts.map +1 -0
- package/package.json +100 -0
- package/src/__storybook__/fixtures.ts +19 -0
- package/src/__tests__/load-map-lib.spec.ts +57 -0
- package/src/__tests__/map-marker.spec.tsx +153 -0
- package/src/__tests__/map-pin.spec.tsx +82 -0
- package/src/__tests__/map-user-location.spec.tsx +48 -0
- package/src/__tests__/maplibre-worker-source.stub.ts +2 -0
- package/src/__tests__/setup.ts +13 -0
- package/src/base-map.json +89 -0
- package/src/base-map.stories.tsx +123 -0
- package/src/base-map.tsx +137 -0
- package/src/constants.ts +11 -0
- package/src/index.css +1 -0
- package/src/index.ts +32 -0
- package/src/load-map-lib.ts +25 -0
- package/src/map-context.tsx +25 -0
- package/src/map-marker.json +84 -0
- package/src/map-marker.stories.tsx +228 -0
- package/src/map-marker.tsx +97 -0
- package/src/map-pin.json +87 -0
- package/src/map-pin.stories.tsx +97 -0
- package/src/map-pin.tsx +174 -0
- package/src/map-user-location.json +70 -0
- package/src/map-user-location.stories.tsx +69 -0
- package/src/map-user-location.tsx +29 -0
- package/src/map-view.json +112 -0
- package/src/map-view.stories.tsx +174 -0
- package/src/map-view.tsx +86 -0
- package/src/user-location-pin.json +58 -0
- package/src/user-location-pin.stories.tsx +43 -0
- package/src/user-location-pin.tsx +27 -0
- package/src/utils/get-bounds-from-points.ts +39 -0
- package/src/worker/maplibre-worker-source.ts +2 -0
- package/src/worker/virtual-maplibre-worker-source.d.ts +5 -0
- package/tailwind.css +9 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2025-2026 Fintama AG
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# @swisper.ai/web-map
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@swisper.ai/web-map)
|
|
4
|
+
[](https://unpkg.com/@swisper.ai/web-map/LICENSE)
|
|
5
|
+
|
|
6
|
+
Interactive MapLibre maps with selectable markers for Swisper web apps. `MapView` frames a set of points and shares selection and hover state with the `MapMarker`s inside it, but it doesn't store that state: your app holds the selected id and passes it back. All text is passed in as props (the package has no i18n dependency), and components are styled with Tailwind v4 utilities against the `@swisper.ai/design-system` theme.
|
|
7
|
+
|
|
8
|
+
## Boundary
|
|
9
|
+
|
|
10
|
+
Code belongs here if it puts a map on screen: the map surface, its markers, controls and overlays, and the engine setup it needs. Heavy map engines stay here, so consumers that never show a map don't download them. Chat-specific UI around a map, such as the chat-card layout that lists places beside it, belongs in `@swisper.ai/web-chat-ui`.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install @swisper.ai/web-map
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
| Peer | Range | Why |
|
|
19
|
+
| ----------- | ---------- | -------------------- |
|
|
20
|
+
| `react` | `>=18.0.0` | Components and hooks |
|
|
21
|
+
| `react-dom` | `>=18.0.0` | Rendering |
|
|
22
|
+
|
|
23
|
+
MapLibre GL (`maplibre-gl`, through `@vis.gl/react-maplibre`) is a regular dependency, loaded lazily with the first map; its worker ships with the package and starts from a same-origin `blob:` URL, so your bundler needs no worker configuration. The package imports `maplibre-gl/dist/maplibre-gl.css` itself. It also depends on `@swisper.ai/ui`, whose peers (`@mui/material`, `@mui/system`, `@mui/icons-material`, `@emotion/react`, `@emotion/styled`) apply too.
|
|
24
|
+
|
|
25
|
+
## Setup
|
|
26
|
+
|
|
27
|
+
1. Load the styles (see [Styles](#styles)).
|
|
28
|
+
2. If you render `MapUserLocation` with its default pin, mount `TooltipProvider` from `@swisper.ai/ui` above the map: the pin shows its label in a tooltip.
|
|
29
|
+
3. Render the map inside a parent with an explicit height, and memoise `fitPoints`: it is compared by identity, so a new array on every render re-frames the map and undoes the user's pan and zoom.
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { MapMarker, MapPin, MapView } from '@swisper.ai/web-map';
|
|
33
|
+
import { useMemo, useState } from 'react';
|
|
34
|
+
|
|
35
|
+
interface Place {
|
|
36
|
+
id: string;
|
|
37
|
+
name: string;
|
|
38
|
+
rating: string;
|
|
39
|
+
lng: number;
|
|
40
|
+
lat: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function PlacesMap({ places }: { places: Place[] }) {
|
|
44
|
+
const [selectedId, setSelectedId] = useState<string | null>(null);
|
|
45
|
+
const fitPoints = useMemo(
|
|
46
|
+
() => places.map((place): [number, number] => [place.lng, place.lat]),
|
|
47
|
+
[places],
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<MapView
|
|
52
|
+
testId="places-map"
|
|
53
|
+
ariaLabel="Restaurants near you"
|
|
54
|
+
fitPoints={fitPoints}
|
|
55
|
+
selectedId={selectedId}
|
|
56
|
+
onSelect={setSelectedId}
|
|
57
|
+
className="h-[400px]"
|
|
58
|
+
>
|
|
59
|
+
{places.map((place) => (
|
|
60
|
+
<MapMarker
|
|
61
|
+
key={place.id}
|
|
62
|
+
id={place.id}
|
|
63
|
+
longitude={place.lng}
|
|
64
|
+
latitude={place.lat}
|
|
65
|
+
label={place.name}
|
|
66
|
+
>
|
|
67
|
+
<MapPin label={place.name} value={place.rating} />
|
|
68
|
+
</MapMarker>
|
|
69
|
+
))}
|
|
70
|
+
</MapView>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Tiles come from OpenFreeMap's Liberty style (`DEFAULT_MAP_STYLE_URL`) unless you pass `mapStyleUrl`.
|
|
76
|
+
|
|
77
|
+
## Styles
|
|
78
|
+
|
|
79
|
+
Pick **one** of the two options.
|
|
80
|
+
|
|
81
|
+
| Your app | Use |
|
|
82
|
+
| ----------------------------------- | --------------------------------------------------------------------------- |
|
|
83
|
+
| Builds its own CSS with Tailwind v4 | `@import '@swisper.ai/web-map/tailwind.css';` after the design-system theme |
|
|
84
|
+
| Has no Tailwind | `import '@swisper.ai/web-map/index.css';` once, at the app's entry |
|
|
85
|
+
|
|
86
|
+
With Tailwind, install `@swisper.ai/design-system` too and import its theme first:
|
|
87
|
+
|
|
88
|
+
```css
|
|
89
|
+
@import '@swisper.ai/design-system/src/tailwind.css'; /* tailwindcss + theme: colors, radii, fonts */
|
|
90
|
+
@import '@swisper.ai/web-map/tailwind.css';
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`@swisper.ai/web-map/tailwind.css` holds only `@source "./dist";`, which makes Tailwind scan the built components for class names. The prebuilt `index.css` instead brings its own preflight, theme and every utility the `@swisper.ai` packages use, so loading it next to your own Tailwind build ships everything twice, and whichever file loads last wins wherever the two conflict.
|
|
94
|
+
|
|
95
|
+
## API
|
|
96
|
+
|
|
97
|
+
Props and live examples are on each component's page in the [Echo DS Storybook](https://fintama.github.io/fintama/).
|
|
98
|
+
|
|
99
|
+
| Export | Why it exists |
|
|
100
|
+
| ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
101
|
+
| `MapView` | Root. Frames `fitPoints` (one point zooms in, none shows the world) and reports marker clicks and hover through `onSelect` / `onHover`; selection and hover are controlled by you. |
|
|
102
|
+
| `MapMarker`, `useMapMarker` | A selectable, hoverable point that wraps its pin in a button and passes `{ isSelected, isHovered }` to it, as an element reading `useMapMarker` or a render function. |
|
|
103
|
+
| `MapPin` | The default callout pin: a value that expands to value and place name on hover or selection, restyled through `--map-pin-*` CSS variables. |
|
|
104
|
+
| `MapUserLocation`, `UserLocationPin` | The user's own position; renders nothing until coordinates are known, and is not added to `fitPoints` for you. |
|
|
105
|
+
| `useMapView` | The map instance (`mapRef`) and selection state, for custom children of a `MapView`. |
|
|
106
|
+
| `BaseMap` | The bare map with loading and error states, framing and style URL, but no selection context. |
|
|
107
|
+
| `Layer`, `Marker`, `Source`, `useMap` | Re-exported from `@vis.gl/react-maplibre`, so what you draw inside a `BaseMap` or `MapView` reads the same map context as this package. |
|
|
108
|
+
| `loadMapLib` | MapLibre with its worker already set up, loaded once and shared by every map; pass it as `mapLib` if you render a react-maplibre `Map` yourself. |
|
|
109
|
+
| `resolveMapStyleUrl`, `DEFAULT_MAP_STYLE_URL`, `DEFAULT_FIT_BOUNDS_PADDING`, `SINGLE_POINT_ZOOM` | The defaults the components use, for maps of your own that should match. |
|
|
110
|
+
| `getBoundsFromPoints`, `getBoundsCentroid`, `isDegenerateBounds` | Helpers for framing a set of `[longitude, latitude]` points. |
|
|
111
|
+
|
|
112
|
+
## Troubleshooting
|
|
113
|
+
|
|
114
|
+
| Symptom | Cause | Fix |
|
|
115
|
+
| --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
|
|
116
|
+
| "Invalid hook call", or a context is missing | The app resolves two copies of React | Add `resolve: { dedupe: ['react', 'react-dom'] }` to the Vite config |
|
|
117
|
+
| Components render without layout or colors | Tailwind never scans the package, because it skips `node_modules` by default | Import the package's `tailwind.css` in your Tailwind entry, or load its prebuilt `index.css` |
|
|
118
|
+
| Layout is right, but colors or radii are wrong or missing | The design-system theme isn't loaded, so theme utilities such as `bg-paper-elevation-1` are empty | Import `@swisper.ai/design-system/src/tailwind.css` before the package's `tailwind.css` |
|
|
119
|
+
| Your own base styles (fonts, headings, resets) get overridden | The prebuilt `index.css` is loaded next to your own Tailwind build, and its preflight wins | Use one of the two: drop `index.css` and import `tailwind.css` |
|
|
120
|
+
| Spacing looks wrong after upgrading (huge gaps, tiny icons) | A number in a spacing class is pixels: `gap-8` is 8px, not Tailwind's default 32px | Write the pixel value you want |
|
|
121
|
+
| Styles are missing or doubled, or the MUI theme doesn't apply | The app resolves two copies of `@emotion/react` or `@mui/material` | Add them to `resolve.dedupe` in the Vite config, next to `react` and `react-dom` |
|
|
122
|
+
| `ERR_UNSUPPORTED_DIR_IMPORT` when a test imports the package | `dist/` uses extensionless imports that only a bundler resolves, and Vitest externalizes it | Set `server.deps.inline: [/@swisper\.ai\//]` in the Vitest config |
|
|
123
|
+
| The map has zero height | `MapView` fills its parent (`size-full`), and the parent has no height | Give the parent (or `className`) an explicit height |
|
|
124
|
+
| The map jumps back to its starting frame whenever a marker is selected | `fitPoints` is a new array on every render, and each new array is framed again | Memoise `fitPoints` |
|
|
125
|
+
| Clicking the map doesn't clear the selection | `MapView` never clears it; selection is controlled by the parent | Set your selected id to `null` where you want to deselect |
|
|
126
|
+
| `VITE_MAP_STYLE_URL` is ignored | The library reads no env vars (Vite would have baked them in when the library was built) | Pass `mapStyleUrl` |
|
|
127
|
+
| `Tooltip` must be used within `TooltipProvider` | `MapUserLocation`'s default pin shows its label in a tooltip | Mount `TooltipProvider` from `@swisper.ai/ui` above the map |
|
|
128
|
+
| The map stays blank under a strict CSP | MapLibre's worker starts from a `blob:` URL, and tiles load from the style's host | Allow `blob:` in `worker-src`, and the style, tile and font hosts in `connect-src` |
|
|
129
|
+
| Bundler error importing `maplibre-gl/dist/maplibre-gl.css` | The package imports MapLibre's stylesheet, and the bundler doesn't handle CSS imports from dependencies | Enable CSS imports for `node_modules` (Vite does by default) |
|
|
130
|
+
| `useMapView must be used within a MapView component`, or `MapMarker` throws | `MapMarker` and `useMapView` read the `MapView` context | Render them inside a `MapView`; inside a bare `BaseMap`, use `Marker` instead |
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
[Apache-2.0](https://unpkg.com/@swisper.ai/web-map/LICENSE)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { MapRef } from '@vis.gl/react-maplibre';
|
|
2
|
+
import { ReactNode, RefObject } from 'react';
|
|
3
|
+
import { MapBounds, MapLngLat } from './utils/get-bounds-from-points';
|
|
4
|
+
interface BaseMapProps {
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
className?: string;
|
|
7
|
+
testId: string;
|
|
8
|
+
ariaLabel: string;
|
|
9
|
+
hasError?: boolean;
|
|
10
|
+
isLoading?: boolean;
|
|
11
|
+
initialViewState: {
|
|
12
|
+
center: MapLngLat | null;
|
|
13
|
+
zoom: number;
|
|
14
|
+
};
|
|
15
|
+
bounds?: MapBounds | null;
|
|
16
|
+
fitBoundsPadding?: number;
|
|
17
|
+
mapStyleUrl?: string;
|
|
18
|
+
mapRef?: RefObject<MapRef>;
|
|
19
|
+
onLoad?: () => void;
|
|
20
|
+
/**
|
|
21
|
+
* Shown when `hasError` is set. A prop rather than a translation lookup, so the
|
|
22
|
+
* package does not tie consumers to one i18n library or namespace.
|
|
23
|
+
*/
|
|
24
|
+
errorLabel?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare function BaseMap({ children, className, testId, ariaLabel, hasError, isLoading, initialViewState, bounds, fitBoundsPadding, mapStyleUrl, mapRef: externalMapRef, onLoad, errorLabel, }: BaseMapProps): import('react').JSX.Element;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=base-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-map.d.ts","sourceRoot":"","sources":["../src/base-map.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAqB,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAQ1E,OAAO,EAAsB,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAEpG,OAAO,kCAAkC,CAAC;AAE1C,UAAU,YAAY;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gBAAgB,EAAE;QAAE,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7D,MAAM,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAaD,wBAAgB,OAAO,CAAC,EACtB,QAAQ,EACR,SAAS,EACT,MAAM,EACN,SAAS,EACT,QAAQ,EACR,SAAS,EACT,gBAAgB,EAChB,MAAa,EACb,gBAA6C,EAC7C,WAAW,EACX,MAAM,EAAE,cAAc,EACtB,MAAM,EACN,UAAmD,GACpD,EAAE,YAAY,+BA+Dd"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const DEFAULT_MAP_STYLE_URL = "https://tiles.openfreemap.org/styles/liberty";
|
|
2
|
+
export declare const DEFAULT_FIT_BOUNDS_PADDING = 48;
|
|
3
|
+
export declare const SINGLE_POINT_ZOOM = 15;
|
|
4
|
+
/**
|
|
5
|
+
* No `import.meta.env` fallback: Vite replaces it when this library is built, so a
|
|
6
|
+
* consumer's `VITE_MAP_STYLE_URL` would never be read. Pass `mapStyleUrl` instead.
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveMapStyleUrl(mapStyleUrl?: string): string;
|
|
9
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,iDAAiD,CAAC;AACpF,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAC7C,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAE/D"}
|