Skip to main content

VectorTileLayer plugin for folium

Project description


Folium-VectorTileLayer

VectorTileLayer plugin for Folium
Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. License
  5. Contact

About The Project

Follow up on folium-vectorgrid that wraps Leaflet.VectorTileLayer to render Mapbox vector tiles in folium maps.

Other than Leaflet.VectorGrid, Leaflet.VectorTileLayer allows to "overzoom" and "underzoom". Even if the tiling provider only provides map tiles for zoom level 5 through 12, Leaflet.VectorTileLayer utilizes data from these upper and lower bounds to render tiles beyond zoom level 12 and 5 respectively.

Built With

Getting Started

Prerequisite

Install uv.

Installation

as dependency

poetry add git+https://github.com/iwpnd/folium-vectortilelayer.git
pip install folium-vectortilelayer
uv add folium-vectortilelayer

local development

  1. Clone and install
    git clone https://github.com/iwpnd/folium-vectortilelayer.git
    uv sync
    
  2. Test it!
    make test
    

Usage

from folium_vectortilelayer import VectorTileLayer
import folium

url = "https://free.tilehosting.com/data/v3/{z}/{x}/{y}.pbf?token=my_token"

m = folium.Map()
options = {
    "layers": ["my_layer"], # define layer to be shown
    # min zoom of your map,
    # if minZoom < minDetailZoom features in minDetailZoom level are used
    # for minDetailZoom to minZoom
    "minZoom": 8,
    # max zoom of your map,
    # if maxZoom > maxDetailZoom features in maxDetailZoom level are used
    # for maxDetailZoom to maxZoom
    "maxZoom": 18,
    # min zoom level provided by source
    "minDetailZoom": 10,
    # max zoom level provided by source
    "maxDetailZoom": 13,
    "vectorTileLayerStyles": {
        "my_layer":{
            "fill": True,
            "weight": 1,
            "fillColor": 'green',
            "color": 'black',
            "fillOpacity":0.6,
            "opacity":0.6
        },
    }
}

vc = VectorTileLayer(url, "folium_layer_name", options)
m.add_child(vc)
m

Or with conditional styling

import folium
from folium_vectortilelayer import VectorTileLayer

m = folium.Map()
url = "https://free.tilehosting.com/data/v3/{z}/{x}/{y}.pbf?token=my_token"

options = '''{
  "layers": ["my_layer"],
  "vectorTileLayerStyles": {
    "my_layer": function(f) {
      if (f.type === 'parks') {
        return {
          "fill": true,
          "weight": 1,
          "fillColor": 'green',
          "color": 'black',
          "fillOpacity":0.6,
          "opacity":0.6
        };
      }

      if (f.type === 'water') {
        return {
          "fill": true,
          "weight": 1,
          "fillColor": 'purple',
          "color": 'black',
          "fillOpacity":0.6,
          "opacity":0.6
        };
      }
    }
  }
}'''

VectorTileLayer(url,"layer_name",options).add_to(m)
m

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Benjamin Ramser - @imwithpanda - ahoi@iwpnd.pw
Project Link: https://github.com/iwpnd/folium-vector

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

folium_vectortilelayer-0.2.5.tar.gz (77.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

folium_vectortilelayer-0.2.5-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file folium_vectortilelayer-0.2.5.tar.gz.

File metadata

  • Download URL: folium_vectortilelayer-0.2.5.tar.gz
  • Upload date:
  • Size: 77.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for folium_vectortilelayer-0.2.5.tar.gz
Algorithm Hash digest
SHA256 dabd35f1a536d7eb0c1d2b02633d2d64500a3975b274eda59ad3044b8c563157
MD5 636385b2118de63a52b982ffc809fea2
BLAKE2b-256 d4b912a313ffb119ffc37e8d8193bab1d1612e27180170094120e414b16810b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for folium_vectortilelayer-0.2.5.tar.gz:

Publisher: main.yml on iwpnd/folium-vectortilelayer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file folium_vectortilelayer-0.2.5-py3-none-any.whl.

File metadata

File hashes

Hashes for folium_vectortilelayer-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b55d59cd07252e3103b504def9673a79bf4387b6e53601b9a0d313e5fcdbdf9f
MD5 7e7c338915d36881dc68bc3803ccb49c
BLAKE2b-256 375560f32135cdde0c9136510c925fc88a6bfbd86e1ada271c023a58c5e7a6e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for folium_vectortilelayer-0.2.5-py3-none-any.whl:

Publisher: main.yml on iwpnd/folium-vectortilelayer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page