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

leaflet.scalefactor-master

v1.0.0

Published

Display a Scale Factor (e.g. 1:50,000) for Leaflet maps, checkout the [Demo](https://marcchasse.github.io/leaflet.ScaleFactor/).

Downloads

2

Readme

leaflet.ScaleFactor

Display a Scale Factor (e.g. 1:50,000) for Leaflet maps, checkout the Demo.

Leaflet.ScaleFactor is based on Leaflet's Control.Scale and works with the latest version of Leaflet, 1.0.0-rc1 it also likely works with older versions. Jquery 1.0 or higher is required for its .height() function. A pure JavaScript alternative would be better but i'm not sure how to go about implementing that.

The calculation to determine the scale factor is approximate and could likely be improved further, as of right now its calculated as follows.

  1. Find half the map height in pixels (middle of map)
  2. Get Leaflet to determine the lat/long of (0,middle of map)
  3. Get Leaflet to determine the lat/long of (100,middle of map)
  4. Get Leaflet to calculate the real world distance in meters between the two points.
  5. Get the pixels per physical screen millimeter
  6. Add a div with height:1mm; to the page
  7. Get jQuery to return the calculated height in pixels
  8. Multiply 100px by the pixels/mm
  9. Convert physical screen size of 100px from milimeters to meters
  10. Divide real world meters per 100px by screen meters per 100px
  11. Format and display the scale

Quick Start

  1. Create a leaflet map. Checkout Leaflets Quick Start Guide for a basic map example.

  2. Include jQuery, Leaflet.ScaleFactor.min.css and Leaflet.ScaleFactor.min.js

    <link rel="stylesheet" type="text/css" href="https://rawgit.com/MarcChasse/leaflet.ScaleFactor/master/leaflet.scalefactor.min.css">
    <script src="https://npmcdn.com/[email protected]/dist/jquery.min.js"></script>
    <script src="https://rawgit.com/MarcChasse/leaflet.ScaleFactor/master/leaflet.scalefactor.min.js"></script>
  3. Add the ScaleFactor control:

    L.control.scalefactor().addTo(map);

Complete Example

Here is everything you need to get this up and running. Copy and past the following to an .html file:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
	<title>Leaflet.ScaleFactor DEMO</title>
	<link rel="stylesheet" href="https://npmcdn.com/[email protected]/dist/leaflet.css" />
	<link rel="stylesheet" type="text/css" href="https://rawgit.com/MarcChasse/leaflet.ScaleFactor/master/leaflet.scalefactor.min.css">
	<style>html,body{margin:0;}#map{width:100vw;height:100vh;}</style>
</head>
<body>
	<div id="map"></div>
	<script src="https://npmcdn.com/[email protected]/dist/jquery.min.js"></script>
	<script src="https://npmcdn.com/[email protected]/dist/leaflet.js"></script>
	<script src="https://rawgit.com/MarcChasse/leaflet.ScaleFactor/master/leaflet.scalefactor.min.js"></script>
	<script>
	    osm = new L.TileLayer(
	    	'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
	    	{attribution: 'Map data &copy; OpenStreetMap contributors'}
	    );

	    var map = L.map('map', {
	        center: [52.26869,-113.81034],
	        zoom: 18
	    });
		map.addLayer(osm);

		L.control.scalefactor().addTo(map);
	</script>
</body>
</html>

Checkout the Demo

Options

L.control.scalefactor

| Option | Type | Default | Description | |----------------|---------|--------------|-------------------------------------------------------------------------------------------------| | position | String | 'bottomleft' | The position of the control (one of the map corners). See control positions. | | updateWhenIdle | Boolean | false | If true, the control is updated on moveend, otherwise it's always up-to-date (updated on move). |