-
Notifications
You must be signed in to change notification settings - Fork 363
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 style callbacks for VectorTileLayer #744
Comments
I don't think this is technically doable without transpiling the Python code into JS. In GeoJSON we can modify the data with a Also, we provide access to styling the VectorTileLayer already IIRC. |
But the VectorGrid plugin has access to it or it couldn't apply the styling functions mentions on the page above. Maybe it's possible to have deeper access to this plugin?
To some degree at least. Maybe @omanges can help. |
Only JavaScript side. A |
I surely share that feeling. ;) How about a JupyterLab extension, then? ;) |
What do you mean? ipyleaflet already contains a JupyterLab extension |
Sure, but maybe the extension could cover the more intricate JS code... |
What kind of API do you have in mind? |
Are there any plans for this? I wouldn't mind providing a small callback function in Javascript if it means I can do conditional styling. For example, I would like to be able to do something like this: var vectorTileOptions = {
minZoom: 0,
maxNativeZoom: 13,
interactive: true,
vectorTileLayerStyles: {
// Define your custom styles for the vector tile layer
"2015ETm3": function (properties, zoom) {
// Function to style the fields in different colors
// based on one attribute (e.g. fieldUse).
var fieldColor = "#ffffcc"; // default color
if (properties.fieldUse >= 0.25) {
fieldColor = "#c2e699";
}
if (properties.fieldUse >= 0.5) {
fieldColor = "#78c679";
}
if (properties.fieldUse >= 0.75) {
fieldColor = "#31a354";
}
if (properties.fieldUse >= 1) {
fieldColor = "#006837";
}
return {
fillOpacity: 1,
fillColor: fieldColor,
fill: true,
weight: 1,
color: "white",
opacity: 1,
};
},
},
}; is this currently possible in ipyleaflet? what other options are there for achieving this? |
This is currently possible using folium with the vectorGrid plugin: where options='''{ |
Would it be possible to add some small typescript code (potentially just one line?) in LeafletVectorTileLayerModel that sets e.g., similar as what the folium vectorgrid plugin does here This way the user has the option to define the vector_tile_layer_styles as a string and optionally include logic for styling features (in javascript). |
Definitely, would you like to try a PR to ipyleaflet? |
Styling for vector tiles can be pretty complex and the current implementation of
VectorTileLayer
only allows for one static style per "tile layer" e.g. "roads". This is a severe limitation as one cannot exploit the rich feature properties stored in vector tiles, e.g. to render different types of roads individually. The Leaflet VectorGrid plugin does support function callbacks for more dynamic styling as described here: https://leaflet.github.io/Leaflet.VectorGrid/vectorgrid-api-docs.html#styling-vectorgrids. So I think it should be possible to wrap this functionality and expose it in ipyleaflet, too, in a way similar to thestyle_callback
parameter forGeoJSON
layer.The text was updated successfully, but these errors were encountered: