eoda-dev / py-maplibregl

Python bindings for MapLibre GL JS
https://eoda-dev.github.io/py-maplibregl/
MIT License
45 stars 5 forks source link

Question: Adding vector tile layer into basemap with PMTiles as source? #91

Closed diehl closed 4 months ago

diehl commented 4 months ago

Hi Stefan,

Building on our original discussion on interleaving data and basemap layers, I have a need to insert a vector tile layer into a basemap and set the fill color as a function of attributes attached to the geometries. In this scenario, I will typically have no more than 10 distinct colors defined that correspond to different attribute settings. In DeckGL, I would accomplish this with an MVTLayer and I think I know how I might set the color as a function of the attributes. I'm wondering if there's a more elegant way of doing this with PMTiles? Hopefully this question makes sense.

crazycapivara commented 4 months ago

Hi Chris,

im maplibre you use data-driven styling like this:

every_person_in_manhattan_circles = Layer(
    type=LayerType.CIRCLE,
    id=LAYER_ID,
    source=every_person_in_manhattan_source,
    paint={
        "circle-color": ["match", ["get", "sex"], 1, MALE_COLOR, FEMALE_COLOR],
        "circle-radius": CIRCLE_RADIUS,
    },
)

See this examples:

And here

diehl commented 4 months ago

Brilliant - thank you for the pointers @crazycapivara !