📚 AtmoSwing Web Viewer Docs

← Back to Home

Map Utils

Files


Modules

components/map/utils/olStyleUtils

Utilities for OpenLayers style creation and color parsing. Supports hex, rgb, rgba, QGIS-style colors, and style configuration objects.

components/map/utils/olProjectionUtils

Centralized projection utilities for OpenLayers with proj4 integration.

components/map/utils/loadWmtsCapabilities

Utilities for loading WMTS (Web Map Tile Service) capabilities and creating tile layers. Handles fetching capabilities XML, parsing layer options, and caching for reuse.

components/map/utils/buildLegendStops

Generates legend gradient stops for map visualization.

components/map/utils/olStyleUtils

Utilities for OpenLayers style creation and color parsing. Supports hex, rgb, rgba, QGIS-style colors, and style configuration objects.

components/map/utils/olStyleUtils.toRGBA(input, [alphaFallback]) ⇒ string

Converts various color formats to CSS rgba() string. Supports hex, rgb/rgba strings, QGIS-style comma-separated values, and arrays.

Kind: static method of components/map/utils/olStyleUtils
Returns: string - CSS rgba() color string

Param Type Default Description
input string | Array Color in various formats
[alphaFallback] number 1 Default alpha value if not specified

Example

toRGBA('#ff0000') // Returns: "rgba(255,0,0,1)"
toRGBA('255,0,0,128') // Returns: "rgba(255,0,0,0.5)"

components/map/utils/olStyleUtils.styleFromConfigObj([obj]) ⇒ function

Creates an OpenLayers style function from a configuration object. Supports different styles for lines, polygons, and points.

Kind: static method of components/map/utils/olStyleUtils
Returns: function - OpenLayers style function

Param Type Default Description
[obj] Object {} Style configuration object
[obj.line] Object Line style configuration
[obj.polygon] Object Polygon style configuration
[obj.point] Object Point/circle style configuration
[obj.strokeColor] string Fallback stroke color
[obj.strokeWidth] number Fallback stroke width
[obj.fillColor] string Fallback fill color

Example

const style = styleFromConfigObj({
  line: { stroke: { color: '#ff0000', width: 3 } },
  polygon: { fill: { color: 'rgba(255,0,0,0.2)' } }
});

components/map/utils/olProjectionUtils

Centralized projection utilities for OpenLayers with proj4 integration.

components/map/utils/olProjectionUtils.ensureProjDefined(epsg)

Ensures a projection is defined in proj4 and registered with OpenLayers. Uses predefined definitions for known EPSG codes. Handles registration errors silently.

Kind: static method of components/map/utils/olProjectionUtils

Param Type Description
epsg string EPSG code (e.g., "EPSG:2154")

Example

ensureProjDefined('EPSG:2154'); // Registers Lambert-93 for France

components/map/utils/olProjectionUtils~PREDEFINED : Object

Predefined proj4 projection definitions for common EPSG codes.

Kind: inner constant of components/map/utils/olProjectionUtils

components/map/utils/loadWmtsCapabilities

Utilities for loading WMTS (Web Map Tile Service) capabilities and creating tile layers. Handles fetching capabilities XML, parsing layer options, and caching for reuse.

components/map/utils/loadWmtsCapabilities.loadWmtsCapabilities(runtimeConfig, [enqueueWarning], [preferStyleForItem]) ⇒ Promise.<Object>

Fetches WMTS capabilities from configured providers and builds options cache. Processes base layers and overlay layers from runtime config, attempts to load capabilities with preferred styles, and returns a cache of layer options.

Kind: static method of components/map/utils/loadWmtsCapabilities
Returns: Promise.<Object> - Cache object mapping wmtsLayer name to OpenLayers WMTS options

Param Type Description
runtimeConfig Object Runtime configuration with providers and layers
[enqueueWarning] function Optional callback to display warning messages
[preferStyleForItem] function Optional function to determine preferred style for an item

Example

const cache = await loadWmtsCapabilities(config, (msg) => console.warn(msg));
// Returns: { 'layerName': { ...wmtsOptions } }

components/map/utils/loadWmtsCapabilities.createWmtsTileLayer(item, wmtsOptionsCache) ⇒ WMTS | null

Creates an OpenLayers WMTS source from cached layer options.

Kind: static method of components/map/utils/loadWmtsCapabilities
Returns: WMTS | null - OpenLayers WMTS source instance, or null if not found in cache

Param Type Description
item Object Layer configuration item with wmtsLayer property
wmtsOptionsCache Object Cache of WMTS options from loadWmtsCapabilities

Example

const source = createWmtsTileLayer({ wmtsLayer: 'myLayer' }, cache);
if (source) {
  const layer = new TileLayer({ source });
}

components/map/utils/buildLegendStops

Generates legend gradient stops for map visualization.

components/map/utils/buildLegendStops.buildLegendStops([maxVal], [samples]) ⇒ Array.<Object>

Builds an array of color stops for a continuous legend gradient. Each stop represents a point in the gradient from 0 to maxVal.

Kind: static method of components/map/utils/buildLegendStops
Returns: Array.<Object> - Array of legend stops with {color: string, pct: number}

Param Type Default Description
[maxVal] number 1 Maximum value for the legend scale
[samples] number LEGEND_SAMPLES Number of gradient samples to generate

Example

const stops = buildLegendStops(100, 10);
// Returns: [
//   {color: 'rgb(255,255,255)', pct: 0},
//   {color: 'rgb(200,255,200)', pct: 10},
//   ...
//   {color: 'rgb(255,0,0)', pct: 100}
// ]