{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Mapboxgl Python Library for location data visualization\n", "\n", "https://github.com/mapbox/mapboxgl-jupyter\n", "\n", "### Requirements\n", "\n", "These examples require the installation of the following python modules\n", "\n", "```\n", "pip install mapboxgl\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "from mapboxgl.viz import RasterTilesViz\n", "\n", "# Set Mapbox Acces Token; Must be a public token, starting with `pk`\n", "token = os.getenv('MAPBOX_ACCESS_TOKEN')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create a map with raster tiles from OpenStreetMap.org" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tiles_url = 'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png'\n", "\n", "# Create an empty style\n", "style = {'version': 8, 'sources': {}, 'layers': []}\n", "\n", "viz = RasterTilesViz(tiles_url, \n", " access_token=token,\n", " tiles_size=256,\n", " height='500px', \n", " zoom=3, \n", " style=style)\n", "viz.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Display raster tiles on a mapbox basemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tiles_url = 'https://cogeo.remotepixel.ca/tiles/{z}/{x}/{y}.jpg?tile=256&nodata=0&url=http://oin-hotosm.s3.amazonaws.com/594ab0ba1b114600111194a3/0/d66720c4-148c-4e11-9d54-4ae2a6ba6351.tif'\n", "\n", "# Define the tile endpoint bounds\n", "tiles_bounds = [124.97480681619507, 10.876763902260592, 124.99391704636035, 10.888369402219947]\n", "tiles_center = [124.9843619312777, 10.88256665224027]\n", "\n", "viz = RasterTilesViz(tiles_url, \n", " access_token=token,\n", " tiles_size=256,\n", " tiles_bounds=tiles_bounds,\n", " height='500px', \n", " center=tiles_center,\n", " tiles_minzoom=13,\n", " tiles_maxzoom=18,\n", " zoom=15,\n", " below_layer='waterway-label')\n", "viz.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }