|
173 | 173 | "m.add_legend(legend_dict=legend_dict)\n",
|
174 | 174 | "m"
|
175 | 175 | ]
|
| 176 | + }, |
| 177 | + { |
| 178 | + "cell_type": "markdown", |
| 179 | + "metadata": {}, |
| 180 | + "source": [ |
| 181 | + "Download [building footprints](https://github.com/opengeos/open-data/blob/main/datasets/libya/Derna_buildings.geojson) of Derna, Libya." |
| 182 | + ] |
| 183 | + }, |
| 184 | + { |
| 185 | + "cell_type": "code", |
| 186 | + "execution_count": null, |
| 187 | + "metadata": {}, |
| 188 | + "outputs": [], |
| 189 | + "source": [ |
| 190 | + "url = 'https://raw.githubusercontent.com/opengeos/open-data/main/datasets/libya/Derna_buildings.geojson'\n", |
| 191 | + "leafmap.download_file(url, 'buildings.geojson')" |
| 192 | + ] |
| 193 | + }, |
| 194 | + { |
| 195 | + "cell_type": "markdown", |
| 196 | + "metadata": {}, |
| 197 | + "source": [ |
| 198 | + "Convert vector to PMTiles." |
| 199 | + ] |
| 200 | + }, |
| 201 | + { |
| 202 | + "cell_type": "code", |
| 203 | + "execution_count": null, |
| 204 | + "metadata": {}, |
| 205 | + "outputs": [], |
| 206 | + "source": [ |
| 207 | + "pmtiles = 'buildings.pmtiles'\n", |
| 208 | + "leafmap.vector_to_pmtiles(\n", |
| 209 | + " 'buildings.geojson', \n", |
| 210 | + " pmtiles, \n", |
| 211 | + " layer_name='buildings', \n", |
| 212 | + " overwrite=True, \n", |
| 213 | + " quiet=True\n", |
| 214 | + ")" |
| 215 | + ] |
| 216 | + }, |
| 217 | + { |
| 218 | + "cell_type": "markdown", |
| 219 | + "metadata": {}, |
| 220 | + "source": [ |
| 221 | + "Start a HTTP Sever" |
| 222 | + ] |
| 223 | + }, |
| 224 | + { |
| 225 | + "cell_type": "code", |
| 226 | + "execution_count": null, |
| 227 | + "metadata": {}, |
| 228 | + "outputs": [], |
| 229 | + "source": [ |
| 230 | + "leafmap.start_server(port=8000)" |
| 231 | + ] |
| 232 | + }, |
| 233 | + { |
| 234 | + "cell_type": "code", |
| 235 | + "execution_count": null, |
| 236 | + "metadata": {}, |
| 237 | + "outputs": [], |
| 238 | + "source": [ |
| 239 | + "url = f'http://127.0.0.1:8000/{pmtiles}'\n", |
| 240 | + "# leafmap.pmtiles_metadata(url)" |
| 241 | + ] |
| 242 | + }, |
| 243 | + { |
| 244 | + "cell_type": "markdown", |
| 245 | + "metadata": {}, |
| 246 | + "source": [ |
| 247 | + "Diplay the PMTiles on the map." |
| 248 | + ] |
| 249 | + }, |
| 250 | + { |
| 251 | + "cell_type": "code", |
| 252 | + "execution_count": null, |
| 253 | + "metadata": {}, |
| 254 | + "outputs": [], |
| 255 | + "source": [ |
| 256 | + "m = leafmap.Map()\n", |
| 257 | + "\n", |
| 258 | + "style = {\n", |
| 259 | + " \"version\": 8,\n", |
| 260 | + " \"sources\": {\n", |
| 261 | + " \"example_source\": {\n", |
| 262 | + " \"type\": \"vector\",\n", |
| 263 | + " \"url\": \"pmtiles://\" + url,\n", |
| 264 | + " \"attribution\": 'PMTiles',\n", |
| 265 | + " }\n", |
| 266 | + " },\n", |
| 267 | + " \"layers\": [\n", |
| 268 | + " {\n", |
| 269 | + " \"id\": \"buildings\",\n", |
| 270 | + " \"source\": \"example_source\",\n", |
| 271 | + " \"source-layer\": \"buildings\",\n", |
| 272 | + " \"type\": \"fill\",\n", |
| 273 | + " \"paint\": {\"fill-color\": \"#3388ff\", \"fill-opacity\": 0.5},\n", |
| 274 | + " },\n", |
| 275 | + " ],\n", |
| 276 | + "}\n", |
| 277 | + "\n", |
| 278 | + "m.add_pmtiles(url, name='Buildings', show=True, zoom_to_layer=True, style=style)\n", |
| 279 | + "m" |
| 280 | + ] |
176 | 281 | }
|
177 | 282 | ],
|
178 | 283 | "metadata": {
|
|
0 commit comments