map styling tools and interactive maps on the web with openlayers - addy pope, gogeo

49
OSM Workshop- Plan A OSM Workshop 2011 Who Themes Cloudmade QGIS Conclusions 0 60 Panic Openlayers Mapnik

Upload: jisc-geco

Post on 06-May-2015

3.500 views

Category:

Technology


1 download

DESCRIPTION

Presentation given as part of the DevCSI/JISC GECO Open Mapping Workshop which was held at the Electron Club, CCA, Glasgow on Thursday 25th August 2011. The event was connected to the OpenStreetMap State of the Map Scotland event.

TRANSCRIPT

Page 1: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

OSM Workshop- Plan A

OSM Workshop 2011

Who

Themes

Cloudmade

QGIS

Conclusions

0

60

Panic

OpenlayersMapnik

Page 2: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

What is EDINA

EDINA is a National Data Centre supported by JISC to provide resources to higher and further institutions.

OSM Workshop 2011

EDINA has extensive experience in delivering and manipulating spatial data and is an active member of the OSGeo foundation providing persistent test beds for various packages.

GECO Geospatial Outreach and Community Outreach, EDINA coordinate this JISC funded project and aim to facilitate the use of geospatial data and tech beyond core user groups http://geco.blogs.edina.ac.uk/

Page 3: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Doing more with GIS/OpenLayers

We’ve seen what OSM is and how we can contribute data to it. Now lets look at what we might want to do with it.

OSM Workshop 2011

Page 4: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Something to work towards

http://bestofosm.org/

OSM Workshop 2011

This site showcases some of the best examples of OSM data/contributions around the world..... The UK looks a bit bare.

Page 5: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

OSM - Pompeii

OSM Workshop 2011

Page 6: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

OSM - CERN

OSM Workshop 2011

Page 7: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

OSM - Bern

OSM Workshop 2011

Page 8: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Doing more with GIS/OpenLayers

But there are some excellent examples of mapping detail from the UK that are not on the map.

OSM Workshop 2011

Page 9: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

OSM – Edinburgh Zoo

OSM Workshop 2011

Page 10: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

OSM – Edinburgh Southside

OSM Workshop 2011

Page 11: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Cloudmade

OSM Workshop 2011

You will have seen the blue plus sign on the right hand side of the map window. This allows you to alter the look of the map.

This is called altering the theme.

Cloudmade is a company that spun out from OSM and they do consultancy work on and around OSM data. In addition they offer some neat tools for OSM.

Page 12: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Cloudmade

OSM Workshop 2011

Cloudmade is a company that spun out from OSM and they do consultancy work on and around OSM data. In addition they offer some neat tools for OSM.

Page 13: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Cloudmade

OSM Workshop 2011

Lets have a closer look at some of the themes that Cloudmade offer. To do this, we need to look at http://maps.cloudmade.com/

Page 14: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Cloudmade - themes

OSM Workshop 2011

Page 15: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Cloudmade - Modify a theme

You can create your own theme using cloudmade. Navigate to: http://maps.cloudmade.com/

To create your own style:• Sign up and login (they send you an email)• Click Edit Map Style• Browse the styles for one close to what you want and select it by clicking Clone Style (bottom right)• Then just select features from the Left Menu and alter colours using the pallet control

PLAY with Cloudmade

OSM Workshop 2011

Page 16: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Mapnik - Modify a theme

What we have been doing is using a GUI to alter a theme, the GUI then generates the code which renders the xml from the OSM database, a bit like a CSS for a webpage.

OSM Workshop 2011

Page 17: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Mapnik- Modify a theme

Mapnik allows you to render osm xml files directly.

OSM Workshop 2011

