-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
loadingstrategy.js
74 lines (70 loc) · 2.21 KB
/
loadingstrategy.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
/**
* @module ol/loadingstrategy
*/
import {fromUserExtent, fromUserResolution, toUserExtent} from './proj.js';
/**
* Strategy function for loading all features with a single request.
* @param {import("./extent.js").Extent} extent Extent.
* @param {number} resolution Resolution.
* @return {Array<import("./extent.js").Extent>} Extents.
* @api
*/
export function all(extent, resolution) {
return [[-Infinity, -Infinity, Infinity, Infinity]];
}
/**
* Strategy function for loading features based on the view's extent and
* resolution.
* @param {import("./extent.js").Extent} extent Extent.
* @param {number} resolution Resolution.
* @return {Array<import("./extent.js").Extent>} Extents.
* @api
*/
export function bbox(extent, resolution) {
return [extent];
}
/**
* Creates a strategy function for loading features based on a tile grid.
* @param {import("./tilegrid/TileGrid.js").default} tileGrid Tile grid.
* @return {function(import("./extent.js").Extent, number, import("./proj.js").Projection): Array<import("./extent.js").Extent>} Loading strategy.
* @api
*/
export function tile(tileGrid) {
return (
/**
* @param {import("./extent.js").Extent} extent Extent.
* @param {number} resolution Resolution.
* @param {import("./proj.js").Projection} projection Projection.
* @return {Array<import("./extent.js").Extent>} Extents.
*/
function (extent, resolution, projection) {
const z = tileGrid.getZForResolution(
fromUserResolution(resolution, projection),
);
const tileRange = tileGrid.getTileRangeForExtentAndZ(
fromUserExtent(extent, projection),
z,
);
/** @type {Array<import("./extent.js").Extent>} */
const extents = [];
/** @type {import("./tilecoord.js").TileCoord} */
const tileCoord = [z, 0, 0];
for (
tileCoord[1] = tileRange.minX;
tileCoord[1] <= tileRange.maxX;
++tileCoord[1]
) {
for (
tileCoord[2] = tileRange.minY;
tileCoord[2] <= tileRange.maxY;
++tileCoord[2]
) {
extents.push(
toUserExtent(tileGrid.getTileCoordExtent(tileCoord), projection),
);
}
}
return extents;
}
);
}