UNPKG

plotly.js

Version:

The open source javascript graphing library that powers plotly

44 lines (43 loc) • 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMapFitBounds = getMapFitBounds; const geo_location_utils_1 = require("../../lib/geo_location_utils"); /** * Compute a lon/lat bounding box from lonlat-bearing traces (`scattermap`, * `densitymap`) on the given map subplot. * * Returns null when: * - no fittable data exists on the subplot; * - a location-based trace (`choroplethmap`) is present — those carry * `locations`/`geojson`, not raw lon/lat, and need geojson bbox handling * that isn't implemented here. * * @param fullData - The full data array (post supply-defaults) * @param subplotId - e.g. `'map'`, `'map2'` */ function getMapFitBounds(fullData, subplotId) { const coordinates = []; for (const trace of fullData) { if (trace.subplot !== subplotId || trace.visible !== true) continue; // choroplethmap traces carry locations/geojson, not raw lon/lat; bail // out rather than frame around a subset of the subplot's data. if (trace.type === 'choroplethmap') return null; const { lat, lon } = trace; if (!lon || !lat) continue; const len = Math.min(lon.length, lat.length); for (let j = 0; j < len; j++) { const lo = lon[j]; const la = lat[j]; if (Number.isFinite(lo) && Number.isFinite(la)) coordinates.push([lo, la]); } } const bbox = (0, geo_location_utils_1.computeBbox)({ type: 'MultiPoint', coordinates }); if (!bbox) return null; const [west, south, east, north] = bbox; return { west, east, south, north }; }