包详细信息

geostyler-sld-parser

geostyler42.3kBSD-2-Clause8.1.0

GeoStyler Style Parser implementation for SLD

geostyler, parser, style, sld

自述文件

geostyler-sld-parser

Coverage Status License npm version

GeoStyler Style Parser implementation for Styled Layer Descriptor (SLD)

: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

ES6:

import SLDParser from 'geostyler-sld-parser';
import { Style } from 'geostyler-style';

const pointSimplePoint = {
  name: 'My Style',
  rules: [
    {
      name: 'My Rule',
      symbolizers: [
        {
          kind: 'Mark',
          wellKnownName: 'circle',
          color: '#FF0000',
          radius: 6
        }
      ]
    }
  ]
};

const parser = new SLDParser();

parser
  .writeStyle(pointSimplePoint)
  .then(({output: sld}) => console.log(sld))
  .catch(error => console.log(error));


// Read style from string
let sldString = '<?xml version="1.0" encoding="UTF-8"?><sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" version="1.0.0"> <sld:NamedLayer> <sld:Name>Default Styler</sld:Name> <sld:UserStyle> <sld:Name>Default Styler</sld:Name> <sld:Title>Gravel_Program_2016</sld:Title> <sld:FeatureTypeStyle> <sld:Name>name</sld:Name> <sld:Rule> <sld:MinScaleDenominator>1.0</sld:MinScaleDenominator> <sld:MaxScaleDenominator>1.0E7</sld:MaxScaleDenominator> <sld:LineSymbolizer> <sld:Stroke> <sld:CssParameter name="stroke">#8000FF</sld:CssParameter> <sld:CssParameter name="stroke-width">3.000</sld:CssParameter> </sld:Stroke> </sld:LineSymbolizer> </sld:Rule> </sld:FeatureTypeStyle> </sld:UserStyle> </sld:NamedLayer> </sld:StyledLayerDescriptor>';

parser
  .readStyle(sldString)
  .then(({output: sldObject}) => console.log(sldObject))
  .catch(error => console.log(error));

Browser:

const pointSimplePoint = {
  name: "My Style",
  rules: [
    {
      name: "My Rule",
      symbolizers: [
        {
          kind: "Mark",
          wellKnownName: "Circle",
          color: "#FF0000",
          radius: 6
        }
      ]
    }
  ]
};
var parser = new GeoStylerSLDParser.SldStyleParser();
parser
  .writeStyle(pointSimplePoint)
  .then(({output: sld}) => console.log(sld))
  .catch(error => console.log(error));

// Read style from string
var sldString = '<?xml version="1.0" encoding="UTF-8"?><sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" version="1.0.0"> <sld:NamedLayer> <sld:Name>Default Styler</sld:Name> <sld:UserStyle> <sld:Name>Default Styler</sld:Name> <sld:Title>Gravel_Program_2016</sld:Title> <sld:FeatureTypeStyle> <sld:Name>name</sld:Name> <sld:Rule> <sld:MinScaleDenominator>1.0</sld:MinScaleDenominator> <sld:MaxScaleDenominator>1.0E7</sld:MaxScaleDenominator> <sld:LineSymbolizer> <sld:Stroke> <sld:CssParameter name="stroke">#8000FF</sld:CssParameter> <sld:CssParameter name="stroke-width">3.000</sld:CssParameter> </sld:Stroke> </sld:LineSymbolizer> </sld:Rule> </sld:FeatureTypeStyle> </sld:UserStyle> </sld:NamedLayer> </sld:StyledLayerDescriptor>';


parser
  .readStyle(sldString)
  .then(({output: sldObject}) => console.log(sldObject))
  .catch(error => console.log(error));

Funding & financial sponsorship

Maintenance and further development of this code can be funded through the GeoStyler Open Collective. 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 💞

更新日志

8.1.0 (2025-06-18)

Features

Bug Fixes

  • replace dense5 wellknownname that is now supported (359e5d1)
  • use geostyler-style 10.3 to fix build (aaad9e5)

8.0.1 (2025-06-06)

Bug Fixes

  • use geostyler-style 10.2 to fix build (4d5cbdc)

8.0.0 (2025-06-06)

⚠ BREAKING CHANGES

  • GeoServerVendorOption was too restrictive. You can now provide an sldEnvironment: GeoServer parameter. It adds VendorOption support.

Features

  • add displacement from point offset for geoserver (e13db64)
  • drop geoservervendoroption add sldenvironment (2eda7a6)
  • support dasharray in stroke in mark symbolizer (bfc2aa8)

