OpenLayers SLD Styler

A JavaScript module to style OpenLayers vector layers using SLD data and optionally generate a map legend and/or embed symbols in a layer selector.
It is primarily designed to help build a web map with data/styles directly exported from QGIS as OGC GeoPackage(s) using the
Package Layers Processing Toolbox operation and to quickly rebuild the map with subsequent updated QGIS exports. However, as the module inputs are collections of OpenLayers "vector sources", SLDs and a "layer configuration" object it can also be used for general SLD styling from other data/style sources. It includes user-defined function hooks for modifying SLD-imported styling where desired styling was not possible due to QGIS export or SLD limitations.
It is implemented as an NPM module which adds symbology generation, "layer configuration" parsing and user-defined symbology enhancement to the following third party NPM modules:
-
@NieuwlandGeo/sldreader: conversion of SLD to OpenLayers style function
-
ol-layerswitcher: a layer list control for an OpenLayers map
To extract vector data and SLD layer styles from QGIS "Package Layers" output, it is intended to be used in conjunction with its sister NPM module:
-
ol-load-geopackage: OpenLayers OGC GeoPackage Loader
By using an OGC GeoPackage as its primary data/styling source, it enables creation of an _offline_ map viewer for mobile phones or tablets which have poor (or non-existent) network connectivity. When a network connection is available, data and stying updates could then be done by downloading just 1 file.
Examples
_(Brief summary - see separate
Examples page for full details of specific functionality incorporated in each example.)_
Each example is presented as the directly viewable web page (generated by the Webpack module bundler) followed by the HTML/JavaScript source code + a "Map Configuration" JSONP file and a brief summary:
-
Basic example:
web page (sources:
HTML,
JavaScript,
Map Config)
- Loads vector tables and associated QGIS "layer_styles" SLD XML strings from an OGC GeoPackage and render all tables as styled layers on an OpenLayers map. Displays details of package contents.
-
SLD File Load example:
web page (sources:
HTML,
JavaScript,
Map Config)
- Additionally include styling data read from separate SLD file(s).
-
Legend example:
web page (sources:
HTML,
JavaScript,
Map Config)
- Generate a map legend (with show/hide toggle).
-
Layer Switcher example:
web page (sources:
HTML,
JavaScript,
Map Config)
- Embed symbology in a layer selector created by third party ol-layerswitcher NPM module.
-
Full Layer Switcher, Legend + Extras example:
web page (sources:
HTML,
JavaScript,
Map Config)
- Style OpenLayers vector layers, embed symbology in a layer selector, create a map legend, plus many extras required for a typical web map incorporating multiple data and SLD styling sources.
Installation
Use Node.js to install the NPM package:
ol-sld-styler
``
bash
npm install --save ol-sld-styler
`
Note: Internet Explorer is not supported.
Basic usage
This package must be imported as a module - it is not designed to be loaded directly with a \