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

fix __geo_interface__ styling #1935

Merged
merged 3 commits into from
Apr 23, 2024
Merged

fix __geo_interface__ styling #1935

merged 3 commits into from
Apr 23, 2024

Conversation

ocefpaf
Copy link
Member

@ocefpaf ocefpaf commented Apr 19, 2024

Closes #1932.

  • Fixes the geopandas (or any __geo_interface__ object) styling regression.
  • Amend the docs with a CAVEAT regarding Late Binding Closures when using style_function in a loop.

@ocefpaf
Copy link
Member Author

ocefpaf commented Apr 19, 2024

This one fixes the geopandas issue but I need to amend the docs for the pitfalls in the loop case and I also need to check if my simplistic solution is good enough and doesn't clash with the current styling options we have.

Screenshot from 2024-04-19 19-28-18

@ocefpaf ocefpaf marked this pull request as ready for review April 19, 2024 18:35
@ocefpaf ocefpaf requested a review from Conengmo April 19, 2024 19:05
@@ -237,6 +237,23 @@ colormap.add_to(m)
m
```

>
> **Caveat**
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Conengmo do you have any suggestion to make this more prominent, like a red warning sign?

Also, I'd like to link the geopandas_and_geo_interface.html#Adding-style to the GeoPandas object suggestion below but I have no idea how to do that here.

Copy link
Collaborator

@hansthen hansthen Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is clear enough with the specified Caveat. It is a very tricky bug, but I also imagine it is not a very common software pattern to create style functions in a loop. (It took some ten years for this to be discovered.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, it is :-/
I recall (now b/c I forgot ;-) adding the geopandas alternative to escape that. We have a few issues reported and question on SO. Hopefully we can point folks to this paragraph instead from now on.

@@ -643,6 +643,10 @@ class GeoJson(Layer):
.done({{ this.get_name() }}_add);
{%- endif %}

{%- if not this.style %}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked all the docs/notebooks we have and none broke. If the user specifies a style_function, whatever is in the geojson will be ignored but, if nothing is specified and the geojson has style info, that will be used instead. I guess this is the best I could come up with but I'm open to suggestions.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change required to fix this bug? It seems like a new feature. If so perhaps it is better to separate this into a new PR.

Also, what happens if a Feature in the GeoJson does not have a style property? Will leaflet handle this correctly?

@@ -643,6 +643,10 @@ class GeoJson(Layer):
.done({{ this.get_name() }}_add);
{%- endif %}

{%- if not this.style %}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change required to fix this bug? It seems like a new feature. If so perhaps it is better to separate this into a new PR.

Also, what happens if a Feature in the GeoJson does not have a style property? Will leaflet handle this correctly?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes required for the issue at hand? If not perhaps it is cleaner to open a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are required to fix the styling for the geopandas case. This fixes a regression introduced during the GeoJson refactoring. I prefer to keep them both in the same PR b/c they are tied together by the same issue, even though they have different origins.

@ocefpaf ocefpaf merged commit 6c0c20e into main Apr 23, 2024
13 checks passed
@ocefpaf ocefpaf deleted the fix_geo_interface_styling branch April 23, 2024 18:14
@ocefpaf
Copy link
Member Author

ocefpaf commented Apr 23, 2024

@Conengmo and @hansthen I'm planning on a new release but I guess we should also try to get #1903 (and maybe others) in before that?

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.

GeoJson style is not being applied correctly
2 participants