-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add identity function example #4057
Conversation
--- | ||
layout: example | ||
category: example | ||
title: Style lines using data-driven styling and the identity property function. |
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.
All that's visible of this title in the page's fixed-width sidebar is
Style lines using data-driven styling an..
Is there a way we can word the title to capture the intent of the example ("Add identity function example")
visible in the sidebar? Perhaps one of these titles:
Style lines using an identity property function
Style lines using an identity function
Style using an identity function
Style using an identity property function
{ | ||
'type': 'Feature', | ||
'properties': { | ||
'color': red, |
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.
You can use the string 'red'
here 😄
'properties': {
'color': 'red',
}
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 @lucaswoj! I added the red
and blue
variables here to show the output color is controllable (the colors are a little more muted than the 'red' and 'blue' string output). But if you think the string should be here can certainly change.
} | ||
] | ||
} | ||
}); |
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.
This example would be more readable if we used simpler geometries (shorter lines, fewer lines, or points)
map.addLayer({ | ||
'id': 'lines-layer', | ||
'type': 'line', | ||
'source': 'lines-source', |
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.
We have a standard of using inline sources when there is a 1 source : 1 layer relationship. See #3901 for an example and a little more context.
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.
@lucaswoj Sorry 😬 I'm a little unclear on this -- should the source obj be added as the value to the layer's source
property?
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.
yep instead of calling map.addSource
separately, you can declare the source inline in the addLayer
function
map.addLayer({
id: 'lines', // this will be the layer _and_ source id
type: 'line',
source: {
type: 'geojson',
data: {...}
},
paint: {...}
})
'type': 'line', | ||
'source': 'lines-source', | ||
// The identity function does not take a 'stops' property | ||
// Instead, the property value (in this case, 'color') on the datasource will be the direct output. |
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.
Instead, the property value (in this case, 'color') on the
datasourcesource will be the direct output.
The word "source" is more idiomatic than "datasource" in the context of Mapbox GL.
'line-width': 3, | ||
'line-color': { | ||
'type': 'identity', | ||
'property': 'color' |
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.
The indentation here looks a little off
Good for another round of review here @mollymerp @lucaswoj |
@sarahkleins the tests are failing on eslint, so once that is fixed ( |
Launch Checklist
This PR adds an example using the
identity
function for data-driven styling, responding to this issue.