Move tile priority function to the TileQueue module
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
import TileState from './TileState.js';
|
||||
import EventType from './events/EventType.js';
|
||||
import PriorityQueue from './structs/PriorityQueue.js';
|
||||
import PriorityQueue, {DROP} from './structs/PriorityQueue.js';
|
||||
|
||||
|
||||
/**
|
||||
@@ -119,3 +119,34 @@ class TileQueue extends PriorityQueue {
|
||||
|
||||
|
||||
export default TileQueue;
|
||||
|
||||
|
||||
/**
|
||||
* @param {import('./PluggableMap.js').FrameState} frameState Frame state.
|
||||
* @param {import("./Tile.js").default} tile Tile.
|
||||
* @param {string} tileSourceKey Tile source key.
|
||||
* @param {import("./coordinate.js").Coordinate} tileCenter Tile center.
|
||||
* @param {number} tileResolution Tile resolution.
|
||||
* @return {number} Tile priority.
|
||||
*/
|
||||
export function getTilePriority(frameState, tile, tileSourceKey, tileCenter, tileResolution) {
|
||||
// Filter out tiles at higher zoom levels than the current zoom level, or that
|
||||
// are outside the visible extent.
|
||||
if (!frameState || !(tileSourceKey in frameState.wantedTiles)) {
|
||||
return DROP;
|
||||
}
|
||||
if (!frameState.wantedTiles[tileSourceKey][tile.getKey()]) {
|
||||
return DROP;
|
||||
}
|
||||
// Prioritize the highest zoom level tiles closest to the focus.
|
||||
// Tiles at higher zoom levels are prioritized using Math.log(tileResolution).
|
||||
// Within a zoom level, tiles are prioritized by the distance in pixels between
|
||||
// the center of the tile and the center of the viewport. The factor of 65536
|
||||
// means that the prioritization should behave as desired for tiles up to
|
||||
// 65536 * Math.log(2) = 45426 pixels from the focus.
|
||||
const center = frameState.viewState.center;
|
||||
const deltaX = tileCenter[0] - center[0];
|
||||
const deltaY = tileCenter[1] - center[1];
|
||||
return 65536 * Math.log(tileResolution) +
|
||||
Math.sqrt(deltaX * deltaX + deltaY * deltaY) / tileResolution;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user