In this lab, you will make something similar to the map above. We will use web mapping technologies, Mapbox, Leaflet, and GitHub. Mapbox is a provider of custom online maps for websites and applications such as Foursquare, Facebook, and The Weather Channel. Leaflet is a widely-used open-source JavaScript library used to build web mapping applications. GitHub provides hosting for software development version control using Git. What is nice about these technologies is that they are highly customizable and can give you a platform to develop online webmaps.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title></title> <!--put your external stylesheet links here--> </head> <body> <!--put your initial page content here--> <!--put your external script links here--> </body> </html> |
<link rel="stylesheet"href= "lib/leaflet.css">
<script src ="lib/leaflet-src.js"> </script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<div id="map" style="width: 100%; height:700px;"></div>
<script src ="js/main.js"></script>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>Dark Terrian</title> <!--put your external stylesheet links here--> <link rel="stylesheet" href="lib/leaflet.css"> <script src ="lib/leaflet-src.js"> </script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> </head> <body> <!--put your initial page content here--> <div id="map" style="width: 100%; height:700px;"></div> <!--put your external script links here--> <script src ="js/main.js"></script> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | //function to start the Leaflet map function createMap(){ //Varibles for attribution box on the map. var mbAttr = '<a href="http://openstreetmap.org">OpenStreetMap</a> |' +' <a href="http://mapbox.com">Mapbox</a>'; //You can add you name to the variable if you want to add yourself to the credits. //Variable for storing your Mapbox API Token var apitoken = 'Your Token' //Enter your API Token - go to 'https://www.mapbox.com/install/' to yours */ //URL used for Stanard MaxBox Styles var mbUrl = 'https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={token}'; //URL used for Custom MapBox Style var mbStyleUrl = 'https://api.mapbox.com/styles/v1/{id}/tiles/256/{z}/{x}/{y}?access_token={token}'; //For Custome basemaps - Replace your username and StyleID var customeBasemap = L.tileLayer(mbStyleUrl, {id: 'MapBoxUserName/StyleId', token: apitoken, attribution: mbAttr}); //For MabBox Standard Basemaps var standardBasemap = L.tileLayer(mbUrl, {id: 'mapbox.light', token: apitoken, attribution: mbAttr}); //create the map*/ var map = L.map('map', { center: [31.00, -5],//Coordinated to center the map zoom: 6, //zoom level layers:customeBasemap //basemap }); }; //calling the funcation $(document).ready(createMap); |
//create the basemap control layer*/ var baseLayers = { "Standard": standardBasemap, "Custom": customeBasemap }; L.control.layers(baseLayers).addTo(map);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | //function to start the Leaflet map function createMap(){ //Varibles needed for running the funcation var mbAttr = '<a href="http://openstreetmap.org">OpenStreetMap</a> |' +' <a href="http://mapbox.com">Mapbox</a> | <a href="https://sounny.github.io/">Sounny Slitine</a>'; var apitoken = 'pk.eyJ1Ijoic291bm55IiwiYSI6ImNqcGRpaGVhbzAwaWsza24wbnhtMnR6NnQifQ.J3MAaLF0GbWo8hWP2MKtsw' //Enter your API Token - go to 'https://www.mapbox.com/install/' to yours */ var mbUrl = 'https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={token}'; //URL used for Stanard MaxBox Styles var mbStyleUrl = 'https://api.mapbox.com/styles/v1/{id}/tiles/256/{z}/{x}/{y}?access_token={token}'; //URL used for Custom MapBox Styles //Variables for the different basemaps var darkTerrain = L.tileLayer(mbStyleUrl, {id: 'sounny/cjy6np5ld1sjg1cme97n3yosk', token: apitoken, attribution: mbAttr}); var grayscale = L.tileLayer(mbUrl, {id: 'mapbox.light', token: apitoken, attribution: mbAttr}); var dark = L.tileLayer(mbUrl, {id: 'mapbox.dark', token: apitoken, attribution: mbAttr}); var outdoors = L.tileLayer(mbUrl, {id: 'mapbox.outdoors', token: apitoken, attribution: mbAttr}); //create the map*/ var map = L.map('map', { center: [31.00, -5],//Coordinated to center the map zoom: 6, //zoom level layers:darkTerrain //default base }); //create the basemap control layer*/ var baseLayers = { "Outdoors": outdoors, "Grayscale": grayscale, "Darkscale": dark, "Dark Terrain": darkTerrain }; L.control.layers(baseLayers).addTo(map); }; //calling the funcation $(document).ready(createMap); |