npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

os-leaflet

v1.0.0

Published

A Leaflet js TileLayer using Ordnance Survey OpenSpace web map service

Downloads

59

Readme

os-leaflet

npm version

A Leafletjs TileLayer to display Ordnance Survey map data in your Leaflet map via the OS OpenSpace web map service.

This project is no way affiliated, nor supported or endorsed by Ordnance Survey. Please review Ordnance Survey OpenSpace service terms and conditions

Description

The os-leaflet project is a new L.TileLayer that can be used to easily get Ordnance Survey products into a Leaflet map, the Leaflet API can be used as normal.

Note: This layer uses an Ordnance Survey service that requires an API KEY - attempt to get one here.

ScreenShot

Versions

Version 1.x supports Leaflet 1.0, we depend on other Leaflet 1.0 compatible libraries too.

If you are using Leaflet version < 1.0 then please use v0.2.1 of this library, or the 0.2-stable branch.

Contents

This repository contains the following sections:

  1. OSOpenSpace.js - This contains the source code to the L.OSOpenSpace tilelayer.
  2. Demo - A simple demo to show off the functionality.

Getting started

You can get hold of the code using npm and it should work fine with browserify. Or you can just manually import the layer.

Dependency management

With npm:

$ npm install os-leaflet --save

Bundle for the browser with whichever tool you're using, eg webpack, browserify.

Then just require the libary along with Leaflet in your app.

require('os-leaflet');
layer = L.OSOpenSpace.tilelayer(apiKey, apiUrl, ...options);

Manually

Download these dependencies and import into your project so that this OS OpenSpace layer can work.

Note: The order of import should be as above; Leaflet, Proj4js, Proj4Leaflet and then OS OpenSpace layer - see the demo for an example.

Register for an API key

Ordnance Survey require an API key for use with their tile service, head over to OS OpenSpace to register before using on own website.

This layer uses the OS Openspace Free service and with the mapstack or products configured for the best experience available with the Free service.

Note: This will work locally an key; both localhost and file:/// hostname and protocol override the hostname check.

Displaying a map

The os-leaflet project extends Leaflet's L.TileLayer.WMS class and integrates easily with Leaflet.

To use the Layer in your map just get the EPSG:27700 L.Proj.CRS (Coordinate Reference System - how the earth is represented on Ordnance Survey maps) - via a factory method as below.

var osgbCrs = L.OSOpenSpace.CRS;

Create a L.Map as normal but specify the L.Proj.CRS from this library, see example below. The zoom levels available are essentially the layers provided by this OSOpenSpace layer so set these as below.

var map = new L.Map('map', {
  zoom: 6,
  crs: L.OSOpenSpace.CRS,
});

Finally, create a new L.TileLayer via the factory method L.OSOpenSpace.tilelayer and add to the map instance as normal. L.OSOpenSpace.tilelayer accepts the parameters below.

| Argument | Required? | Description | |---|---|---| | apiKey | Yes | The Ordnance Survey OpenSpace API key for the website domain name to be used. | | apiUrl | No | The URL of your site associated with the API key, as provided to OSOpenSpace | | options | No | An object of layer options to pass to the tilelayer |

var options = {};
var openspaceLayer = L.OSOpenSpace.tilelayer("<API Key>", "<API URL>", options);
map.addLayer(openspaceLayer);

Don't forget to set the map centre to somewhere in Great Britain too 😉

Example

Check out the demo for an example of how to use the layer.

Map products

This layer is currently hard-coded to work with only Ordnance Survey products that have 200x200 pixel tiles at the moment, the resolutions available are below. Other products have varying tile sizes which don't play well with Leaflet, it prefers a power-of-2 stack.

// OV0, OV1, OV2, MSR, MS, 250KR, 250K, 50KR, 50K, VMD
[2500, 1000, 500, 200, 100, 50, 25, 10, 5, 2.5]

For the full spec, see OS website.

Coordinates

Points can be added to the map in WGS84 reference system - if you have British National Grid coords then these should be converted.

L.polygon([
  [50.978633, -1.5740458],
  [51.068553, -1.5732215],
  [51.067945, -1.4305097],
  [50.978027, -1.4316098]
]).addTo(map).bindPopup('I am the SU32 10K square');

OS Logo

The Ordnance Survey logo in the bottom left can be removed, along with other attribution, by supplying the option { attributionControl: false } to the map constructor. It it enabled by default.

map = new L.Map('map', {
  zoom: 6,
  crs: L.OSOpenSpace.CRS,
  attributionControl: false
});

Issues

Please open an issue for any problems.

Contributions

Please use the GitHub pull-request mechanism to submit contributions.

License

This project is available for use under the MIT software license. See LICENSE