binaryquadkey v0.0.1
BinaryQuadkey
Node.js library to create an object to represent map tile Quadkeys in a binary format using 64-bit integers via long.js for the benefits of constant time comparsions, consistent byte-length storage, integer indexing, cache optimization, and potential space savings. Read more here: Binary quadkeys
Kind: global class
Properties
Name | Type | Description |
---|---|---|
x | number | The X coordinate of the tile |
y | number | The Y coordinate of the tile |
zoom | number | The zoomlevel or level of detail of the tile (1-23) |
UInt64Quadkey | object | long.js Long object representing an unsigned 64 bit integer |
- BinaryQuadkey
- new BinaryQuadkey([x], [y], [zoom], [uint64quadkey])
- instance
- .toQuadkey() ⇒ string
- .toBuffer() ⇒ Buffer
- .toString([radix]) ⇒ string
- .isParentOf(other) ⇒ boolean
- .equals(other) ⇒ boolean
- .getHighBits() ⇒ number
- .getLowBits() ⇒ number
- .getZoom() ⇒ string
- static
new BinaryQuadkey(x, y, zoom, uint64quadkey)
Constructs a BinaryQuadkey object that internally uses an unsigned 64-bit integer representation of Quadkey of a map tile at the given coordinates See the from* functions below for more convenient ways of constructing BinaryQuadkey objects.
Returns: BinaryQuadkey - The corresponding BinaryQuadkey object
Param | Type | Default | Description |
---|---|---|---|
x | number | 0 | The X coordinate of the tile |
y | number | 0 | The Y coordinate of the tile |
zoom | number | 0 | The zoomlevel or level of detail of the tile (1-23) |
uint64quadkey | object | Long.fromInt(0) | (Optional) long.js Long object encapsulating an unsigned 64 bit integer representation of a binary Quadkey |
Example
var BinaryQuadkey = require("binaryquadkey");
var binaryQuadkey = new BinaryQuadkey(35210, 21493, 16);
binaryQuadkey.toQuadkey() ⇒ string
Returns a Quadkey string that corresponds to the BinaryQuadkey
Kind: instance method of BinaryQuadkey
Returns: string - Quadkey string
Example
var BinaryQuadkey = require("binaryquadkey");
var binaryQuadkey = new BinaryQuadkey(35210, 21493, 16);
console.log(binaryQuadkey.toQuadkey()); // "1202102332221212"
binaryQuadkey.toBuffer() ⇒ Buffer
Returns a new Node.js Buffer() from BinaryQuadkey's internal unsigned 64 bit integer representation
Kind: instance method of BinaryQuadkey
Returns: Buffer - Node.js new Buffer()
Example
var BinaryQuadkey = require("binaryquadkey");
var binaryQuadkey = new BinaryQuadkey(35210, 21493, 16);
console.log(binaryQuadkey.toBuffer()); // <Buffer 62 4b ea 66 00 00 00 10>
binaryQuadkey.toString(radix) ⇒ string
Converts the BinaryQuadkey's internal 64bit integer representation to a string written in the specified radix.
Kind: instance method of BinaryQuadkey
Returns: string - unsigned 64bit integer string in radix frmat
Throws:
- RangeError If
radix
is out of range
Param | Type | Description |
---|---|---|
radix | number | The radix in which the text is written (2-36), defaults to 10 |
Example
var BinaryQuadkey = require("binaryquadkey");
var binaryQuadkey = new BinaryQuadkey(29, 50, 7);
console.log(binaryQuadkey.toString()); // 3270739229377822727
console.log(binaryQuadkey.toString(16)); // 2d64000000000007
console.log(binaryQuadkey.toString(2)); // 10010011100001110010011011001000000000000000000000000000010000
binaryQuadkey.isParentOf(other) ⇒ boolean
Determines weather the current BinaryQuadkey is a parent of the passed in BinaryQuadkey
Kind: instance method of BinaryQuadkey
Returns: boolean - if the BinaryQuadkey is a parent of the other BinaryQuadkey
Param | Type | Description |
---|---|---|
other | BinaryQuadkey | BinaryQuadkey object which may or may not be a child |
Example
var BinaryQuadkey = require("binaryquadkey");
var binaryQuadkey1 = new BinaryQuadkey.fromQuadkey("120210");
var binaryQuadkey2 = new BinaryQuadkey.fromQuadkey("1202102332221212");
console.log(binaryQuadkey1.isParentOf(binaryQuadkey2)); // true
binaryQuadkey.equals(other) ⇒ boolean
Determines weather the current BinaryQuadkey identical to the passed in BinaryQuadkey
Kind: instance method of BinaryQuadkey
Returns: boolean - if the BinaryQuadkey represents the same tile as the other BinaryQuadkey
Param | Type | Description |
---|---|---|
other | BinaryQuadkey | BinaryQuadkey object which may or may not be identical |
Example
var BinaryQuadkey = require("binaryquadkey");
var binaryQuadkey1 = new BinaryQuadkey(35210, 21493, 16);
var binaryQuadkey2 = new BinaryQuadkey.fromQuadkey("1202102332221212");
var binaryQuadkey3 = new BinaryQuadkey.fromQuadkey("120210");
console.log(binaryQuadkey1.equals(binaryQuadkey2)); // true
console.log(binaryQuadkey1.equals(binaryQuadkey3)); // false
binaryQuadkey.getHighBits() ⇒ number
Gets the high 32 bits as the 64 bit unsigned integer.
Kind: instance method of BinaryQuadkey
Returns: number - Unsigned high bits
Example
var BinaryQuadkey = require("binaryquadkey");
var binaryQuadkey = new BinaryQuadkey.fromBits(11, 618776576);
console.log(binaryQuadkey.getHighBits()); // 618776576
binaryQuadkey.getLowBits() ⇒ number
Gets the low 32 bits as the 64 bit unsigned integer.
Kind: instance method of BinaryQuadkey
Returns: number - Unsigned low bits
Example
var BinaryQuadkey = require("binaryquadkey");
var binaryQuadkey = new BinaryQuadkey.fromBits(11, 618776576);
console.log(binaryQuadkey.getLowBits()); // 11
binaryQuadkey.getZoom() ⇒ string
Returns the zoom level / level of detail of the specific referenced tile.
Kind: instance method of BinaryQuadkey
Returns: string - zoom level of tile
Example
var BinaryQuadkey = require("binaryquadkey");
var binaryQuadkey = new BinaryQuadkey.fromQuadkey("021032013");
console.log(binaryQuadkey.getZoom()); // 9
BinaryQuadkey.fromTileXY(x, y, zoom) ⇒ BinaryQuadkey
Returns a BinaryQuadkey representation of the tile at the given coordinates
Kind: static method of BinaryQuadkey
Returns: BinaryQuadkey - The corresponding BinaryQuadkey object
Param | Type | Description |
---|---|---|
x | number | The X coordinate of the tile |
y | number | The Y coordinate of the tile |
zoom | number | The zoomlevel or level of detail of the tile (1-23) |
Example
var BinaryQuadkey = require("binaryquadkey");
var binaryQuadkey = new BinaryQuadkey.fromTileXY(35210, 21493, 16);
BinaryQuadkey.fromQuadkey(quadKeyString) ⇒ BinaryQuadkey
Returns a BinaryQuadkey representing the Quadkey string
Kind: static method of BinaryQuadkey
Returns: BinaryQuadkey - The corresponding BinaryQuadkey object created from Quadkey string
Param | Type | Description |
---|---|---|
quadKeyString | string | The string that corresponds to the Quadkey |
Example
var BinaryQuadkey = require("binaryquadkey");
var binaryQuadkey = new BinaryQuadkey.fromQuadkey("1202102332221212");
BinaryQuadkey.fromUInt64(uint64quadkey, zoom) ⇒ BinaryQuadkey
Returns a BinaryQuadkey representation of a long.js unsigned int64 Long object
Kind: static method of BinaryQuadkey
Returns: BinaryQuadkey - The corresponding BinaryQuadkey object
Param | Type | Description |
---|---|---|
uint64quadkey | object | long.js Long object representing an unsigned 64 bit integer |
zoom | number | (Optional) The zoomlevel or level of detail of the tile (1-23) |
Example
var BinaryQuadkey = require("binaryquadkey");
var binaryQuadkey1 = new BinaryQuadkey(35210, 21493, 16);
var binaryQuadkey2 = new BinaryQuadkey.fromUInt64(binaryQuadkey1.UInt64Quadkey);
...
var Long = require("long"); //requires you to install long.js
var uint64 = new Long.fromString("18446744073709289495");
var binaryQuadkey = new BinaryQuadkey.fromUInt64(uint64);
BinaryQuadkey.fromBits(low, high) ⇒ BinaryQuadkey
Returns a BinaryQuadkey representing the unsigned 64 bit integer that comes by concatenating the given low and high bits. Each is assumed to use 32 bits.
Kind: static method of BinaryQuadkey
Returns: BinaryQuadkey - The corresponding BinaryQuadkey object created from the low and high bits
Param | Type | Description |
---|---|---|
low | number | The low (unsigned) 32 bits of the long |
high | number | The high (unsigned) 32 bits of the long |
Example
var BinaryQuadkey = require("binaryquadkey");
var binaryQuadkey1 = new BinaryQuadkey.fromBits(11, 618776576);
var binaryQuadkey2 = new BinaryQuadkey.fromBits(0xFFFFFFFF, 0x7FFFFFFF);
BinaryQuadkey.isBinaryQuadkey(obj) ⇒ boolean
Tests if the specified object is a BinaryQuadkey.
Kind: static method of BinaryQuadkey
Param | Type | Description |
---|---|---|
obj | * | Object |
9 years ago