Closed lopezvoliver closed 2 months ago
@martinRenou could you please suggest someone for review?
Thanks! I'll have a look
Here's an example using the ms-buildings from Microsoft Planetary Computer, with the new default (svg):
@lopezvoliver I was curious to run this example, but it seems I'm getting 404s on this https://planetarycomputer.microsoft.com url when LeafletJS tries to download the tiles. Is there anything particular to do to allow this example to work?
Here's an example using the ms-buildings from Microsoft Planetary Computer, with the new default (svg):
@lopezvoliver I was curious to run this example, but it seems I'm getting 404s on this https://planetarycomputer.microsoft.com url when LeafletJS tries to download the tiles. Is there anything particular to do to allow this example to work?
I just checked and it should work as is. Are you able to access the following tile directly?
This layer is only available until z=13, so the maxNativeZoom
(added in #1206) is set to 13.
Here's a description of the recent five commits:
As suggested, I used feature_style
as a traitlets property so that we can add observe its change in javascript and call the setFeatureStyle
method. The user can call the set_feature_style
method with an id and a layer_style
dictionary. The user can also call the reset_feature_style
method with an id, which updates the same feature_style
traitlets property but with a reset
value set to True. At this time, only one id should be used at a time, as is the intended use case of the original setFeatureStyle
and resetFeatureStyle
methods in VectorGrid.
I realized that in #1210 one small issue persisted: when initializing a VectorTileLayer with visible=False
, this wasn't reflected initially. This commit fixes this issue by setting opacity=0
after initializing the vector tile layer with visible=False
.
3, 4, and 5: Each of these commits is a decision to rename vector_tile_layer_styles
, renderer_factory
, and get_feature_id
(the latter two are additions in this pull request) to a different name in python (layer_styles
, renderer
, and feature_id
, respectively). The reason for this is that because all three are converted to functions in javascript, they shouldn't be synced to the python model. Instead, they are used to construct the javascript counterparts VectorTileLayerStyles
, rendererFactory
, and getFeatureId
.
I will update the original PR comment to reflect these changes where needed.
This layer is only available until z=13, so the maxNativeZoom (added in https://github.com/jupyter-widgets/ipyleaflet/pull/1206) is set to 13.
Ah right I was not using the main branch! Thanks for the clarification.
Here's a description of the recent five commits:
Is it ready for another review?
Happy to make a release of your recent PRs after this one is merged
Is it ready for another review?
Yes, it's ready for review. (Edit: I just pushed one last commit -- I figured out a way to keep vector_tile_layer_styles
as input for backwards compatibility)
Happy to make a release of your recent PRs after this one is merged
That would be great, thanks!
The CI would deserve some love, let's do that separately
Renderer factory
Vector tile layers can be rendered using either
L.canvas.tile
orL.svg.tile
. Currently, only the canvas option is implemented in ipyleaflet and it's not doing a great job at higher levels of zoom, see for example #1095.Here a new
renderer
option was added toVectorTileLayer
, which can be eithersvg
orcanvas
, with the new default beingsvg
.Here's an example using the
ms-buildings
from Microsoft Planetary Computer, with the new default (svg):And here's how it renders using
renderer='canvas'
:Interactivity
A new
interactive
option was added withFalse
as default, which enables the user to add listeners to the layer, which include information about the feature. Note that the defaultrenderer='svg'
option should be used for interactivity. For example:feature_id
This is an optional attribute that is used to construct a simple javascript function to uniquely identify a feature. This is required if you will be updating feature styles through the new
set_feature_style
andreset_feature_style
methods. The javascript function is of the form:where
feat
is the feature, andidVar
is the name of the (numeric) attribute in the layer to identify a feature. Note that features with the same id will be treated as one when changing style (see the originalgetFeatureId
documentation here).Updating styles
Two new methods for
VectorTileLayer
were added:set_feature_style
andreset_feature_style
. The first one is used to update the style for an individual feature, which is useful for highlighting a feature (e.g., on click or mouseover), while the second one is useful for resetting the style to the default (e.g. to clear the highlight).Example
Here's a motivating example that demonstrates all of the new features.