Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
The following pages provide an overview of how to get started using the OS NGD API – Tiles. They cover the core elements to get started in the most common GIS software and web mapping libraries.
These pages should be used in conjunction with the more detailed pages within the Data Structure section and Technical Specification.
Accessing OS NGD data with OS NGD API – Tiles via Cadcorp SIS
The Cadcorp Spatial Information System® (Cadcorp SIS®) is an integrated family of geospatial products comprising desktop, web, and developer applications.
Cadcorp SIS Desktop connects directly to the OS Data Hub through dedicated wizards.
Cadcorp SIS (version SIS 9.1 or later).
OS NGD API – Tiles added to an API project in the OS Data Hub. (See for more information.)
These instructions are based on Cadcorp SIS Desktop version 9.1.2109.64.
In Cadcorp SIS Desktop, open an existing map or create a new one.
In the Home tab, click Add Overlay.
In the Overlay Types dialog, select Ordnance Survey (GB) > OS (GB) Data Hub, and then click Next.
In the OS (GB) Data Hub dialog:
Select OS National Geographic Database (NGD) API - Tiles.
API Key: Enter your API key.
Premium / Public Sector Plan: Select this option if you have this plan.
Save in the UI settings database (encrypted): Select this option.
Click Next.
In the OS (GB) Data Hub NGD API - Tiles dialog, select the appropriate layer from the list of available options, and then click Finish.
The selected layer will automatically display in the map area.
The following sub-sections provide step-by-step instructions on how to access OS NGD data via OS NGD API – Tiles in various GIS software packages:
The following sub-sections provide step-by-step instructions on how to access OS NGD data via OS NGD API – Tiles in various web mapping libraries:
Accessing OS NGD API – Tiles via Leaflet
Leaflet is an open-source JavaScript library for displaying interactive maps on the web or mobile. A simple and lightweight library that will enable you to display and visualise location data and build dynamic applications.
OS NGD API – Tiles added to an API project in the OS Data Hub with an API Key.
A text editor like Visual Studio Code or Notepad to edit and save your HTML and JavaScript files.
Create a new HTML file with a text editor (for example, Notepad, Visual Studio Code).
Add the basic HTML structure to your file with a placeholder <div>
for the map.
To enable access to OS APIs an API Key is required. Inside the <script>
tag, add a variable called apiKey
, replacing 'INSERT_API_KEY_HERE'
with the API Key from your project.
Inside the <script>
tag, add another variable called collectionId
with the collection ID for the OS NGD API – Tiles basemap – ngd-base
.
We need to intercept and customise the style request, adding a tiles property to provide a correctly formatted URL and ensure authentication through the apiKey
is enabled to make sure that the correct tiles are requested.
Add the following code inside the JavaScript block:
Initialize the map object using the L.Map
class to configure the vector tile layer and the mapOptions
variable to define its properties – minZoom
, maxZoom
, maxBounds
, center
and zoom
.
The above code creates the main map instance using the Leaflet library where you can specify various properties:
minZoom
and maxZoom
: Sets the minimum and maximum zoom level for the map. Users will not be able to go beyond these levels.
maxBounds
: Defines the maximum bounds and restricts panning the map.
center
: Sets the initial centre point of the map.
zoom
: Sets the initial zoom level of the map.
Congratulations! You've successfully created a vector map using Leaflet using OS NGD API – Tiles in a few steps.
Now you can continue to explore Ordnance Survey's code examples to learn more about advanced features and functionality, such as adding markers, pop-ups, and additional layers.
Accessing OS NGD data with OS NGD API – Tiles via QGIS
QGIS is an open GIS (Geospatial Information System) desktop application that allows you to display, interrogate, visualise and create geospatial information including from geo-centric APIs (for example, a Vector Tiles Service).
The instructions that follow demonstrate how to connect to OS NGD API – Tiles using QGIS.
QGIS (version 3.22.0 or later).
Open an existing project or create a new one.
Deselect the Render checkbox in the bottom bar, if necessary.
Navigate to Layer > Add Layer > Add Vector Tile Layer...
In Data Source Manager | Vector Tile, click the New button below the drop-down menu and select New Generic Connection...
The Vector Tiles Connection dialog that pops up requires you to input the API information you obtained in the OS Data Hub.
In the Vector Tiles Connection dialog, provide the service details of the API:
Name: Provide a name for the connection. It is good practice to name your connections in a way that makes them instantly recognisable. You can reuse this connection in the future.
URL: Copy the OS NGD API – Tiles endpoint address from the OS Data Hub and paste it into this field.
Your API Key is automatically appended to this URL in the key
parameter.
Min. and Max. Zoom Levels: Set these as follows based on your preferred projection:
Web Mercator (EPSG: 3857): Min Zoom = 6; Max Zoom = 19
British National Grid (BNG: EPSG: 27700): Min Zoom = 0; Max Zoom = 15
Style URL: Input the OS NGD API – Tiles style URL to style the tiles based on the default style for the specified OS NGD collection.
Authentication: Leave these settings at their defaults. You do not need a username or password as authentication is done through your API Key.
Other: Leave all other settings at their defaults.
Click OK.
To retrieve tiles and style them appropriately, you will need two URLs. The URLs have slight variations based on the collection ID and projection.
Here are some example URLs to retrieve the basemap (ngd-base) in Web Mercator (EPSG: 3857):
https://api.os.uk/maps/vector/ngd/ota/v1/collections/ngd-base/styles/3857?key={INSERT_YOUR_API_KEY}
Please note: You will need to replace the /{tileMatrix}/{tileRow}/{tileCol} used in the default 'retrieve tile' URL with /{z}/{y}/{x} to be able to connect to OS NGD API – Tiles.
In Data Source Manager | Vector Tile, click Add and Close. You'll then see the map displayed in the main QGIS UI.
Accessing OS NGD API – Tiles via MapLibre GL JS
is a free and powerful JavaScript library for displaying interactive maps on the web. It's based on Mapbox GL JS and provides a wide range of features for creating maps with custom styles, markers and interactivity.
OS NGD API – Tiles added to an API project in the with an API Key.
A text editor like Visual Studio Code or Notepad to edit and save your HTML and JavaScript files.
Create a new HTML file with a text editor (for example, Notepad, Visual Studio Code).
Add the basic HTML structure to your file with a placeholder <div>
for the map.
To enable access to OS APIs an API Key is required. Inside the <script>
tag, add a variable called apiKey
, replacing 'INSERT_API_KEY_HERE'
with the API Key from your project.
Inside the <script>
tag, add another variable called collectionId
with the collection ID for the OS NGD API – Tiles basemap – ngd-base
.
We need to intercept and customise the style request, adding a tiles
property to provide a correctly formatted URL and ensuring authentication through the apiKey
is enabled to make sure that the correct tiles are requested.
Add the following code inside the JavaScript block:
Initialise the map object using the maplibregl.Map
class to configure the vector tile layer and define its properties – container
, minZoom
, maxZoom
, maxBounds
, style
, center
and zoom
.
Add navigation controls to the map, excluding the compass button and disabling map rotation.
The above code creates the main map instance using the MapLibre GL JS library where you can specify various properties:
container
: Defines where the map should be displayed. In this instance, it is set to the ID
of the <div>
element.
minZoom
and maxZoom
: Sets the minimum and maximum zoom level for the map. Users will not be able to go beyond these levels.
maxBounds
: Defines the maximum bounds and restricts panning the map.
style
: Defines the style of the map, configured via a URL pointing at the default style for the 'collectionId
' defined.
center
: Sets the initial centre point of the map.
zoom
: Sets the initial zoom level of the map.
Congratulations! You've successfully created a vector map using MapLibre GL JS using OS NGD API – Tiles in a few steps.
Accessing OS NGD API – Tiles via OpenLayers
is a free and open-source JavaScript library for displaying interactive maps on the web. It is a powerful tool that can be used to create a wide variety of map-based applications, from simple web maps to complex GIS applications.
OpenLayers is easy to use and can be integrated with a variety of other web development frameworks.
OS NGD API – Tiles added to an API project in the with an API Key.
A text editor like Visual Studio Code or Notepad to edit and save your HTML and JavaScript files.
Create a new HTML file with a text editor (for example, Notepad, Visual Studio Code).
Add the basic HTML structure to your file with a placeholder <div>
for the map.
To enable access to OS APIs an API Key is required. Inside the <script>
tag, add a variable called apiKey
, replacing 'INSERT_API_KEY_HERE'
with the API Key from your project.
Inside the <script>
tag, add another variable called collectionId
with the collection ID for the OS NGD API – Tiles basemap – ngd-base
.
To correctly render the vector tiles within OpenLayers, you will need to fetch
the defined EPSG:3857 Tile Matrix Set and style definitions from the OS NGD API – Tiles service. The two endpoints provide information about the structure of the vector tiles and how the styles are to be applied.
A promise.all
is used to process the data to ensure that both requests are completed before proceeding.
Based on the fetched Tile Matrix Set data, a tile grid is defined using the ol.tilegrid.TileGrid class. The tile grid provides information about the resolution, origin and tile sizes to handle the vector tiles correctly.
Add the following code inside the JavaScript block:
Define the a new vector tiles layer and source that will be used to fetch vector tiles from OS NGD API – Tiles. The ol.layer.VectorTile
uses a ol.source.OGCVectorTile
source to retrieve tiles from the API.
After creating the vector layer, you will need to use a style function to ensure that the Ordnance Survey styles are applied to each tile. Use the olms.applyStyle
function to retrieve the style sheets available for the basemap.
Initialize the map object using the ol.map
class to configure the vector tile layer and define its properties – target
, layers
and view
.
The above code creates the main map instance using the OpenLayers library where you can specify various properties:
target
: Defines where the map should be displayed. In this instance it is set to the ID
of the <div>
element.
layers
: An array containing the layers to be added to the map.
view
: Defines the initial view of the main, containing various settings such as projection, extent (the geographic bounds of the map), minimum and maximum zoom levels, centre of the map and the initial zoom level.
Congratulations! You've successfully created a vector map using OpenLayers using OS NGD API – Tiles in a few steps.
To learn more about the available collections in OS NGD API – Tiles, you can view what data is available .
Now you can continue to explore Ordnance Survey's to learn more about advanced features and functionality, such as adding markers, pop-ups, and additional layers.
Now you can continue to explore Ordnance Survey's to learn more about advanced features and functionality, such as adding markers, pop-ups, and additional layers.