GeoStyler

18.4.2 · active · verified Sun Apr 19

GeoStyler is an open-source JavaScript library and framework for styling geospatial data, providing a robust set of modular React UI components for map styling in web applications. It is currently at version 18.4.2 and receives frequent updates, with minor releases for features and bug fixes occurring regularly. A core differentiator is its "micro packages" approach, allowing users to leverage standalone parsers for translating between various styling formats like SLD, OpenLayers, QGIS, and Mapbox without needing the full UI component suite. Internally, it uses its own `GeoStyler Style` definition as an exchange format for seamless conversion. This modularity enables developers to either integrate high-level, opinionated UI components like the `StyleEditor` or build custom interfaces using its fundamental building blocks. It also offers command-line and REST API tools for style conversion outside of a UI context.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic GeoStyler `Style` (the main UI component) integrated into a React application, allowing users to view and edit a geospatial style. It initializes a simple point style, handles style changes, and shows how to pass parser instances to the `Style` component.

import React, { useState } from 'react';
import { Style } from 'geostyler';
import SLDParser from 'geostyler-sld-parser';
import OpenLayersParser from 'geostyler-openlayers-parser';
import { Style as GeoStylerCoreStyle } from 'geostyler-style';

const initialGeoStylerStyle: GeoStylerCoreStyle = {
  name: 'My Initial Style',
  rules: [
    {
      name: 'Orange Point Rule',
      symbolizers: [
        { kind: 'Mark', wellKnownName: 'circle', color: '#FFA500', radius: 8 }
      ],
    },
  ],
};

const MyStyleEditor: React.FC = () => {
  const [currentStyle, setCurrentStyle] = useState<GeoStylerCoreStyle>(initialGeoStylerStyle);
  const sldParser = new SLDParser();
  const olParser = new OpenLayersParser();

  // Note: For a fully functional setup, you might need to provide a data source
  // and more comprehensive locale and editor configurations via the Style component's props.
  // This example focuses on basic style management.
  return (
    <div style={{ width: '100%', height: 'calc(100vh - 20px)', padding: '10px' }}>
      <h1>GeoStyler Style Editor</h1>
      <Style
        style={currentStyle}
        onStyleChange={(newStyle: GeoStylerCoreStyle) => {
          console.log('Style changed:', newStyle);
          setCurrentStyle(newStyle);
        }}
        // The Style component often needs parsers to function correctly,
        // enabling read/write operations for different formats.
        sldParser={sldParser}
        olParser={olParser}
        // Other parsers can be added as props: qmlParser, mapboxStyleParser, etc.
        // locale={{ /* custom locale */ }}
        // data={{ /* data source */ }}
      />
      <pre style={{ marginTop: '20px', backgroundColor: '#eee', padding: '10px' }}>
        {JSON.stringify(currentStyle, null, 2)}
      </pre>
    </div>
  );
};

export default MyStyleEditor;

view raw JSON →