-
-
Notifications
You must be signed in to change notification settings - Fork 7
Add "geoJSONToTile" method #38
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f20f6dc
Add #92 - Generate exact single tile
montzkie18 0172ed7
Merge branch 'main' of https://github.com/maplibre/geojson-vt into ge…
lucaswoj 65bf0cf
Simplify diff
lucaswoj fbf177a
Convert geoJSONToTile tests from tape to vitest
lucaswoj a67fc7c
Revert package-lock.json
lucaswoj 62e3d79
Simplify diff
lucaswoj f6632c7
Simplify diff
lucaswoj 101b32c
Simplify diff
lucaswoj baba064
Update CHANGELOG.md
lucaswoj 63fd860
Remove defaultTileOptions
lucaswoj ab95904
Remove code comments
lucaswoj f283e9f
Create dedicated GeoJSONToTileOptions type
lucaswoj 14f50fa
Export geoJSONToTile from index.ts
lucaswoj c4e2bf3
Add TSDoc comments to geoJSONToTile function
lucaswoj c55c1fc
Fix CHANGELOG.md
lucaswoj 6b6c3c4
Fix CHANGELOG.md
lucaswoj 6a493fa
Fix CHANGELOG.md
lucaswoj 9f7a249
Fix CHANGELOG.md
lucaswoj 454a431
Simplify diff
lucaswoj eb5c66d
Revert changes to defaultOptions
lucaswoj c96b8a3
Move geoJSONToTile to a new file
lucaswoj bb7048f
Update tests
lucaswoj cd5b765
Improve tests
lucaswoj ff64c23
Add return type to 'geoJSONToTile'
lucaswoj 57ecfc5
Return an empty tile instead of null
lucaswoj 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 hidden or 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 hidden or 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 hidden or 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,58 @@ | ||
| import {clip} from './clip'; | ||
| import {convert} from './convert'; | ||
| import type {GeoJSONToTileOptions} from './definitions'; | ||
| import {defaultOptions} from './geojsonvt'; | ||
| import {createTile} from './tile'; | ||
| import {transformTile, type GeoJSONVTTile} from './transform'; | ||
| import {wrap} from './wrap'; | ||
|
|
||
| /** | ||
| * Converts GeoJSON data directly to a single vector tile without building a tile index. | ||
| * | ||
| * Unlike the {@link GeoJSONVT} class which builds a hierarchical tile index for efficient | ||
| * repeated tile access, this function generates a single tile on-demand. This is useful when: | ||
| * - You only need one specific tile and don't need to query multiple tiles | ||
| * - The source data is already spatially filtered to the tile's bounding box | ||
| * - You want to avoid the overhead of building a full tile index | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import {geoJSONToTile} from '@maplibre/geojson-vt'; | ||
| * | ||
| * const geojson = { | ||
| * type: 'FeatureCollection', | ||
| * features: [{ | ||
| * type: 'Feature', | ||
| * geometry: { type: 'Point', coordinates: [-77.03, 38.90] }, | ||
| * properties: { name: 'Washington, D.C.' } | ||
| * }] | ||
| * }; | ||
| * | ||
| * const tile = geoJSONToTile(geojson, 10, 292, 391, { extent: 4096 }); | ||
| * ``` | ||
| * | ||
| * @param data - GeoJSON data (Feature, FeatureCollection, or Geometry) | ||
| * @param z - Tile zoom level | ||
| * @param x - Tile x coordinate | ||
| * @param y - Tile y coordinate | ||
| * @param options - Optional configuration for tile generation | ||
| * @returns The generated tile with geometries in tile coordinates, or null if no features | ||
| */ | ||
|
|
||
| export function geoJSONToTile(data: GeoJSON.GeoJSON, z: number, x: number, y: number, options: GeoJSONToTileOptions = {}): GeoJSONVTTile { | ||
| options = {...defaultOptions, ...options}; | ||
| const {wrap: shouldWrap = false, clip: shouldClip = false} = options; | ||
|
|
||
| let features = convert(data, options); | ||
| if (shouldWrap) { | ||
| features = wrap(features, options); | ||
| } | ||
| if (shouldClip || options.lineMetrics) { | ||
| const pow2 = 1 << z; | ||
| const buffer = options.buffer / options.extent; | ||
| const left = clip(features, pow2, (x - buffer), (x + 1 + buffer), 0, -1, 2, options); | ||
| features = clip(left || [], pow2, (y - buffer), (y + 1 + buffer), 1, -1, 2, options); | ||
| } | ||
|
|
||
| return transformTile(createTile(features ?? [], z, x, y, options), options.extent); | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.