-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add getNeighbors() and tilesToFeatureCollection() #40
Open
douglasg14b
wants to merge
5
commits into
mapbox:main
Choose a base branch
from
douglasg14b:newFeatures
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7eef702
Create types.d.ts
douglasg14b 6c81351
Adds @types/geojson as a dev dependancy
douglasg14b 726f04e
Adds proper JSDoc comments from source
douglasg14b 49246c2
Adds getNeighbors(tile) function
douglasg14b 1ba46f4
Adds tilesToFeatureCollection(tiles)
douglasg14b File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
declare module '@mapbox/tilebelt' { | ||
import { BBox, FeatureCollection, Geometry } from "geojson"; | ||
|
||
export type Tile = [number, number, number]; // [x, y, z] | ||
|
||
/** | ||
* Get the bbox of a tile | ||
* | ||
* @name tileToBBOX | ||
* @param {Array<number>} tile | ||
* @returns {Array<number>} bbox | ||
* @example | ||
* var bbox = tileToBBOX([5, 10, 10]) | ||
* //=bbox | ||
*/ | ||
export function tileToBBOX(time: Tile): BBox; | ||
|
||
/** | ||
* Get a geojson representation of a tile | ||
* | ||
* @name tileToGeoJSON | ||
* @param {Array<number>} tile | ||
* @returns {Feature<Polygon>} | ||
* @example | ||
* var poly = tileToGeoJSON([5, 10, 10]) | ||
* //=poly | ||
*/ | ||
export function tileToGeoJSON(tile: Tile): Geometry; | ||
|
||
/** | ||
* Get the tile for a point at a specified zoom level | ||
* | ||
* @name pointToTile | ||
* @param {number} lon | ||
* @param {number} lat | ||
* @param {number} z | ||
* @returns {Array<number>} tile | ||
* @example | ||
* var tile = pointToTile(1, 1, 20) | ||
* //=tile | ||
*/ | ||
export function pointToTile(lon: number, lat: number, zoom: number): Tile; | ||
|
||
/** | ||
* Get the 4 tiles one zoom level higher | ||
* | ||
* @name getChildren | ||
* @param {Array<number>} tile | ||
* @returns {Array<Array<number>>} tiles | ||
* @example | ||
* var tiles = getChildren([5, 10, 10]) | ||
* //=tiles | ||
*/ | ||
export function getChildren(tile: Tile): Tile[]; | ||
|
||
/** | ||
* Get the tile one zoom level lower | ||
* | ||
* @name getParent | ||
* @param {Array<number>} tile | ||
* @returns {Array<number>} tile | ||
* @example | ||
* var tile = getParent([5, 10, 10]) | ||
* //=tile | ||
*/ | ||
export function getParent(tile: Tile): Tile; | ||
|
||
/** | ||
* Get the 3 sibling tiles for a tile | ||
* | ||
* @name getSiblings | ||
* @param {Array<number>} tile | ||
* @returns {Array<Array<number>>} tiles | ||
* @example | ||
* var tiles = getSiblings([5, 10, 10]) | ||
* //=tiles | ||
*/ | ||
export function hasSiblings(tiles: Tile[], tile: Tile): boolean; | ||
|
||
/** get the 3 sibling tiles for a tile */ | ||
export function getSiblings(tile: Tile): Tile[]; | ||
|
||
/** | ||
* Check to see if an array of tiles contains a particular tile | ||
* | ||
* @name hasTile | ||
* @param {Array<Array<number>>} tiles | ||
* @param {Array<number>} tile | ||
* @returns {boolean} | ||
* @example | ||
* var tiles = [ | ||
* [0, 0, 5], | ||
* [0, 1, 5], | ||
* [1, 1, 5], | ||
* [1, 0, 5] | ||
* ] | ||
* hasTile(tiles, [0, 0, 5]) | ||
* //=boolean | ||
*/ | ||
export function hasTile(tiles: Tile[], tile: Tile): boolean; | ||
|
||
/** | ||
* Check to see if two tiles are the same | ||
* | ||
* @name tilesEqual | ||
* @param {Array<number>} tile1 | ||
* @param {Array<number>} tile2 | ||
* @returns {boolean} | ||
* @example | ||
* tilesEqual([0, 1, 5], [0, 0, 5]) | ||
* //=boolean | ||
*/ | ||
export function tilesEqual(tile1: Tile, tile2: Tile): boolean; | ||
|
||
/** | ||
* Get the quadkey for a tile | ||
* | ||
* @name tileToQuadkey | ||
* @param {Array<number>} tile | ||
* @returns {string} quadkey | ||
* @example | ||
* var quadkey = tileToQuadkey([0, 1, 5]) | ||
* //=quadkey | ||
*/ | ||
export function tileToQuadkey(tile: Tile): string; | ||
|
||
/** | ||
* Get the tile for a quadkey | ||
* | ||
* @name quadkeyToTile | ||
* @param {string} quadkey | ||
* @returns {Array<number>} tile | ||
* @example | ||
* var tile = quadkeyToTile('00001033') | ||
* //=tile | ||
*/ | ||
export function quadkeyToTile(quadkey: string): Tile; | ||
|
||
/** | ||
* Get the smallest tile to cover a bbox | ||
* | ||
* @name bboxToTile | ||
* @param {Array<number>} bbox | ||
* @returns {Array<number>} tile | ||
* @example | ||
* var tile = bboxToTile([ -178, 84, -177, 85 ]) | ||
* //=tile | ||
*/ | ||
export function bboxToTile(bbox: BBox): Tile; | ||
|
||
/** | ||
* Get the precise fractional tile location for a point at a zoom level | ||
* | ||
* @name pointToTileFraction | ||
* @param {number} lon | ||
* @param {number} lat | ||
* @param {number} z | ||
* @returns {Array<number>} tile fraction | ||
* var tile = pointToTileFraction(30.5, 50.5, 15) | ||
* //=tile | ||
*/ | ||
export function pointToTileFraction(lon: number, lat: number, zoom: number): Tile; | ||
|
||
/** | ||
* Get the 8 neighbors surrounding a tile | ||
* | ||
* @name getNeighbors | ||
* @param {Array<number>} tile | ||
* @returns {Array<Array<number>>} tiles | ||
* var tiles = getNeighbors([5, 10, 10]) | ||
* //=tiles | ||
*/ | ||
export function getNeighbors(tile: Tile): Tile[] | ||
|
||
/** | ||
* Generates the GeoJSON FeatureCollection from an array or tiles | ||
* | ||
* @name tilesToFeatureCollection | ||
* @param {Array<Array<number>>} tiles | ||
* @returns {FeatureCollection} featureCollection | ||
* var tiles = [ | ||
* [0, 0, 5], | ||
* [0, 1, 5], | ||
* [1, 1, 5], | ||
* [1, 0, 5] | ||
* ] | ||
* var featureCollection = tilesToFeatureCollection(tiles) | ||
* //=featureCollection | ||
*/ | ||
export function tilesToFeatureCollection(tiles: Tile[]): FeatureCollection | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't check for valid tiles.
what about
[-1, -1, 3]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been quite some time since I touched this and I've lost all familiarity. Do you already have a function that checks for valid tiles? If not, can you define what such a check might look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remember correctly many other functions don't perform these checks (I assume for performance reasons), Is there a reason this function is special in that regard?