59
Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 A super short introduction to webmapping with Leaflet Numa Gremling, Maptime Berlin, 21.02.2017

A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Embed Size (px)

Citation preview

Page 1: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

A super short introduction towebmapping with Leaflet

Numa Gremling, Maptime Berlin, 21.02.2017

Page 2: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Slides and Data

http://geosysnet.de/en/downloads.html

http://geosysnet.de

Page 3: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Getting started

Page 4: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• To get started with webmapping you first need a basic knowledge of web development

• And that requires just three things:

– HTML

– CSS

– JavaScript

The Holy Trinity

Page 5: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• Actually… four things: you also need a text editor

• There are a lot of editors to assist you specificallywith web development. Such a software is called IDE (Integrated Development Environment)

• Avoid a complex IDE at first!

• We will use Notepad++ tonight

Page 6: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

HTML

the elements that are shown in the webpage

CSS

the appearance (styling) of these elements

JavaScript

functionality

HTML, CSS, JavaScript – What they do

Page 7: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

HTML

heading, table, list, button

CSS

colors, positioning, sizes

JavaScript

something happens

HTML, CSS, JavaScript – Examples

Page 8: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Example - HTML

Page 9: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Example – HTML, CSS

Page 10: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Imagine that our little friend only appeared after we clicked thebutton

Example – HTML, CSS, JavaScript

Page 11: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Some resources – Books

Page 12: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Page 13: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• http://www.w3schools.com/

• https://www.codecademy.com

Some resources – Websites

Page 14: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Leaflet

Page 15: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• By Vladimir Agafonkin

• Since 2010

• Leaflet: Past, Present, Futurehttps://www.youtube.com/watch?v=_P2SaCPbJ4w

Page 16: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• Not as complex as other libraries

• Easy to learn

• Very well documented

• Large community to help you:

– Google Grouphttps://groups.google.com/forum/#!forum/leaflet-js

– GIS Stack Exchangehttp://gis.stackexchange.com/questions/tagged/leaflet

– Stack Overflowhttps://stackoverflow.com/questions/tagged/leaflet

Why pick Leaflet?

Page 17: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• Including Leaflet

• Creating a template

• Adding the map container

• Adding a basemap

• Adding markers

• Adding a polygon

• Adding a GeoJSON

What you will learn tonight

Page 18: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Including Leaflet

Example 1

Page 19: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• Let’s first create an empty HTML page:

<!DOCTYPE html>

<html>

<head>

...

</head>

<body>

...

</body>

</html>

Page 20: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

<!DOCTYPE html>

<html>

<head>

...

</head>

<body>

...

</body>

</html>

metadata

The actual content of the page;what you will see in the browser!

Page 21: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• One way to get Leaflet:

http://leafletjs.com/download.html

• Two ways to use Leaflet:

– Use a CDN

– Download and use locally

Getting and including Leaflet

Page 22: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

To get started with Leaflet we include these two lines in our <head>:

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" /> <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>

Way 1: CDN

Page 23: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

<!DOCTYPE>

<html>

<head>

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />

<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>

</head>

<body>

</body>

</html>

That’s it!That is all it takes to use Leaflet!Easy, isn’t it?

Page 24: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• Download

• Unzip

• Include both the JS and CSS files, like we did in theprevious step

Way 2: Download

Page 25: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Creating our first map

Example 2

Page 26: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• The map needs to be displayed somewhere

• We create a container that is dedicated to the map

• We use the HTML element <div>

• We assign an ID to that div, so we can reference the div to add the map to it

• Let’s call that ID myMapContainer

The map container

Page 27: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

<!DOCTYPE html>

<html>

<head>

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />

<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>

</head>

<body>

<div id='myMapContainer'></div>

</body>

</html>

The map container

1. We add our map container

Page 28: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

<!DOCTYPE html>

<html>

<head>

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />

<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>

<style>

#myMapContainer {

border: red 1px solid;

width: 500px;

height: 500px;

}

</style>

</head>

<body>

<div id='myMapContainer'></div>

</body>

</html>

Some styling

2. We assign a style to that container

Sidenote: IDs are selected using the pound sign (#).So the ID myMapContainer is selected like this: #myMapContainer

IMPORTANT: in order for the map to bedisplayed its container must have a height!!!

Page 29: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

<body>

<div id='myMapContainer'></div>

<script>

</script>

</body>

</html>

The script tag

3. We add a script tag at theend of our body, so we canexecute JavaScript

Page 30: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

<body>

<div id='myMapContainer'></div>

<script>

var myMap = L.map('myMapContainer');

</script>

</body>

</html>

Creating the map

Page 31: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• L.map creates a map container; it does not add an actualbasemap or any data: we need to do that

Where is our map?

Page 32: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• Let’s add some options so our map loads in Berlin

• We need:

– A center (latitude: 52.494 - longitude: 13.446)

– A zoom level (10)

• Options are added with {curly braces}

• Available map options are shown here:

http://leafletjs.com/reference-1.0.3.html#map-factory

We need the options center and zoom

Page 33: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

<body>

<div id='myMapContainer'></div>

<script>

var myMap = L.map('myMapContainer', {

center: [52.494, 13.446],

zoom: 10

});

</script>

</body>

</html>

Adding a center and a zoom level

Page 34: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

var myMap= L.map('myMapContainer', {center: [52.494, 13.446],zoom: 15

});

variable:Lets us use the map later on

Leaflet Map method

the div we created:

<div id='myMapContainer'></div>

the option center

the option zoom

Page 35: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

<script>

var myMap = L.map('myMapContainer', {

center: [52.494, 13.446],

zoom: 10

});

var basemap = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {

attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'

});

