UNPKG

@globalfishingwatch/react-map-gl

Version:

A React wrapper for MapboxGL-js and overlay API.

19 lines (15 loc) 516 B
// @flow /* global window */ const pixelRatio = (typeof window !== 'undefined' && window.devicePixelRatio) || 1; export const crispPixel = (size: number) => Math.round(size * pixelRatio) / pixelRatio; export const crispPercentage = ( el: null | HTMLElement, percentage: number, dimension: 'x' | 'y' = 'x' ) => { if (el === null) { return percentage; } const origSize = dimension === 'x' ? el.offsetWidth : el.offsetHeight; return (crispPixel((percentage / 100) * origSize) / origSize) * 100; };