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

bound2osmtile

v0.2.1

Published

convert wgs84 bounds to osm sloppy tile format

Downloads

2

Readme

bound2osmtile

This package converts passed WGS84 bounds to the closest OSM slippy tile request values. This is done by following the suggestions in the OSM Wiki.

Installation

Use standard npm installation

npm install --save bound2osmtile

Usage

Pass the WGS84 bounds to the function:

var bound2tile = require('bound2osmtile');

// [north, east, south, west]
bound2tile([48.1354432, 11.6037082, 48.123412, 11.621389]);

// [[north, east], [south, west]]
bound2tile([[48.1354432, 11.6037082], [48.123412, 11.621389]]);

// [L.LatLng, L.LatLng]
bound2tile([L.latLng(48.1354432, 11.6037082), L.latLng(48.123412, 11.621389)]);

// L.LatLngBounds
bound2tile(L.latLngBounds([48.1354432, 11.6037082], [48.123412, 11.621389]));

// GeoBounds
bound2tile(new (require('geobound-object'))([48.1354432, 11.6037082], [48.123412, 11.621389]));

// output:
// { 
//     valid: true, 
//     x: 8720, 
//     y: 5686, 
//     z: 14 
// }

Options

You can pass additional options to control the behavior.

zoom (default: 19)

Zoom level the algorithm should start with. If no zoom is passed, the algorithm starts with the most detailed OSM zoom level (19). This can be used to define a minimal zoom level that should be used.

bound2osmtile([48.1354432, 11.6037082, 48.123412, 11.621389], {
    zoom : 12
});

// output (note different zoom and x/y values compared to the above output):
// { 
//     valid: true, 
//     x: 2180, 
//     y: 1421, 
//     z: 12
// }

toUrl (default: false)

Convert the output tile to a OSM sloppy tile URL. If urlBase or fileExtension is not specified, the output returns an URL to openstreetmap.org.

bound2osmtile([48.1354432, 11.6037082, 48.123412, 11.621389], {
    zoom : 12,
    toUrl : true
});

// output
// "http://tile.openstreetmap.org/12/2180/1421.png"

urlBase (default: "http://tile.openstreetmap.org/")

Base url that should be used for url conversion. Please note that this parameter requires "toUrl" to be set true.

fileExtension (default: ".png")

File extension that should be used for the url output. Please note that this parameter requires "toUrl" to be set true.

bound2osmtile([48.1354432, 11.6037082, 48.123412, 11.621389], {
    zoom : 12,
    toUrl : true,
    urlBase : 'http://my.own.com',
    fileExtension : '.json'
});

// output
// "http://my.own.com/12/2180/1421.json"

Contribute

Feel free to add issues or pull requests. I'm glad for every kind of feedback!