quadkey-tilemath

Tile System math for the Spherical Mercator projection coordinate system (EPSG:3857)

MIT License

Downloads
149
Stars
7
Committers
2

quadkey-tilemath

The quadkey-tilemath provides functions for converting between geographical coordinates and tile coordinates using the Quadkey system. This system represents a hierarchical tiling of the Earth's surface as a quadtree, with each tile being assigned a unique identifier known as a Quadkey.

The quadkey-tilemath implements the TileSystem static class described here as a reference: http://msdn.microsoft.com/en-us/library/bb259689.aspx

Given a (longitude, latitude) and level produce a quadkey to be used in Bing Maps. Can also supply methods to generate a Google Maps TileXYZ

Class diagram

It is a conceptual class diagram for explanation only and differs from the actual implementation. plantuml

Install

$ npm install quadkey-tilemath

or

$ yarn add quadkey-tilemath

Usage

Converts a longitude, latitude to a quadkey.

import { tileMath } from 'quadkey-tilemath'

// Shibuya
const quadkey = tileMath.pointToQuadkey([139.69116, 35.63051], 20)

// 133002112303213
console.log(quadkey)

Converts a quadkey to lng lat point.

import { tileMath } from 'quadkey-tilemath'

const point = tileMath.quadkeyToPoint('13300211230301333312')

// 139.7014617919922, 35.657854158137965
console.log(point)

Demo using map

Here is a demo that actually draws the quadkey on the map using this library. https://9revolution9.com/tools/geo/geocode/