Skip to content

Commit 707f578

Browse files
committed
Add scale ruler option
1 parent 7d2ab13 commit 707f578

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Parameters that can be used (can be passed to the app server as GET query params
3030
| imagemin | enable lossless compression with [optipng](https://github.com/imagemin/imagemin-optipng) / [jpegtran](https://github.com/imagemin/imagemin-jpegtran) | `false` |
3131
| oxipng | enable losslsess compression with [oxipng](https://github.com/shssoichiro/oxipng) | `false` |
3232
| arrows | render arrows to show the direction of linestrings | `false` |
33+
| scale | enable render a scale ruler (boolean or [a json options object](https://leafletjs.com/reference-1.6.0.html#control-scale-option)) | `false` |
3334

3435
## How to use
3536

lib/lib.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Control } from "leaflet";
2+
13
export = _default;
24

35
interface OsmStaticMapsOptions {
@@ -96,6 +98,12 @@ interface OsmStaticMapsOptions {
9698
* @defaultValue `false`
9799
*/
98100
arrows?: boolean;
101+
102+
/**
103+
* enable render a scale ruler (boolean or [a json options object](https://leafletjs.com/reference-1.6.0.html#control-scale-option))
104+
* @defaultValue `false`
105+
*/
106+
scale?: boolean | Control.ScaleOptions;
99107
}
100108

101109
/** Renders a map controlled by the options passed and returns an image */

lib/lib.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module.exports = function(options) {
4040
options.imagemin = options.imagemin || false;
4141
options.oxipng = options.oxipng || false;
4242
options.arrows = options.arrows || false;
43+
options.scale = (options.scale && (typeof options.scale === 'string' ? options.scale : JSON.stringify(options.scale))) || false;
4344

4445
const html = replacefiles(template(options));
4546

lib/template.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
});
6464
map.attributionControl.setPrefix('').addAttribution('{{ attribution }}');
6565

66+
{{#if scale}}
67+
L.control.scale({{{scale}}}).addTo(map);
68+
{{/if}}
69+
6670
{{#if geojson }}
6771
var myIcon = L.icon({
6872
iconUrl: "data:image/png;base64,//markericonpng//",

0 commit comments

Comments
 (0)