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

Improve vector tile layer #1206

Merged

Conversation

lopezvoliver
Copy link
Contributor

@lopezvoliver lopezvoliver commented Jun 12, 2024

This PR aims to add the ability to use dynamic styling to VectorTileLayer. That is, styling may be defined as a function of properties and zoom. This is possible with Leaflet.VectorGrid, but is not yet implemented in ipyleaflet, because there is currently no way to define python callbacks that can be used by the leaflet map.

One compromise is to allow the user to define the javascript code for the dynamic style as a string.

Following the example from the documentation, here's a simple dynamic style that the user could define for use with ipyleaflet.VectorTileLayer:

jstyle='''{
    water:{opacity:0},
    places:{opacity:0},
    transit:{opacity:0},
    pois:{opacity:0},
    boundaries:{opacity:0},
    roads:{opacity:0},
    earth:{opacity:0},
    landuse: function(properties, zoom){
        var color = "gray";
        var fill = true;

        if(properties.kind=="forest"){
            color="green";
        }

        if(zoom<10){
            color="purple";
        }

        return {
            color: color,
            fill: fill
        }
        
    }
}
'''

it should only show landuse in purple for zoom levels less than 10, and otherwise show features as gray, except if they are "forest".

Here's an animation of the behavior achieved by this PR:

ipyleaflet_new

Here's another example using my own vector tile layer:

ipyleaflet_new_pivots

Related issue: #744

@martinRenou
Copy link
Member

Thanks for your PR!

Concerning the CI build failure, you should be able to fix it by running yarn run lint from the python/jupyter_leaflet directory

@lopezvoliver
Copy link
Contributor Author

@martinRenou thanks, that worked for the "run" tests. What about the UI / Visual regression test? is there something I can do?

Copy link
Member

@martinRenou martinRenou left a comment

Choose a reason for hiding this comment

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

Thanks! I believe the CI failures are unrelated

python/jupyter_leaflet/src/layers/VectorTileLayer.ts Outdated Show resolved Hide resolved
python/ipyleaflet/ipyleaflet/leaflet.py Outdated Show resolved Hide resolved
Copy link
Member

@martinRenou martinRenou left a comment

Choose a reason for hiding this comment

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

Thanks!

@martinRenou martinRenou merged commit 52f4cb7 into jupyter-widgets:master Jun 14, 2024
3 of 4 checks passed
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