Skip to content

Commit d26edbe

Browse files
committed
Merge branch 'main' into v3.0.0
# Conflicts: # CHANGELOG.md # package-lock.json # package.json
2 parents 4e19ab4 + c9886b9 commit d26edbe

File tree

4 files changed

+78
-4
lines changed

4 files changed

+78
-4
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,19 @@
88
### Bug Fixes
99
- Navigation now relies on `Map` methods instead of `Transform` methods for bearing due to globe projection being available
1010

11+
## 2.5.1
12+
### Bug Fixes
13+
- Better control of the status of `monitoredStyleUrls` in Map instance when error is caught (https://github.com/maptiler/maptiler-sdk-js/pull/141)
14+
- Added extra integrity checks on style object when updating language (https://github.com/maptiler/maptiler-sdk-js/pull/142)
15+
- The Geolocate control no longer throwing error when window is lost (issue on Firefox only) (https://github.com/maptiler/maptiler-sdk-js/pull/140)
16+
17+
## 2.5.0
18+
### others
19+
- Update MapTiler Client library to v2.5.0
1120

1221
## 2.4.2
1322
### Bug Fixes
1423
- The language switching is now more robust and preserves the original formatting from the style (`Map.setPrimaryLangage()`) (https://github.com/maptiler/maptiler-sdk-js/pull/134)
15-
1624
### Others
1725
- Now able to GitHub action a beta on NPM from the GH release creation process
1826
- Updated GH action to v4

readme.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,40 @@ Turning off *zoom compensation* allows for more accurate adjustments to the visu
11031103

11041104
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).
11051105

1106-
# Other helper
1106+
# Other helpers
1107+
## Convert GPX and KML to GeoJSON
1108+
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:
1109+
1110+
```ts
1111+
import { gpx } from "@maptiler/sdk";
1112+
1113+
// ... assuming inside an async function
1114+
1115+
// Fetching the GPX file as a string:
1116+
const gpxFilePath = "some_gps_trace.gpx";
1117+
const gpxResponse = await fetch(gpxFilePath);
1118+
const gpxStr = await res.text();
1119+
1120+
// Converting the GPX payload into a GeoJSON FeatureCollection:
1121+
const features = maptilersdk.gpx(gpxStr);
1122+
```
1123+
1124+
And for KML files:
1125+
```ts
1126+
import { kml } from "@maptiler/sdk";
1127+
1128+
// ... assuming inside an async function
1129+
1130+
// Fetching the KML file as a string:
1131+
const kmlFilePath = "some_gps_trace.kml";
1132+
const kmlResponse = await fetch(kmlFilePath);
1133+
const kmlStr = await res.text();
1134+
1135+
// Converting the KML payload into a GeoJSON FeatureCollection:
1136+
const features = maptilersdk.gpx(kmlStr);
1137+
```
1138+
1139+
11071140
## Take Screenshots, programmatically
11081141
There are two different ways to create screenshot, corresponding to two very different usecases. Note that screenshots will not contain *DOM elements* such as `Marker` and `Popup`, since those are not part of the rendering context.
11091142

src/Map.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ export class Map extends maplibregl.Map {
307307
// If the URL is present in the list of monitored style URL,
308308
// that means this AJAXError was about a style, and we want to fallback to
309309
// the default style
310-
if (this.monitoredStyleUrls.has(clearnUrlStr)) {
310+
if (this.monitoredStyleUrls && this.monitoredStyleUrls.has(clearnUrlStr)) {
311311
this.monitoredStyleUrls.delete(clearnUrlStr);
312312
applyFallbackStyle();
313313
}
@@ -975,7 +975,7 @@ export class Map extends maplibregl.Map {
975975
}
976976

977977
private getStyleLanguage(): LanguageInfo | null {
978-
if (!this.style.stylesheet.metadata) return null;
978+
if (!this.style || !this.style.stylesheet || !this.style.stylesheet.metadata) return null;
979979
if (typeof this.style.stylesheet.metadata !== "object") return null;
980980

981981
if (

src/MaptilerGeolocateControl.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,37 @@ export class MaptilerGeolocateControl extends GeolocateControl {
166166
this._updateCircleRadius();
167167
}
168168
};
169+
170+
// We are overwriting the method _setErrorState from Maplibre's GeolocateControl because the
171+
// case BACKGROUND_ERROR is not dealt with in the original function and yields an error.
172+
// Related issue: https://github.com/maplibre/maplibre-gl-js/issues/2294
173+
_setErrorState() {
174+
switch (this._watchState) {
175+
case "WAITING_ACTIVE":
176+
this._watchState = "ACTIVE_ERROR";
177+
this._geolocateButton.classList.remove("maplibregl-ctrl-geolocate-active");
178+
this._geolocateButton.classList.add("maplibregl-ctrl-geolocate-active-error");
179+
break;
180+
case "ACTIVE_LOCK":
181+
this._watchState = "ACTIVE_ERROR";
182+
this._geolocateButton.classList.remove("maplibregl-ctrl-geolocate-active");
183+
this._geolocateButton.classList.add("maplibregl-ctrl-geolocate-active-error");
184+
this._geolocateButton.classList.add("maplibregl-ctrl-geolocate-waiting");
185+
// turn marker grey
186+
break;
187+
case "BACKGROUND":
188+
this._watchState = "BACKGROUND_ERROR";
189+
this._geolocateButton.classList.remove("maplibregl-ctrl-geolocate-background");
190+
this._geolocateButton.classList.add("maplibregl-ctrl-geolocate-background-error");
191+
this._geolocateButton.classList.add("maplibregl-ctrl-geolocate-waiting");
192+
// turn marker grey
193+
break;
194+
case "ACTIVE_ERROR":
195+
break;
196+
case "BACKGROUND_ERROR":
197+
break;
198+
default:
199+
throw new Error(`Unexpected watchState ${this._watchState}`);
200+
}
201+
}
169202
}

0 commit comments

Comments
 (0)