Giter Club home page Giter Club logo

ol-esri-style's Introduction

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).

ol-esri-style's People

Contributors

bojko108 avatar dependabot[bot] avatar categulario avatar zakariah1 avatar jnystad avatar bierett avatar

Stargazers

Youssef Harby avatar Jinghao Hu avatar  avatar jiaqu avatar Soundarya0 avatar  avatar Christoph avatar  avatar Will Breitkreutz avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

ol-esri-style's Issues

Support for dashed lines

Dashed line with label such esriSLSDash are rendered as solid lines. Is there support for dashed lines?

Openlayers - georeferencing with affine function

Hi Bogdan,
Sorry for creating an issue, but I couldn't find any other way to directly contact you.

I stumbled upon your question on SO: https://stackoverflow.com/questions/52904587/displaying-georeferenced-images-using-openlayers-5

I'm trying to do the same thing (georeference rotated maps in openlayers). I was wondering how Affine.js (https://codesandbox.io/s/kw9l85y5po?file=/src/Affine.js) is working under the hood. Is there any explanation for the calculations I could read and understand how it works?
Also, in your code there is no inverse function. Would calling the existing Affine.calculate function with reversed arguments do the trick?

Thanks and sorry for offtopic issue,
Patryk

Unable to render labels

Thanks for the great package. I am having some issues with labels. I am using 2 layers and I get the colors and styles of the features but no labels. I have installed the release from yesterday. These are the renderers:

Renderer:
Simple Renderer:
Symbol:
Style: esriSLSDash
Color: [0, 92, 230, 255]
Width: 0
Label:
Description:
Transparency: 0
Labeling Info:
Label Placement: esriServerLinePlacementCenterAlong
Label Expression: [DEPTH_M]
Use Coded Values: true
Symbol:
Color: [0, 77, 168, 255]
Background Color: N/A
Outline Color: N/A
Vertical Alignment: bottom
Horizontal Alignment: center
Right to Left: false
Angle: 0
XOffset: 0
YOffset: 0
Size: 8
Font Family: Arial
Font Style: normal
Font Weight: bold
Font Decoration: none
Min. Scale: 0.0
Max. Scale: 0.0

AND

Renderer:
Unique Value Renderer:
Field 1: ITZ_FORM
Field 2: null
Field 3: null
Field Delimiter: ,
Default Symbol:
N/A
Default Label: null
UniqueValueInfos:
Value: beach
Label: beach
Description:
Symbol:
Style: esriSLSSolid
Color: [0, 92, 230, 255]
Width: 2
Value: cliff
Label: cliff
Description:
Symbol:
Style: esriSLSSolid
Color: [255, 0, 0, 255]
Width: 2
Value: delta
Label: delta
Description:
Symbol:
Style: esriSLSSolid
Color: [255, 170, 0, 255]
Width: 2
Value: dune
Label: dune
Description:
Symbol:
Style: esriSLSSolid
Color: [255, 255, 0, 255]
Width: 2
Value: low-islets
Label: low-islets
Description:
Symbol:
Style: esriSLSSolid
Color: [0, 168, 132, 255]
Width: 2
Value: platform
Label: platform
Description:
Symbol:
Style: esriSLSSolid
Color: [255, 115, 223, 255]
Width: 2
Value: salt marsh
Label: salt marsh
Description:
Symbol:
Style: esriSLSSolid
Color: [76, 230, 0, 255]
Width: 2
Value: tidal Flat
Label: tidal flat
Description:
Symbol:
Style: esriSLSSolid
Color: [168, 112, 0, 255]
Width: 2
Transparency: 0
Labeling Info:
Label Placement: esriServerLinePlacementAboveAlong
Label Expression: [ITZ_FORM]
Use Coded Values: true
Symbol:
Color: [0, 0, 0, 255]
Background Color: N/A
Outline Color: N/A
Vertical Alignment: bottom
Horizontal Alignment: center
Right to Left: false
Angle: 0
XOffset: 0
YOffset: 0
Size: 8
Font Family: Arial
Font Style: normal
Font Weight: normal
Font Decoration: none
Min. Scale: 0.0
Max. Scale: 0.0

I am adding the layer to the map like this:

const esriVector = new VectorLayer({
source: vectorSource
});

setMapProjection(map.getView().getProjection());

createStyleFunctionFromUrl(esriUrl).then(styleFunction => {
esriVector.setStyle(styleFunction);
});

esriVector.set('name', layerID);

map.addLayer(esriVector);

Thanks in advance.

Inner global variable would cause problems if library is used in multiple views

the setMapProjection function alters a global variable that is shared among all uses of this library. This means that if a second map with a different projection is shown on the same page the second call to this function would replace the private mapProjection value and perhaps cause problems with labels for the first map.

I think a better approach would be for the createStyleFunction[fromUrl] functions to accept an optional projection parameter the user can pass if labels are in use.

Of course that would be a breaking change (because API changes).

If this is acceptable I would be happy to make a pull request.

And thanks for this amazing work (:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.