UNPKG

mobility-toolbox-js

Version:

Toolbox for JavaScript applications in the domains of mobility and logistics.

26 lines (25 loc) 1.04 kB
export const DEFAULT_GRAPH = 'osm'; export const DEFAULT_GRAPH_MAPPING = { 1: DEFAULT_GRAPH, }; /** * This function return which graph to use based on the current zoom level. * * The list of graphs available for a maplibre style is available in the style metadata. * * @param {number} zoom - The current zoom level of the map. * @param {StyleMetadataGraphs} styleMetadata - The style metadata containing the graph mapping. * @returns {string} - The graph to use for the given zoom level. */ export default function getGraphByZoom(zoom = 0, styleMetadata = DEFAULT_GRAPH_MAPPING) { var _a; const breakPoints = Object.keys(styleMetadata).map((k) => { return parseFloat(k); }); const closest = breakPoints.reverse().find((bp) => { return bp <= Math.floor(zoom) - 1; // - 1 due to ol zoom !== mapbox zoom }); let key = closest; key !== null && key !== void 0 ? key : (key = Math.min(...breakPoints)); return (_a = styleMetadata[key]) !== null && _a !== void 0 ? _a : DEFAULT_GRAPH; }