Skip to content

Commit

Permalink
Compute elevation (#32)
Browse files Browse the repository at this point in the history
* WIP basic geo math

* WIP more geo math

* ADD some more basic geo math

* ADD elevation with tile caching for a single point

* ADD exposing the tile parsing function to config

* ENH simplified the index.ts

* ADD batch elevation

* ADD elevation for GeoJSON LineString and MultiLineString

* ADD more math functions

* ENH rounding pixel coord rather than truncate them

* changelog

* FIX typo

* FIX from code review

* FIX better naming for tile cache
  • Loading branch information
jonathanlurie authored Dec 5, 2023
1 parent 87cdf0c commit cead13a
Show file tree
Hide file tree
Showing 23 changed files with 43,819 additions and 690 deletions.
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ docs
docsmd
images
test
src
examples
dist/*.umd.*
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
### Bug Fixes
### Others

## 1.8.0
### New Features
- Rework of the elevation API to be improve developper experience (new module `elevation`)
- Expoing some geo math with the new `math` module

## 1.7.0
### New Features
- DEM elevation API (https://github.com/maptiler/maptiler-client-js/pull/24)
Expand Down
114 changes: 114 additions & 0 deletions examples/elevation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<html>
<head>
<title>tslib</title>
</head>

<body>
<p>
This demo is using the UMD bundle. Add <code>?key=YOUR_API_KEY</code> to the URL.
</p>
<p>
Open JS console.
</p>
<div id="images"></div>

<script src ="../dist/maptiler-client.umd.js"></script>

<script>
// The API key must be in the URL param as `?key=ABCD1234`
maptilerClient.config.apiKey = (new URLSearchParams(location.search)).get("key");

(async () => {


// A basic example with only a line string
// const resGeojson = await fetch("linestring.geojson");
// const geojson = await resGeojson.json();
// console.log(geojson);

// const allLines = maptilerClient.extractLineStrings(geojson);

// const ls = allLines[0]
// console.log(ls)

// const elevatedLs = await maptilerClient.elevation.fromLineString(ls);
// console.log(elevatedLs)



// an example with a single multilinestring
// const resGeojson = await fetch("multilinestring.geojson");
// const geojson = await resGeojson.json();
// console.log(geojson);

// const allMLS = maptilerClient.extractLineStrings(geojson);

// const mls = allMLS[0]
// console.log(mls)

// console.time("1")
// const elevatedMls = await maptilerClient.elevation.fromMultiLineString(mls);
// console.timeEnd("1")
// console.log(elevatedMls)



// a long multilinestrin
// const resGeojson = await fetch("long.geojson");
// const geojson = await resGeojson.json();
// console.log(geojson);

// const allMLS = maptilerClient.extractLineStrings(geojson);

// const mls = allMLS[0]
// console.log(mls)

// console.time("1")
// const elevatedMls = await maptilerClient.elevation.fromMultiLineString(mls);
// console.timeEnd("1")
// console.log(elevatedMls)




// A basic example with only a line string
// a long multilinestrin
// const resGeojson = await fetch("long.geojson");
// const geojson = await resGeojson.json();
// console.log(geojson);

// const allMLS = maptilerClient.extractLineStrings(geojson);

// const mls = allMLS[0]
// console.log(mls.coordinates[0])

// console.time("1")
// const ds = maptilerClient.math.haversineCumulatedDistanceWgs84(mls.coordinates[0]);
// console.timeEnd("1")
// console.log(ds);

// Batch elevation
// const all = await maptilerClient.elevation.batch(
// [
// [6.864884, 45.832743], // Mont Blanc, Alps, 4808m
// [6.864884, 45.832743], // Mont Blanc, Alps, 4808m
// [6.864884, 45.832743], // Mont Blanc, Alps, 4808m
// [6.864884, 45.832743], // Mont Blanc, Alps, 4808m
// [6.864884, 45.832743], // Mont Blanc, Alps, 4808m
// [6.864884, 45.832743], // Mont Blanc, Alps, 4808m
// // [86.9250, 27.9881], // Mount Everest, Himalayas, 8848m
// // [-70.0109, -32.6532], // Aconcagua, Andes, 6960m
// // [-151.0064, 63.0695], // Denali, Alaska, 6190m
// // [37.3556, -3.0674], // Mount Kilimanjaro, 5895m
// // [42.4453, 43.3499], // Mount Elbrus, Caucasus, 5642m
// // [137.1595, -4.0784], // Puncak Jaya, Sudirman Range, 4884m
// // [-140.4055, 60.5672], // Mount Logan, Saint Elias Mountains, 5956m
// // [138.73111, 35.358055], // Mount Fuji, 3776m
// ]
// );
// console.log(all);

})()
</script>
</body>
</html>
164 changes: 164 additions & 0 deletions examples/linestring.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@

{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
6.249869,
46.402238,
424.3
],
[
6.249877,
46.40224,
424.4
],
[
6.249877,
46.402237,
424.4
],
[
6.249871,
46.402232,
424.5
],
[
6.249863,
46.402227,
424.6
],
[
6.249856,
46.402223,
424.7
],
[
6.249849,
46.402224,
424.8
],
[
6.249846,
46.402226,
424.8
],
[
6.249844,
46.402228,
424.8
],
[
6.249843,
46.402228,
424.8
],
[
6.249834,
46.402226,
424.9
],
[
6.249828,
46.402225,
425
],
[
6.249812,
46.402222,
425.2
],
[
6.249803,
46.402219,
425.3
],
[
6.249793,
46.402217,
425.4
],
[
6.249783,
46.402214,
425.5
],
[
6.249773,
46.402211,
425.6
],
[
6.249743,
46.402183,
426.1
],
[
6.249713,
46.402158,
426.5
],
[
6.24968,
46.402124,
427.1
],
[
6.249654,
46.40209,
427.6
],
[
6.249629,
46.402061,
428
],
[
6.249609,
46.402035,
428.4
],
[
6.249576,
46.402004,
428.8
],
[
6.249564,
46.401996,
428.9
],
[
6.249515,
46.401992,
429.5
],
[
6.249496,
46.401995,
429.5
],
[
6.249457,
46.402003,
429.6
],
[
6.249411,
46.402019,
429.6
]
]
},
"id": "d22fc9f8-ba40-4f46-b46d-939564068e0a",
"properties": {
"name": "It's been a while",
"type": "1"
}
}
]
}
Loading

0 comments on commit cead13a

Please sign in to comment.