0.1.3 • Published 4 months ago

openlayers-style-editor v0.1.3

Weekly downloads
-
License
-
Repository
github
Last release
4 months ago

npm.io npm.io npm.io npm.io npm.io npm.io

npm.io npm.io npm.io npm.io

Demo

Contents

Background

This package was created in the context of the LAND IT project, a decision support system to help stakeholders planning a new landscape for the most affected areas by wildfires in Portugal. LAND IT uses OpenLayers as its main GIS dependency, and throughout the project the need to edit layers styles increased.

Presentation

This Style Editor for OpenLayers allows the user to change the style of layers. This editor was inspired in both QGIS and ArcMap editors.

There are three edition modes:

  • Unique Symbol: Allows the user to change the layer's color, opacity, and stroke.
  • Categorized: Allows the user to change the layer's color, opacity, and stroke based on the values of an attribute.
  • Graduated: Allows the user to change the layer's color, opacity, and stroke based on a numeric attribute and the mode used to group its values. This package has six modes implemented, some of them are implemented using the GeoBuckets package. The implemented modes are:
    • Manual
    • Equal Intervals
    • Defined Intervals
    • Quantile
    • Natural Breaks (Jenks)
    • Standard Deviation

A detailed explanation of each mode can be found here.

Installation

Depending on the installed package provider, this package can be installed with one of the following commands.

npm install openlayers-style-editor
yarn add openlayers-style-editor

Usage

Firstly it is necessary to import the styles of the package. This can be done by adding the following code snippet to your index/main file.

import 'openlayers-style-editor/dist/openlayers-style-editor.css';

It is possible to enjoy this package by adding the following code snippets to your code.

import { Render, RenderType, StyleEditor } from "openlayers-style-editor";
const [visible, setVisible] = useState<boolean>(false);

const defaultRender: Render = {
    type: RenderType.Unique,
    rendererOL: {
        'fill-color': [255, 255, 50, 1],
        'stroke-color': [0, 0, 0, 1],
        'stroke-width': 1,
    }
}

const [renderer, setRenderer] = useState<Render>(defaultRender);
<StyleEditor visible={visible}
               setVisible={setVisible}
               layerDefaultRenderer={defaultRender}
               layerCurrentRenderer={renderer}
               applyRenderer={(renderer) => setRenderer(renderer)}
               features={features}
               primeReactTheme={"bootstrap4-light-blue"}
               showPreDefinedRamps={true} />

To see a full example click here.

Props Details

NameTypeRequirementDescriptionExample
visiblebooleanmandatoryDefines if the component is visible or nottrue
setVisiblefunctionmandatoryFunction to set the visibility of the component() => setVisible(!visible)
layerDefaultRendererRendermandatoryDefault renderer of the layer to be edited{type: RenderType.Unique, rendererOL: { 'fill-color': 255, 255, 50, 1, 'stroke-color': 0, 0, 0, 1, 'stroke-width': 1}}
layerCurrentRendererRendermandatoryCurrent renderer of the layer{type: RenderType.Unique, rendererOL: { 'fill-color': 255, 255, 50, 1, 'stroke-color': 0, 0, 0, 1, 'stroke-width': 1}}
applyRendererfunctionmandatoryFunction to apply the renderer to the layer, it has as parameter the renderer to be applied(renderer: Render) => setRenderer(renderer)
featuresFeature[]mandatoryFeatures to be rendered on the map
showPreDefinedRampsbooleanmandatoryShow the predefined ramps of the packagetrue
moreRampsColorRamp[]optionalAn array of color ramps that can be added to the package[{id: 28, //id needs to be >=28 name: "GnBu", palette: {offset: 0.25, color: fromString("rgb(186,228,188)")},{offset: 0.5,color: fromString("rgb(123,204,196)")}, {offset: 0.75, color: fromString("rgb(67,162,202)")}}]
predefinedStylesPredefinedRenderer[]optionalPredefined styles to be used on the categorized style type[{name: "Dangerousness",renderer: [{value: "Very High", color: 255, 0, 0},{value: "High", color: 255, 128, 0},{value: "Medium", color: 255, 255, 0},{value: "Low", color: 139, 209, 0},{value: "Very Low", color: 56, 168, 0}]}]
addingToHeaderstringoptionalText to be added to the header- Dangerousness Layer
primeReactThemestringoptionalPrimeReact theme to be used, all option can be found herebootstrap4-light-blue
numbersLocalestringoptionalLocale to be used on numbers, represented using BCP 47 language tag. Default is 'en-US'en-US
textLocalestringoptionalLocale to be used for text. This package has two options available: 'en' and 'pt'. Default is 'en'. To add a custom locale, use the customLocale prop and in the textLocale prop use 'custom'.pt
customLocaleRecord<string, any>optionalCustom locale to be used in case the textLocale is set to 'custom'. This prop must have the same structure as the default locale, that can be found here{"common": {"style_editor": "Editor de Estilos","reset_style": "Repor Estilo",...}}

TODOs

  • Add the condition style type
  • Add a license

Show your support

Give a ⭐️ if this project helped you!

Author & Maintainer

Márcia Matias