[ThreeMap](../README.md) > [Utils](../modules/utils.md)

# External module: Utils

## Index

### Variables

* [merc](utils.md#merc)
* [mercatorExtend](utils.md#mercatorextend)
* [scale](utils.md#scale)
* [tileExtend](utils.md#tileextend)
* [tileRegex](utils.md#tileregex)

### Functions

* [buildFromWorkerData](utils.md#buildfromworkerdata)
* [doesTileExists](utils.md#doestileexists)
* [getCameraPosition](utils.md#getcameraposition)
* [getTileFromMerc](utils.md#gettilefrommerc)
* [getTilePosition](utils.md#gettileposition)
* [getTileScale](utils.md#gettilescale)
* [getURLForTile](utils.md#geturlfortile)
* [getZoom](utils.md#getzoom)
* [getZoomLevel](utils.md#getzoomlevel)
* [intersects](utils.md#intersects)
* [ll2merc](utils.md#ll2merc)
* [merc2ll](utils.md#merc2ll)
* [readStyle](utils.md#readstyle)
* [realTile](utils.md#realtile)
* [removeTile](utils.md#removetile)
* [tileBounds](utils.md#tilebounds)

---

## Variables

<a id="merc"></a>

### `<Const>` merc

**● merc**: *`SphericalMercator`* =  new SphericalMercator({
  size: 2048,
})

*Defined in [utils.ts:30](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L30)*

SphericalMercator library instance for latLng to mercator coordinates conversion.

___
<a id="mercatorextend"></a>

### `<Const>` mercatorExtend

**● mercatorExtend**: *`number`* = 20037510

*Defined in [utils.ts:18](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L18)*

X and y size of Mercator map.

___
<a id="scale"></a>

### `<Const>` scale

**● scale**: *`number`* =  mercatorExtend / tileExtend

*Defined in [utils.ts:26](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L26)*

Pre-calculated scale (tile to mercator size).

___
<a id="tileextend"></a>

### `<Const>` tileExtend

**● tileExtend**: *`number`* = 2048

*Defined in [utils.ts:22](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L22)*

X and y size of tile.

___
<a id="tileregex"></a>

### `<Const>` tileRegex

**● tileRegex**: *`RegExp`* =  /{([zxy])}/g

*Defined in [utils.ts:36](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L36)*

Regular expression for matching tile properties in url.

___

## Functions

<a id="buildfromworkerdata"></a>

###  buildFromWorkerData

▸ **buildFromWorkerData**(data: *[ITileBuffers](../interfaces/interfaces.itilebuffers.md)*): `void`

*Defined in [utils.ts:230](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L230)*

Processes data returned from worker & creates tile's mesh.
*__example__*: `buildFromWorkerData({...});`

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| data | [ITileBuffers](../interfaces/interfaces.itilebuffers.md) |  Position, color & normal buffers generated by WebWorker. |

**Returns:** `void`

___
<a id="doestileexists"></a>

###  doesTileExists

▸ **doesTileExists**(quadkey: *`string`*): `boolean`

*Defined in [utils.ts:156](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L156)*

Checks if tile exists in grid.
*__example__*: `doesTileExists('0123');`

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| quadkey | `string` |  Tile's quadkey. |

**Returns:** `boolean`

___
<a id="getcameraposition"></a>

###  getCameraPosition

▸ **getCameraPosition**(): `number`[]

*Defined in [utils.ts:212](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L212)*

Returns camera base plane (x & z) position.
*__example__*: `getCameraPosition()`;`

**Returns:** `number`[]

___
<a id="gettilefrommerc"></a>

###  getTileFromMerc

▸ **getTileFromMerc**(pos: *`number`[]*, z: *`number`*): [TilePrimitive](interfaces.md#tileprimitive)

*Defined in [utils.ts:130](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L130)*

Returns tile coordinates for given mercator x & y and zoom level values.
*__example__*: `getTileFromMerc([130533.56363, 106826.5536], 14);`

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| pos | `number`[] |  Array of mercator x & y coordinates. |
| z | `number` |  Specified zoom level. |

**Returns:** [TilePrimitive](interfaces.md#tileprimitive)

___
<a id="gettileposition"></a>

###  getTilePosition

▸ **getTilePosition**(id: *`string`*): `number`[]

*Defined in [utils.ts:177](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L177)*

Returns given tile's center in mercator coordinates.
*__example__*: `getTilePosition('0123');`

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| id | `string` |  Tile's quadkey. |

**Returns:** `number`[]

___
<a id="gettilescale"></a>

###  getTileScale

▸ **getTileScale**(id: *`string`*): `number`

*Defined in [utils.ts:197](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L197)*

Returns number representing x and y scale for resizing tile local coordinates to mercator coordinates.
*__example__*: `getTileScale('0123');`

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| id | `string` |  Tile's quadkey. |

**Returns:** `number`

___
<a id="geturlfortile"></a>

###  getURLForTile

▸ **getURLForTile**(tileObject: *[ITileObject](../interfaces/interfaces.itileobject.md)*): `string`

*Defined in [utils.ts:44](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L44)*

Get url for tile object.
*__example__*: `getURLForTile({x: 1, y: 3, z: 7);`

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| tileObject | [ITileObject](../interfaces/interfaces.itileobject.md) |  Tile primitive represented as object of x, y, z values. |

**Returns:** `string`

___
<a id="getzoom"></a>

###  getZoom

▸ **getZoom**(): `number`

*Defined in [utils.ts:220](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L220)*

Returns distance from controls' target to camera.
*__example__*: `getZoom();`

**Returns:** `number`

___
<a id="getzoomlevel"></a>

###  getZoomLevel

▸ **getZoomLevel**(distance: *`number`*): `number`

*Defined in [utils.ts:142](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L142)*

Converts distance from camera to controls target into zoom level.
*__example__*: `getZoomLevel(357200);`

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| distance | `number` |  Distance between camera and controls target. |

**Returns:** `number`

___
<a id="intersects"></a>

###  intersects

▸ **intersects**(bounds: *`Box3`*): `boolean`

*Defined in [utils.ts:271](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L271)*

Checks if bounding box intersects camera's frustum.
*__example__*: `intersects(new THREE.Box3(...));`

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| bounds | `Box3` |  Bounding box. |

**Returns:** `boolean`

___
<a id="ll2merc"></a>

###  ll2merc

▸ **ll2merc**(ll: *`number`[]*): `number`[]

*Defined in [utils.ts:108](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L108)*

Convert longitude - latitude coordinates to mercator coordinates.
*__example__*: `ll2merc([77.35262, 40.2525]);`

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| ll | `number`[] |  Array of longitude & latitude coordinates. |

**Returns:** `number`[]
Array of mercator x & y coordinates.

___
<a id="merc2ll"></a>

###  merc2ll

▸ **merc2ll**(xy: *`number`[]*): `number`[]

*Defined in [utils.ts:119](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L119)*

Converts mercator coordinates to longitude - latitude coordinates.
*__example__*: `ThreeMap.mercToLonLat([462073.1353, 295052.562]);`

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| xy | `number`[] |  Array of mercator x & y coordinates. |

**Returns:** `number`[]
Array of longitude & latitude coordinates.

___
<a id="readstyle"></a>

###  readStyle

▸ **readStyle**(style: *[IStyle](../interfaces/interfaces.istyle.md)*): [IStyle](../interfaces/interfaces.istyle.md)

*Defined in [utils.ts:65](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L65)*

Parses ThreeMap style configuration and applies default values.
*__example__*: `readStyle({...});`

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| style | [IStyle](../interfaces/interfaces.istyle.md) |  Style configuration. |

**Returns:** [IStyle](../interfaces/interfaces.istyle.md)

___
<a id="realtile"></a>

###  realTile

▸ **realTile**(tile: *[TilePrimitive](interfaces.md#tileprimitive)*): `boolean`

*Defined in [utils.ts:166](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L166)*

Checks if tile coordinates are in specified bounds (max is 2^zoom level).
*__example__*: `realTile([3,4,4]);`

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| tile | [TilePrimitive](interfaces.md#tileprimitive) |  Tile to be checked. |

**Returns:** `boolean`

___
<a id="removetile"></a>

###  removeTile

▸ **removeTile**(quadkey: *`string`*): `void`

*Defined in [utils.ts:280](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L280)*

Removes tile from grid & disposes its geometry.
*__example__*: `removeTile('0123');`

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| quadkey | `string` |  Quadkey of tile to remove. |

**Returns:** `void`

___
<a id="tilebounds"></a>

###  tileBounds

▸ **tileBounds**(tile: *`string`*): `Box3`

*Defined in [utils.ts:255](https://github.com/areknawo/ThreeMap/blob/master/src/utils.ts#L255)*

Returns bounding box for tile.
*__example__*: `tileBounds('0123');`

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| tile | `string` |  Tile's quadkey to get bounds for. |

**Returns:** `Box3`

___

