Skip to content

jazida-opensource/geostyler-mapnik-parser

Repository files navigation

geostyler-mapnik-parser

GeoStyler Style Parser implementation for Mapnik XML

How to use

Converting SLD to Mapnk XML

CLI

npm install

npm run build

node dist/bin/sld2mapnik.js input.sld > output.mapnik.xml

Programmatically

import SLDParser from 'geostyler-sld-parser'
import { MapnikStyleParser } from './geostyler-mapnik-parser'

export async function sld2mapnik(sldString: string) {
  const sldParser = new SLDParser()
  const mapnikParser = new MapnikStyleParser({
    output: {
      includeMap: true,
      wellKnownBasePath: 'icons',
      map: {
        srs: '+init=epsg:3857',
      },
      style: {
        name: 'style',
      },
      symbolizers: {
        MarkersSymbolizer: {
          'allow-overlap': 'true',
          'avoid-edges': 'true',
        },
      },
    },
  })

  const style = await sldParser.readStyle(sldString)
  const xml = await mapnikParser.writeStyle(style)

  return xml
}