-
-
Notifications
You must be signed in to change notification settings - Fork 918
Split tiles on-the-fly to improve over scale vector handling #6521
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
Open
HarelM
wants to merge
55
commits into
main
Choose a base branch
from
2507-overzoom-geojson-vt
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
55 commits
Select commit
Hold shift + click to select a range
2f97f4a
Allow over zooming using geojson-vt
HarelM 26807ca
Allow overzooming using geojson-vt
HarelM 3490a30
Use map's max zoom
HarelM 7ac64c8
Merge branch 'main' into 2507-overzoom-geojson-vt
HarelM cba4fd4
Vector source overzoom improvements (#6532)
wayofthefuture 789a094
Reduce diff changes
HarelM 26ba334
Improve comments
HarelM 020e565
Simplify assignment
HarelM 29c7476
Reduce diff changes
HarelM 50fb9d2
Move code to a different file
HarelM 11165bf
Move comment to method description
HarelM b643b16
Update some render test results
HarelM 524270c
Update min test, more render tests
HarelM 425fc24
Merge branch 'main' into 2507-overzoom-geojson-vt
HarelM 1ac4695
Revert bug that was added...
HarelM b5ec5ce
Remove redundant code
HarelM 8e334d7
Fix missing ID in overscaled tiles
HarelM 2a6d8fa
Add changelog
HarelM 82e3669
Revert change that will be introduced in another PR.
HarelM 463e02f
Revert changes in worker_tile
HarelM 97529d7
Update another render test
HarelM 06fdc1b
Merge branch 'main' into 2507-overzoom-geojson-vt
HarelM b3292d3
Reduce changes in example
HarelM 619a73b
Improve names in the example
HarelM 5f06216
Improve docs
HarelM c7b66fa
Fix spelling
HarelM 0f7a3ab
Add unit tests for LRU cache
HarelM e818b2d
Merge branch 'main' into 2507-overzoom-geojson-vt
HarelM 32d599c
Fix lint
HarelM 8508e61
Add experimental flag to default this behavior only on Safari.
HarelM a90f70e
Revert "Update some render test results"
HarelM 342f53a
Revert "Update another render test"
HarelM dceabad
Revert "Update min test, more render tests"
HarelM 52581cf
Revert last render test change
HarelM 0b1a2d3
More detailed changelog message.
HarelM 4e3379c
Update CHANGELOG.md
HarelM e3e2345
Merge branch '2507-overzoom-geojson-vt' of https://github.com/maplibr…
HarelM b9ec430
Update doc comment
HarelM e8f1749
Merge branch 'main' into 2507-overzoom-geojson-vt
HarelM 48e44e0
Remove default
HarelM 8ae4135
Update min test
HarelM a1ee81d
Added maxOverzoom to key
HarelM 9a0efa7
Update src/ui/map.ts
HarelM 7c7d1c6
Fix typo
HarelM a210bc6
Merge branch 'main' into 2507-overzoom-geojson-vt
HarelM f4d14cf
Merge branch 'main' into 2507-overzoom-geojson-vt
HarelM 744dee0
Only clip tiles instead of using geojson index
HarelM 6126261
Fix lint
HarelM 5d509e6
Update expected bytes
HarelM 7ccb2f7
Merge branch 'main' into 2507-overzoom-geojson-vt
HarelM 9e619a0
Renames to match existing files
HarelM ac6b817
Update changelog
HarelM 6fcccab
Update docs to remove geojson-vt where it's not relevant
HarelM da6c0e5
Merge branch 'main' into 2507-overzoom-geojson-vt
HarelM d80771a
Merge branch 'main' into 2507-overzoom-geojson-vt
HarelM 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
Some comments aren't visible on the classic Files Changed page.
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
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
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,119 @@ | ||
| import {type VectorTile, VectorTileFeature, VectorTileLayer} from '@mapbox/vector-tile'; | ||
| import Protobuf from 'pbf'; | ||
| import Point from '@mapbox/point-geometry'; | ||
| import {fromVectorTileJs} from '@maplibre/vt-pbf'; | ||
| import {clipGeometry} from '../symbol/clip_line'; | ||
| import type {LoadVectorTileResult} from './vector_tile_worker_source'; | ||
| import type {CanonicalTileID} from './tile_id'; | ||
|
|
||
| class VectorTileFeatureOverzoomed extends VectorTileFeature { | ||
| pointsArray: Point[][]; | ||
|
|
||
| constructor(type: 0 | 1 | 2 | 3, geometry: Point[][], properties: any, id: number, extent: number) { | ||
| super(new Protobuf(), 0, extent, [], []); | ||
| this.type = type; | ||
| this.properties = properties ? properties : {}; | ||
| this.extent = extent; | ||
| this.pointsArray = geometry; | ||
| this.id = id; | ||
| } | ||
|
|
||
| loadGeometry() { | ||
| // Clone the geometry and ensure all points are Point instances | ||
| return this.pointsArray.map(ring => | ||
| ring.map(point => new Point(point.x, point.y)) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class VectorTileLayerOverzoomed extends VectorTileLayer { | ||
| private _myFeatures: VectorTileFeatureOverzoomed[]; | ||
| name: string; | ||
| extent: number; | ||
| version: number = 2; | ||
| length: number; | ||
|
|
||
| constructor(features: VectorTileFeatureOverzoomed[], layerName: string, extent: number) { | ||
| super(new Protobuf()); | ||
| this._myFeatures = features; | ||
| this.name = layerName; | ||
| this.length = features.length; | ||
| this.extent = extent; | ||
| } | ||
|
|
||
| feature(i: number): VectorTileFeature { | ||
| return this._myFeatures[i]; | ||
| } | ||
| } | ||
|
|
||
| export class VectorTileOverzoomed implements VectorTile { | ||
| layers: Record<string, VectorTileLayer> = {}; | ||
|
|
||
| addLayer(layer: VectorTileLayerOverzoomed) { | ||
| this.layers[layer.name] = layer; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Encodes the virtual tile into binary vector tile form. | ||
| * This is a convenience that allows `FeatureIndex` to operate the same way across `VectorTileSource` and `GeoJSONSource` data. | ||
| * @param virtualVectorTile - a syntetically created vector tile, this tile should have the relevant layer and features already added to it. | ||
| * @returns - the encoded vector tile along with the original virtual tile binary data. | ||
| */ | ||
| export function toVirtualVectorTile(virtualVectorTile: VectorTile): LoadVectorTileResult { | ||
| let pbf: Uint8Array = fromVectorTileJs(virtualVectorTile); | ||
| if (pbf.byteOffset !== 0 || pbf.byteLength !== pbf.buffer.byteLength) { | ||
| pbf = new Uint8Array(pbf); // Compatibility with node Buffer (https://github.com/mapbox/pbf/issues/35) | ||
| } | ||
| return { | ||
| vectorTile: virtualVectorTile, | ||
| rawData: pbf.buffer | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * This function slices a source tile layer into an overzoomed tile layer for a target tile ID. | ||
| * @param sourceLayer - the source tile layer to slice | ||
| * @param maxZoomTileID - the maximum zoom tile ID | ||
| * @param targetTileID - the target tile ID | ||
| * @returns - the overzoomed tile layer | ||
| */ | ||
| export function sliceVectorTileLayer(sourceLayer: VectorTileLayer, maxZoomTileID: CanonicalTileID, targetTileID: CanonicalTileID): VectorTileLayerOverzoomed { | ||
| const {extent} = sourceLayer; | ||
| const dz = targetTileID.z - maxZoomTileID.z; | ||
| const scale = Math.pow(2, dz); | ||
|
|
||
| // Calculate the target tile's position within the source tile in target coordinate space | ||
| // This ensures all tiles share the same coordinate system | ||
| const offsetX = (targetTileID.x - maxZoomTileID.x * scale) * extent; | ||
| const offsetY = (targetTileID.y - maxZoomTileID.y * scale) * extent; | ||
|
|
||
| const featureWrappers: VectorTileFeatureOverzoomed[] = []; | ||
| for (let index = 0; index < sourceLayer.length; index++) { | ||
| const feature: VectorTileFeature = sourceLayer.feature(index); | ||
| let geometry = feature.loadGeometry(); | ||
|
|
||
| // Transform all coordinates to target tile space | ||
| for (const ring of geometry) { | ||
| for (const point of ring) { | ||
| point.x = point.x * scale - offsetX; | ||
| point.y = point.y * scale - offsetY; | ||
| } | ||
| } | ||
|
|
||
| const buffer = 128; | ||
| geometry = clipGeometry(geometry, feature.type, -buffer, -buffer, extent + buffer, extent + buffer); | ||
| if (geometry.length === 0) { | ||
| continue; | ||
| } | ||
|
|
||
| featureWrappers.push(new VectorTileFeatureOverzoomed( | ||
| feature.type, | ||
| geometry, | ||
| feature.properties, | ||
| feature.id, | ||
| extent | ||
| )); | ||
| } | ||
| return new VectorTileLayerOverzoomed(featureWrappers, sourceLayer.name, 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
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.