1 / 11

Making maps with Leaflet.js

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

erling
Télécharger la présentation

Making maps with Leaflet.js

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Leaflet.js • Leaflet.js: An Open-Source JavaScript Library for Mobile-Friendly Interactive Maps: http://leafletjs.com • 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: http://www.sublimetext.com/3 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 • 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). • Add the subways stations layer to the map by copying and modifying the code from the previous slide. • Don’t forget to your new layer to the layerControl. Optionally, you can also load it onto the map by default. • 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. • 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 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.

More Related