ol-esri-style

3.0.0 • Public • Published

Convert ESRI styles to OpenLayers styles

Info

This module can convert ESRI style definition to OpenLayers style function. ESRI style definition must be in JSON format - https://developers.arcgis.com/documentation/common-data-types/renderer-objects.htm

Getting started

Import as ES6 module:

import { createStyleFunctionFromUrl } from 'ol-esri-style';

// create a new vector layer
const vector = new VectorLayer({
  ...
});


// set layer style
// Passing the projection is need for labeling features. Visible resolutions for
// the labels are calculated using map projection units.
createStyleFunctionFromUrl('arcgis_server_layer_url', map.getView().getProjection()).then(styleFunction => {
  vector.setStyle(styleFunction);
});

You can modify the styles before applying them to the features:

// set layer style
createStyleFunctionFromUrl('arcgis_server_layer_url').then(styleFunction => {
  vector.setStyle((feature, resolution) => {
    const styles = styleFunction(feature, resolution);

    // modify styles

    return styles;
  });
});

Example

To check the example stored in /example directory run:

npm run dev

The example loads data from https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSFields/FeatureServer/0 and the style definition is from https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSFields/FeatureServer/0?f=json.

Dependencies

License

The MIT License (MIT).

Readme

Keywords

Package Sidebar

Install

npm i ol-esri-style

Weekly Downloads

2,229

Version

3.0.0

License

ISC

Unpacked Size

30.6 kB

Total Files

8

Last publish

Collaborators

  • bojko108