You can have a go at this if you fancy it. What you will need to do is:1.Download mapnik – i tend to use the Mapnik bundled in OSGeo4W (http://www.mapnik.org/documentation/) 2.Find some examples to copy - http://wiki.openstreetmap.org/wiki/Mapnik_Example 3.Hack til you break it, then start again

Page 18: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Openlayers

is an open source JavaScript library for displaying map data in web browsers.

You will probably interacted and used Openlayers if you have used online mapping tools.

In this section we will look at what you can do with Openlayers.

http://openlayers.org/dev/examples/

OSM Workshop 2011

Page 19: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

OpenLayers: Digimap

Digimap is a service run by EDINA that supplies maps to education institutes across Britain.

http://edina.ac.uk/digimap/OSM Workshop 2011

Page 20: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

OpenLayers - Examples

The Openlayers website has some excellent examples of the functionality that Openlayers offers. You can view the code for each example and integrate it into your own mapping apps.

OSM Workshop 2011

http://openlayers.org/dev/examples/

Page 21: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

OpenLayers - Code

Google overlay:

var map; function init() { map = new OpenLayers.Map({ div: "map", allOverlays: true }); var osm = new OpenLayers.Layer.OSM(); var gmap = new OpenLayers.Layer.Google("Google Streets", {visibility: false});

// note that first layer must be visible map.addLayers([osm, gmap]); map.addControl(new OpenLayers.Control.LayerSwitcher()); map.zoomToMaxExtent(); }

OSM Workshop 2011

Page 22: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Doing more with GIS/OpenLayers

But what if i want to have a map and put some of my own data onto in?Not a problem we can use QGIS to do most of the hard stuff.

QGIS is a free, open source GIS package that runs on Window, Linux and Mac’s.It is (relatively) easy and intuitive to useThere are loads of useful plugins that do neat thingsThere is an active user group developing toolsThere are great demos and help pages to get you startedwww.qgis.org

OSM Workshop 2011

Page 23: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

QGIS - Recipe

OSM Workshop 2011

http://www.flickr.com/photos/indieb0i/101943682/

Not mine, honest

Recipe• Take some data (kml/shp/GeoJSON)• Load into QGIS• Download OGR2Layer plugin• Run Data thru plugin• Integrate the code in your website• Pretend it was much harder than it was

Page 24: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Shameful Plug I

OSM Workshop 2011

All the data that i am going to overlay on OSM is available through www.sharegeo.ac.uk ShareGeo is a spatial data repository fro open data

Page 25: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

QGIS main screen

Add vector layer

Layer list

Map

Window

IWMW 2011

Page 26: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Plugins

IWMW 2011

Page 27: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

OGR2Layer

Set an output folder Set map size

IWMW 2011

Page 28: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Output (OSM)

• No coded written

• Can add in attributes

• Can apply styles to data in QGIS

• Works in all good browsers (even IE, well, almost.........)

IWMW 2011

Page 29: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

OpenLayers Code

<script src="http://www.openlayers.org/api/OpenLayers.js"></script>

<script type="text/javascript">

var map, selectsControls

function init(){

var option = {

projection: new OpenLayers.Projection("EPSG:900913"),

displayProjection: new OpenLayers.Projection("EPSG:4326")

};

map = new OpenLayers.Map('map', option);

olmapnik = new OpenLayers.Layer.OSM("OpenStreetMap", "http://tile.openstreetmap.org/${z}/${x}/${y}.png");

map.addLayer(olmapnik);

map.setBaseLayer(olmapnik);

var ls= new OpenLayers.Control.LayerSwitcher();

map.addControl(ls);

ls.maximizeControl();

map.addControl(new OpenLayers.Control.Scale());

var OGRGeoJSON_style = new OpenLayers.Style(

OpenLayers.Util.applyDefaults({

strokeColor: "${getStrokeColor}",

strokeOpacity: 1,

strokeWidth: "${getLineWidth}",

fillColor: "${getFillColor}",

fillOpacity: 1

}

//START QUERY OGRGeoJSONfunction onPopupCloseOGRGeoJSON(evt) {

selectControl.unselect(selectedFeature);}function onFeatureSelectOGRGeoJSON(feature){

selectedFeature = feature;tableOGRGeoJSON="<html><meta http-

equiv='Content-Type' content='text/html; charset=UTF-8'><body><table><tr><td><b>alignment:</b></td><td><i>"+feature.attributes.alignment+"</i></td></tr><tr><td><b>fcode:</b></td><td><i>"+feature.attributes.fcode+"</i></td></tr><tr><td><b>fillColor:</b></td><td><i>"+feature.attributes.fillColor+"</i></td></tr><tr><td><b>fillOpacity:</b></td><td><i>"+feature.attributes.fillOpacity+"</i></td></tr><tr><td><b>fontColor:</b></td><td><i>"+feature.attributes.fontColor+"</i></td></tr><tr><td><b>fontFamily:</b></td><td><i>"+feature.attributes.fontFamily+"</i></td></tr><tr><td><b>fontSize:</b></td><td><i>"+feature.attributes.fontSize+"</i></td></tr><tr><td><b>fontWeight:</b></td><td><i>"+feature.attributes.fontWeight+"</i></td></tr><tr><td><b>internal:</b></td><td><i>"+feature.attributes.internal+"</i></td></tr><tr><td><..........></td></tr></table></body></html>";

popup = new OpenLayers.Popup.FramedCloud("chicken",

feature.geometry.getBounds().getCenterLonLat(),new OpenLayers.Size(1000,500),tableOGRGeoJSON,null,true,onPopupCloseOGRGeoJSON

);feature.popup = popup;map.addPopup(popup);

}function onFeatureUnselectOGRGeoJSON(feature) {

map.removePopup(feature.popup);feature.popup.destroy();feature.popup = null;

}//STOP QUERY OGRGeoJSON

IWMW 2011

Page 30: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

QGIS Demo

QGIS demo of OGR2Layerhttp://www.qgis.org

OSM Workshop 2011

Page 31: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

QGIS Demo

Quick maps that reveal worrying things....

OSM Workshop 2011

Page 32: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

QGIS Demo

This time we add queryable attributes to less worrying data.

OSM Workshop 2011

Page 33: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Shameful plug II

You may wishto use OS Opendata, in which case you can access DigimapOpenstream

•Grab the example code from OpenStream site•Copy the variables to the beginning of the script•Add a new OpenLayer.map to the index.html•Discover the projections dont match•Panic!•Find someone clever•Copy their code (function proj2.js)

IWMW 2011

Page 34: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Shameful plug II

IWMW 2011

Page 35: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Useful Links

http://edina.ac.ukhttp://edina.ac.uk/digimap/http://www.gogeo.ac.uk/http://openstream.edina.ac.uk/registration/http://www.qgis.orghttp://fwtools.maptools.org/http://openlayers.org/dev/examples/http://maps.cloudmade.com/https://github.com/lucadelu/OGR2Layers/

wiki/How-to-use

IWMW 2011

Page 36: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Campus Maps - Plan A

IWMW 2011

Who

Digimap

ROAM

Questions

Conclusions

0

90

Confession

Next StepsPractical

Page 37: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Practical

Onto the practical exercise

Familiarising yourself with Digimap ROAM

This should take around 30 minutes

Then we will look at what we can do with the output.

IWMW 2011

Page 38: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

After the magic button?

Well, this is the bit has still to be decided and we want your help.

IWMW 2011

Page 39: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Theoretical process 1

1. Do some digitising – I would recommend that you theme your polygons. The colours are retained in the output so it makes it easier to re-interpret.

2. When you are happy with it, press the magic button

3. Get the code and load it into a GIS or load it into a web page through an API such as openlayers/google

Magic button may appear

here....

IWMW 2011

Page 40: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

What to do next?

Now we have digitised the buildings and grabbed the GeoJSON through the “magic button” what options are there?Here we will outline 3 options:

– Google Earth– Image files as output (for print or Google Earth)– OpenLayers dynamic map

There may be other options/needs. If you have any thoughts, we would like to hear them.

IWMW 2011

Page 41: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Google Earth

To get the annotations into Google Earth it is pretty easy. We need to convert the GeoJSON to KML

Using the ogr2ogr libraries:

ogr2ogr –f “KML” campusmap.kml input.geoJSON

IWMW 2011

OGR2OGR libraries available through FWToolshttp://fwtools.maptools.org/

Page 42: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Google Earth

IWMW 2011

Page 43: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Case study

Campus maps for Edinburgh University

Requirements:– Make map that can be integrated into

MobileCampus App– Define all university buildings as polygons– Link to attributes– Make maps which show uni building

• Maps must be “lite” enough to deploy on mobile

IWMW 2011

Page 44: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Recipe – part 1

1 x IS intern

30 minute intro to Digimap ROAM

1 x copy of current campus map

1 x access to Google Streetview

2 x lunch time walks

1 – 2 days of digitising

http://www.flickr.com/photos/indieb0i/101943682/

Not mine, honest

Take intern and train on how to digitise, set intern loose and copy existing map, checking it is correct with google streetmap, Openstreetmap and ground truthing (lunchtime walks).

IWMW 2011

Page 45: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Recipe Part 2

• Once you have the JSON, convert to shapefile format: – Ogr2ogr –f “ESRI SHAPE FILE” campusmap.shp

input.geoJSON

• Import into GIS and theme• Add basemap• Export to desired file format (png in this

case)• Re-project png from OSGB to WGS84 for use

in google maps.

IWMW 2011

Page 46: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Edinburgh Central Campus

IWMW 2011

Page 47: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Kings Buildings

IWMW 2011

Page 48: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Western General Hospital

IWMW 2011

Page 49: Map Styling Tools and Interactive maps on the web with OpenLayers - Addy Pope, GoGeo

Easter Bush

Issue with the buildings here, they are new

and don’t appear on OS

maps yet.

IWMW 2011