├── LICENSE
├── README.md
├── leaflet.scalefactor.css
├── leaflet.scalefactor.js
├── leaflet.scalefactor.min.css
└── leaflet.scalefactor.min.js
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # leaflet.ScaleFactor
2 | Display a Scale Factor (e.g. 1:50,000) for Leaflet maps, checkout the [Demo](https://marcchasse.github.io/leaflet.ScaleFactor/).
3 |
4 | Leaflet.ScaleFactor is based on [Leaflet's Control.Scale](http://leafletjs.com/reference.html#control-scale) and works with the latest version of Leaflet, [1.0.0-rc1](http://leafletjs.com/reference-1.0.0.html) it also likely works with older versions. Jquery 1.0 or higher is required for its [`.height()`](http://api.jquery.com/height/) function. A pure JavaScript alternative would be better but i'm not sure how to go about implementing that.
5 |
6 | The calculation to determine the scale factor is approximate and could likely be improved further, as of right now its calculated as follows.
7 |
8 | 1. Find half the map height in pixels (middle of map)
9 | 2. Get Leaflet to determine the lat/long of (0,middle of map)
10 | 3. Get Leaflet to determine the lat/long of (100,middle of map)
11 | 4. Get Leaflet to calculate the real world distance in meters between the two points.
12 | 5. Get the pixels per physical screen millimeter
13 | 1. Add a div with height:1mm; to the page
14 | 2. Get jQuery to return the calculated height in pixels
15 | 6. Multiply 100px by the pixels/mm
16 | 7. Convert physical screen size of 100px from milimeters to meters
17 | 8. Divide real world meters per 100px by screen meters per 100px
18 | 9. Format and display the scale
19 |
20 |
21 | ## Quick Start
22 |
23 | 1. Create a leaflet map. Checkout Leaflets [Quick Start Guide](http://leafletjs.com/examples/quick-start.html) for a basic map example.
24 |
25 | 2. Include jQuery, Leaflet.ScaleFactor.min.css and Leaflet.ScaleFactor.min.js
26 |
27 | ```html
28 |
29 |
30 |
31 | ```
32 | 3. Add the ScaleFactor control:
33 | ```javascript
34 | L.control.scalefactor().addTo(map);
35 | ```
36 | ## Complete Example
37 | Here is everything you need to get this up and running. Copy and past the following to an `.html` file:
38 | ```html
39 |
40 |
41 |