UNPKG

geostyler-openlayers-parser

Version:

GeoStyler Style Parser implementation for OpenLayers styles

82 lines (66 loc) 2.52 kB
# geostyler-openlayers-parser [![Coverage Status](https://coveralls.io/repos/github/geostyler/geostyler-openlayers-parser/badge.svg?branch=main)](https://coveralls.io/github/geostyler/geostyler-openlayers-parser?branch=main) [![License](https://img.shields.io/github/license/geostyler/geostyler-openlayers-parser)](https://github.com/geostyler/geostyler-openlayers-parser/blob/main/LICENSE) [![npm version](https://badge.fury.io/js/geostyler-openlayers-parser.svg)](https://www.npmjs.com/package/geostyler-openlayers-parser) [GeoStyler Style](https://github.com/geostyler/geostyler) Parser implementation for OpenLayers styles ## :rocket: GeoStyler Code Sprint 2025 We are happy to announce the next GeoStyler Code Sprint from **02.-06.06.2025** in Switzerland. Be part of it! More infos on https://geostyler.org/. ### How to use The example below shows how to take a raw GeoStyler style, use the OpenLayersParser to parse the style into an OpenLayers style, and then apply it to an OpenLayers vector layer. ES6: ```js import OpenLayersParser from "geostyler-openlayers-parser"; import OlLayerVector from "ol/layer/Vector"; const pointSimplePoint = { name: "OL Style", rules: [ { name: "OL Style Rule 0", symbolizers: [ { kind: "Mark", wellKnownName: "circle", color: "#FF0000", radius: 6 } ] } ] }; const parser = new OpenLayersParser(); const layer = new OlLayerVector(); parser .writeStyle(pointSimplePoint) .then(({output: olStyle}) => layer.setStyle(olStyle)) .catch(error => console.log(error)); ``` Browser: ```js var pointSimplePoint = { name: "OL Style", rules: [{ name: "OL Style Rule 0", symbolizers: [{ kind: "Mark", wellKnownName: "circle", color: "#FF0000", radius: 6 }] }] }; var vectorLayer = new ol.layer.Vector(); var parser = new GeoStylerOpenlayersParser.OlStyleParser(ol); parser.writeStyle(pointSimplePoint) .then(function(style) { if (style.errors) { console.log(style.errors); } else { vectorLayer.setStyle(style.output); } }); ``` ## <a name="funding"></a>Funding & financial sponsorship Maintenance and further development of this code can be funded through the [GeoStyler Open Collective](https://opencollective.com/geostyler). All contributions and expenses can transparently be reviewed by anyone; you see what we use the donated money for. Thank you for any financial support you give the GeoStyler project 💞