Skip to content
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

Arbitrary states for feature interactivity #6263

Merged
merged 30 commits into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1fd379e
Track feature id to feature index in paint buffers.
Apr 13, 2018
aafefb5
Fix minor typo
Feb 28, 2018
d49d7f6
Implement state as properties
Apr 13, 2018
7cdd0dc
Update API args order and support retrieval of all states
Mar 2, 2018
03ba765
Append state to features returned from queryRenderedFeatures
Mar 2, 2018
a25e350
Support source-layers
Mar 2, 2018
5839647
Implement state expression
Apr 13, 2018
3179d09
Implement state dependenance
Apr 13, 2018
68666cc
Move feature states management to SourceFeatureState. Fix typos, go w…
Mar 7, 2018
d395539
Only some layers in a bucket may have state dependency
Mar 8, 2018
25502f4
Support multiple symbol placements. Also inadvertently supports dupli…
Mar 9, 2018
28abe7e
Add basic unit tests.
Mar 9, 2018
35c99ee
Address review feedback
Apr 13, 2018
2ab766e
Add feature-state render and query tests
Apr 13, 2018
8643ce3
Add points hover demo
Apr 3, 2018
6bb378c
Rearrange and simplify arguments to Map#setfeatureState. Fire error f…
Apr 5, 2018
d82ff17
Fix this.needsUpload short-circuit, and make `Map#getFeatureState(...…
Apr 13, 2018
9050725
Update feature state on symbols queried from a global collision index.
Apr 14, 2018
b3f8b97
Rename features state get/set to get(set)FeatureStateValue
Apr 14, 2018
f6f4a20
Fix integration tests
Apr 17, 2018
d2887af
Fix debug page and symbol querying
Apr 17, 2018
38bd87a
Fix sourceLayer identification for geojson sources
Apr 18, 2018
f78ab96
Fix bug that affects first (0th) feature in every tile
Apr 18, 2018
b96b661
Rename 'state' expression to 'feature-state'. Add documentation in v8…
Apr 18, 2018
f3174e8
Separately signal upload and update for SybmolBuffer
Apr 18, 2018
adcc01e
Rename setFatureStateValue to updateState. Allow setting/getting mult…
Apr 19, 2018
2721a29
Fix query integration tests.
Apr 19, 2018
ad5e67e
Rename feature state setter to `Map#setFeatureState`. Update document…
Apr 19, 2018
9a2f755
Update highlightpoints.html to use setFeatureState
ChrisLoer Apr 20, 2018
2bde933
Add Feature states benchmark
Apr 24, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bench/benchmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function register(Benchmark) {
import Layout from './benchmarks/layout';
import LayoutDDS from './benchmarks/layout_dds';
import Paint from './benchmarks/paint';
import PaintStates from './benchmarks/paint_states';
import LayerBenchmarks from './benchmarks/layers';
import Load from './benchmarks/map_load';
import Validate from './benchmarks/style_validate';
Expand All @@ -31,6 +32,7 @@ import FilterEvaluate from './benchmarks/filter_evaluate';
register(Layout);
register(LayoutDDS);
register(Paint);
register(PaintStates);
LayerBenchmarks.forEach(register);
register(Load);
register(Validate);
Expand Down
68 changes: 68 additions & 0 deletions bench/benchmarks/paint_states.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

import style from '../data/empty.json';
import Benchmark from '../lib/benchmark';
import createMap from '../lib/create_map';

function generateLayers(layer) {
const generated = [];
for (let i = 0; i < 50; i++) {
const id = layer.id + i;
generated.push(Object.assign({}, layer, {id: id}));
}
return generated;
}

const width = 1024;
const height = 768;
const zoom = 4;

export default class PaintStates extends Benchmark {
setup() {
return fetch('/bench/data/naturalearth-land.json')
.then(response => response.json())
.then(data => {
this.numFeatures = data.features.length;
return Object.assign({}, style, {
sources: {'land': {'type': 'geojson', 'data': data, 'maxzoom': 23}},
layers: generateLayers({
'id': 'layer',
'type': 'fill',
'source': 'land',
'paint': {
'fill-color': [
'case',
['boolean', ['feature-state', 'bench'], false],
['rgb', 21, 210, 210],
['rgb', 233, 233, 233]
]
}
})
});
})
.then((style) => {
return createMap({
zoom,
width,
height,
center: [-77.032194, 38.912753],
style: style
}).then(map => {
this.map = map;
});
});
}

bench() {
this.map._styleDirty = true;
this.map._sourcesDirty = true;
this.map._render();
for (let i = 0; i < this.numFeatures; i += 50) {
this.map.setFeatureState({ source: 'land', id: i }, { bench: true });
}
this.map._render();
}

teardown() {
this.map.remove();
}
}
2 changes: 1 addition & 1 deletion bench/data/naturalearth-land.json

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions debug/highlightpoints.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!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">
<link rel='stylesheet' href='/dist/mapbox-gl.css' />
<style>
body { margin: 0; padding: 0; }
html, body, #map { height: 100%; }
</style>
</head>

<body>
<div id='map'></div>

<script src='/dist/mapbox-gl-dev.js'></script>
<script src='/debug/access_token_generated.js'></script>
<script>

var map = window.map = new mapboxgl.Map({
container: 'map',
zoom: 2.5,
center: [0, 0],
style: 'mapbox://styles/mapbox/light-v9',
hash: true
});
map.showTileBoundaries = true;
map.on('load', function() {
map.addSource('places', {
type: "geojson",
data: "/test/integration/data/places.geojson"
});
map.addLayer({
id:"places",
source: "places",
type:"circle",
paint: {
"circle-radius": ["case",
["boolean", ["feature-state", "hover"], false],
["number", ["*", ["get", "scalerank"], 2]],
["number", ["*", ["get", "scalerank"], 1.5]]
],
"circle-color": ["case",
["boolean", ["feature-state", "hover"], false],
["rgb", 21, 210, 210],
["rgb", 233, 103, 233]
]
}
});
let hoveredFeature;
map.on('mousemove', 'places', function(e) {
if (e.features.length) {
const f = e.features[0];
if (!f.state.hover) {
map.setFeatureState(f, {'hover': true});
if (hoveredFeature) {
map.setFeatureState(hoveredFeature, {'hover': false});
}
hoveredFeature = f;
}
}
});
});

</script>
</body>
</html>
Loading