-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Style Parsing #164
Style Parsing #164
Conversation
Thank you @RobertOrthofer, Edit: Sorry, my bad, forgot to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After more experimentation, I think this is a great solution! I think I would like it better if the property name was different, since style
could be a property that is natively supported by OL (thinking of flat styles that could look very similar and cause confusion). What do you think if we make it really explicit, by introducing an e.g. mapbox-style
property? So a layer JSON with style
would be native OL style, and one with mapbox-style
would apply a mapbox style instead.
{
"type": "Vector",
"mapbox-style": {
// the mapbox style
}
}
Another solution would be to pass a mapbox
property into the native style, something like:
{
"type": "Vector",
"style": {
"mapbox": {
// the mapbox style
}
}
}
What do you prefer?
Originally i was thinking about using the Differentiating between the style notations should be trivial, as the "version" property is mandatory for mapbox styles, but not allowed in ol-styles. |
Right, but in the current test the style is set as a property, not as a style - there is a difference between those two things:
So in the current state, the user could both apply a style and a style property. What we could do is to check a bit sooner (during the layer generation), if the style includes e.g. a "version", then don't apply it as a style but apply it with mapbox-styles at a later stage.
versus
👍 from my side to have both defined as |
Ah, now i understand. Yes, that would be best, i will update the code. |
Thank you for the updates, works well with Vector layers but I am struggling to make it work with VectorTile layers - trying to find out what the issue could be. |
To sum it up: The issue was the missing flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work!
elements/map/test/vectorLayer.json
Outdated
"properties": { | ||
"id": "regions" | ||
"id": "regions", | ||
"style": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great if here in the test we could use a minimal example to show what the minimum fields are to make this work. I understand that version
is necessary, but other things are not. Also, the source
name does not need to match the layer id, maybe it's better to explicitly show this in the test, for example:
{
version: 8,
layers: [
{
type: "fill",
source: "foobar",
paint: {
"fill-color": ["get", "COLOR"],
"fill-opacity": 1,
},
},
{
type: "line",
source: "foobar",
paint: {
"line-color": "#fff",
"line-width": 1.5,
},
},
],
}
Maybe, for convenience, the source
property could be automatically generated with an arbitrary string, since it serves no purpose. Or am I missing a functionality here?
This feature implements style parsing for vector layers. This is achieved by combining
ol-mapbox-style
as a parser for mapbox styles, while keeping the simpler layer and source definition that is already implemented in the project.The basic idea is that the
properties
of our custom layer-JSON-format can, additionally to theid
and thesource
of the layer, also hold astyle
object, which should be a simple mapbox style object. Alllayers
from that object should reference the samesource
. This mabox style will not override the source, if no source is defined, a dummy source will be added, since it is needed to create a valid mapbox style object.This solution is meant to style vector data (
Vector
orVectorTile
sources). Style expressions can be used to implement more complex and dynamic styles, like referencing object properties of features for dynamic styling or filtering.