@mapka/maplibre-gl-sdk 0.12.0 → 0.13.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/README.md +325 -3
- package/lib/.buildInfo.json +1 -1
- package/lib/components/DownloadIcon.d.ts +4 -0
- package/lib/components/DownloadIcon.d.ts.map +1 -0
- package/lib/components/DownloadIcon.js +10 -0
- package/lib/components/PopupContent.d.ts.map +1 -1
- package/lib/components/ProgressDownIcon.d.ts +4 -0
- package/lib/components/ProgressDownIcon.d.ts.map +1 -0
- package/lib/components/ProgressDownIcon.js +14 -0
- package/lib/controls/MapkaExportControl.d.ts +21 -0
- package/lib/controls/MapkaExportControl.d.ts.map +1 -0
- package/lib/controls/MapkaExportControl.js +76 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/map.d.ts +11 -2
- package/lib/map.d.ts.map +1 -1
- package/lib/map.js +10 -5
- package/lib/modules/export.d.ts +4 -0
- package/lib/modules/export.d.ts.map +1 -0
- package/lib/modules/export.js +40 -0
- package/lib/modules/popup.d.ts +2 -2
- package/lib/modules/popup.d.ts.map +1 -1
- package/lib/modules/popup.js +6 -5
- package/lib/types/export.d.ts +7 -0
- package/lib/types/export.d.ts.map +1 -0
- package/lib/types/export.js +1 -0
- package/package.json +3 -2
- package/src/components/DownloadIcon.tsx +25 -0
- package/src/components/PopupContent.tsx +1 -0
- package/src/components/ProgressDownIcon.tsx +29 -0
- package/src/controls/MapkaExportControl.tsx +111 -0
- package/src/index.ts +5 -0
- package/src/map.ts +17 -4
- package/src/modules/export.ts +55 -0
- package/src/modules/popup.tsx +13 -23
- package/src/types/export.ts +6 -0
package/README.md
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Mapka MapLibre SDK
|
|
2
2
|
|
|
3
3
|
```bash
|
|
4
4
|
yarn add @mapka/maplibre-gl-sdk
|
|
5
5
|
|
|
6
|
+
# or
|
|
7
|
+
|
|
8
|
+
npm install @mapka/maplibre-gl-sdk
|
|
9
|
+
|
|
6
10
|
```
|
|
7
11
|
|
|
8
12
|
## Usage
|
|
9
13
|
|
|
10
|
-
```
|
|
14
|
+
```ts
|
|
11
15
|
import "@mapka/maplibre-gl-sdk/styles.css";
|
|
12
16
|
import { Map } from '@mapka/maplibre-gl-sdk';
|
|
13
17
|
|
|
14
|
-
const map = new
|
|
18
|
+
const map = new Map({
|
|
15
19
|
apiKey: 'YOUR_MAPKA_API_KEY_HERE',
|
|
16
20
|
container: 'map',
|
|
17
21
|
style: mapkasdk.MapStyle.STREETS,
|
|
@@ -19,3 +23,321 @@ const map = new mapkasdk.Map({
|
|
|
19
23
|
zoom: 14,
|
|
20
24
|
});
|
|
21
25
|
```
|
|
26
|
+
|
|
27
|
+
## Markers
|
|
28
|
+
|
|
29
|
+
Add markers to the map with optional styling and popups.
|
|
30
|
+
|
|
31
|
+
### Basic Markers
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
// Add simple markers
|
|
35
|
+
map.addMarkers([
|
|
36
|
+
{
|
|
37
|
+
id: 'marker-1',
|
|
38
|
+
lngLat: [18, 54],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: 'marker-2',
|
|
42
|
+
lngLat: [18.01, 54.01],
|
|
43
|
+
color: '#ff0000',
|
|
44
|
+
},
|
|
45
|
+
]);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Markers with Popups
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
map.addMarkers([
|
|
52
|
+
{
|
|
53
|
+
id: 'marker-1',
|
|
54
|
+
lngLat: [18, 54],
|
|
55
|
+
popup: {
|
|
56
|
+
trigger: 'click', // 'click' | 'hover' | 'always'
|
|
57
|
+
content: {
|
|
58
|
+
title: 'Location Name',
|
|
59
|
+
description: 'A description of this place',
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Updating Markers
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
map.updateMarkers([
|
|
70
|
+
{
|
|
71
|
+
id: 'marker-1',
|
|
72
|
+
lngLat: [18.005, 54.005], // Update position
|
|
73
|
+
popup: {
|
|
74
|
+
trigger: 'click',
|
|
75
|
+
content: {
|
|
76
|
+
title: 'Updated Title',
|
|
77
|
+
description: 'New description',
|
|
78
|
+
imageUrls: ['https://example.com/image.jpg'],
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
]);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Removing Markers
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
map.removeMarkers();
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Marker Options
|
|
92
|
+
|
|
93
|
+
Markers also support all standard maplibre-gl [marker options](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MarkerOptions/).
|
|
94
|
+
|
|
95
|
+
| Option | Type | Description |
|
|
96
|
+
|--------|------|-------------|
|
|
97
|
+
| `id` | `string` | Unique identifier for the marker |
|
|
98
|
+
| `lngLat` | `[number, number]` | Marker position as `[longitude, latitude]` |
|
|
99
|
+
| `color` | `string` | Marker color (CSS color value) |
|
|
100
|
+
| `icon` | `string` | URL to a custom marker icon |
|
|
101
|
+
| `popup` | `MapkaMarkerPopupOptions` | Popup configuration (see Popup Options) |
|
|
102
|
+
|
|
103
|
+
## Popups
|
|
104
|
+
|
|
105
|
+
Popups can be attached to markers or displayed independently on the map.
|
|
106
|
+
|
|
107
|
+
### Standalone Popups
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
// Open a popup at a specific location
|
|
111
|
+
map.openPopup({
|
|
112
|
+
lngLat: [18, 54],
|
|
113
|
+
trigger: 'always',
|
|
114
|
+
content: {
|
|
115
|
+
title: 'Popup Title',
|
|
116
|
+
description: 'Popup description text',
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Open popup with custom ID
|
|
121
|
+
map.openPopup({
|
|
122
|
+
id: 'custom-popup-id',
|
|
123
|
+
lngLat: [18, 54],
|
|
124
|
+
trigger: 'always',
|
|
125
|
+
content: {
|
|
126
|
+
title: 'My Popup',
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Popup with Image Carousel
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
map.openPopup({
|
|
135
|
+
lngLat: [18, 54],
|
|
136
|
+
trigger: 'always',
|
|
137
|
+
content: {
|
|
138
|
+
title: 'Photo Gallery',
|
|
139
|
+
description: 'Beautiful views',
|
|
140
|
+
imageUrls: [
|
|
141
|
+
'https://example.com/image1.jpg',
|
|
142
|
+
'https://example.com/image2.jpg',
|
|
143
|
+
'https://example.com/image3.jpg',
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Popup with Favorite Action
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
map.openPopup({
|
|
153
|
+
lngLat: [18, 54],
|
|
154
|
+
trigger: 'always',
|
|
155
|
+
content: {
|
|
156
|
+
title: 'Save this place',
|
|
157
|
+
imageUrls: ['https://example.com/image.jpg'],
|
|
158
|
+
onFavorite: (id) => {
|
|
159
|
+
console.log('Favorited popup:', id);
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Custom HTML Popup
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
// Using an HTMLElement
|
|
169
|
+
const customElement = document.createElement('div');
|
|
170
|
+
customElement.innerHTML = '<strong>Custom Content</strong>';
|
|
171
|
+
|
|
172
|
+
map.openPopup({
|
|
173
|
+
lngLat: [18, 54],
|
|
174
|
+
trigger: 'always',
|
|
175
|
+
content: customElement,
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// Using a factory function
|
|
179
|
+
map.openPopup({
|
|
180
|
+
id: 'custom-popup-id',
|
|
181
|
+
lngLat: [18, 54],
|
|
182
|
+
trigger: 'always',
|
|
183
|
+
content: (id) => {
|
|
184
|
+
const el = document.createElement('div');
|
|
185
|
+
el.innerHTML = `<p>Popup ID: ${id}</p>`;
|
|
186
|
+
return el;
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Updating Popups
|
|
192
|
+
|
|
193
|
+
Requires the `id` property to be set on the popup options.
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
map.updatePopup({
|
|
197
|
+
id: 'popup-id',
|
|
198
|
+
lngLat: [18, 54],
|
|
199
|
+
trigger: 'always',
|
|
200
|
+
content: {
|
|
201
|
+
title: 'Updated Title',
|
|
202
|
+
description: 'New content',
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Closing and Removing Popups
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
// Close a specific popup by ID
|
|
211
|
+
map.closePopup('popup-id');
|
|
212
|
+
|
|
213
|
+
// Remove all visible popups
|
|
214
|
+
map.removePopups();
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Popup Options
|
|
218
|
+
|
|
219
|
+
Popups also support all standard maplibre-gl [popup options](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/PopupOptions/).
|
|
220
|
+
|
|
221
|
+
| Option | Type | Description |
|
|
222
|
+
|--------|------|-------------|
|
|
223
|
+
| `id` | `string` | Unique identifier for the popup |
|
|
224
|
+
| `lngLat` | `[number, number]` | Popup position as `[longitude, latitude]` |
|
|
225
|
+
| `trigger` | `'hover' \| 'click' \| 'always'` | When the popup should appear |
|
|
226
|
+
| `content` | `MapkaPopupContent \| HTMLElement \| Function` | Popup content (see below) |
|
|
227
|
+
|
|
228
|
+
### Popup Content Options
|
|
229
|
+
|
|
230
|
+
| Option | Type | Description |
|
|
231
|
+
|--------|------|-------------|
|
|
232
|
+
| `title` | `string` | Popup title text |
|
|
233
|
+
| `description` | `string` | Popup description text |
|
|
234
|
+
| `imageUrls` | `string[]` | Array of image URLs for the carousel |
|
|
235
|
+
| `onFavorite` | `(id: string) => void` | Callback when favorite button is clicked |
|
|
236
|
+
|
|
237
|
+
### Max Popups
|
|
238
|
+
|
|
239
|
+
Control how many popups can be open simultaneously:
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
const map = new Map({
|
|
243
|
+
apiKey: 'YOUR_MAPKA_API_KEY_HERE',
|
|
244
|
+
container: 'map',
|
|
245
|
+
style: mapkasdk.MapStyle.STREETS,
|
|
246
|
+
maxPopups: 3, // Allow up to 3 popups open at once (default: 1)
|
|
247
|
+
});
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Exporting Maps
|
|
251
|
+
|
|
252
|
+
### Using the Export Control
|
|
253
|
+
|
|
254
|
+
Add a UI button to export the map as PNG:
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
import "@mapka/maplibre-gl-sdk/styles.css";
|
|
258
|
+
import { Map, MapkaExportControl } from '@mapka/maplibre-gl-sdk';
|
|
259
|
+
|
|
260
|
+
const map = new Map({
|
|
261
|
+
apiKey: 'YOUR_MAPKA_API_KEY_HERE',
|
|
262
|
+
container: 'map',
|
|
263
|
+
style: mapkasdk.MapStyle.STREETS,
|
|
264
|
+
center: [18, 54],
|
|
265
|
+
zoom: 14,
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
// Add export control with default options
|
|
269
|
+
map.addControl(new MapkaExportControl());
|
|
270
|
+
|
|
271
|
+
// Or with custom filename
|
|
272
|
+
map.addControl(new MapkaExportControl({
|
|
273
|
+
filename: 'my-custom-map',
|
|
274
|
+
}));
|
|
275
|
+
|
|
276
|
+
// Or with additional export options
|
|
277
|
+
map.addControl(new MapkaExportControl({
|
|
278
|
+
filename: 'clean-map',
|
|
279
|
+
hideControls: true,
|
|
280
|
+
hideMarkers: true,
|
|
281
|
+
hidePopups: true,
|
|
282
|
+
}));
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Programmatic Export
|
|
286
|
+
|
|
287
|
+
Export the map programmatically using the `export()` method:
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
import "@mapka/maplibre-gl-sdk/styles.css";
|
|
291
|
+
import { Map } from '@mapka/maplibre-gl-sdk';
|
|
292
|
+
|
|
293
|
+
const map = new Map({
|
|
294
|
+
apiKey: 'YOUR_MAPKA_API_KEY_HERE',
|
|
295
|
+
container: 'map',
|
|
296
|
+
style: mapkasdk.MapStyle.STREETS,
|
|
297
|
+
center: [18, 54],
|
|
298
|
+
zoom: 14,
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
// Basic export - returns an HTMLImageElement
|
|
302
|
+
const image = await map.export();
|
|
303
|
+
|
|
304
|
+
// Export with options
|
|
305
|
+
const image = await map.export({
|
|
306
|
+
hideControls: true, // Hide map controls in export
|
|
307
|
+
hideMarkers: false, // Show markers in export
|
|
308
|
+
hidePopups: false, // Show popups in export
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
// Export specific bounding box
|
|
312
|
+
const image = await map.export({
|
|
313
|
+
bbox: [17.9, 53.9, 18.1, 54.1], // [west, south, east, north]
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// Download the exported image
|
|
317
|
+
function downloadImage(img: HTMLImageElement, filename: string) {
|
|
318
|
+
const link = document.createElement('a');
|
|
319
|
+
link.download = `${filename}.png`;
|
|
320
|
+
link.href = img.src;
|
|
321
|
+
link.click();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const image = await map.export({ hideControls: true });
|
|
325
|
+
downloadImage(image, 'my-map-export');
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### Export Options
|
|
329
|
+
|
|
330
|
+
| Option | Type | Default | Description |
|
|
331
|
+
|--------|------|---------|-------------|
|
|
332
|
+
| `hideControls` | `boolean` | `false` | Hide map controls in the exported image |
|
|
333
|
+
| `hideMarkers` | `boolean` | `false` | Hide markers in the exported image |
|
|
334
|
+
| `hidePopups` | `boolean` | `false` | Hide popups in the exported image |
|
|
335
|
+
| `bbox` | `[number, number, number, number]` | - | Bounding box to export `[west, south, east, north]` |
|
|
336
|
+
|
|
337
|
+
### Export Control Options
|
|
338
|
+
|
|
339
|
+
The `MapkaExportControl` accepts all export options plus:
|
|
340
|
+
|
|
341
|
+
| Option | Type | Default | Description |
|
|
342
|
+
|--------|------|---------|-------------|
|
|
343
|
+
| `filename` | `string` | `'map-export'` | Filename for the downloaded PNG (without extension) |
|