Documents/Leaflet_workshop
)cd Documents cd Leaflet_workshop
python -m SimpleHTTPServer
You should now see a web page with "Directory listing for /"
at the top.
my-map.html
in your Leaflet Workshop folder<head>
, after the <title>
section):
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.3/leaflet.css" /> <script src="http://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.3/leaflet.js"></script>
<head>
, after the above section):
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<body>
):
<div id="map-canvas"></div>
<body>
in between the <script>
tags):
$(document).ready(function () { var map = L.map( 'map-canvas', { center: [-31.95, 115.86], zoom: 11 } ); L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' }).addTo(map); });
<head>
in between the <style>
tags):
body { padding: 0; margin: 0; } html, body, #map-canvas { height: 100%; width: 100%; }
You should now have a file similar to stage-1.0-basic-web-map.html.
$.getJSON("walibraryaddresses.geojson", function(geojson) { L.geoJSON(geojson).addTo(map); });
L.control.scale().addTo(map);
You should now have a file similar to stage-2.0-adding-data.html.
Change the map pins to 8 pixel orange circles:
$.getJSON("walibraryaddresses.geojson", function(geojson) { var geojsonMarkerOptions = { radius: 8, fillColor: "#ff7800", color: "#000", weight: 1, opacity: 1, fillOpacity: 0.8 }; L.geoJSON(geojson, { pointToLayer: function(feature, latlng) { return L.circleMarker(latlng, geojsonMarkerOptions); } }).addTo(map); });
You should now have a file similar to stage-3.0-visualising-data.html.
Now change the markers for libraries with a 'Street Suburb' attribute of South Perth
to a larger green circle:
$.getJSON("walibraryaddresses.geojson", function(geojson) { var libraryMarker = { radius: 8, fillColor: "#ff7800", // Orange. color: "#000", weight: 1, opacity: 1, fillOpacity: 0.8 }; var specialLibraryMarker = { radius: 16, fillColor: "#0faa9b", // Green color: "#fff", weight: 1, opacity: 1, fillOpacity: 0.8 }; L.geoJSON(geojson, { pointToLayer: function(feature, latlng) { var style; switch(feature.properties["Street Suburb"]) { case "South Perth": style = specialLibraryMarker; break; default: style = libraryMarker; } return L.circleMarker(latlng, style); } }).addTo(map); });
You should now have a file similar to stage-3.1-dynamic-styling.html.
Now add a popup box so that you can see the library name when you click on the orange circle.
L.geoJSON(geojson, { pointToLayer: function(feature, latlng) { /* Code here is unchanged */ }, onEachFeature: function(feature, layer) { if (feature.properties) { layer.bindPopup(feature.properties["Name"]); } } }).addTo(map);
You should now have a file similar to stage-4.0-adding-popups.html.
your-username.github.io
repository, initialized with a README filemy-map.html
and the GeoJSON file to that repo