@mapka/maplibre-gl-sdk 0.12.0 → 0.13.1

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.
Files changed (41) hide show
  1. package/README.md +330 -4
  2. package/lib/.buildInfo.json +1 -1
  3. package/lib/components/DownloadIcon.d.ts +4 -0
  4. package/lib/components/DownloadIcon.d.ts.map +1 -0
  5. package/lib/components/DownloadIcon.js +10 -0
  6. package/lib/components/PopupContent.d.ts.map +1 -1
  7. package/lib/components/ProgressDownIcon.d.ts +4 -0
  8. package/lib/components/ProgressDownIcon.d.ts.map +1 -0
  9. package/lib/components/ProgressDownIcon.js +14 -0
  10. package/lib/constants/styles.d.ts +5 -0
  11. package/lib/constants/styles.d.ts.map +1 -0
  12. package/lib/constants/styles.js +3 -0
  13. package/lib/controls/MapkaExportControl.d.ts +21 -0
  14. package/lib/controls/MapkaExportControl.d.ts.map +1 -0
  15. package/lib/controls/MapkaExportControl.js +76 -0
  16. package/lib/index.d.ts +3 -0
  17. package/lib/index.d.ts.map +1 -1
  18. package/lib/index.js +3 -0
  19. package/lib/map.d.ts +11 -2
  20. package/lib/map.d.ts.map +1 -1
  21. package/lib/map.js +10 -5
  22. package/lib/modules/export.d.ts +4 -0
  23. package/lib/modules/export.d.ts.map +1 -0
  24. package/lib/modules/export.js +40 -0
  25. package/lib/modules/popup.d.ts +2 -2
  26. package/lib/modules/popup.d.ts.map +1 -1
  27. package/lib/modules/popup.js +19 -6
  28. package/lib/types/export.d.ts +7 -0
  29. package/lib/types/export.d.ts.map +1 -0
  30. package/lib/types/export.js +1 -0
  31. package/package.json +3 -2
  32. package/src/components/DownloadIcon.tsx +25 -0
  33. package/src/components/PopupContent.tsx +1 -0
  34. package/src/components/ProgressDownIcon.tsx +29 -0
  35. package/src/constants/styles.ts +5 -0
  36. package/src/controls/MapkaExportControl.tsx +111 -0
  37. package/src/index.ts +6 -0
  38. package/src/map.ts +17 -4
  39. package/src/modules/export.ts +55 -0
  40. package/src/modules/popup.tsx +26 -24
  41. package/src/types/export.ts +6 -0
package/README.md CHANGED
@@ -1,21 +1,347 @@
1
- # React Mapka MapLibre map components
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
- ```tsx
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 mapkasdk.Map({
18
+ const map = new Map({
15
19
  apiKey: 'YOUR_MAPKA_API_KEY_HERE',
16
20
  container: 'map',
17
- style: mapkasdk.MapStyle.STREETS,
21
+ style: MapStyle.MaputnikOSMLiberty,
18
22
  center: [18, 54],
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: MapStyle.MaputnikOSMLiberty,
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 {
259
+ Map,
260
+ MapStyle,
261
+ MapkaExportControl
262
+ } from '@mapka/maplibre-gl-sdk';
263
+
264
+ const map = new Map({
265
+ apiKey: 'YOUR_MAPKA_API_KEY_HERE',
266
+ container: 'map',
267
+ style: MapStyle.MaputnikOSMLiberty,
268
+ center: [18, 54],
269
+ zoom: 14,
270
+ });
271
+
272
+ // Add export control with default options
273
+ map.addControl(new MapkaExportControl());
274
+
275
+ // Or with custom filename
276
+ map.addControl(new MapkaExportControl({
277
+ filename: 'my-custom-map',
278
+ }));
279
+
280
+ // Or with additional export options
281
+ map.addControl(new MapkaExportControl({
282
+ filename: 'clean-map',
283
+ hideControls: true,
284
+ hideMarkers: true,
285
+ hidePopups: true,
286
+ }));
287
+ ```
288
+
289
+ ### Programmatic Export
290
+
291
+ Export the map programmatically using the `export()` method:
292
+
293
+ ```ts
294
+ import "@mapka/maplibre-gl-sdk/styles.css";
295
+ import { Map, MapStyle } from '@mapka/maplibre-gl-sdk';
296
+
297
+ const map = new Map({
298
+ apiKey: 'YOUR_MAPKA_API_KEY_HERE',
299
+ container: 'map',
300
+ style: MapStyle.MaputnikOSMLiberty,
301
+ center: [18, 54],
302
+ zoom: 14,
303
+ });
304
+
305
+ // Basic export - returns an HTMLImageElement
306
+ const image = await map.export();
307
+
308
+ // Export with options
309
+ const image = await map.export({
310
+ hideControls: true, // Hide map controls in export
311
+ hideMarkers: false, // Show markers in export
312
+ hidePopups: false, // Show popups in export
313
+ });
314
+
315
+ // Export specific bounding box
316
+ const image = await map.export({
317
+ bbox: [17.9, 53.9, 18.1, 54.1], // [west, south, east, north]
318
+ });
319
+
320
+ // Download the exported image
321
+ function downloadImage(img: HTMLImageElement, filename: string) {
322
+ const link = document.createElement('a');
323
+ link.download = `${filename}.png`;
324
+ link.href = img.src;
325
+ link.click();
326
+ }
327
+
328
+ const image = await map.export({ hideControls: true });
329
+ downloadImage(image, 'my-map-export');
330
+ ```
331
+
332
+ ### Export Options
333
+
334
+ | Option | Type | Default | Description |
335
+ |--------|------|---------|-------------|
336
+ | `hideControls` | `boolean` | `false` | Hide map controls in the exported image |
337
+ | `hideMarkers` | `boolean` | `false` | Hide markers in the exported image |
338
+ | `hidePopups` | `boolean` | `false` | Hide popups in the exported image |
339
+ | `bbox` | `[number, number, number, number]` | - | Bounding box to export `[west, south, east, north]` |
340
+
341
+ ### Export Control Options
342
+
343
+ The `MapkaExportControl` accepts all export options plus:
344
+
345
+ | Option | Type | Default | Description |
346
+ |--------|------|---------|-------------|
347
+ | `filename` | `string` | `'map-export'` | Filename for the downloaded PNG (without extension) |