@maptiler/sdk 4.2.0-rc.1 → 5.0.0-beta.m-r.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.
- package/README.md +276 -30
- package/dist/ImageViewer/ImageViewer.d.ts +6 -8
- package/dist/ImageViewer/ImageViewerMarker.d.ts +9 -9
- package/dist/ImageViewer/monkeyPatchML.d.ts +1 -1
- package/dist/Map.d.ts +155 -11
- package/dist/Marker/Marker.d.ts +397 -0
- package/dist/Marker/MarkerManager.d.ts +137 -0
- package/dist/Marker/altitude-math.d.ts +24 -0
- package/dist/Marker/collision-helpers.d.ts +160 -0
- package/dist/Marker/index.d.ts +2 -0
- package/dist/Marker/marker-adaptive-colors.d.ts +35 -0
- package/dist/Marker/marker-animation-presets.d.ts +60 -0
- package/dist/Marker/marker-constants.d.ts +111 -0
- package/dist/Marker/marker-content-registry.d.ts +17 -0
- package/dist/Marker/marker-dom-utils.d.ts +66 -0
- package/dist/Marker/marker-icons.d.ts +31 -0
- package/dist/Marker/marker-state-helpers.d.ts +2 -0
- package/dist/Marker/marker-svg-config.d.ts +84 -0
- package/dist/Marker/marker-symbols.d.ts +12 -0
- package/dist/Marker/marker-text-fit.d.ts +20 -0
- package/dist/Marker/marker-transitions.d.ts +29 -0
- package/dist/Marker/types.d.ts +458 -0
- package/dist/bundler/maplibre-gl-worker.mjs +13839 -0
- package/dist/bundler/next-worker.mjs +16 -0
- package/dist/bundler/next.cjs +42 -0
- package/dist/bundler/next.d.ts +6 -0
- package/dist/bundler/next.mjs +48 -0
- package/dist/bundler/side-effect.d.ts +2 -0
- package/dist/bundler/vite-worker.mjs +11 -0
- package/dist/bundler/webpack-worker.mjs +11 -0
- package/dist/config.d.ts +18 -0
- package/dist/constants/defaults.d.ts +0 -5
- package/dist/controls/MaptilerGeolocateControl.d.ts +1 -1
- package/dist/controls/MaptilerLogoControl.d.ts +1 -2
- package/dist/controls/MaptilerNavigationControl.d.ts +3 -4
- package/dist/controls/Minimap.d.ts +3 -3
- package/dist/eslint.mjs +4 -4
- package/dist/index.d.ts +9 -81
- package/dist/mapstyle.d.ts +11 -3
- package/dist/maptiler-sdk.css +108 -1
- package/dist/maptiler-sdk.d.ts +1 -1
- package/dist/maptiler-sdk.mjs +16763 -14351
- package/dist/maptiler-sdk.mjs.map +1 -1
- package/dist/routing.d.ts +1 -1
- package/dist/tools.d.ts +6 -7
- package/dist/utils/defaultWorkerUrl.d.ts +17 -0
- package/dist/utils/object.d.ts +1 -0
- package/package.json +26 -8
- package/dist/MLAdapters/AttributionControl.d.ts +0 -5
- package/dist/MLAdapters/BoxZoomHandler.d.ts +0 -7
- package/dist/MLAdapters/CanvasSource.d.ts +0 -5
- package/dist/MLAdapters/CooperativeGesturesHandler.d.ts +0 -5
- package/dist/MLAdapters/FullscreenControl.d.ts +0 -5
- package/dist/MLAdapters/GeoJSONSource.d.ts +0 -5
- package/dist/MLAdapters/GeolocateControl.d.ts +0 -5
- package/dist/MLAdapters/ImageSource.d.ts +0 -5
- package/dist/MLAdapters/KeyboardHandler.d.ts +0 -5
- package/dist/MLAdapters/LogoControl.d.ts +0 -5
- package/dist/MLAdapters/MapMouseEvent.d.ts +0 -5
- package/dist/MLAdapters/MapTouchEvent.d.ts +0 -5
- package/dist/MLAdapters/MapWheelEvent.d.ts +0 -5
- package/dist/MLAdapters/Marker.d.ts +0 -5
- package/dist/MLAdapters/NavigationControl.d.ts +0 -5
- package/dist/MLAdapters/Popup.d.ts +0 -5
- package/dist/MLAdapters/RasterDEMTileSource.d.ts +0 -5
- package/dist/MLAdapters/RasterTileSource.d.ts +0 -5
- package/dist/MLAdapters/ScaleControl.d.ts +0 -5
- package/dist/MLAdapters/ScrollZoomHandler.d.ts +0 -5
- package/dist/MLAdapters/Style.d.ts +0 -5
- package/dist/MLAdapters/TerrainControl.d.ts +0 -5
- package/dist/MLAdapters/TwoFingersTouchPitchHandler.d.ts +0 -5
- package/dist/MLAdapters/VectorTileSource.d.ts +0 -5
- package/dist/MLAdapters/VideoSource.d.ts +0 -5
- package/dist/ml-types.d.ts +0 -638
package/README.md
CHANGED
|
@@ -47,7 +47,72 @@ In addition, the MapTiler SDK JS provides well-documented and easy-to-use wrappe
|
|
|
47
47
|
npm install --save @maptiler/sdk
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
⚠️ Please keep in mind that if you use any additional [MapTiler modules](https://docs.maptiler.com/sdk-js/modules/), you must update them to a version that supports MapTiler SDK JS
|
|
50
|
+
⚠️ Please keep in mind that if you use any additional [MapTiler modules](https://docs.maptiler.com/sdk-js/modules/), you must update them to a version that supports MapTiler SDK JS v5.
|
|
51
|
+
|
|
52
|
+
### Setting up the map worker with a bundler
|
|
53
|
+
|
|
54
|
+
Since MapLibre GL JS v6, the map runs its background worker from separate files that most bundlers don't pick up on their own.
|
|
55
|
+
|
|
56
|
+
By default, the SDK installed from npm loads the worker from the MapTiler CDN (`https://cdn.maptiler.com/maptiler-sdk-js/v<VERSION>/`), which works with any bundler. If your site uses a Content Security Policy, it needs `worker-src 'self' blob: https://cdn.maptiler.com`.
|
|
57
|
+
|
|
58
|
+
To bundle the worker with your app instead (e.g. for offline or intranet use, or a stricter CSP), import the helper for your bundler once, before creating a map:
|
|
59
|
+
|
|
60
|
+
**Vite**
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import "@maptiler/sdk/vite-worker";
|
|
64
|
+
import { Map } from "@maptiler/sdk";
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
For the Vite dev server, also exclude the helper from dependency pre-bundling:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
// vite.config.ts
|
|
71
|
+
import { defineConfig } from "vite";
|
|
72
|
+
|
|
73
|
+
export default defineConfig({
|
|
74
|
+
optimizeDeps: { exclude: ["@maptiler/sdk/vite-worker"] },
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**webpack 5 / rspack**
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import "@maptiler/sdk/webpack-worker";
|
|
82
|
+
import { Map } from "@maptiler/sdk";
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Next.js** (Turbopack and webpack)
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
// next.config.mjs (or `require("@maptiler/sdk/next")` in next.config.js)
|
|
89
|
+
import { withMaptilerWorker } from "@maptiler/sdk/next";
|
|
90
|
+
|
|
91
|
+
export default withMaptilerWorker({
|
|
92
|
+
// your Next.js config
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
// the client component creating the map
|
|
98
|
+
"use client";
|
|
99
|
+
import "@maptiler/sdk/next-worker";
|
|
100
|
+
import { Map } from "@maptiler/sdk";
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`withMaptilerWorker` copies the worker files into `public/_maptiler/` on every `next dev` and `next build`, you may want to add that folder to your `.gitignore`.
|
|
104
|
+
|
|
105
|
+
**Other setups**
|
|
106
|
+
|
|
107
|
+
Copy `node_modules/@maptiler/sdk/dist/bundler/maplibre-gl-worker.mjs` into your build output (it is self-contained, and works the same with npm, yarn or pnpm), and set the worker URL before creating a map:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { setWorkerUrl } from "@maptiler/sdk";
|
|
111
|
+
|
|
112
|
+
setWorkerUrl("/path/to/maplibre-gl-worker.mjs");
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### From CDN
|
|
51
116
|
|
|
52
117
|
From CDN and using the UMD bundle, in the `<head></head>` section of your HTML file:
|
|
53
118
|
|
|
@@ -107,37 +172,20 @@ import "@maptiler/sdk/dist/maptiler-sdk.css";
|
|
|
107
172
|
|
|
108
173
|
#### TypeScript
|
|
109
174
|
|
|
110
|
-
The SDK is fully typed,
|
|
175
|
+
The SDK is fully typed, including the types re-exported from MapLibre GL JS.
|
|
111
176
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
1. **With `esModuleInterop`**
|
|
115
|
-
|
|
116
|
-
Set the following in your `tsconfig.json`:
|
|
117
|
-
|
|
118
|
-
```js
|
|
119
|
-
{
|
|
120
|
-
"compilerOptions": {
|
|
121
|
-
// ...
|
|
122
|
-
"esModuleInterop": true,
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
2. **With `moduleResolution`**
|
|
128
|
-
|
|
129
|
-
Set the following in your `tsconfig.json`:
|
|
177
|
+
The SDK is an ES module whose entry points (such as `@maptiler/sdk/next`) are declared with `package.json` `exports`. TypeScript only reads `exports` with a modern module resolution, so set one of the following in your `tsconfig.json`:
|
|
130
178
|
|
|
131
179
|
```js
|
|
132
180
|
{
|
|
133
181
|
"compilerOptions": {
|
|
134
182
|
// ...
|
|
135
|
-
"moduleResolution": "Bundler",
|
|
183
|
+
"moduleResolution": "Bundler", // or "Node16" / "NodeNext"
|
|
136
184
|
}
|
|
137
185
|
}
|
|
138
186
|
```
|
|
139
187
|
|
|
140
|
-
|
|
188
|
+
With the legacy `"moduleResolution": "Node"` (or `"Node10"`), the main `@maptiler/sdk` types still resolve, but the entry points under `@maptiler/sdk/...` don't get types.
|
|
141
189
|
|
|
142
190
|
### With CDN
|
|
143
191
|
|
|
@@ -163,13 +211,13 @@ The SDK hosted on our CDN is bundled as _[Universal Module Definition](https://g
|
|
|
163
211
|
</style>
|
|
164
212
|
|
|
165
213
|
<!-- Load the SDK CSS -->
|
|
166
|
-
<link rel="stylesheet" href="
|
|
214
|
+
<link rel="stylesheet" href="build/maptiler-sdk.css" />
|
|
167
215
|
</head>
|
|
168
216
|
|
|
169
217
|
<body>
|
|
170
218
|
<div id="map-container"></div>
|
|
171
219
|
|
|
172
|
-
<script src="
|
|
220
|
+
<script src="build/maptiler-sdk.umd.min.js"></script>
|
|
173
221
|
|
|
174
222
|
<script>
|
|
175
223
|
// Add your MapTiler API key to the config
|
|
@@ -190,6 +238,30 @@ The SDK hosted on our CDN is bundled as _[Universal Module Definition](https://g
|
|
|
190
238
|
|
|
191
239
|
Check out the minimalist code samples in the [demos](demos) directory.
|
|
192
240
|
|
|
241
|
+
#### Map worker files and Content Security Policy (CSP)
|
|
242
|
+
|
|
243
|
+
Since MapLibre GL JS v6, the map loads its background worker as two separate files, `maplibre-gl-worker.mjs` and `maplibre-gl-shared.mjs`. The UMD bundle looks for them in the same folder as `maptiler-sdk.umd.min.js`. Our CDN serves them there, so when using the CDN without a CSP, there is nothing to set up.
|
|
244
|
+
|
|
245
|
+
If you **self-host the UMD bundle**, copy both `.mjs` files next to `maptiler-sdk.umd.min.js`. They must be served with a JavaScript content type (e.g. `text/javascript`).
|
|
246
|
+
|
|
247
|
+
If your site uses a **Content Security Policy**, the worker needs to be allowed:
|
|
248
|
+
|
|
249
|
+
- **SDK loaded from our CDN**: since the worker comes from another origin, it is started through a `blob:` URL that then loads the worker from the CDN, so both must be allowed. `blob:` alone is not enough:
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
worker-src 'self' blob: https://cdn.maptiler.com;
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
- **CSP that cannot allow `blob:`**: host `maplibre-gl-worker.mjs` and `maplibre-gl-shared.mjs` on your own origin (in the same folder) and point the SDK to the worker before creating any map. Then `worker-src 'self'` is enough:
|
|
256
|
+
|
|
257
|
+
```html
|
|
258
|
+
<script>
|
|
259
|
+
maptilersdk.setWorkerUrl("/path/to/maplibre-gl-worker.mjs");
|
|
260
|
+
</script>
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
`setWorkerUrl` is also needed if the UMD bundle is not loaded with a regular `<script src="...">` tag (e.g. concatenated into another file or loaded with AMD/RequireJS), since the worker location is then no longer known.
|
|
264
|
+
|
|
193
265
|
<br>
|
|
194
266
|
|
|
195
267
|
## 💡 Related Examples
|
|
@@ -1048,12 +1120,9 @@ Here is a sample of some compatible languages:
|
|
|
1048
1120
|
|
|
1049
1121
|
#### Built-in support for right-to-left languages
|
|
1050
1122
|
|
|
1051
|
-
Languages that are written right-to-left such as Arabic and Hebrew are fully supported by default.
|
|
1052
|
-
|
|
1053
|
-
If you wish to opt of applying the rtl plugin or wish to use a different compatible rtl text plugin, you can pass the `rtlTextPlugin`
|
|
1054
|
-
constructor option as either `false` (disable the rtl plugin) or a url to load a different plugin.
|
|
1123
|
+
Languages that are written right-to-left such as Arabic and Hebrew, as well as complex scripts such as Devanagari, Khmer or Burmese, are fully supported by default. MapLibre shapes them natively, no need to install any plugins!
|
|
1055
1124
|
|
|
1056
|
-
|
|
1125
|
+
If you still need a custom RTL text plugin, `setRTLTextPlugin` is re-exported from MapLibre. Note that it is deprecated by MapLibre and a plugin *replaces* the built-in shaping.
|
|
1057
1126
|
|
|
1058
1127
|
<p align="center">
|
|
1059
1128
|
<img src="images/screenshots/lang-arabic.jpeg" width="48%"></img>
|
|
@@ -1337,6 +1406,182 @@ When defining a new _ramp_, the colors can be an RGB array (`[number, number, nu
|
|
|
1337
1406
|
|
|
1338
1407
|
Many methods are available on color ramps, such as getting the `<canvas>` element of it, rescaling it, flipping it or [resampling it in a non-linear way](colorramp.md). Read more on [our reference page](https://docs.maptiler.com/sdk-js/api/color-ramp/) and have a look at our [examples](https://docs.maptiler.com/sdk-js/examples/?q=colorramp) to see how they work.
|
|
1339
1408
|
|
|
1409
|
+
### Markers
|
|
1410
|
+
|
|
1411
|
+
The SDK's `Marker` is designed for MapTiler maps. It is built on the MapLibre marker and adds built-in shapes and sizes, colours that follow the active MapTiler style, collision handling, interaction states, transitions and animations.
|
|
1412
|
+
|
|
1413
|
+
#### Adding markers
|
|
1414
|
+
|
|
1415
|
+
Create a marker, give it a position, and add it through the map. Markers added this way take part in collision handling and follow the style's colours:
|
|
1416
|
+
|
|
1417
|
+
```ts
|
|
1418
|
+
import { Map, Marker } from "@maptiler/sdk";
|
|
1419
|
+
|
|
1420
|
+
const marker = new Marker({ lngLat: [8.54, 47.37], shape: "bubble-circle", size: "m", content: "A1" });
|
|
1421
|
+
map.addMarker(marker);
|
|
1422
|
+
|
|
1423
|
+
// or straight from options
|
|
1424
|
+
map.addMarker({ lngLat: [8.55, 47.38], shape: "circle" });
|
|
1425
|
+
map.addMarkers([
|
|
1426
|
+
{ lngLat: [8.53, 47.36], shape: "square" },
|
|
1427
|
+
new Marker({ shape: "circle" }).setLngLat([8.56, 47.39]),
|
|
1428
|
+
]);
|
|
1429
|
+
|
|
1430
|
+
map.getMarker(marker.id);
|
|
1431
|
+
map.getMarkers();
|
|
1432
|
+
map.removeMarker(marker.id);
|
|
1433
|
+
map.removeMarkers(); // all markers, or pass a list of ids
|
|
1434
|
+
```
|
|
1435
|
+
|
|
1436
|
+
Removing a marker plays its exit animation first, if it has one (see [Animations](#animations)). Pass `{ immediate: true }` to `removeMarker()` or `removeMarkers()` to remove markers straight away.
|
|
1437
|
+
|
|
1438
|
+
> [!WARNING]
|
|
1439
|
+
> `marker.addTo(map)` is deprecated. It now delegates to `map.addMarker(marker)` and logs a one-time warning. Use `map.addMarker()` instead.
|
|
1440
|
+
|
|
1441
|
+
#### Appearance
|
|
1442
|
+
|
|
1443
|
+
```ts
|
|
1444
|
+
const marker = new Marker({
|
|
1445
|
+
shape: "maptiler", // "circle" | "square" | "bubble-circle" | "bubble-square" | "maptiler" | "maptiler-full"
|
|
1446
|
+
size: "l", // "xs" | "s" | "m" | "l"
|
|
1447
|
+
shadow: "soft", // "none" | "soft" | "medium" | "strong"
|
|
1448
|
+
content: "42", // text shown inside the marker
|
|
1449
|
+
outline: true,
|
|
1450
|
+
scale: [1.2, 1.2],
|
|
1451
|
+
title: "Zurich", // native tooltip
|
|
1452
|
+
});
|
|
1453
|
+
```
|
|
1454
|
+
|
|
1455
|
+
The appearance options have matching setters and getters, such as `setShape()`, `setSize()` or `getContent()`.
|
|
1456
|
+
|
|
1457
|
+
Unless you set them, the marker's colours (`innerColor`, `outerColor`, `contentColor` and `outlineColor`) are picked for the current MapTiler style and update when the style changes. A colour you set explicitly stays fixed, and setting it back to `undefined` returns it to the style's colour:
|
|
1458
|
+
|
|
1459
|
+
```ts
|
|
1460
|
+
marker.setInnerColor("#ff5a1f");
|
|
1461
|
+
marker.setInnerColor(undefined); // back to the style's colour
|
|
1462
|
+
```
|
|
1463
|
+
|
|
1464
|
+
Instead of text, a marker can show an image, or any HTML or SVG element, for example one managed by React:
|
|
1465
|
+
|
|
1466
|
+
```ts
|
|
1467
|
+
new Marker({ url: "https://example.com/icon.svg" });
|
|
1468
|
+
new Marker({ element: myElement });
|
|
1469
|
+
```
|
|
1470
|
+
|
|
1471
|
+
With `element`, the shape and size options do not apply. The colour and shadow options are set on the element as CSS custom properties, so its own styles can use them.
|
|
1472
|
+
|
|
1473
|
+
#### Collisions
|
|
1474
|
+
|
|
1475
|
+
By default, markers are always shown even when they overlap. To declutter the map, choose what happens when markers collide. Where markers overlap, the one with the higher `priority` wins:
|
|
1476
|
+
|
|
1477
|
+
```ts
|
|
1478
|
+
// default for every marker on the map
|
|
1479
|
+
map.setMarkerCollisionOptions({ behaviour: "hide-by-priority" });
|
|
1480
|
+
|
|
1481
|
+
// or per marker
|
|
1482
|
+
new Marker({ priority: 10, collisionBehaviour: "minimize-by-priority" });
|
|
1483
|
+
```
|
|
1484
|
+
|
|
1485
|
+
- `always-show`: never hidden (the default)
|
|
1486
|
+
- `hide-by-priority`: hidden behind a higher-priority marker
|
|
1487
|
+
- `minimize-by-priority`: shrinks to a small dot behind a higher-priority marker. `minimizedOptions` changes how the minimized marker looks.
|
|
1488
|
+
|
|
1489
|
+
`setMarkerCollisionOptions()` also sets the `proximityPadding` used for `markerproximity` events and the duration and easing of the hide and show fade. `marker.getCollisionDisplayState()` returns `"visible"`, `"hidden"` or `"minimized"`.
|
|
1490
|
+
|
|
1491
|
+
Markers fire `markeroverlap` and `markerproximity` when other markers start or stop colliding with them:
|
|
1492
|
+
|
|
1493
|
+
```ts
|
|
1494
|
+
marker.on("markeroverlap", ({ entered, exited, current }) => {
|
|
1495
|
+
console.log(`${current.length} markers overlap this one`);
|
|
1496
|
+
});
|
|
1497
|
+
```
|
|
1498
|
+
|
|
1499
|
+
#### Interaction states
|
|
1500
|
+
|
|
1501
|
+
Change a marker's look while it is hovered, focused, pressed or dragged. The marker returns to its own values when the state ends:
|
|
1502
|
+
|
|
1503
|
+
```ts
|
|
1504
|
+
const marker = new Marker({
|
|
1505
|
+
draggable: true,
|
|
1506
|
+
states: {
|
|
1507
|
+
hover: { scale: [1.2, 1.2] },
|
|
1508
|
+
active: { shadow: "strong" },
|
|
1509
|
+
dragging: { opacity: 0.6 },
|
|
1510
|
+
},
|
|
1511
|
+
});
|
|
1512
|
+
|
|
1513
|
+
marker.setUIState("focus", { outline: 3 });
|
|
1514
|
+
```
|
|
1515
|
+
|
|
1516
|
+
#### Transitions
|
|
1517
|
+
|
|
1518
|
+
Ease a property to its new value instead of jumping to it. `position`, `scale`, `rotation` and the four colours can be transitioned, each with `[duration, easing?, delay?]`:
|
|
1519
|
+
|
|
1520
|
+
```ts
|
|
1521
|
+
const marker = new Marker({
|
|
1522
|
+
transitions: {
|
|
1523
|
+
position: [600, "QuadraticInOut"],
|
|
1524
|
+
innerColor: [300],
|
|
1525
|
+
},
|
|
1526
|
+
});
|
|
1527
|
+
|
|
1528
|
+
marker.setLngLat([8.6, 47.4]); // glides to the new position
|
|
1529
|
+
marker.setTransitionForProperty("scale", [200, "CubicOut"]);
|
|
1530
|
+
```
|
|
1531
|
+
|
|
1532
|
+
The `transitionstart` and `transitionend` events report the property being transitioned.
|
|
1533
|
+
|
|
1534
|
+
#### Animations
|
|
1535
|
+
|
|
1536
|
+
Play an animation when a marker is added, loop one while it is on the map, and play another when it is removed:
|
|
1537
|
+
|
|
1538
|
+
```ts
|
|
1539
|
+
const marker = new Marker({
|
|
1540
|
+
animations: {
|
|
1541
|
+
enter: { preset: "drop" }, // "grow" | "drop" | "pop" | "bounce" | "fade"
|
|
1542
|
+
idle: { preset: "pulsescale", iterations: 3 }, // "pulsescale" | "pulseopacity" | "ring" | "bounce"
|
|
1543
|
+
exit: { preset: "fade", duration: 300 }, // "shrink" | "fade" | "pop" | "explode"
|
|
1544
|
+
},
|
|
1545
|
+
});
|
|
1546
|
+
|
|
1547
|
+
map.addMarker(marker); // plays "drop"
|
|
1548
|
+
map.removeMarker(marker.id); // plays "fade", then removes the marker
|
|
1549
|
+
map.removeMarker(marker.id, { immediate: true }); // removes it without the exit animation
|
|
1550
|
+
```
|
|
1551
|
+
|
|
1552
|
+
Each animation also accepts `duration`, `delay`, `easing` and `magnitude`. Instead of a preset, `custom` takes a function called every frame with the animation's progress (`0` to `1`) and the marker. Animations fire events such as `enteranimationstart`, `idleanimationiteration` and `exitanimationend`.
|
|
1553
|
+
|
|
1554
|
+
#### Altitude (experimental)
|
|
1555
|
+
|
|
1556
|
+
Raise a marker above the ground. The marker is placed in 3D, so it stays in the right place as the camera moves, with terrain and under globe projection:
|
|
1557
|
+
|
|
1558
|
+
```ts
|
|
1559
|
+
marker.setAltitude(500); // 500 m above the terrain under the marker
|
|
1560
|
+
marker.setAltitude(1200, { relativeTo: "sea" }); // 1200 m above sea level
|
|
1561
|
+
marker.setAltitude(false); // back on the map surface
|
|
1562
|
+
|
|
1563
|
+
marker.setGroundLine(true); // dashed line from the marker down to the ground
|
|
1564
|
+
```
|
|
1565
|
+
|
|
1566
|
+
Style the ground line with your own CSS on the `maptiler-marker-groundline` class, or add a class of your own with `setGroundLine(true, { className: "my-line" })`.
|
|
1567
|
+
|
|
1568
|
+
#### The MapLibre marker
|
|
1569
|
+
|
|
1570
|
+
Compared with the MapLibre marker:
|
|
1571
|
+
- The `color` option is removed. Use `innerColor`, `outerColor`, `contentColor` and `outlineColor`.
|
|
1572
|
+
- `scale` is a 2D vector, `[x, y]`.
|
|
1573
|
+
- `setRotation()` rotates the marker's shape rather than its container.
|
|
1574
|
+
|
|
1575
|
+
The plain MapLibre marker is still available as `MarkerMLGL`:
|
|
1576
|
+
|
|
1577
|
+
```ts
|
|
1578
|
+
import { MarkerMLGL } from "@maptiler/sdk";
|
|
1579
|
+
|
|
1580
|
+
new MarkerMLGL({ color: "#f00" }).setLngLat([8.54, 47.37]).addTo(map);
|
|
1581
|
+
```
|
|
1582
|
+
|
|
1583
|
+
See `demos/16-maptiler-markers.html` to `demos/20-marker-altitude.html` for examples.
|
|
1584
|
+
|
|
1340
1585
|
### Camera routes and animations
|
|
1341
1586
|
|
|
1342
1587
|
The SDK comes with several classes to help with animations, particularly route animations.
|
|
@@ -1369,7 +1614,8 @@ const marker = new Marker().setLngLat(
|
|
|
1369
1614
|
-7.449346225791231,
|
|
1370
1615
|
39.399728941536836,
|
|
1371
1616
|
)
|
|
1372
|
-
)
|
|
1617
|
+
);
|
|
1618
|
+
map.addMarker(marker);
|
|
1373
1619
|
|
|
1374
1620
|
// TimeUpdate is fired every frame
|
|
1375
1621
|
animation.addEventListener(AnimationEventTypes.TimeUpdate, (e) => {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EaseToOptions, DoubleClickZoomHandler, DragPanHandler, TwoFingersTouchZoomRotateHandler, FlyToOptions, MapOptions, JumpToOptions, ScrollZoomHandler, BoxZoomHandler, KeyboardHandler, CooperativeGesturesHandler, LngLat, MapDataEvent, PointLike } from '..';
|
|
1
|
+
import { EaseToOptions, DoubleClickZoomHandler, DragPanHandler, TwoFingersTouchZoomRotateHandler, FlyToOptions, MapOptions, JumpToOptions, ScrollZoomHandler, BoxZoomHandler, KeyboardHandler, CooperativeGesturesHandler, LngLat, PointLike } from '..';
|
|
3
2
|
import { Map } from '../Map';
|
|
3
|
+
import { Evented } from 'maplibre-gl';
|
|
4
4
|
import { ImageViewerFitImageToBoundsControl } from '../controls/ImageViewerFitImageToBoundsControl';
|
|
5
5
|
import { lngLatToPxInternalSymbolKey, pxToLngLatInternalSymbolKey } from './symbols';
|
|
6
|
-
declare const Evented: typeof MaplibreGL.Evented;
|
|
7
6
|
export type AllowedConstructorOptions = "container" | "apiKey" | "maxZoom" | "minZoom" | "zoom" | "bearing";
|
|
8
7
|
export type ImageViewerFlyToOptions = Omit<FlyToOptions, "pitch"> & {
|
|
9
8
|
center: [number, number];
|
|
@@ -305,18 +304,18 @@ export default class ImageViewer extends Evented {
|
|
|
305
304
|
* Fly to a given center.
|
|
306
305
|
*
|
|
307
306
|
* @param {ImageViewerFlyToOptions} options - The options for the fly to.
|
|
308
|
-
* @param
|
|
307
|
+
* @param eventData - Additional properties merged into the camera events fired by the map, as in MapLibre.
|
|
309
308
|
* @returns {ImageViewer} The ImageViewer instance.
|
|
310
309
|
*/
|
|
311
|
-
flyTo(options: ImageViewerFlyToOptions, eventData?:
|
|
310
|
+
flyTo(options: ImageViewerFlyToOptions, eventData?: Parameters<Map["flyTo"]>[1]): this;
|
|
312
311
|
/**
|
|
313
312
|
* Jump to a given center.
|
|
314
313
|
*
|
|
315
314
|
* @param {ImageViewerJumpToOptions} options - The options for the jump to.
|
|
316
|
-
* @param
|
|
315
|
+
* @param eventData - Additional properties merged into the camera events fired by the map, as in MapLibre.
|
|
317
316
|
* @returns {ImageViewer} The ImageViewer instance.
|
|
318
317
|
*/
|
|
319
|
-
jumpTo(options: ImageViewerJumpToOptions, eventData?:
|
|
318
|
+
jumpTo(options: ImageViewerJumpToOptions, eventData?: Parameters<Map["jumpTo"]>[1]): this;
|
|
320
319
|
/**
|
|
321
320
|
* Set the zoom level.
|
|
322
321
|
*
|
|
@@ -405,4 +404,3 @@ export default class ImageViewer extends Evented {
|
|
|
405
404
|
[lngLatToPxInternalSymbolKey]: (lngLat: LngLat) => [number, number];
|
|
406
405
|
[pxToLngLatInternalSymbolKey]: (px: [number, number]) => LngLat;
|
|
407
406
|
}
|
|
408
|
-
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Alignment, Subscription, MarkerOptions, PointLike, Popup } from '../index';
|
|
2
|
-
import {
|
|
2
|
+
import { Evented, Event as EventML } from 'maplibre-gl';
|
|
3
3
|
import { default as ImageViewer } from './ImageViewer';
|
|
4
|
-
declare const Evented: typeof MapLibreGL.Evented;
|
|
5
4
|
export type ImageViewerMarkerOptions = MarkerOptions & {};
|
|
6
5
|
export interface ImageViewerMarkerInterface {
|
|
7
6
|
on(event: MarkerEventTypes, listener: (e: ImageViewerMarkerEvent) => void): Subscription;
|
|
@@ -28,7 +27,7 @@ export interface ImageViewerMarkerInterface {
|
|
|
28
27
|
toggleClassName(className: string): void;
|
|
29
28
|
togglePopup(): void;
|
|
30
29
|
}
|
|
31
|
-
export declare class ImageViewerMarker extends Evented {
|
|
30
|
+
export declare class ImageViewerMarker extends Evented<ImageViewerMarkerEventType> {
|
|
32
31
|
private viewer;
|
|
33
32
|
private readonly marker;
|
|
34
33
|
private readonly position;
|
|
@@ -67,7 +66,7 @@ export declare class ImageViewerMarker extends Evented {
|
|
|
67
66
|
* @returns {PointLike} The offset of the ImageViewerMarker.
|
|
68
67
|
* @see [PointLike](https://docs.maptiler.com/sdk-js/api/geography/#pointlike)
|
|
69
68
|
*/
|
|
70
|
-
getOffset():
|
|
69
|
+
getOffset(): import('maplibre-gl').Point;
|
|
71
70
|
/**
|
|
72
71
|
* Gets the pitch alignment of the ImageViewerMarker.
|
|
73
72
|
*
|
|
@@ -81,7 +80,7 @@ export declare class ImageViewerMarker extends Evented {
|
|
|
81
80
|
* @returns {Popup} The popup of the ImageViewerMarker.
|
|
82
81
|
* @see [Popup](https://docs.maptiler.com/sdk-js/api/markers/#popup)
|
|
83
82
|
*/
|
|
84
|
-
getPopup():
|
|
83
|
+
getPopup(): Popup;
|
|
85
84
|
/**
|
|
86
85
|
* Gets the rotation of the ImageViewerMarker.
|
|
87
86
|
*
|
|
@@ -108,7 +107,8 @@ export declare class ImageViewerMarker extends Evented {
|
|
|
108
107
|
* @param {Record<string, any>} data - The data to fire the event with.
|
|
109
108
|
* @returns {ImageViewerMarker} The ImageViewerMarker instance.
|
|
110
109
|
*/
|
|
111
|
-
fire(event:
|
|
110
|
+
fire(event: ImageViewerMarkerEvent): this;
|
|
111
|
+
fire(event: MarkerEventTypes, data?: Record<string, any>): this;
|
|
112
112
|
/**
|
|
113
113
|
* Removes an event listener from the ImageViewerMarker.
|
|
114
114
|
*
|
|
@@ -227,9 +227,9 @@ export declare class ImageViewerMarker extends Evented {
|
|
|
227
227
|
}
|
|
228
228
|
declare const MARKER_EVENT_TYPES: readonly ["dragstart", "drag", "dragend"];
|
|
229
229
|
type MarkerEventTypes = (typeof MARKER_EVENT_TYPES)[number];
|
|
230
|
-
export
|
|
231
|
-
|
|
232
|
-
|
|
230
|
+
export type ImageViewerMarkerEventType = Record<MarkerEventTypes, ImageViewerMarkerEvent>;
|
|
231
|
+
export declare class ImageViewerMarkerEvent extends EventML<MarkerEventTypes> {
|
|
232
|
+
target: ImageViewerMarker;
|
|
233
233
|
[key: string]: any;
|
|
234
234
|
constructor(type: MarkerEventTypes, marker: ImageViewerMarker, data: Record<string, any>);
|
|
235
235
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LngLat, Marker, Point, PositionAnchor, TransformConstrainFunction } from '../index';
|
|
1
|
+
import { LngLat, MarkerMLGL as Marker, Point, PositionAnchor, TransformConstrainFunction } from '../index';
|
|
2
2
|
export declare function unprojectFromWorldCoordinates(worldSize: number, point: Point): LngLat;
|
|
3
3
|
export declare const overpanningUnderzoomingTransformConstrain: TransformConstrainFunction;
|
|
4
4
|
export declare const anchorTranslate: Record<PositionAnchor, string>;
|