@dossierhq/leaflet
Version:
A library for rendering maps in Dossier with Leaflet.
43 lines • 1.6 kB
JavaScript
import { Icon } from 'leaflet';
const transparentImage = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
const markerIcon = new Icon({
iconUrl: transparentImage,
className: 'icon-map-marker',
iconSize: [22, 28],
iconAnchor: [11, 27],
});
const currentMarkerIcon = new Icon({
iconUrl: transparentImage,
className: 'icon-map-marker-current',
iconSize: [22, 28],
iconAnchor: [11, 27],
});
const markerIconStats = (() => {
let maxLeft = 0;
let maxRight = 0;
let maxTop = 0;
let maxBottom = 0;
for (const icon of [markerIcon, currentMarkerIcon]) {
const [width, height] = icon.options.iconSize;
const [x, y] = icon.options.iconAnchor;
maxLeft = Math.max(maxLeft, x);
maxRight = Math.max(maxRight, width - x);
maxTop = Math.max(maxTop, y);
maxBottom = Math.max(maxBottom, height - y);
}
return { maxLeft, maxRight, maxTop, maxBottom };
})();
export function getMarkerIcon(color) {
return color === 'current' ? currentMarkerIcon : markerIcon;
}
export function expandBoundingBoxForMarkers(boundingBox, zoomMetrics) {
const { maxLeft, maxRight, maxTop, maxBottom } = markerIconStats;
const result = {
minLat: boundingBox.minLat - zoomMetrics.pixelToLat * maxTop,
maxLat: boundingBox.maxLat + zoomMetrics.pixelToLat * maxBottom,
minLng: boundingBox.minLng - zoomMetrics.pixelToLat * maxLeft,
maxLng: boundingBox.maxLng + zoomMetrics.pixelToLat * maxRight,
};
return result;
}
//# sourceMappingURL=MarkerUtils.js.map