Bug Fixes

  • #993: add missing code (b206151), closes #993
  • deps: update dependency geostyler-style to v10.1.0 (82e0f77)
  • fix and cleanup workflows (bf104b3)
  • join graphic-margin values with spaces for GeoServer vendor option (fe8db5b)
  • support only spaces as separator in vendor-option graphic-margin (b01783d)
  • support spaces as separator for vendor-option graphic-margin (9e357b1)
  • update geostyler-style imports (9b5c088)

7.3.0 (2025-02-19)

Features

  • add wellknownnames to support qgis markers (#978) (04b9090)

7.2.1 (2025-01-14)

Bug Fixes

7.2.0 (2025-01-14)

Features

7.1.0 (2025-01-13)

Features

Bug Fixes

  • update image format handling (0093c6b)

7.0.0 (2024-10-09)

⚠ BREAKING CHANGES

  • opacity will no longer be set to 1 on text symbolizer if opacity was not explicitly set.

Bug Fixes

6.1.2 (2024-08-26)

Bug Fixes

  • updates fast-xml-parser (511e02f)

6.1.1 (2024-07-09)

Bug Fixes

  • fix reading CDATA values from SLD (3afb066)

6.1.0 (2024-07-04)

Features

6.0.0 (2024-06-25)

⚠ BREAKING CHANGES

  • You may need to adapt your imports. Also the location of the browser build has changed.

Features

  • update package versions and switch to esm build (42e6a2c)

Bug Fixes

  • fix commitlint config (c1db90d)
  • update commitlint (390e668)
  • update geostyler-style & cleanup package.json (4183cb2)
  • update geostyler-style version (fe34f47)
  • update null checks for number values (299b6c3)
  • update semantic release (809698c)
  • use bundler module resolution (79eebaf)
  • use node 20 (aa0cdcd)
  • use preserve module strategy (40ffc9c)

6.0.0-next.1 (2024-06-25)

⚠ BREAKING CHANGES

  • You may need to adapt your imports. Also the location of the browser build has changed.

Features

  • update package versions and switch to esm build (42e6a2c)

Bug Fixes

  • fix commitlint config (c1db90d)
  • update commitlint (390e668)
  • update geostyler-style & cleanup package.json (4183cb2)
  • update geostyler-style version (fe34f47)
  • update null checks for number values (299b6c3)
  • update semantic release (809698c)
  • use bundler module resolution (79eebaf)
  • use node 20 (aa0cdcd)
  • use preserve module strategy (40ffc9c)

Bug Fixes

6.0.0-next.7 (2024-06-19)

Bug Fixes

6.0.0-next.6 (2024-06-19)

Bug Fixes

  • use preserve module strategy (6934882)

6.0.0-next.5 (2024-06-19)

Bug Fixes

  • use bundler module resolution (05f3055)

6.0.0-next.4 (2024-06-19)

Bug Fixes

6.0.0-next.3 (2024-06-19)

Bug Fixes

  • update semantic release (3897a2c)

6.0.0-next.2 (2024-06-19)

Bug Fixes

6.0.0-next.1 (2024-06-19)

⚠ BREAKING CHANGES

  • You may need to adapt your imports. Also the location of the browser build has changed.

Features

  • update package versions and switch to esm build (3284c97)

5.4.0 (2024-06-21)

Features

5.3.1 (2024-02-13)

Bug Fixes

  • actually set xmlns on filter (bc12246)

5.3.0 (2024-02-13)

Features

  • read/write labelplacement (260c80d)

Bug Fixes

  • omit setting style title for sld 1.1.0 (2f24602)
  • remove unintended se namespace prefix from filter (389b010)
  • remove unnecessary ogc: prefix from filter (450ee8f)

5.2.0 (2023-12-04)

Features

  • deps: updates geostyler-style to v8 (7200e79)

Bug Fixes

  • deps: update dependency fast-xml-parser to v4.2.4 [security] (cba8616)
  • deps: update dependency fast-xml-parser to v4.2.5 [security] (72e5b96)
  • deps: update dependency fast-xml-parser to v4.2.7 (aeee571)
  • update semantic-release configs (fa147d9)

Version 5.0.0

  • prettyOutput constructor option was removed
    • use format in builderOptions instead
  • forceCasting constructor option was removed
    • TagValues will be cast to their respective types by default
    • use parseTagValue option of parserOptions to change behaviour
  • Labels with leading or dangling whitespaces have to use <![CDATA[]]> compare point_styledLabel_literalPlaceholder.sld in data/slds