Skip to content

Commit b6d1e14

Browse files
Update readme with gpx and kml converter (#139)
1 parent c73f84e commit b6d1e14

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

readme.md

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

988988
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).
989989

990-
# Other helper
990+
# Other helpers
991+
## Convert GPX and KML to GeoJSON
992+
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:
993+
994+
```ts
995+
import { gpx } from "@maptiler/sdk";
996+
997+
// ... assuming inside an async function
998+
999+
// Fetching the GPX file as a string:
1000+
const gpxFilePath = "some_gps_trace.gpx";
1001+
const gpxResponse = await fetch(gpxFilePath);
1002+
const gpxStr = await res.text();
1003+
1004+
// Converting the GPX payload into a GeoJSON FeatureCollection:
1005+
const features = maptilersdk.gpx(gpxStr);
1006+
```
1007+
1008+
And for KML files:
1009+
```ts
1010+
import { kml } from "@maptiler/sdk";
1011+
1012+
// ... assuming inside an async function
1013+
1014+
// Fetching the KML file as a string:
1015+
const kmlFilePath = "some_gps_trace.kml";
1016+
const kmlResponse = await fetch(kmlFilePath);
1017+
const kmlStr = await res.text();
1018+
1019+
// Converting the KML payload into a GeoJSON FeatureCollection:
1020+
const features = maptilersdk.gpx(kmlStr);
1021+
```
1022+
1023+
9911024
## Take Screenshots, programmatically
9921025
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.
9931026

0 commit comments

Comments
 (0)