Sharing cycling routes using newly released OS APIs

News

HomeHome / News / Sharing cycling routes using newly released OS APIs

Jul 08, 2023

Sharing cycling routes using newly released OS APIs

In this month’s article we are looking at the new OS APIs which can be found on

In this month's article we are looking at the new OS APIs which can be found on the OS Data Hub.

The data hub gives access to OS Open Data and to the OS APIs which can be used to access our content. The APIs can be used to access our data from our servers without having to download large amounts of data onto your machine. Currently available are:

As with previous articles, let us go through an example of how to put the use of OS Maps API into context. Here a cycling enthusiast is putting together a website to show the cycle routes that they and a group of colleagues take every week. To display the routes visually, they want to overlay the routes they take on a map, while also recording the condition and length of each route.

Questions customers need support with include:

How can I use OS APIs in my GIS software?

The OS Maps API is provided as a WMTS or ZXY Endpoint within the Data Hub. This allows the various layers to be added within most modern GIS software. Make sure you set your extent within the software before rendering the APIs, otherwise costs can increase quickly!

How can I integrate an OS API into my website?

OS APIs can easily be accessed in HTML using some basic JavaScript alongside other mapping APIs such as Mapbox (free with premium options) or Leaflet (free and open-source). This example uses Leaflet, but other examples can be found on OS Labs. The following code was used within the body of the example website, found at the end of the article.

How can I ensure that I only allow users to access OpenData within my APIs?

Simply choosing an Open-only map style and applying the right zoom threshold values for minZoom and maxZoom will allow you to keep your users within OpenData, which is free-to-use OS Data. You can also restrict panning using an array with southwest and northeast bounding coordinates within the object key mapOptions.maxBounds.

How can I incorporate non-OS data into the application?

This can be done using the mapping API that is being used to display the OS Maps data. In this example, Leaflet has a repository called omnivore which can be used to display multiple GeoJSON files over a map. Mapbox and other mapping tools have similar methods available to them. The example also uses mouse-over tooltips.

Incorporating a map built with the OS API into an example website results in this. Please note the cycle route data is NOT included within the API and was collected specifically for this example:

To summarise:

Whether you’re new to geospatial or a GIS data expert, the OS Data Hub grants access to our data. Discover our platform and the benefits of using it, along with an explanation of the types of GIS data you can get.

Our highly accurate geospatial data and printed maps help individuals, governments and companies to understand the world, both in Britain and overseas.

An API to filter Ordnance Survey data for buildings, roads, rivers, hospitals, playing fields, greenspaces.

OS MasterMap Topography Layer is a dataset showing building heights for Great Britain.

A vector tile service providing detailed Ordnance Survey data as a customisable basemap.

A geographic directory with basic information on identifiable places. Find the closest location to a given point through the API.

Access the relationships between properties, streets and OS MasterMap identifiers for free.

The OS Downloads API lets you script and automate your downloads of OS OpenData and OS Premium data. Save valuable time by automating the process.

Questions customers need support with include: How can I use OS APIs in my GIS software? How can I integrate an OS API into my website? How can I ensure that I only allow users to access OpenData within my APIs? How can I incorporate non-OS data into the application? To summarise