-
Notifications
You must be signed in to change notification settings - Fork 317
Expand file tree
/
Copy pathLayerUpdateStrategy.js
More file actions
77 lines (69 loc) · 2.77 KB
/
Copy pathLayerUpdateStrategy.js
File metadata and controls
77 lines (69 loc) · 2.77 KB
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
import { EMPTY_TEXTURE_ZOOM } from 'Renderer/RasterTile';
/**
* This modules implements various layer update strategies.
*
* Default strategy is STRATEGY_MIN_NETWORK_TRAFFIC which aims
* to reduce the amount of network traffic.
*/
export const STRATEGY_MIN_NETWORK_TRAFFIC = 0;
export const STRATEGY_GROUP = 1;
export const STRATEGY_PROGRESSIVE = 2;
export const STRATEGY_DICHOTOMY = 3;
function _minimizeNetworkTraffic(node, nodeLevel) {
return nodeLevel;
}
// Maps nodeLevel to groups defined in layer's options
// eg with groups = [3, 7, 12]:
// * nodeLevel = 2 -> 3
// * nodeLevel = 4 -> 3
// * nodeLevel = 7 -> 7
// * nodeLevel = 15 -> 12
function _group(nodeLevel, options) {
const f = options.groups.filter(val => (val <= nodeLevel));
return f.length ? f[f.length - 1] : options.groups[0];
}
function _progressive(nodeLevel, currentLevel, options) {
return Math.min(nodeLevel,
currentLevel + (options.increment || 1));
}
// Load textures at mid-point between current level and node's level.
// This produces smoother transitions and a single fetch updates multiple
// tiles thanks to caching.
function _dichotomy(nodeLevel, currentLevel, options = {}) {
if (currentLevel == EMPTY_TEXTURE_ZOOM) {
return options.zoom ? options.zoom.min : 0;
}
return Math.min(
nodeLevel,
Math.ceil((currentLevel + nodeLevel) / 2));
}
export function chooseNextLevelToFetch(strategy, node, nodeLevel = node.level, currentLevel, layer, failureParams) {
let nextLevelToFetch;
const maxZoom = layer.source.zoom ? layer.source.zoom.max : Infinity;
if (failureParams.lowestLevelError != Infinity) {
nextLevelToFetch = _dichotomy(failureParams.lowestLevelError, currentLevel, layer.source);
nextLevelToFetch = failureParams.lowestLevelError == nextLevelToFetch ? nextLevelToFetch - 1 : nextLevelToFetch;
if (strategy == STRATEGY_GROUP) {
nextLevelToFetch = _group(nextLevelToFetch, layer.updateStrategy.options);
}
} else {
switch (strategy) {
case STRATEGY_GROUP:
nextLevelToFetch = _group(nodeLevel, layer.updateStrategy.options);
break;
case STRATEGY_PROGRESSIVE: {
nextLevelToFetch = _progressive(nodeLevel, currentLevel, layer.updateStrategy.options);
break;
}
case STRATEGY_DICHOTOMY:
nextLevelToFetch = _dichotomy(nodeLevel, currentLevel, layer.source);
break;
// default strategy
case STRATEGY_MIN_NETWORK_TRAFFIC:
default:
nextLevelToFetch = _minimizeNetworkTraffic(node, nodeLevel);
}
nextLevelToFetch = Math.min(nextLevelToFetch, maxZoom);
}
return nextLevelToFetch;
}