basemap.addTo(myMap);

</script>

</body>

</html>

Adding a basemap

Page 36: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Page 37: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

<!DOCTYPE html>

<html>

<head>

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />

<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>

<style>

#myMapContainer {

border: red 1px solid;

width: 500px;

height: 500px;

}

</style>

</head>

<body>

<div id='myMapContainer'></div>

<script>

var myMap = L.map('myMapContainer', {

center: [52.494, 13.446],

zoom: 10

});

var basemap = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {

attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'

});

basemap.addTo(myMap);

</script>

</body>

</html>

Page 38: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• More basemaps:https://leaflet-extras.github.io/leaflet-providers/preview/

• Pick a basemap and copy the code:

Page 39: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Adding geometries

Page 40: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• Reminder: there are only three types of geometries in GIS:

Point Line Polygon

Page 41: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• In Leaflet these geometries are called:

Leaflet jargon

Marker PolyLine Polygon

Page 42: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Adding markers

Example 3

Page 43: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• Let’s add two famous Berlin landmarks:

– Fernsehturm

• Latitude: 52.520861

• Longitude: 13.409564

– Brandenburger Tor:

• Latitude: 52.516312

• Longitude: 13.377624

Page 44: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• A point is called marker in Leaflet

• To add it we use L.marker([latitude,longitude]);

Brandenburger Tor:

L.marker([52.516312, 13.377624]);

Fernsehturm:

L.marker([52.520861, 13.409564]);

Page 45: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• We assign the markers to variables

• Then we add the markers to the map

Adding the markers

// Creating markersvar brandenburgerTor = L.marker([52.516312, 13.377624]);var fernsehturm = L.marker([52.520861, 13.409564]);

// Adding the marker to the mapfernsehturm.addTo(myMap);brandenburgerTor.addTo(myMap);

Page 46: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

// Creating markers

var brandenburgerTor = L.marker([52.516312, 13.377624]);

var fernsehturm = L.marker([52.520861, 13.409564]);

// Adding the marker to the map

fernsehturm.addTo(myMap);

brandenburgerTor.addTo(myMap);

// Adding popups

fernsehturm.bindPopup('Fernsehturm');

brandenburgerTor.bindPopup('Brandenburger Tor');

Adding popups

Page 47: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

<script>var myMap = L.map('myMapContainer', {

center: [52.52050, 13.39791],zoom: 14

});

var basemap = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'

});

basemap.addTo(myMap);

// Creating markersvar brandenburgerTor = L.marker([52.516312, 13.377624]);var fernsehturm = L.marker([52.520861, 13.409564]);

// Adding the marker to the mapfernsehturm.addTo(myMap);brandenburgerTor.addTo(myMap);

// Adding popupsfernsehturm.bindPopup('Fernsehturm');brandenburgerTor.bindPopup('Brandenburger Tor');

</script>

Page 48: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Adding a polygon

Example 4

Page 49: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• Let’s add the most important block in Berlin: the „Maptime block“

52.498107, 13.421515

52.497225, 13.424503

52.495729, 13.423194

52.496493, 13.420244

Page 50: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

// Creating a polygonvar block = L.polygon(

[[52.498107, 13.421515],[52.497225, 13.424503],[52.495729, 13.423194],[52.496493, 13.420244]

]);

// Adding the polygon to the mapblock.addTo(myMap);

Page 51: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Adding a GeoJSON

Example 5

Page 52: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• Data: we have a Shapefile of Berlin districts (Bezirke)

• Goal: we’d like to add it to our map

• Problem: Leaflet does not support shapefiles

• Solution: we convert the shapefile to a data formatthat Leaflet understands

We convert the shapefile to a GeoJSON

Page 53: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• There are many ways to convert a shapefile to a GeoJSON, such as:

– http://geojson.io/

– ogr2ogr

– QGIS

Shapefile to GeoJSON

Page 54: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Using QGIS as a conversion tool

Always use EPSG:4326(WGS 84)

Page 55: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Having a look at our QGIS export

Page 56: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

• We can now paste that GeoJSON into our script and assign it to a variable, so we can use it later on to create a „Leaflet GeoJSON“

Assigning the GeoJSON to a variable

Page 57: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Creating a Leaflet GeoJSON// Creating a Leaflet GeoJSON

var districtsFinal = L.geoJson(districtsRaw);

// adding the GeoJSON

districtsFinal.addTo(myMap);

Page 58: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Thanks, Contact, Questions

console.log('Thank you! :-)!');

• gis.stackexchange.com/users/23263/britishsteel

[email protected]

• twitter.com/Gremling89

• geosysnet.de

• gis-trainer.de

New: instagram.com/gis_trainer/Slides and data: http://geosysnet.de/en/downloads.html

• twitter.com/geoSYSnet

• twitter.com/gis_trainer

Page 59: A super short introduction to webmapping with …geosysnet.de/custom/downloads/MaptimeBerlin_Leaflet_21...Praxisqualifizierung & Weiterbildung Maptime Berlin, 21.02.2017 •Actually…

Praxisqualifizierung & WeiterbildungMaptime Berlin, 21.02.2017

Imprint

gis-trainer.de / geoSYSPflügerstr. 5612047 Berlin, Germany

Telefon: 030/82070659Telefax: 030/82070658

Email: [email protected] / [email protected]: www.gis-trainer.de / www.geosysnet.de