|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "from ipyleaflet import Map, VectorTileLayer, TileLayer" |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "code", |
| 14 | + "execution_count": null, |
| 15 | + "metadata": {}, |
| 16 | + "outputs": [], |
| 17 | + "source": [ |
| 18 | + "from traitlets import Unicode, Dict\n", |
| 19 | + "\n", |
| 20 | + "class CustomVectorTileLayer(VectorTileLayer):\n", |
| 21 | + " api_key = Unicode('gCZXZglvRQa6sB2z7JzL1w').tag(sync=True, o=True)\n", |
| 22 | + " attribution = Unicode('<a href=\"https://nextzen.com/\">© NextZen</a>, <a href=\"http://www.openstreetmap.org/copyright\">© OpenStreetMap</a> contributors').tag(sync=True, o=True)\n" |
| 23 | + ] |
| 24 | + }, |
| 25 | + { |
| 26 | + "cell_type": "code", |
| 27 | + "execution_count": null, |
| 28 | + "metadata": {}, |
| 29 | + "outputs": [], |
| 30 | + "source": [ |
| 31 | + "water_style = dict(\n", |
| 32 | + " fill=\"true\",\n", |
| 33 | + " weight=1,\n", |
| 34 | + " fillColor=\"#06cccc\",\n", |
| 35 | + " color=\"#06cccc\",\n", |
| 36 | + " fillOpacity=0.2,\n", |
| 37 | + " opacity=0.4,\n", |
| 38 | + ")\n", |
| 39 | + "\n", |
| 40 | + "waterway_style = dict(\n", |
| 41 | + " weight=1, fillColor=\"#2375e0\", color=\"#2375e0\", fillOpacity=0.2, opacity=0.4\n", |
| 42 | + ")\n", |
| 43 | + "\n", |
| 44 | + "admin_style = dict(\n", |
| 45 | + " weight=1, fillColor=\"pink\", color=\"pink\", fillOpacity=0.2, opacity=0.4\n", |
| 46 | + ")\n", |
| 47 | + "\n", |
| 48 | + "landcover_style = dict(\n", |
| 49 | + " fill=\"true\",\n", |
| 50 | + " weight=1,\n", |
| 51 | + " fillColor=\"#53e033\",\n", |
| 52 | + " color=\"#53e033\",\n", |
| 53 | + " fillOpacity=0.2,\n", |
| 54 | + " opacity=0.4,\n", |
| 55 | + ")\n", |
| 56 | + "\n", |
| 57 | + "landuse_style = dict(\n", |
| 58 | + " fill=\"true\",\n", |
| 59 | + " weight=1,\n", |
| 60 | + " fillColor=\"#e5b404\",\n", |
| 61 | + " color=\"#e5b404\",\n", |
| 62 | + " fillOpacity=0.2,\n", |
| 63 | + " opacity=0.4,\n", |
| 64 | + ")\n", |
| 65 | + "\n", |
| 66 | + "park_style = dict(\n", |
| 67 | + " fill=\"true\",\n", |
| 68 | + " weight=1,\n", |
| 69 | + " fillColor=\"#84ea5b\",\n", |
| 70 | + " color=\"#84ea5b\",\n", |
| 71 | + " fillOpacity=0.2,\n", |
| 72 | + " opacity=0.4,\n", |
| 73 | + ")\n", |
| 74 | + "\n", |
| 75 | + "boundary_style = dict(\n", |
| 76 | + " weight=1, fillColor=\"#c545d3\", color=\"#c545d3\", fillOpacity=0.2, opacity=0.4\n", |
| 77 | + ")\n", |
| 78 | + "\n", |
| 79 | + "\n", |
| 80 | + "aeroway = dict(\n", |
| 81 | + " weight=1, fillColor=\"#51aeb5\", color=\"#51aeb5\", fillOpacity=0.2, opacity=0.4\n", |
| 82 | + ")\n", |
| 83 | + "road = dict(\n", |
| 84 | + " weight=1, fillColor=\"#f2b648\", color=\"#f2b648\", fillOpacity=0.2, opacity=0.4\n", |
| 85 | + ")\n", |
| 86 | + "transit = dict(\n", |
| 87 | + " weight=0.5, fillColor=\"#f2b648\", color=\"#f2b648\", fillOpacity=0.2, opacity=0.4\n", |
| 88 | + ")\n", |
| 89 | + "buildings = dict(\n", |
| 90 | + " fill=\"true\",\n", |
| 91 | + " weight=1,\n", |
| 92 | + " fillColor=\"#2b2b2b\",\n", |
| 93 | + " color=\"#2b2b2b\",\n", |
| 94 | + " fillOpacity=0.2,\n", |
| 95 | + " opacity=0.4,\n", |
| 96 | + ")\n", |
| 97 | + "water_name = dict(\n", |
| 98 | + " weight=1, fillColor=\"#022c5b\", color=\"#022c5b\", fillOpacity=0.2, opacity=0.4\n", |
| 99 | + ")\n", |
| 100 | + "transportation_name = dict(\n", |
| 101 | + " weight=1, fillColor=\"#bc6b38\", color=\"#bc6b38\", fillOpacity=0.2, opacity=0.4\n", |
| 102 | + ")\n", |
| 103 | + "place = dict(\n", |
| 104 | + " weight=1, fillColor=\"#f20e93\", color=\"#f20e93\", fillOpacity=0.2, opacity=0.4\n", |
| 105 | + ")\n", |
| 106 | + "housenumber = dict(\n", |
| 107 | + " weight=1, fillColor=\"#ef4c8b\", color=\"#ef4c8b\", fillOpacity=0.2, opacity=0.4\n", |
| 108 | + ")\n", |
| 109 | + "poi = dict(weight=1, fillColor=\"#3bb50a\", color=\"#3bb50a\", fillOpacity=0.2, opacity=0.4)\n", |
| 110 | + "earth = dict(\n", |
| 111 | + " fill=\"true\",\n", |
| 112 | + " weight=1,\n", |
| 113 | + " fillColor=\"#c0c0c0\",\n", |
| 114 | + " color=\"#c0c0c0\",\n", |
| 115 | + " fillOpacity=0.2,\n", |
| 116 | + " opacity=0.4,\n", |
| 117 | + ")\n" |
| 118 | + ] |
| 119 | + }, |
| 120 | + { |
| 121 | + "cell_type": "code", |
| 122 | + "execution_count": null, |
| 123 | + "metadata": {}, |
| 124 | + "outputs": [], |
| 125 | + "source": [ |
| 126 | + "url = 'https://tile.nextzen.org/tilezen/vector/v1/512/all/{z}/{x}/{y}.mvt?api_key={apiKey}'\n", |
| 127 | + "vectorTileLayerStyles=dict(water=water_style,\n", |
| 128 | + " waterway=waterway_style,\n", |
| 129 | + " admin=admin_style,\n", |
| 130 | + " andcover=landcover_style,\n", |
| 131 | + " landuse=landuse_style,\n", |
| 132 | + " park=park_style,\n", |
| 133 | + " boundaries=boundary_style,\n", |
| 134 | + " aeroway=aeroway,\n", |
| 135 | + " roads=road,\n", |
| 136 | + " transit=transit,\n", |
| 137 | + " buildings=buildings,\n", |
| 138 | + " water_name=water_name,\n", |
| 139 | + " transportation_name=transportation_name,\n", |
| 140 | + " places=place,\n", |
| 141 | + " housenumber=housenumber,\n", |
| 142 | + " pois=poi,\n", |
| 143 | + " earth=earth,)\n", |
| 144 | + "m = Map(center=(52.204793, 360.121558), zoom=9)\n", |
| 145 | + "vl = CustomVectorTileLayer(url=url, vector_tile_layer_styles=vectorTileLayerStyles)\n", |
| 146 | + "m.add_layer(vl)\n", |
| 147 | + "m" |
| 148 | + ] |
| 149 | + }, |
| 150 | + { |
| 151 | + "cell_type": "code", |
| 152 | + "execution_count": null, |
| 153 | + "metadata": {}, |
| 154 | + "outputs": [], |
| 155 | + "source": [ |
| 156 | + "m.zoom=3.58" |
| 157 | + ] |
| 158 | + }, |
| 159 | + { |
| 160 | + "cell_type": "code", |
| 161 | + "execution_count": null, |
| 162 | + "metadata": {}, |
| 163 | + "outputs": [], |
| 164 | + "source": [ |
| 165 | + "vl.url = \"https://basemaps.arcgis.com/v1/arcgis/rest/services/World_Basemap/VectorTileServer/tile/{z}/{y}/{x}.pbf\"" |
| 166 | + ] |
| 167 | + }, |
| 168 | + { |
| 169 | + "cell_type": "code", |
| 170 | + "execution_count": null, |
| 171 | + "metadata": {}, |
| 172 | + "outputs": [], |
| 173 | + "source": [ |
| 174 | + "m.remove_layer(m.layers[0])" |
| 175 | + ] |
| 176 | + } |
| 177 | + ], |
| 178 | + "metadata": { |
| 179 | + "kernelspec": { |
| 180 | + "display_name": "Python 3", |
| 181 | + "language": "python", |
| 182 | + "name": "python3" |
| 183 | + }, |
| 184 | + "language_info": { |
| 185 | + "codemirror_mode": { |
| 186 | + "name": "ipython", |
| 187 | + "version": 3 |
| 188 | + }, |
| 189 | + "file_extension": ".py", |
| 190 | + "mimetype": "text/x-python", |
| 191 | + "name": "python", |
| 192 | + "nbconvert_exporter": "python", |
| 193 | + "pygments_lexer": "ipython3", |
| 194 | + "version": "3.7.3" |
| 195 | + } |
| 196 | + }, |
| 197 | + "nbformat": 4, |
| 198 | + "nbformat_minor": 4 |
| 199 | +} |
0 commit comments