This version of the course is several years out of date and parts of it will not work - it is here just for the benefit of my 2022 dissertation students who want some grounding in Leaflet and associated technologies.

Week 2 Solution

<!DOCTYPE html>
		<!-- This is the HEAD of the HTML file, things in here do not appear on the page. It is
		 used for settings, such as the language and page title, as well as loading CSS styles and
		 scripts that you want to load before the content of the page. -->
		<meta charset="UTF-8">
		<title>GIS and the Web</title>

		<!-- This is loading the stylesheet for the Leaflet map from their website.
		 Make sure you put this BEFORE Leaflet's JavaScript -->
 		<link rel="stylesheet" href="" />

		<!-- This is loading the Leaflet JavaScript library from their website
		 Make sure you put this AFTER Leaflet's CSS -->
		<script src=""></script>

		<!-- Load the Proj4js library -->
		<script src=""></script>

		<!-- This is where we set the style for the different elements in the page's content -->

			/* Set the font for the entire page */
			html, body {
				padding: 0;
				margin: 0;
				width: 100%;
				height: 100%;

			/* Style the map */
			#map {
				/* This is the dimensions of the map on the screen, you can set it in
				 px (pixels) or % of the total screen size*/
				width:  100%;
				height: 100%;


	<!-- The onload event of the body tag is being used to call the function that creates the map.
	 This means that nothing will happen until the body is completely loaded, giving us a little more
	 control over the order in which the web page loads. -->
	<body onload='initMap();'>

		<!-- This is where the map will go -->
		<div id='map'></div>

		<!-- This is where we put our JavaScript, note that it is below the div, as the div needs
		 to exist before we can put a map in it!-->

			//setup global variables
			let map, transformer, marker;

			 * Initialise the Map
			function initMap(){

				// set the centre of the map as a variable
				const mapCentre = L.latLng(55, -4);

				// this is a variable that holds the reference to the Leaflet map object
				map ='map').setView(mapCentre, 6);

				// this adds the basemap tiles to the map
				L.tileLayer('https://{s}{z}/{x}/{y}.png', {
					attribution: '&copy; <a href="">OpenStreetMap</a> contributors'

				// set the proj4 string for the WGS84 CRS
				const wgs84 = "+proj=longlat +datum=WGS84 +no_defs";

				// set the proj4 string for the OSGB CRS
				const osgb = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs";

				// build a proj4 object to handle forward and inverse transformations
				transformer = proj4(wgs84, osgb);

				// add a marker at the centre of the map

				// add listener for click event on the map
				map.on('click', onMapClick);


			 * Event handler for map click
			function onMapClick(e) {

				// remove the previous marker from the map

				//add the new marker

			 * Add a marker with popup displaying the OSGB coordinates at a given location
			function addMarker(latLng) {

				// transform coordinates to OSGB
				const xy = transformer.forward([latLng.lng,]);

				// create a marker at the clicked location
				marker = L.marker(latLng);

				// add the marker to the map

				// create a popup displaying OSGB coordinates
				const popup = marker.bindPopup(parseInt(xy[0]).toString() + ", " + parseInt(xy[1]).toString());

				// open the popup


This course has not yet begun.
Course material will appear here week by week as the course progresses.