Registry / web-framework / geostyler-openlayers-parser

geostyler-openlayers-parser

JSON →
library5.6.1jsnpmunverified

The `geostyler-openlayers-parser` package provides a robust implementation of a GeoStyler style parser specifically tailored for OpenLayers. It enables developers to convert GeoStyler's abstract style definitions into concrete OpenLayers style objects, and vice-versa, facilitating cross-platform style management for geospatial applications. The current stable version is 5.6.1, released in April 2026. The project maintains a very active release cadence, with multiple minor and patch updates occurring monthly, indicating continuous development and bug fixing. A key differentiator is its seamless integration within the broader GeoStyler ecosystem, allowing for consistent style representation across various mapping libraries, and its support for advanced OpenLayers styling features like `graphicStroke` and `WellKnownNames` for enhanced symbolization.

npm install geostyler-openlayers-parser
INSTALL
IMPORT
SIG · GEOSTYLER-OPENLAYE
G
geostyler-openlayers-parser
web-frameworkjavascriptv5.6.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OpenLayersParser
import OpenLayersParser from 'geostyler-openlayers-parser';
const OpenLayersParser = require('geostyler-openlayers-parser');
The primary class for parsing GeoStyler styles to/from OpenLayers styles. Package is primarily ESM, but older Node versions might attempt CommonJS.
OlLayerVector
import OlLayerVector from 'ol/layer/Vector';
import { Vector as OlLayerVector } from 'ol/layer';
This is a common import pattern for OpenLayers vector layers, often used in conjunction with the parser output.
OlStyleParser
import OpenLayersParser from 'geostyler-openlayers-parser';
var parser = new GeoStylerOpenlayersParser.OlStyleParser(ol);
In browser environments, the `OlStyleParser` might be exposed globally or via a namespace. For modern ES modules, `OpenLayersParser` is the correct named export. `GeoStylerOpenlayersParser.OlStyleParser` is typically seen in older UMD/IIFE bundles.

This example demonstrates how to convert a GeoStyler JSON style definition into an OpenLayers style object using `geostyler-openlayers-parser` and apply it to an `ol/layer/Vector`.

import OpenLayersParser from 'geostyler-openlayers-parser'; import OlLayerVector from 'ol/layer/Vector'; import OlMap from 'ol/Map'; import OlView from 'ol/View'; import OlSourceVector from 'ol/source/Vector'; import Feature from 'ol/Feature'; import Point from 'ol/geom/Point'; const pointSimplePoint = { name: 'OL Style', rules: [ { name: 'OL Style Rule 0', symbolizers: [ { kind: 'Mark', wellKnownName: 'circle', color: '#FF0000', radius: 6, stroke: { color: '#000000', width: 2 } } ] } ] }; const parser = new OpenLayersParser(); // Create a dummy feature and source for the layer const feature = new Feature({ geometry: new Point([0, 0]) }); const source = new OlSourceVector({ features: [feature] }); const layer = new OlLayerVector({ source }); parser .writeStyle(pointSimplePoint) .then(({output: olStyle}) => { if (olStyle) { layer.setStyle(olStyle); console.log('OpenLayers style applied to layer.'); } else { console.error('Failed to parse style: output is undefined.'); } }) .catch(error => console.error('Error parsing or applying style:', error)); // Basic OpenLayers Map setup for demonstration (optional, but makes code runnable) const map = new OlMap({ target: document.createElement('div'), // Render to a div, not necessarily visible layers: [layer], view: new OlView({ center: [0, 0], zoom: 10 }) }); console.log('OpenLayers map initialized with layer.');
Debug
Known issues
gotchaThis package has a peer dependency on `ol` (OpenLayers). Ensure your OpenLayers version is compatible with the version specified in the `peerDependencies` (currently `>=7.4`), otherwise, runtime errors or unexpected styling behavior may occur.
fix
Check your `package.json` for `ol` and `geostyler-openlayers-parser` to ensure their versions meet the specified peer dependency range. Upgrade `ol` if necessary.
affects: >=5.0.0
gotchaThe package primarily uses ES Modules (ESM). Using `require()` for CommonJS imports in an ESM-only project will lead to `TypeError: require is not a function` or incorrect module resolution.
fix
Always use `import OpenLayersParser from 'geostyler-openlayers-parser';` for modern JavaScript/TypeScript projects. If using older Node.js or a CommonJS environment, check if a separate CommonJS build is available or configure your bundler (e.g., Webpack, Rollup) to handle ESM.
affects: >=5.0.0
gotchaThe `OlFlatStyleParser` was introduced in `v5.1.0` to support flat style objects in OpenLayers. If you are working with these flat styles, ensure you are on `v5.1.0` or higher to utilize its capabilities for parsing expressions and specific symbolizer properties like `icon-width`.
fix
Upgrade to `geostyler-openlayers-parser@5.1.0` or newer to leverage the `OlFlatStyleParser` and its enhanced parsing features for flat OpenLayers styles.
affects: <5.1.0
gotchaRecent versions (e.g., `v5.6.0`, `v5.5.0`) introduced support for `graphicStroke` in `LineSymbolizer` and additional `WellKnownNames`. If your styles utilize these features, earlier versions of the parser will not correctly interpret or apply them.
fix
To ensure full compatibility with modern GeoStyler and OpenLayers styles that use features like `graphicStroke` or expanded `WellKnownNames`, upgrade to the latest stable version of `geostyler-openlayers-parser`.
affects: <5.6.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'setStyle')
The `olStyle` returned from `parser.writeStyle()` might be undefined or null, indicating a parsing error or an invalid input GeoStyler style, leading to attempts to call `setStyle` on a non-object.
fix
Add error handling and null/undefined checks for the `olStyle` output. Thoroughly validate your input GeoStyler style object against the `geostyler-style` schema to ensure it's well-formed.
TypeError: Class constructor Vector cannot be invoked without 'new'
This error typically arises in OpenLayers when a class constructor (like `Vector` for `ol/layer/Vector`) is called as a function instead of with the `new` keyword, often due to incorrect destructuring or module imports.
fix
Ensure that OpenLayers classes are imported and instantiated correctly, e.g., `import OlLayerVector from 'ol/layer/Vector'; const layer = new OlLayerVector();`. Avoid direct destructuring like `import { Vector } from 'ol/layer';` which can sometimes lead to this issue depending on the bundler configuration.
ERR_REQUIRE_ESM
Attempting to `require()` an ES Module in a CommonJS context, or when Node.js is configured for ESM-only.
fix
If your project is ES Module-based, use `import` statements. If you are in a CommonJS environment that needs to consume an ESM package, consider using dynamic `import()` or upgrading your project to ESM.
Upgrade
Version history
5.6.1latest on npm
Audit
Dependencies
olrequiredPeer dependency required for OpenLayers style generation and application.
geostyler-stylerequiredCore dependency providing the abstract GeoStyler style definitions and utilities.
Agent activity
4 hits · last 30 days
node
4
Resources
geostyler-openlayers-parser — npm install geostyler-openlayers-parser · libregistry