Tag Archives: web map

Matters relating to web mapping

Merry Christmas 2015

As another year draws to a close at Cranfield University, sure enough we have another Christmas map for you. As with previous years, we’ve collected a sample of tweets from Twitter that match a number of Christmas related keywords and mapped them using the same process we outlined last year.

The colour range from green to red indicates the density of Christmas related tweets from low to high in that county, relative to the normal density of twitter activity in that area (taken from a random sample of all tweets in the UK).

We’ll let you draw your own conclusions from the map. This time we thought we’d use the opportunity to focus on some of the web mapping technologies we’ve started using this year in other projects and hope to develop our use of heading into 2016. The biggest difference between the map you see above and some of the other maps we’ve published in the past is that this one doesn’t makes use of any GIS server or map hosting platform. Traditionally we’ve used either Geoserver or ArcGIS Server to publish our map tiles and other geospatial data for consumption with JavaScript web mapping APIs. Alternatively, web map hosting services can be used if one doesn’t have access to their own GIS Server, these include ArcGIS Online, Mapbox, CartoDB and others. The example here doesn’t use any of these services, but instead is running from a set of map tiles hosted on this very webserver. Interactivity (roll your mouse over the map to view the county names) is provided via a set of UTF-Grid tiles, also hosted on this webserver.

UTFGrid tiles use a combination of JSON encoding and ASCII grid files that sit alongside the map’s image tiles. For each PNG image tile there is a corresponding ASCII tile with a one pixel to one ASCII character mapping. An accompanying JSON lookup table provides the full set of attributes so that you can go beyond a simple raster map and offer full identify style interactivity.

UTFGrid functionality is available in many of the popular JavaScript web mapping APIs, either out of the box or as easily downloadable plugins. This particular map makes use of the Mapbox JS API, an extension of the Leaflet API.

The tiles used by this map are generated using the TileMill software and stored as a .mbtiles file (which is actually an SQLite database). A small PHP file, acting as a tile server, exposes this SQLite/MBTiles database to web mapping APIs as a large nested folder of image and UTFGrid files in the usual {z}/{x}/{y}.png or {z}/{x}/{y}.json fashion.

We like this approach to web mapping as it is reasonably lightweight and portable. The whole application, including web pages, JavaScript, map tiles and PHP tile server can be picked up and dropped onto any web server that supports PHP and is ready to go. It might not provide some of the advanced features you get with more heavyweight solutions, but a simple interactive map with query-able attributes is often all that’s needed for many web mapping applications. It’s also extremely fast and can be built using entirely open source software and tools.

More information on some of the packages and technologies used can be found here:

Merry Christmas and a happy New Year from all at Geothread!

Merry Christmas from all at Geothread

Once again, we’re preparing to wrap up for the year here at Cranfield University. Before we sign off, we’ll leave you with something that’s become a bit of a tradition with the Geothread team over the past couple of years; our Christmas Twitter map. Last year we mapped the spread of festive cheer across the country, according to Twitter users. Once again, we’ve collected a sample of 60,000 georeferenced tweets mentioning the word Christmas, along with a handful of other related keywords. These have been grouped by county and then normalised against a random sample of tweets taken earlier in the year to eliminate the effects of population density.

Comparing against the same map last year, it’s clear that there are several areas that are consistent in their anticipation of the festive season; Central Wales and North Yorkshire in particular. Anglesey and Conwy in North Wales certainly seem to be getting excited about things this year, whilst Cumbria and the Scottish Highlands don’t seem to be feeling the same level of enthusiasm that they did 12 months ago.

Christmas tweets 2014
Apologies to anyone we missed out in Ireland. Unfortunately the random sample of tweets we used for normalisation did not include coverage of all of the British Isles, which is why there are some holes in the final map.

As a bonus this year, we’ve included an interactive map of the raw data collected from twitter, for you to explore below.

Merry Christmas and a happy New Year from all at Geothread!

UK Soil Observatory nominated for Geospatial Excellence award

UK Soil Observatory

UK Soil Observatory

Cranfield is pleased to announce that the UK Soil Observatory (UKSO) has been shortlisted by the Association for Geographic Information (AGI) in their upcoming 2014 Awards for Geospatial Excellence. The UKSO was nominated for the AGI Award for Excellence with Impact. AGI describe this award as recognising projects which have achieved outstanding success or impact, measured against societal, humanitarian, environmental or financial benchmarks.

Cranfield University’s National Soil Resources Institute (NSRI) was pleased to play a part in the development of the UKSO, contributing several of its soil related datasets to the project. The UKSO draws together soils data from institutions such as the British Geological Survey (BGS), the James Hutton Institute (JHI) and the Agri-Food and Biosciences Institute (AFBI) and provides a unified starting point for accessing consolidated soil datasets via a series of interactive web maps and other web based resources. Further information on the UKSO is available on the project website.

The AGI awards have been launched to mark the AGI’s 25th anniversary. They are due to take place on Tuesday 11th November 2014. Further details on the awards are available here.

Building a mobile mapping application

Leaflet mobile mapping application

Leaflet mobile mapping application

Our earlier articles on mobile application development demonstrated the process of getting an app up and running on an Android phone using Adobe PhoneGap and GitHub. For the purposes of this article we’re going to assume that you are now comfortable with that process and will demonstrate how easy it is begin building mobile mapping applications. This is something we are developing a lot of interest in here at Cranfield University.

As with previous examples, the app is going to be based on a package of HTML, CSS and JavaScript code and will therefore use one of the many JavaScript web mapping APIs available. Any of the following APIs would work well:

  • Google Maps API
  • ArcGIS API for Javascript
  • Leaflet
  • OpenLayers
  • OS OpenSpace API

