Giter VIP home page Giter VIP logo

z-factory's Introduction

z-factory

Add elevation to your lon/lats with PNG elevation tiles

Features

  • Works in browser and on server-side with Node.js
  • Defaults to AWS Terrain Tiles data source so elevation sampling is free with no API key
  • Bilinear and nearest neighbor sampling
  • Mapbox, Maptiler, and NasaDEM elevation sources with API key
  • Supports local disk cache in addition to remote source
  • Well-tested to be sure calculations are accurate
  • Promise-based, written in TypeScript

Install

npm install z-factory

Basic example

import { ZFactory } from 'z-factory';

// default uses in-memory cache & AWS Terrain Tiles & bilinear sampling
const zfactory = new ZFactory();
const mtEverest = [86.9250, 27.9881];

// get elevation using terrain tiles at zoom level 10
zfactory.getZ(mtEverest, 10).then(ele => {
  console.log(ele);
});

// 8672.794844986805

More in-depth options

import { ZFactory, MapTilerTileSource, FileTileCache } from 'z-factory';

// FileTileCache uses a local elevation tile if it exists, or if not downloads
// the tile from tile source and caches it (note: node.js only)
const localCache = new FileTileCache('./tiles');

// custom tile source; also MapboxTileSource and NasaDemTileSource
const tileSource = new MapTilerTileSource({ apiKey: "[API_KEY]"});

const zfactory = new ZFactory(tileSource, localCache);
const mtEverest = [86.9250, 27.9881];

Promise.all([
  zfactory.getZ(mtEverest, 10, "nearest"),
  zfactory.getZ(mtEverest, 10, "bilinear")
]).then(([nn, bi]) => {
  console.log(`nn: ${nn}; bi: ${bi}`);
});

// nn: 8663; bi: 8672.794844986805

Notes

  • While the result of the sampling calculation is guaranteed to be accurate, the value may be off due to the resolution of the underlying data; make sure to consult the documentation of each terrain tile source.
  • In-browser package comes bundled with pako in order to decode PNG tiles; this adds a considerable amount of file size
  • Contributions welcome!

License

MIT

z-factory's People

Contributors

1papaya avatar

Stargazers

Daven Quinn avatar John J Czaplewski avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.