@maptiler/sdk 3.3.0-rc2 → 3.4.0-rc2
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/.husky/pre-commit +2 -2
- package/README.md +160 -124
- package/e2e/global.d.ts +12 -0
- package/e2e/public/animated-route.geojson +82 -0
- package/e2e/public/animatedRouteLayer.html +24 -0
- package/e2e/public/mapLoad.html +24 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-0-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-1-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-10-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-11-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-12-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-13-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-14-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-15-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-16-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-17-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-18-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-19-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-2-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-3-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-4-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-5-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-6-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-7-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-8-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-9-chromium-darwin.png +0 -0
- package/e2e/snapshots/tests/map-load.test.ts-snapshots/mapLoad-chromium-darwin.png +0 -0
- package/e2e/tests/AnimatedRouteLayer.test.ts +45 -0
- package/e2e/tests/consts.ts +0 -0
- package/e2e/tests/expected-results/animatedRouteLayer-1.json +202 -0
- package/e2e/tests/helpers/fetchGeojson.ts +21 -0
- package/e2e/tests/helpers/getMapInstanceForFixture.ts +86 -0
- package/e2e/tests/map-load.test.ts +14 -0
- package/e2e/tests/mocks/maptiler-style.json +27 -0
- package/e2e/tests/mocks/tile.png +0 -0
- package/e2e/tsconfig.json +10 -0
- package/eslint.config.mjs +75 -3
- package/package.json +13 -13
- package/playwright.config.ts +82 -0
- package/tsconfig.json +3 -0
- package/typedoc.json +3 -2
- package/vite.config-e2e.ts +13 -0
- package/vite.config-es.ts +3 -2
- package/vite.config-umd.ts +12 -0
- package/dist/eslint.config.d.mts +0 -2
- package/dist/maptiler-sdk.d.ts +0 -2
- package/dist/maptiler-sdk.mjs +0 -11938
- package/dist/maptiler-sdk.mjs.map +0 -1
- package/dist/src/ColorRamp.d.ts +0 -359
- package/dist/src/MLAdapters/AttributionControl.d.ts +0 -5
- package/dist/src/MLAdapters/BoxZoomHandler.d.ts +0 -7
- package/dist/src/MLAdapters/CanvasSource.d.ts +0 -5
- package/dist/src/MLAdapters/CooperativeGesturesHandler.d.ts +0 -5
- package/dist/src/MLAdapters/FullscreenControl.d.ts +0 -5
- package/dist/src/MLAdapters/GeoJSONSource.d.ts +0 -5
- package/dist/src/MLAdapters/GeolocateControl.d.ts +0 -5
- package/dist/src/MLAdapters/ImageSource.d.ts +0 -5
- package/dist/src/MLAdapters/KeyboardHandler.d.ts +0 -5
- package/dist/src/MLAdapters/LogoControl.d.ts +0 -5
- package/dist/src/MLAdapters/MapMouseEvent.d.ts +0 -5
- package/dist/src/MLAdapters/MapTouchEvent.d.ts +0 -5
- package/dist/src/MLAdapters/MapWheelEvent.d.ts +0 -5
- package/dist/src/MLAdapters/Marker.d.ts +0 -5
- package/dist/src/MLAdapters/NavigationControl.d.ts +0 -5
- package/dist/src/MLAdapters/Popup.d.ts +0 -5
- package/dist/src/MLAdapters/RasterDEMTileSource.d.ts +0 -5
- package/dist/src/MLAdapters/RasterTileSource.d.ts +0 -5
- package/dist/src/MLAdapters/ScaleControl.d.ts +0 -5
- package/dist/src/MLAdapters/ScrollZoomHandler.d.ts +0 -5
- package/dist/src/MLAdapters/Style.d.ts +0 -5
- package/dist/src/MLAdapters/TerrainControl.d.ts +0 -5
- package/dist/src/MLAdapters/TwoFingersTouchPitchHandler.d.ts +0 -5
- package/dist/src/MLAdapters/VectorTileSource.d.ts +0 -5
- package/dist/src/MLAdapters/VideoSource.d.ts +0 -5
- package/dist/src/Map.d.ts +0 -422
- package/dist/src/Point.d.ts +0 -177
- package/dist/src/Telemetry.d.ts +0 -21
- package/dist/src/caching.d.ts +0 -4
- package/dist/src/config.d.ts +0 -85
- package/dist/src/constants/defaults.d.ts +0 -15
- package/dist/src/controls/MaptilerGeolocateControl.d.ts +0 -21
- package/dist/src/controls/MaptilerLogoControl.d.ts +0 -19
- package/dist/src/controls/MaptilerNavigationControl.d.ts +0 -17
- package/dist/src/controls/MaptilerProjectionControl.d.ts +0 -14
- package/dist/src/controls/MaptilerTerrainControl.d.ts +0 -16
- package/dist/src/controls/Minimap.d.ts +0 -57
- package/dist/src/controls/index.d.ts +0 -6
- package/dist/src/converters/index.d.ts +0 -1
- package/dist/src/converters/xml.d.ts +0 -54
- package/dist/src/custom-layers/CubemapLayer/CubemapLayer.d.ts +0 -29
- package/dist/src/custom-layers/CubemapLayer/constants.d.ts +0 -3
- package/dist/src/custom-layers/CubemapLayer/index.d.ts +0 -2
- package/dist/src/custom-layers/CubemapLayer/loadCubemapTexture.d.ts +0 -6
- package/dist/src/custom-layers/CubemapLayer/types.d.ts +0 -37
- package/dist/src/custom-layers/RadialGradientLayer/RadialGradientLayer.d.ts +0 -23
- package/dist/src/custom-layers/RadialGradientLayer/index.d.ts +0 -2
- package/dist/src/custom-layers/RadialGradientLayer/types.d.ts +0 -11
- package/dist/src/custom-layers/extractCustomLayerStyle.d.ts +0 -17
- package/dist/src/custom-layers/index.d.ts +0 -5
- package/dist/src/helpers/index.d.ts +0 -13
- package/dist/src/helpers/screenshot.d.ts +0 -18
- package/dist/src/helpers/stylehelper.d.ts +0 -28
- package/dist/src/helpers/vectorlayerhelpers.d.ts +0 -508
- package/dist/src/index.d.ts +0 -87
- package/dist/src/language.d.ts +0 -107
- package/dist/src/mapstyle.d.ts +0 -17
- package/dist/src/tools.d.ts +0 -84
- package/dist/src/types.d.ts +0 -1
- package/dist/src/utils/dom.d.ts +0 -2
- package/dist/src/utils/geo-utils.d.ts +0 -6
- package/dist/src/utils/index.d.ts +0 -1
- package/dist/src/utils/math-utils.d.ts +0 -4
- package/dist/src/utils/webgl-utils.d.ts +0 -49
- package/dist/vite.config-test.d.ts +0 -2
- package/dist/vitest-setup-tests.d.ts +0 -1
package/.husky/pre-commit
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
npx lint-staged;
|
|
2
|
-
|
|
3
|
-
npm run
|
|
2
|
+
npm run test;
|
|
3
|
+
npm run docs;
|
package/README.md
CHANGED
|
@@ -32,7 +32,12 @@ npm install --save @maptiler/sdk
|
|
|
32
32
|
⚠️ 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 v3.
|
|
33
33
|
|
|
34
34
|
# API documentation
|
|
35
|
-
|
|
35
|
+
For further documentation and examples, check out [docs.maptiler.com](https://docs.maptiler.com/sdk-js/api/).
|
|
36
|
+
|
|
37
|
+
Full api typedoc documentation can also be generated via the commands:
|
|
38
|
+
|
|
39
|
+
`npm run docs:md` to generate markdown in `docs`
|
|
40
|
+
`npm run docs:html` to generate html docs in `docs-html`
|
|
36
41
|
|
|
37
42
|
# Quick start
|
|
38
43
|
|
|
@@ -40,30 +45,30 @@ In addition to the details and examples provided in this readme, check out the [
|
|
|
40
45
|
**Recommended for:** advanced applications
|
|
41
46
|
|
|
42
47
|
```ts
|
|
43
|
-
import
|
|
48
|
+
import { config, Map } from '@maptiler/sdk';
|
|
44
49
|
|
|
45
50
|
// Add your MapTiler Cloud API key to the config
|
|
46
51
|
// (Go to https://cloud.maptiler.com/account/keys/ to get one for free!)
|
|
47
|
-
|
|
52
|
+
config.apiKey = 'YOUR_API_KEY';
|
|
48
53
|
|
|
49
54
|
// Let's say you have a DIV ready to receive a map
|
|
50
55
|
const mapContainer = document.getElementById('my-container-div');
|
|
51
56
|
|
|
52
57
|
// Instantiate the map
|
|
53
|
-
const map = new
|
|
58
|
+
const map = new Map({
|
|
54
59
|
container: mapContainer,
|
|
55
60
|
});
|
|
56
61
|
```
|
|
57
62
|
|
|
58
63
|
Alternatively, the `apiKey` can be set as Map option instead of in the `config` object. Yet, this will still internally propagate to the `config` object:
|
|
59
64
|
```ts
|
|
60
|
-
import
|
|
65
|
+
import { Map } from '@maptiler/sdk';
|
|
61
66
|
|
|
62
67
|
// Let's say you have a DIV ready to receive a map
|
|
63
68
|
const mapContainer = document.getElementById('my-container-div');
|
|
64
69
|
|
|
65
70
|
// Instantiate the map
|
|
66
|
-
const map = new
|
|
71
|
+
const map = new Map({
|
|
67
72
|
container: mapContainer,
|
|
68
73
|
apiKey: 'YOUR_API_KEY'
|
|
69
74
|
});
|
|
@@ -540,125 +545,7 @@ map.on("terrainAnimationStop", (e) => {
|
|
|
540
545
|
});
|
|
541
546
|
});
|
|
542
547
|
```
|
|
543
|
-
# Halo and Space Options
|
|
544
|
-
|
|
545
|
-
The `halo` and `space` options allow for enhanced visual customization of the map, especially for globe projections.
|
|
546
|
-
|
|
547
|
-
## `halo` (Atmospheric Glow)
|
|
548
|
-
The `halo` option adds a gradient-based atmospheric glow around the globe, simulating the visual effect of Earth's atmosphere when viewed from space.
|
|
549
|
-
|
|
550
|
-
### Usage:
|
|
551
|
-
You can enable a simple halo by setting it to `true`:
|
|
552
|
-
```ts
|
|
553
|
-
const map = new maptilersdk.Map({
|
|
554
|
-
container: document.getElementById("map"),
|
|
555
|
-
style: maptilersdk.MapStyle.OUTDOOR,
|
|
556
|
-
halo: true,
|
|
557
|
-
});
|
|
558
|
-
```
|
|
559
|
-
For more customization, you can define a radial gradient with scale and stops:
|
|
560
|
-
```ts
|
|
561
548
|
|
|
562
|
-
const map = new maptilersdk.Map({
|
|
563
|
-
container: document.getElementById("map"),
|
|
564
|
-
style: maptilersdk.MapStyle.OUTDOOR,
|
|
565
|
-
halo: {
|
|
566
|
-
scale: 1.5, // Controls the halo size
|
|
567
|
-
stops: [
|
|
568
|
-
[0.2, "transparent"],
|
|
569
|
-
[0.2, "red"],
|
|
570
|
-
[0.4, "red"],
|
|
571
|
-
[0.4, "transparent"],
|
|
572
|
-
[0.6, "transparent"],
|
|
573
|
-
[0.6, "red"],
|
|
574
|
-
[0.8, "red"],
|
|
575
|
-
[0.8, "transparent"],
|
|
576
|
-
[1.0, "transparent"],
|
|
577
|
-
],
|
|
578
|
-
},
|
|
579
|
-
});
|
|
580
|
-
```
|
|
581
|
-
You can also set the halo dynamically after the map loads:
|
|
582
|
-
```ts
|
|
583
|
-
map.on("load", () => {
|
|
584
|
-
map.setHalo({
|
|
585
|
-
scale: 2,
|
|
586
|
-
stops: [
|
|
587
|
-
[0.0, "rgba(135,206,250,1)"],
|
|
588
|
-
[0.5, "rgba(0,0,250,0.75)"],
|
|
589
|
-
[0.75, "rgba(250,0,0,0.0)"],
|
|
590
|
-
],
|
|
591
|
-
});
|
|
592
|
-
});
|
|
593
|
-
```
|
|
594
|
-
## `space` (Background Environment)
|
|
595
|
-
|
|
596
|
-
The space option allows customizing the background environment of the globe, simulating deep space or skybox effects.
|
|
597
|
-
### Usage
|
|
598
|
-
|
|
599
|
-
You can enable a simple space background with a solid color:
|
|
600
|
-
```ts
|
|
601
|
-
const map = new maptilersdk.Map({
|
|
602
|
-
container: document.getElementById("map"),
|
|
603
|
-
style: maptilersdk.MapStyle.OUTDOOR,
|
|
604
|
-
space: {
|
|
605
|
-
color: "#111122", // Dark space-like color
|
|
606
|
-
},
|
|
607
|
-
});
|
|
608
|
-
```
|
|
609
|
-
Alternatively, you can provide a cubemap for a realistic skybox effect using one of the following methods:
|
|
610
|
-
|
|
611
|
-
Predefined Presets:
|
|
612
|
-
```ts
|
|
613
|
-
const map = new maptilersdk.Map({
|
|
614
|
-
container: document.getElementById("map"),
|
|
615
|
-
style: maptilersdk.MapStyle.OUTDOOR,
|
|
616
|
-
space: {
|
|
617
|
-
preset: "universe-dark",
|
|
618
|
-
},
|
|
619
|
-
});
|
|
620
|
-
```
|
|
621
|
-
Cubemap Images (Custom Skybox):
|
|
622
|
-
```ts
|
|
623
|
-
const map = new maptilersdk.Map({
|
|
624
|
-
container: document.getElementById("map"),
|
|
625
|
-
style: maptilersdk.MapStyle.OUTDOOR,
|
|
626
|
-
space: {
|
|
627
|
-
faces: {
|
|
628
|
-
pX: '/path-to-image/pX.png',
|
|
629
|
-
nX: '/path-to-image/nX.png',
|
|
630
|
-
pY: '/path-to-image/pY.png',
|
|
631
|
-
nY: '/path-to-image/nY.png',
|
|
632
|
-
pZ: '/path-to-image/pZ.png',
|
|
633
|
-
nZ: '/path-to-image/nZ.png',
|
|
634
|
-
},
|
|
635
|
-
},
|
|
636
|
-
});
|
|
637
|
-
```
|
|
638
|
-
Cubemap Path with image format, fetches all images from a path, this assumes all files are named px, nx, py, ny, pz, nz and suffixed with the appropriate extension specified in `format`.
|
|
639
|
-
```ts
|
|
640
|
-
const map = new maptilersdk.Map({
|
|
641
|
-
container: document.getElementById("map"),
|
|
642
|
-
style: maptilersdk.MapStyle.OUTDOOR,
|
|
643
|
-
space: {
|
|
644
|
-
path: {
|
|
645
|
-
baseUrl: "spacebox/transparent",
|
|
646
|
-
format: "png", // Defaults to PNG
|
|
647
|
-
},
|
|
648
|
-
},
|
|
649
|
-
});
|
|
650
|
-
```
|
|
651
|
-
You can also set the space background dynamically:
|
|
652
|
-
```ts
|
|
653
|
-
map.on("load", () => {
|
|
654
|
-
map.setSpace({
|
|
655
|
-
color: "red",
|
|
656
|
-
path: {
|
|
657
|
-
baseUrl: "spacebox/transparent",
|
|
658
|
-
},
|
|
659
|
-
});
|
|
660
|
-
});
|
|
661
|
-
```
|
|
662
549
|
|
|
663
550
|
# Easy language switching
|
|
664
551
|
The language generally depends on the style but we made it possible to easily set and update from a built-in list of languages.
|
|
@@ -1227,6 +1114,155 @@ Turning off *zoom compensation* allows for more accurate adjustments to the visu
|
|
|
1227
1114
|
All the other options are documented on [our reference page](https://docs.maptiler.com/sdk-js/api/helpers/#heatmap) and more examples are available [here](https://docs.maptiler.com/sdk-js/examples/?q=heatmap+helper).
|
|
1228
1115
|
|
|
1229
1116
|
# Other helpers
|
|
1117
|
+
|
|
1118
|
+
## Camera routes and animations
|
|
1119
|
+
|
|
1120
|
+
The SDK comes with several classes to help with animations, particularly route animations.
|
|
1121
|
+
|
|
1122
|
+
See `demos/07-animated-routes.html` for examples.
|
|
1123
|
+
|
|
1124
|
+
### 🧩 `MaptilerAnimation`
|
|
1125
|
+
|
|
1126
|
+
MaptilerAnimation is a utility class for smoothly animating between keyframes using custom easing and playback control. It supports event-based hooks for frame updates and completion, and works well within rendering loops or UI transitions.
|
|
1127
|
+
|
|
1128
|
+
#### 🚀 Usage
|
|
1129
|
+
|
|
1130
|
+
```ts
|
|
1131
|
+
// linearly animated between values
|
|
1132
|
+
const animation = new MaptilerAnimation({
|
|
1133
|
+
keyframes: [
|
|
1134
|
+
// `props` are interpolated across the duration
|
|
1135
|
+
{ delta: 0, props: { lon: -7.445, } },
|
|
1136
|
+
// `userData` can hold any type of custom data to pass with the keyframe
|
|
1137
|
+
{ delta: 0.5, userData: { mydata: "whoa!" } },
|
|
1138
|
+
{ delta: 1, props: { lon: -7.455 } }
|
|
1139
|
+
],
|
|
1140
|
+
duration: 1000, // 1 second
|
|
1141
|
+
iterations: Infinity // loop forever
|
|
1142
|
+
});
|
|
1143
|
+
|
|
1144
|
+
const marker = new Marker().setLngLat(
|
|
1145
|
+
new LngLat(
|
|
1146
|
+
-7.449346225791231,
|
|
1147
|
+
39.399728941536836,
|
|
1148
|
+
)
|
|
1149
|
+
).addTo(map);
|
|
1150
|
+
|
|
1151
|
+
// TimeUpdate is fired every frame
|
|
1152
|
+
animation.addEventListener(AnimationEventTypes.TimeUpdate, (e) => {
|
|
1153
|
+
marker.setLngLat(
|
|
1154
|
+
new LngLat(
|
|
1155
|
+
e.props.lon,
|
|
1156
|
+
39.399728941536836,
|
|
1157
|
+
)
|
|
1158
|
+
)
|
|
1159
|
+
})
|
|
1160
|
+
// fired when the keyframe changes
|
|
1161
|
+
animation.addEventListener(AnimationEventTypes.Keyframe, ({ userData }) => {
|
|
1162
|
+
console.log(userData.mydata) // "whoa!"
|
|
1163
|
+
});
|
|
1164
|
+
|
|
1165
|
+
animation.play();
|
|
1166
|
+
```
|
|
1167
|
+

|
|
1168
|
+
|
|
1169
|
+
```ts
|
|
1170
|
+
// eased between values
|
|
1171
|
+
const animation = new MaptilerAnimation({
|
|
1172
|
+
keyframes: [
|
|
1173
|
+
// `props` are interpolated across the duration
|
|
1174
|
+
{ delta: 0, easing: EasingFunctionName.ElasticInOut, props: { lon: -7.445, } },
|
|
1175
|
+
{ delta: 1, props: { lon: -7.455 } }
|
|
1176
|
+
],
|
|
1177
|
+
duration: 1000, // 1 second
|
|
1178
|
+
iterations: Infinity // loop forever
|
|
1179
|
+
});
|
|
1180
|
+
```
|
|
1181
|
+

|
|
1182
|
+
|
|
1183
|
+
### 🗺️ `AnimatedRouteLayer`
|
|
1184
|
+
|
|
1185
|
+
`AnimatedRouteLayer` is custom layer that animates a path or route on the map based on keyframes or GeoJSON data. It supports animated line styling and camera following, making it ideal for visualizing routes, playback tracks, or timeline-based geographic events.
|
|
1186
|
+
|
|
1187
|
+
Note: At present, to avoid problems arising from the camera being manipulated by two animatioons at any one time, there can only ever be one instance of `AnimatedRouteLayer` on the map at any time. This API may change in the future, but at present you must remove each instance of `AnimatedRouteLayer` from the map before adding another.
|
|
1188
|
+
|
|
1189
|
+
#### ✨ Features
|
|
1190
|
+
- Animate a path using keyframes or GeoJSON data
|
|
1191
|
+
- Optional animated stroke styles to indicate progress
|
|
1192
|
+
- Camera movement smoothing, following along the route
|
|
1193
|
+
- Configurable duration, easing, delay, and iterations via geojson properties
|
|
1194
|
+
- Event-based lifecycle hooks for adaptibility.
|
|
1195
|
+
- Optional manual frame advancement (e.g., for scrubbing or syncing with map events, scroll etc etc)
|
|
1196
|
+
|
|
1197
|
+
#### 🚀 Basic Usage
|
|
1198
|
+
```ts
|
|
1199
|
+
const myGeoJSONSource = {
|
|
1200
|
+
"type": "FeatureCollection",
|
|
1201
|
+
"features": [
|
|
1202
|
+
{
|
|
1203
|
+
"type": "Feature",
|
|
1204
|
+
"geometry": {
|
|
1205
|
+
"type": "LineString",
|
|
1206
|
+
"coordinates": [
|
|
1207
|
+
[-74.0060, 40.7128],
|
|
1208
|
+
[-73.9352, 40.7306],
|
|
1209
|
+
[-73.9851, 40.7580]
|
|
1210
|
+
]
|
|
1211
|
+
},
|
|
1212
|
+
"properties": {
|
|
1213
|
+
"@duration": 5000, // animation params are prepended with '@'
|
|
1214
|
+
"@iterations": 3,
|
|
1215
|
+
"@delay": 1000,
|
|
1216
|
+
"@autoplay": true,
|
|
1217
|
+
"bearing": [
|
|
1218
|
+
40,
|
|
1219
|
+
30,
|
|
1220
|
+
10,
|
|
1221
|
+
10,
|
|
1222
|
+
20,
|
|
1223
|
+
40,
|
|
1224
|
+
]
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
]
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
const animatedRoute = new AnimatedRouteLayer({
|
|
1231
|
+
source: {
|
|
1232
|
+
// assumes that the source is already added to the map with the given layer ID
|
|
1233
|
+
id: "my-geojson-source", // the name of the source
|
|
1234
|
+
layerID: "route-layer", // the name of the layer
|
|
1235
|
+
featureSetIndex: 0, // the index of the featureset within the geojson
|
|
1236
|
+
},
|
|
1237
|
+
// OR
|
|
1238
|
+
keyframes: [], // an array of keyframes
|
|
1239
|
+
|
|
1240
|
+
duration: 5000,
|
|
1241
|
+
pathStrokeAnimation: {
|
|
1242
|
+
// will only be appliued to LineString GeoJSON types
|
|
1243
|
+
activeColor: [0, 128, 0, 1], // color of the line that has already been traversed
|
|
1244
|
+
inactiveColor: [128, 128, 128, 0.5],
|
|
1245
|
+
},
|
|
1246
|
+
cameraAnimation: {
|
|
1247
|
+
follow: true, // should the camera follow the route?
|
|
1248
|
+
pathSmoothing: {
|
|
1249
|
+
resolution: 20, // the resolution of the smoothness
|
|
1250
|
+
epsilon: 10, // how much the path is simplified before smoothing
|
|
1251
|
+
},
|
|
1252
|
+
},
|
|
1253
|
+
autoplay: true,
|
|
1254
|
+
});
|
|
1255
|
+
|
|
1256
|
+
// Add to map
|
|
1257
|
+
map.addLayer(animatedRoute);
|
|
1258
|
+
|
|
1259
|
+
// Playback controls
|
|
1260
|
+
animatedRoute.play();
|
|
1261
|
+
animatedRoute.pause();
|
|
1262
|
+
```
|
|
1263
|
+
|
|
1264
|
+
For a full example of how to use this, look at [the example](./demos/07-animated-routes.html)
|
|
1265
|
+
|
|
1230
1266
|
## Convert GPX and KML to GeoJSON
|
|
1231
1267
|
In the [Polyline helper section](#polyline-layer-helper) above, we have seen that one can feed the helper directly with a path to a GPX or KML file, that is then converted under the hood client-side into a GeoJSON `FeatureCollection` object. This conversion feature is also exposed and can be used as such:
|
|
1232
1268
|
|
package/e2e/global.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Map } from "@maptiler/sdk";
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
__map: Map;
|
|
6
|
+
__pageLoadTimeout: number;
|
|
7
|
+
notifyScreenshotStateReady: (data: TTestTransferData) => Promise<void>;
|
|
8
|
+
__pageObjects: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type TTestTransferData = string | number | boolean | string[] | number[] | boolean[] | null | Record<string, unknown> | [number, number];
|
|
12
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "FeatureCollection",
|
|
3
|
+
"features": [
|
|
4
|
+
{
|
|
5
|
+
"type": "Feature",
|
|
6
|
+
"properties": {
|
|
7
|
+
"pitch": [
|
|
8
|
+
30,
|
|
9
|
+
40,
|
|
10
|
+
50,
|
|
11
|
+
60,
|
|
12
|
+
50,
|
|
13
|
+
40,
|
|
14
|
+
30
|
|
15
|
+
],
|
|
16
|
+
"bearing": [
|
|
17
|
+
0,
|
|
18
|
+
180,
|
|
19
|
+
360
|
|
20
|
+
],
|
|
21
|
+
"zoom": [
|
|
22
|
+
13.5,
|
|
23
|
+
14,
|
|
24
|
+
14.5,
|
|
25
|
+
15,
|
|
26
|
+
14.5,
|
|
27
|
+
14,
|
|
28
|
+
13.5
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"geometry": {
|
|
32
|
+
"coordinates": [
|
|
33
|
+
[
|
|
34
|
+
-5.513465218122661,
|
|
35
|
+
55.44452556522981
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
-5.498757996681263,
|
|
39
|
+
55.45488849896259
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
-5.4776627901701715,
|
|
43
|
+
55.459774141237716
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
-5.450773829757111,
|
|
47
|
+
55.45446729456921
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
-5.434581030391769,
|
|
51
|
+
55.44241894502119
|
|
52
|
+
],
|
|
53
|
+
[
|
|
54
|
+
-5.434433020938883,
|
|
55
|
+
55.42337006037573
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
-5.447655667245527,
|
|
59
|
+
55.40895140980018
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
-5.474692405196635,
|
|
63
|
+
55.40169789075969
|
|
64
|
+
],
|
|
65
|
+
[
|
|
66
|
+
-5.504997423959253,
|
|
67
|
+
55.410637475280794
|
|
68
|
+
],
|
|
69
|
+
[
|
|
70
|
+
-5.520595992154796,
|
|
71
|
+
55.42809094495976
|
|
72
|
+
],
|
|
73
|
+
[
|
|
74
|
+
-5.513910891499705,
|
|
75
|
+
55.44393572290733
|
|
76
|
+
]
|
|
77
|
+
],
|
|
78
|
+
"type": "LineString"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>MapTiler E2E Animated Route Layer</title>
|
|
7
|
+
<style>
|
|
8
|
+
#map {
|
|
9
|
+
width: 100vw;
|
|
10
|
+
height: 100vh;
|
|
11
|
+
border: 1px solid red;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
body {
|
|
15
|
+
margin: 0;
|
|
16
|
+
padding: 0;
|
|
17
|
+
}
|
|
18
|
+
</style>
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
<div id="map"></div>
|
|
22
|
+
<script type="module" src="/src/animatedRouteLayer.ts"></script>
|
|
23
|
+
</body>
|
|
24
|
+
</html>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>MapTiler E2E Map Load</title>
|
|
7
|
+
<style>
|
|
8
|
+
#map {
|
|
9
|
+
width: 100vw;
|
|
10
|
+
height: 100vh;
|
|
11
|
+
border: 1px solid red;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
body {
|
|
15
|
+
margin: 0;
|
|
16
|
+
padding: 0;
|
|
17
|
+
}
|
|
18
|
+
</style>
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
<div id="map"></div>
|
|
22
|
+
<script type="module" src="/src/mapLoad.ts"></script>
|
|
23
|
+
</body>
|
|
24
|
+
</html>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { expect, test } from "@playwright/test";
|
|
2
|
+
import getMapInstanceForFixture from "./helpers/getMapInstanceForFixture";
|
|
3
|
+
import { AnimatedRouteLayer } from "index";
|
|
4
|
+
import { Map } from "@maptiler/sdk";
|
|
5
|
+
import expected from "./expected-results/animatedRouteLayer-1.json" assert { type: "json" };
|
|
6
|
+
|
|
7
|
+
test("Follows the correct path taking screenshots at each interval", async ({ page }) => {
|
|
8
|
+
await getMapInstanceForFixture({
|
|
9
|
+
fixture: "animatedRouteLayer",
|
|
10
|
+
page,
|
|
11
|
+
timeout: 10000,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
expect(await page.title()).toBe("MapTiler E2E Animated Route Layer");
|
|
15
|
+
|
|
16
|
+
await page.exposeFunction("notifyScreenshotStateReady", async (data: Record<string, TTestTransferData>) => {
|
|
17
|
+
await expect(page).toHaveScreenshot(`animated-route-${data.frame}.png`);
|
|
18
|
+
expect(data).toEqual(expected[data.frame as number]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
await page.clock.install();
|
|
22
|
+
|
|
23
|
+
await page.evaluate(async () => {
|
|
24
|
+
const NUM_SCREENSHOTS = 20;
|
|
25
|
+
const NUM_FRAMES_BETWEEN_SCREENSHOTS = 20;
|
|
26
|
+
|
|
27
|
+
const { animatedRouteLayer } = window.__pageObjects as { animatedRouteLayer: AnimatedRouteLayer };
|
|
28
|
+
const map = window.__map as Map;
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < NUM_SCREENSHOTS; i++) {
|
|
31
|
+
for (let j = 0; j < NUM_FRAMES_BETWEEN_SCREENSHOTS; j++) {
|
|
32
|
+
animatedRouteLayer.updateManual();
|
|
33
|
+
}
|
|
34
|
+
await window.notifyScreenshotStateReady({
|
|
35
|
+
frame: i,
|
|
36
|
+
center: map.getCenter().toArray(),
|
|
37
|
+
zoom: map.getZoom(),
|
|
38
|
+
pitch: map.getPitch(),
|
|
39
|
+
bearing: map.getBearing(),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
await page.clock.runFor(10000);
|
|
45
|
+
});
|
|
File without changes
|