What’s in a name?

An exploration of the Ordnance Survey’s OS Names API using Leaflet.

The OS has made a number of APIs available via its DataHub. Individuals can sign up for the DataHub and use the APIs for no charge as long as usage is kept within reasonable limits. This is a great invitation to experiment. This particular exercise was based on the OS’s Find a name example using the JavaScript mapping library Leaflet.

Backdrop Mapping

The DataHub gives you access to a number of different mapping backdrops. The mapping is, of course, a thing of beauty, far removed from the cluttered mess of Google Maps.

There are a number of different base map styles available, the three below are based on the usual 3857 projection for web mapping. The traditional OS style, familiar to paper map users, is also available, but with the OSGB 27700 projection.

Road map © Crown copyright
Outdoor map © Crown copyright
Light map © Crown copyright

The methods to create a basic web map are the same as any Leaflet project using OpenStreetMap, say. The main difference is that it is necessary to register for a unique key, via the DataHub

The Names API

You will need to register to use each of the OS APIs, but since I had already signed up for the Maps API, adding a new API is easy and an API endpoint address is generated, based on your key.

The Names API is advertised as an “ambigous, fuzzy search” and this proves to be true! A search for Largs, for example, returns Largs, Cargo, Lower Largo, Upper Largo, Argos Hill, Cock Clarks, West Barns, Hale Barns. Fortunately the nearerst matches are returned first in the list and it is possible to be more specific and search for Largs the Town by searching on the LOCAL_PLACE attribute of the Names dataset.

For my version of the example map, I extracted a subset of the LOCAL_PLACE list from the Technical Specification and added them to a multiple select box. This is very useful since I can then distinguish between the Victoria railway station and coach station, for example.

The API also allows you to limit your search to a bounding box. This is again is useful, since a search for a Railway Station named Victoria returns 7 results.

Implementation

The experiment was based on OS’s supplied example with the following tweaks:

  • The bounding box is based on the current map view not hard coded – this required the map Lat/Lng to be converted to OS co-ordinates.
  • A select box was added to allow the user to filter by LOCAL_TYPE
  • The maximum number of results returned can be set
  • When the results are returned, a link is created for each result allowing the user to zoom to a particular result.

The working map can be seen here.