3.0.1 • Published 7 months ago

ol-esri-style v3.0.1

Weekly downloads
23
License
ISC
Repository
github
Last release
7 months ago

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 { createStyleFunction, createStyleFunctionFromUrl } from 'ol-esri-style';

// create a new vector layer
const vector = new VectorLayer({
  ...
});
const proj = map.getView().getProjection();

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

// You can also retrieve the layer info yourself and use it to create the style
// function
fetch(`${arcgis_server_layer_url}?f=json`)
    .then(res => res.json())
    .then(json => createStyleFunction(json, proj))
    .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://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/2020_Earthquakes/FeatureServer and the style definition is from https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/2020_Earthquakes/FeatureServer/0?f=json.

Dependencies

License

The MIT License (MIT).

3.0.1

7 months ago

3.0.0

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.10

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.2

7 years ago