|
| 1 | +Vector Tile Layer |
| 2 | +================= |
| 3 | + |
| 4 | +Example |
| 5 | +------- |
| 6 | + |
| 7 | +.. jupyter-execute:: |
| 8 | + |
| 9 | + from ipyleaflet import Map, VectorTileLayer |
| 10 | + |
| 11 | + from traitlets import Unicode, Dict |
| 12 | + |
| 13 | + # This is a custom VectorTileLayer subclass, allowing to pass our api key to the url |
| 14 | + class CustomVectorTileLayer(VectorTileLayer): |
| 15 | + api_key = Unicode('gCZXZglvRQa6sB2z7JzL1w').tag(sync=True, o=True) |
| 16 | + |
| 17 | + water_style = dict( |
| 18 | + fill="true", |
| 19 | + weight=1, |
| 20 | + fillColor="#06cccc", |
| 21 | + color="#06cccc", |
| 22 | + fillOpacity=0.2, |
| 23 | + opacity=0.4, |
| 24 | + ) |
| 25 | + |
| 26 | + waterway_style = dict( |
| 27 | + weight=1, fillColor="#2375e0", color="#2375e0", fillOpacity=0.2, opacity=0.4 |
| 28 | + ) |
| 29 | + |
| 30 | + admin_style = dict( |
| 31 | + weight=1, fillColor="pink", color="pink", fillOpacity=0.2, opacity=0.4 |
| 32 | + ) |
| 33 | + |
| 34 | + landcover_style = dict( |
| 35 | + fill="true", |
| 36 | + weight=1, |
| 37 | + fillColor="#53e033", |
| 38 | + color="#53e033", |
| 39 | + fillOpacity=0.2, |
| 40 | + opacity=0.4, |
| 41 | + ) |
| 42 | + |
| 43 | + landuse_style = dict( |
| 44 | + fill="true", |
| 45 | + weight=1, |
| 46 | + fillColor="#e5b404", |
| 47 | + color="#e5b404", |
| 48 | + fillOpacity=0.2, |
| 49 | + opacity=0.4, |
| 50 | + ) |
| 51 | + |
| 52 | + park_style = dict( |
| 53 | + fill="true", |
| 54 | + weight=1, |
| 55 | + fillColor="#84ea5b", |
| 56 | + color="#84ea5b", |
| 57 | + fillOpacity=0.2, |
| 58 | + opacity=0.4, |
| 59 | + ) |
| 60 | + |
| 61 | + boundary_style = dict( |
| 62 | + weight=1, fillColor="#c545d3", color="#c545d3", fillOpacity=0.2, opacity=0.4 |
| 63 | + ) |
| 64 | + |
| 65 | + |
| 66 | + aeroway = dict( |
| 67 | + weight=1, fillColor="#51aeb5", color="#51aeb5", fillOpacity=0.2, opacity=0.4 |
| 68 | + ) |
| 69 | + |
| 70 | + road = dict( |
| 71 | + weight=1, fillColor="#f2b648", color="#f2b648", fillOpacity=0.2, opacity=0.4 |
| 72 | + ) |
| 73 | + |
| 74 | + transit = dict( |
| 75 | + weight=0.5, fillColor="#f2b648", color="#f2b648", fillOpacity=0.2, opacity=0.4 |
| 76 | + ) |
| 77 | + |
| 78 | + buildings = dict( |
| 79 | + fill="true", |
| 80 | + weight=1, |
| 81 | + fillColor="#2b2b2b", |
| 82 | + color="#2b2b2b", |
| 83 | + fillOpacity=0.2, |
| 84 | + opacity=0.4, |
| 85 | + ) |
| 86 | + |
| 87 | + water_name = dict( |
| 88 | + weight=1, fillColor="#022c5b", color="#022c5b", fillOpacity=0.2, opacity=0.4 |
| 89 | + ) |
| 90 | + |
| 91 | + transportation_name = dict( |
| 92 | + weight=1, fillColor="#bc6b38", color="#bc6b38", fillOpacity=0.2, opacity=0.4 |
| 93 | + ) |
| 94 | + |
| 95 | + place = dict( |
| 96 | + weight=1, fillColor="#f20e93", color="#f20e93", fillOpacity=0.2, opacity=0.4 |
| 97 | + ) |
| 98 | + |
| 99 | + housenumber = dict( |
| 100 | + weight=1, fillColor="#ef4c8b", color="#ef4c8b", fillOpacity=0.2, opacity=0.4 |
| 101 | + ) |
| 102 | + |
| 103 | + poi = dict(weight=1, fillColor="#3bb50a", color="#3bb50a", fillOpacity=0.2, opacity=0.4) |
| 104 | + |
| 105 | + earth = dict( |
| 106 | + fill="true", |
| 107 | + weight=1, |
| 108 | + fillColor="#c0c0c0", |
| 109 | + color="#c0c0c0", |
| 110 | + fillOpacity=0.2, |
| 111 | + opacity=0.4, |
| 112 | + ) |
| 113 | + |
| 114 | + url = 'https://tile.nextzen.org/tilezen/vector/v1/512/all/{z}/{x}/{y}.mvt?api_key={apiKey}' |
| 115 | + vector_tile_layer_styles = dict( |
| 116 | + water=water_style, |
| 117 | + waterway=waterway_style, |
| 118 | + admin=admin_style, |
| 119 | + andcover=landcover_style, |
| 120 | + landuse=landuse_style, |
| 121 | + park=park_style, |
| 122 | + boundaries=boundary_style, |
| 123 | + aeroway=aeroway, |
| 124 | + roads=road, |
| 125 | + transit=transit, |
| 126 | + buildings=buildings, |
| 127 | + water_name=water_name, |
| 128 | + transportation_name=transportation_name, |
| 129 | + places=place, |
| 130 | + housenumber=housenumber, |
| 131 | + pois=poi, |
| 132 | + earth=earth |
| 133 | + ) |
| 134 | + |
| 135 | + m = Map(center=(52.204793, 360.121558), zoom=9) |
| 136 | + vl = CustomVectorTileLayer(url=url, vector_tile_layer_styles=vector_tile_layer_styles) |
| 137 | + m.add_layer(vl) |
| 138 | + m |
| 139 | + |
| 140 | + |
| 141 | +Attributes |
| 142 | +---------- |
| 143 | + |
| 144 | +========================= ================================================================================= ===================================================== |
| 145 | +Attribute Default Value Doc |
| 146 | +========================= ================================================================================= ===================================================== |
| 147 | +url '' Url for the source protobuf data. |
| 148 | +attribution 'Map data (c) <a href="https://openstreetmap.org">OpenStreetMap</a> contributors' Attribution for the map. |
| 149 | +vector_tile_layer_styles {} Styles for the various data layer of protobuf layers. |
| 150 | +========================= ================================================================================= ===================================================== |
0 commit comments