watergis / terrain-rgb

This module is to get elevation from terrain RGB tilesets by longitude and latitude.
MIT License
14 stars 7 forks source link

Can't get elevation from mapbox terrain webp #9

Open geobuilding opened 2 years ago

geobuilding commented 2 years ago

https://codesandbox.io/s/terrain-rgb-g4nym?file=/src/index.ts

import { TerrainRGB } from "@watergis/terrain-rgb";

const url = "https://api.mapbox.com/raster/v1/mapbox.mapbox-terrain-dem-v1/{z}/{x}/{y}.webp?sku=10149h63PJzgC&access_token=pk.eyJ1IjoiZGV2LWFhYyIsImEiOiJjbDI5MGl5N3QwZGNlM2NuN3l6bGtxaTd6In0.ornsESAnvKKQedUSw2fKyA";
const trgb = new TerrainRGB(url, 512);
const coordinate = [78.34336242946887, 22.133570853753696];
const zoom = 14;

trgb.getElevation(coordinate, zoom).then((elevation: number | undefined) => {
  const doc = document.getElementById("app");
  if (doc) {
    doc.innerHTML = `
    <h1>Hello terrain-rgb!</h1>
    <div>
      <ul>
        <li>URL: ${url}</li>
        <li>Longitude: ${coordinate[0]}</li>
        <li>Latitude: ${coordinate[1]}</li>
        <li>Zoom level: ${zoom}</li>
        <li>Elevation: ${elevation}</li>
      </ul>
    </div>
    <div>
    Look the repository at <a href= "https://github.com/watergis/terrain-rgb" >watergis/terrain-rgb</a>
    </div>
    `;
  }
});
image
JinIgarashi commented 2 years ago

@hong4k Thank you for reporting. Getting value from terrain rgb webp in the browser is currently not working. the plugin only support WEBP for nodejs application. But welcome any pull request to fix this issue.