Skip to content
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

Allow to send options directly as str #702

Merged
merged 2 commits into from
Mar 13, 2024

Conversation

lopezvoliver
Copy link
Collaborator

Adds the possibility to send options for the folium.plugins.VectorGridProtobuf directly as a string, so that a JS function may be used for conditional styling (e.g., see the second example here)

Here's an example with the normal styles:

image

Here's an example with conditional styling:

image

where options was defined as a string as follows:

options='''{
"vectorTileLayerStyles": {
"myLayer": function(f) {
var color = "#86340c";
if (f.ET >= 250) {
color = "#c49e0d";
}
if (f.ET >= 500) {
color = "#f3fe34";
}
if (f.ET >= 750) {
color = "#aefeae";
}
if (f.ET >= 1000) {
color = "#11f9fd";
}
if (f.ET >= 1250) {
color = "#698afc";
}
if (f.ET >= 1500) {
color = "#5813fc";
}
return {
fillOpacity: 1,
fillColor: color,
fill: true,
weight: 1,
color: "white",
opacity: 1,
};
}
}
}'''

  • Also removed attribution since it is not being used.
  • Also rearranged the order to match the one by VectorGridProtobuf ( url, layer_name, options/styles)

@giswqs
Copy link
Member

giswqs commented Mar 13, 2024

Great improvement! Thanks.

@giswqs giswqs merged commit 8e30645 into opengeos:master Mar 13, 2024
14 checks passed
@lopezvoliver
Copy link
Collaborator Author

lopezvoliver commented Mar 14, 2024

I just noticed that I forgot to add my last commit to do this:

  • Remove "attribution" from the docstring.
  • Rearrange the order to match the one by VectorGridProtobuf ( url, layer_name, options/styles)

@giswqs Would you agree with these two changes? I would also need to make these changes in the ipyleaflet version of the function, to be consistent*

I also noticed that notebook 17 needs updating:

  • The url is broken. Here's the correct one.
  • It mentions that folium is not supported.
  • It uses add_vector_tile_layer instead of add_vector_tile.
  • The example shown doesn't give too much details about styling.

If I add an example with conditional styling in the notebook, will it work in the docs? I remember you mentioning that in the docs-build process the notebooks are executed with the folium backend.. so it should be fine?

*Note that currently conditional styling doesn't work with ipyleaflet backend (see jupyter-widgets/ipyleaflet#744)

@giswqs
Copy link
Member

giswqs commented Mar 14, 2024

Sure. Please feel free to submit another PR

sthagen pushed a commit to sthagen/giswqs-leafmap that referenced this pull request Jul 10, 2024
* Allow to send options directly as str

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
kuzja111 pushed a commit to kuzja111/leafmap that referenced this pull request Jul 25, 2024
* Allow to send options directly as str

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants