Presentation is loading. Please wait.

Presentation is loading. Please wait.

Making maps with Leaflet.js Steve Signell, Instructor Robert Poirier, TA School of Science Rensselaer Polytechnic Institute.

Similar presentations


Presentation on theme: "Making maps with Leaflet.js Steve Signell, Instructor Robert Poirier, TA School of Science Rensselaer Polytechnic Institute."— Presentation transcript:

1 Making maps with Leaflet.js Steve Signell, Instructor Robert Poirier, TA School of Science Rensselaer Polytechnic Institute Monday, March 31, 2014 GIS in the Sciences ERTH 4750 (38031)

2 Leaflet.js Leaflet.js: An Open-Source JavaScript Library for Mobile-Friendly Interactive Maps: Javascript is embedded in an.html file What is an.html file?

3 Before we start, we must: Download & Install the Sublime Text 3 text editor: Next we will create a webserver on your machine: What is a webserver? A folder on your machine that can be viewed accessed via a web browser.

4 PgAdmin/Postgres Installed? Open Application Stack Builder and select Web Development  Apache/PHP. Direct your browser to ‘localhost:800’– does it show a message from Apache? If not, ask for help and we’ll find it. The folder containing your web server MAY be something like ‘Program Files\ApachePHP\apache\www’ If not, ask for help and we’ll find it. Copy the ‘giscience_leaflet_template’ folder into your webserver folder. Now open up your browser again and paste ‘/ giscience_leaflet_template ‘ onto the end of the URL: You should see something like this:

5 OpenGeo Suite installed? Open up your OpenGeo Suite Dashboard and note the URL. It will probably be something like ‘localhost:8080’ On windows, the folder containing your web server MAY be something like ‘Program Files\Boundless\OpenGeo\jetty\webapps.’ If not, ask for help and we’ll find it. Copy the ‘giscience_leaflet_template’ folder into your webserver folder. Now open up the OpenGeo Dashboard again and paste ‘/ giscience_leaflet_template ‘ onto the end of the URL: You should see something like this:

6 Explore your folder Open the helloworld.html file, and then right-click  View Page Source Do the same with leaflet_template.html Open the data and img folders and explore their contents. how are GeoJSON files structured? (‘JSONView’ is a nice little Chrome/Firefox extension that helps you decipher GeoJson files.)

7 Parts of a Leaflet Map Script files Map area Zoom tool layerControl data

8 Edit your html Open your helloworld.html in Sublime Text 3, and modify the text between the ‘title’ and ‘body’ tags. Make sure you save it, and then reload the webpage in your browser. Did anything change? Open leaflet_template.html in Sublime Text, and make the following changes. After each step, save the file and then check the effect by refreshing the page in your browser. Change the title (line 5) Make the map a square shape (line 16) Change the initial zoom from 9 to 8 (line 26) Change the color of the borough boundaries from black to red (line 47) Change the default basemap from OpenStreetMap to NAIP (line 63) Change the name of the boroughs in the layerControl from ‘Boroughs’ to ‘NYC Boroughs’ (line 73)

9 Add another overlay layer Add another overlay layer by adding the following text to leaflet_template.html, after the boroughs data gets loaded (line 60): //make a variable for the museums layer and set the style var museums = L.geoJson(null, { pointToLayer: function (feature, latlng) { return L.marker(latlng, { icon: L.icon({ iconUrl: "img/museum.png", iconSize: [24, 28], iconAnchor: [12, 28], popupAnchor: [0, -25] }), title: feature.properties.NAME, riseOnHover: true }); } }); //load the museums data from geojson $.getJSON("data/museums.geojson", function (data) { museums.addData(data); }); Also add the ‘museums’ layer to the overlays in your layerControl.

10 Add your own layer 1)Use QGIS to save the nyc_subway_stations layer as a GeoJSON file in your /data folder. Make sure you reproject the data from UTM18N to WGS84 (EPGS:4326). 2)Add the subways stations layer to the map by copying and modifying the code from the previous slide. 3)Don’t forget to your new layer to the layerControl. Optionally, you can also load it onto the map by default. 4)Find a more appropriate.jpg or.png image for subway stops and save it to your /img folder. Then change the ‘iconURL’ so it points to this new image. 5)If you want some text to appear when you hover over the feature, you’ll have to change the ‘title: feature.properties.NAME’ to point to a field name that exists in your geojson (this is case sensitive).

11 Homework 11 Experiment with adding more layers and with the tutorials at leaflet.js.com. Create a new.html file that creates a leaflet map of the RPI area and include one or more layers from your group project.


Download ppt "Making maps with Leaflet.js Steve Signell, Instructor Robert Poirier, TA School of Science Rensselaer Polytechnic Institute."

Similar presentations


Ads by Google