kartotherian/quadtile-index

Name: quadtile-index

Owner: kartotherian

Description: Convert between x,y tile coordinates and a bitwise-interleaved single integer

Created: 2017-03-19 16:58:55.0

Updated: 2018-04-29 21:21:08.0

Pushed: 2018-04-29 21:21:07.0

Homepage: null

Size: 16

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status

quadtile-index

Convert between x,y map tile coordinates and a bitwise-interleaved single integer

Quadtile index has many useful properties. For example, it makes zoom calculations much easier: for a tile at zoom N, the “parent” tile at zoom N-1 is simply math.Floor(index/4). A single index integer makes iteration easier as well - 0 .. 4^zoom-1 are all the tiles at the current zoom level, and makes it much simpler to subdivide work between multiple machines. Iterating tends to go over the tiles in one area before moving to a different area, which may benefit caching.

Quadtiles use a 2-bit tile interleaved addresses. An x and y coordinate value bit representation of up to 26 bits each can be converted to a single integer value up to 56 bits. The limit is due to JavaScript's maximum lossless integer representation. For example, two 8 bit values xxxx xxxx and yyyy yyyy would produce a single xyxyxyxy xyxyxyxy xyxyxyxy xyxyxyxy index value.

The library will assert the validity of each value, and allows optional zoom for additional verification.

For more info, see quadtile indexes info

xyToIndex(x, y, [zoom])

Convert x,y into a single integer with alternating bits

indexToXY(index, [zoom])

Convert index into the x,y coordinates (as a [x,y] array)

isValidCoordinate(val, [zoom]), isValidIndex(index, [zoom]), isValidZoom(zoom)

Boolean validation functions

maxZoom

Constant: Maximum supported zoom level (26)


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.