The decision on which one to use will depend on what the functional requirements of your app are, how familiar you are with a particular API and a number of other factors. For this example we are going to build a simple mobile web map using the Leaflet mapping API. Leaflet is an extremely lightweight JavaScript library which makes it ideal for bundling with a mobile app, as we shall see shortly. It is also relatively simple to use and has great flexibility for puling in geospatial resources from a number of different sources, in a variety of formats.

The Leaflet website provides a page of useful examples to get you started with creating basic web maps. Below is a typical web page that would display a basic web map using Leaflet. You can save this code to a HTML file and view it in a browser to test it out for yourself.

<!DOCTYPE html>
<html>
<head>
<title>Basic Leaflet Map</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.css" />

<style type="text/css">
body {
	padding: 0;
	margin: 0;
}
html, body, #map {
	height: 100%;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
</head>
<body>
<div id="map"></div>
<script src="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.js"></script> 
<script>
	var map = L.map('map').setView([52.04, -0.73], 12);
        L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
		maxZoom: 18			
	}).addTo(map);
</script>
</body>
</html>

The process of turning this into a mobile app is very straightforward, assuming you’ve already got your PhoneGap/Cordova framework in place. Rather than build a new index.htm for our project, we’ll take the default index.htm that has been created for us and drop in the relevant sections of the Leaflet map example above into the correct places. The index.htm file that sits within the www folder of you mobile app framework (taken from the default PhoneGap example on GitHub) should look something like this:

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">
            <h1>PhoneGap</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
        </div>
        <script type="text/javascript" src="phonegap.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript">
            app.initialize();
        </script>
    </body>
</html>

The key parts of the Leaflet map example are as follows:

<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.css" />

This ensures the appropriate CSS files are loaded so that the map is is styled correctly.

body {
	padding: 0;
	margin: 0;
}
html, body, #map {
	height: 100%;
}

Here we are defining some layout parameters, including how much space the #map element of the page should use

<div id=”map”></div>

This is the container in the body of the page that will house our map

<script src="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.js"></script> 

Load in the Leaflet API

<script>
	var map = L.map('map').setView([52.04, -0.73], 12);
	L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
		maxZoom: 18			
	}).addTo(map);
</script>

This is the code that generates and renders the map on the page.

Dropping these elements into our existing index.htm whilst retaining the important components (such as app.initialise(); and the calls to phonegap.js and js/index.js) that are already there, gives a page that looks as follows:

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.css" />
        <title>Basic Leaflet Mobile Map</title>
    </head>
    <body>
        <div class="app">
            <div id="map"></div>

        </div>
	<script src="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.js"></script> 
	<script>
		var map = L.map('map').setView([52.04, -0.73], 12);		
	        L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
			maxZoom: 18					
		}).addTo(map);
	</script>
        <script type="text/javascript" src="phonegap.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript">
            app.initialize();
        </script>
    </body>
</html>

This can now be compiled and deployed to your device using the process detailed earlier to give you a simple mobile mapping application.

Hosting libraries and APIs locally

Before we finish, we shall make one more minor alteration to our app to improve efficiency and performance. Currently the app loads up the Leaflet API from http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.js. We are going to take a copy of the full API, copy it to our app’s folder tree and deploy it to the phone so that our app can reference it locally rather than having to load it over web each time the app is launched. This will reduce the reliance on network connectivity and speed up application launch times as well as eliminate any reliance on the Leaflet website; we want our app to continue to work regardless of whether any remote websites may be experiencing problems of their own.

The full leaflet API can be downloaded here:
http://leafletjs.com/download.html
Unpack the zipfile and place the contents into a subfolder of your www folder named leaflet within your mobile app framework. All that needs to be done now is to modify the calls in your code that load the Leaflet API and CSS so that they reference your local copies. They should be changed from

<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.js?2"></script>

to

<link rel="stylesheet" href="leaflet/leaflet.css" />
<script src="leaflet/leaflet.js"></script>

This change will make your app almost fully self sufficient, without any reliance on loading libraries from external websites. Note that the map tiles that make up your map are still being loaded from the following location:
http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png
Your app will therefore still require a working internet connection in order to function correctly. In our next post we’ll discuss bundling a selection of map tiles with your application so it can be used completely offline with no internet connection

Leaflet mobile mapping application

Leaflet mobile mapping application

Spreading some festive cheer

Before we wrap up for the Christmas and New Year break at Cranfield University, here’s fun little map we’ve put together. Using the twitter4j Java library and the Twitter API, we collected a sample of 80,000 geotagged tweets over a three day period this week that matched a short list of festive and Christmas related keywords. The data was then plotted onto a map of the UK and grouped by county. The totals were then normalised against a random sample of 38,000 tweets, also grouped by county, that were collected earlier in the year. This removed the effect of Twitter population density, leaving the concentration of Christmas tweets in relation to that county’s normal levels of Twitter activity.

The Highlands, Cumbria, North Yorkshire, Norfolk and central Wales certainly seem to be getting into the spirit of things. The south of England on the other hand has some catching up to do, in comparison. We should add that at no stage have we measured sentiment (good or bad), simply instances of related keywords.

Merry Christmas and a happy New Year from all at Geothread!

Festive cheer Twitter map

Santa sightings

It seems appropriate that we leave you with something festive and fun before we take a break here at Cranfield University for Christmas and New Year. We’ve pooled together our mapping and data processing expertise and are proud to present you with The Unofficial Santa Sightings Map, 2012. The map takes its data from Twitter in the form of geotagged tweets posted over the past few days. It would appear Santa’s been doing a fair bit of travelling this week, with a surprising number of sightings as far north as the Highlands of Scotland.

A very merry Christmas and happy New Year to you all, see you in 2013.

Santa sightings, 2012

Santa sightings, 2012