-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
s̶y̶m̶b̶o̶l̶-̶c̶l̶i̶p̶ dynamic-filtering with
pitch
and `distance-f…
…rom-camera` expressions (#10795) * Setup plumbing for pitch and distance-from-camera expressions * Add symbol-clip with support for pitch and distance-from-camera expressions * hackily working pitch expression * distance clipping * Track clipped state in JointPlacement and JointOpacity, reflect clipping using notUsed state in debug buffers * Rename distance-from-camera to distance-from-center * symbol-clip: splitting filter expressions into dynamic and static parts (#10923) * symbol-clip: dynamic filter style spec changes (#10977) * symbol-clip: Render tests, debug page and distance matrix rework (#11065) * WIP dynamic filter splitting stage 1 * Add tests for isDynamicFilter * More test cases for isDynamicFilter * Existing static filters get passed through unmodified. * WIP extracting static filters * Working case -> any translation * More tests for case -> any conversion * Add support for match branches * WIP: V0 of adding collapsing of dynamic expressions to true * more test cases * tests and some more refactoring * remove temory inspection code from unit tests * Fix dynamic filter detection * Fix failing spec test * Units tests hopefully :green: now * Add test to cover for `null` in expressions * Address CR comments and reduce number of temporary allocations * remove gl-matrix as dependency of style-spec and inline a matrix multiplication function * Fix lint issues * Add better error messages for expression compilation failures * Ensure location parameter is passed down * Remove symbol-clip from the style-spec * Remove unused property-expression type * Move filterSpec to v8.json and replace symbol-clip with dynamic filter * Fix unit tests * Fix most flow errors * finally flow is happy * Add expression validation code * Add api-supported tests for validation * Fix some failing unit tests * Ensure layer._featureFIlter is updated on main thread as well * Ensure layerType is passed down to validation * Fix flow and linting * Fix unit tests * Pass 1 of addressing CR comments * Add basic placementTime metric * Move to using total placement time * Fix lint errors * simplify placement time tracking * Fix silent conflict in with SymbolInstanceStruct changes * try benchmarking with filter splitting algorithm removed * Fix versions microbenchmark page * Revert "try benchmarking with filter splitting algorithm removed" This reverts commit 865f354. * Simplify by calculating distance using tile coordinates of the symbol directly * Use new specific centerDistanceMatrix * Sign flipping for consistency * add new debug page with distance visualizer * First set of pure distance based render tests * Pitch thresholding tests * Fix lint errors * More tests * Add first batch of point symbol render tests * Increase threshold * Increase allowed threshold for the correct tests 🤦 * remove flaky collision debug boxes instead * Move geojson test data to be in separate files instead of inlined into styles * Update flaky render test expectation * Fix distanceMatrix comment Co-authored-by: Aidan H <aidan.hendrickson@mapbox.com> * Switch to linear scale and update line placement tests * Update point placement tests * Update test expectations * Fix lint error * Remove flaky collision boxes Co-authored-by: Aidan H <aidan.hendrickson@mapbox.com> * Remove frametime logging change * Ensure that feature deserialization happens only when needed * Fix matrixKey naming leftover from copying fogMatrix code Co-authored-by: Karim Naaji <karim.naaji@gmail.com> * Rename matrices as per CR comments * Default layerType inside filter validation function. * add `VectorTileFeature` deserialization cache * Switch to matrix-free distance calculation * Add cache in Transform * Precompute bearing vector * prescale by windowScaleFactor * Inline `getSymbolFeature` * Lazy filter compilation * Move distance matrix calculation out to the debug page Co-authored-by: Aidan H <aidan.hendrickson@mapbox.com> Co-authored-by: Karim Naaji <karim.naaji@gmail.com>
- Loading branch information
1 parent
e8ca715
commit cb4778f
Showing
90 changed files
with
8,678 additions
and
101 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Mapbox GL JS debug page</title> | ||
<meta charset='utf-8'> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> | ||
<script src="https://cdn.jsdelivr.net/npm/@turf/turf@6/turf.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/gl-matrix@3.3.0/gl-matrix-min.js"></script> | ||
<link rel='stylesheet' href='../dist/mapbox-gl.css' /> | ||
<style> | ||
body { margin: 0; padding: 0; } | ||
html, body, #map { height: 100%; } | ||
#tooltip { | ||
position: absolute; | ||
left: 0px; | ||
top: 0px; | ||
background-color: white; | ||
z-index: 5; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id='map'> | ||
<div id='tooltip'></div> | ||
</div> | ||
|
||
<script src='../dist/mapbox-gl-dev.js'></script> | ||
<script src='../debug/access_token_generated.js'></script> | ||
<script> | ||
|
||
/*global glMatrix, turf*/ | ||
|
||
var map = window.map = new mapboxgl.Map({ | ||
container: 'map', | ||
zoom: 10.852, | ||
center: [-120.30344797631889, 38.11726797649675], | ||
style: 'mapbox://styles/mapbox/streets-v11', | ||
// hash: true | ||
}); | ||
|
||
function calcMercatorDistanceMatrix() { | ||
const center = map.transform.point; | ||
|
||
const m = new Float64Array(16); | ||
const worldSize = map.transform.worldSize; | ||
const windowScaleFactor = 1 / map.transform.height; | ||
glMatrix.mat4.fromScaling(m, [windowScaleFactor, -windowScaleFactor, windowScaleFactor]); | ||
glMatrix.mat4.rotateZ(m, m, map.transform.angle); | ||
glMatrix.mat4.translate(m, m, [-center.x, -center.y, 0]); | ||
|
||
return glMatrix.mat4.scale([], m, [worldSize, worldSize, 1]); | ||
} | ||
|
||
function generateDistanceScales() { | ||
const center = map.getCenter(); | ||
const bearing = map.getBearing(); | ||
const numSteps = 10; | ||
const step = 0.25; | ||
|
||
const matrix = glMatrix.mat4.invert([], calcMercatorDistanceMatrix()); | ||
const lines = []; | ||
for (let i = -numSteps; i <= numSteps; i++) { | ||
const distance = step * i; | ||
const v0 = [-2, distance, 0]; | ||
const v1 = [0, distance, 0]; | ||
const v2 = [2, distance, 0]; | ||
const p0 = new mapboxgl.MercatorCoordinate(...glMatrix.vec3.transformMat4([], v0, matrix)).toLngLat(); | ||
const p1 = new mapboxgl.MercatorCoordinate(...glMatrix.vec3.transformMat4([], v1, matrix)).toLngLat(); | ||
const p2 = new mapboxgl.MercatorCoordinate(...glMatrix.vec3.transformMat4([], v2, matrix)).toLngLat(); | ||
const line = turf.lineString([[p0.lng, p0.lat], [p1.lng, p1.lat], [p2.lng, p2.lat]], {distance: `${distance.toFixed(2)}`}); | ||
lines.push(line); | ||
} | ||
|
||
return turf.featureCollection(lines); | ||
} | ||
|
||
const tooltip = document.getElementById('tooltip'); | ||
map.on('mousemove', (e) => { | ||
const loc = map.unproject(e.point); | ||
const m = calcMercatorDistanceMatrix(); | ||
const {x, y, z} = mapboxgl.MercatorCoordinate.fromLngLat(loc); | ||
const v = glMatrix.vec3.transformMat4([], [x, y, z], m); | ||
|
||
const dist = v[1]; | ||
tooltip.innerText = dist.toFixed(2); | ||
tooltip.style.transform = `translate(${e.point.x + 10}px,${e.point.y + 10}px)`; | ||
}); | ||
|
||
map.once('load', () => { | ||
map.setFilter('building-number-label', | ||
["case", | ||
["<", ["pitch"], 60], true, | ||
["all", [">=", ["pitch"], 60], ["<", ["distance-from-center"], 0]], true, | ||
false | ||
] | ||
); | ||
|
||
map.addSource('rings', { | ||
type: 'geojson', | ||
data: { | ||
"type": "FeatureCollection", | ||
"features": [] | ||
} | ||
}); | ||
|
||
map.addLayer({ | ||
type: 'line', | ||
id: 'rings-layer', | ||
source: 'rings', | ||
paint: { | ||
"line-width": 10 | ||
} | ||
}); | ||
|
||
map.addLayer({ | ||
type: 'symbol', | ||
id: 'rings-labels', | ||
source: 'rings', | ||
layout: { | ||
"symbol-placement": 'line', | ||
"text-field": ["get", "distance"], | ||
"text-pitch-alignment": "viewport", | ||
"text-allow-overlap": true | ||
}, | ||
paint: { | ||
"text-color": 'red', | ||
"text-halo-color": 'white', | ||
"text-halo-width": 2 | ||
} | ||
}); | ||
|
||
map.on('idle', () => { | ||
const scale = generateDistanceScales(); | ||
map.getSource('rings').setData(scale); | ||
}); | ||
|
||
}); | ||
|
||
</script> | ||
</body> | ||
</html> |
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
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
Oops, something went wrong.