-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
remove_paint_state.js
114 lines (98 loc) · 3.16 KB
/
remove_paint_state.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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}));
}
return generated;
}
const width = 1024;
const height = 768;
const zoom = 4;
class RemovePaintState extends Benchmark {
constructor(center) {
super();
this.center = center;
}
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, '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: this.center,
style
}).then(map => {
this.map = map;
})
.catch(error => {
console.error(error);
});
});
}
bench() {
this.map._styleDirty = true;
this.map._sourcesDirty = true;
this.map._render();
}
teardown() {
this.map.remove();
}
}
export class PropertyLevelRemove extends RemovePaintState {
bench() {
for (let i = 0; i < this.numFeatures; i += 50) {
this.map.setFeatureState({source: 'land', id: i}, {bench: true});
}
for (let i = 0; i < this.numFeatures; i += 50) {
this.map.removeFeatureState({source: 'land', id: i}, 'bench');
}
this.map._render();
}
}
export class FeatureLevelRemove extends RemovePaintState {
bench() {
for (let i = 0; i < this.numFeatures; i += 50) {
this.map.setFeatureState({source: 'land', id: i}, {bench: true});
}
for (let i = 0; i < this.numFeatures; i += 50) {
this.map.removeFeatureState({source: 'land', id: i});
}
this.map._render();
}
}
export class SourceLevelRemove extends RemovePaintState {
bench() {
for (let i = 0; i < this.numFeatures; i += 50) {
this.map.setFeatureState({source: 'land', id: i}, {bench: true});
}
for (let i = 0; i < this.numFeatures; i += 50) {
this.map.removeFeatureState({source: 'land', id: i});
}
this.map._render();
}
}