tracktracker/src/front/map/common.js

60 lines
1.6 KiB
JavaScript

import color from "color";
/** Make a value scale according to the zoom level. */
export const scaleZoom = value => [
"interpolate",
["exponential", 2],
["zoom"],
10, value,
24, ["*", value, ["^", 2, 6]]
];
/**
* Turn the main color of a line into a color suitable for using as a border.
* @param {string} mainColor Original color.
* @returns {string} Hexadecimal representation of the border color.
*/
export const makeBorderColor = mainColor => {
return color(mainColor).darken(0.2).hex();
};
/**
* Turn the main color of a line into a color suitable for using as a border.
* @param {string} mainColor Original color.
* @returns {string} Hexadecimal representation of the border color.
*/
export const makeCourseColor = mainColor => {
return color(mainColor).lighten(0.2).hex();
};
/**
* Make an OpenLayers style function cache its results.
* @param {Function} createStyle Create a style based on the cache key value.
* @param {Function} [cacheKey] Return the cache key for each feature
* (default: identity function).
* @return {Function} Style function that caches the generated styles.
*/
export const cacheStyle = (createStyle, cacheKey = x => x) => {
const cache = {};
return (feature) => {
const key = cacheKey(feature);
if (!(key in cache)) {
cache[key] = createStyle(key);
}
return cache[key];
};
};
export const sizes = {
segmentOuter: 8,
segmentInner: 12,
stopOuter: 8,
stopInner: 6,
courseSize: 15,
courseOuterBorder: 13,
courseBorder: 10,
courseInnerBorder: 7
};