Skip to content

Commit cb5b914

Browse files
committed
Added support for toggle mode
1 parent 8e0b78f commit cb5b914

File tree

7 files changed

+63
-10
lines changed

7 files changed

+63
-10
lines changed

L.Control.Basemaps-min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

L.Control.Basemaps.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ L.Control.Basemaps = L.Control.extend({
9595

9696
}, this);
9797

98-
L.DomEvent.on(container, 'mouseenter', function() {
99-
L.DomUtil.removeClass(container, 'closed');
100-
}, this);
98+
if (this.options.basemaps.length > 2) {
99+
L.DomEvent.on(container, 'mouseenter', function () {
100+
L.DomUtil.removeClass(container, 'closed');
101+
}, this);
101102

102-
L.DomEvent.on(container, 'mouseleave', function() {
103-
L.DomUtil.addClass(container, 'closed');
104-
}, this);
103+
L.DomEvent.on(container, 'mouseleave', function () {
104+
L.DomUtil.addClass(container, 'closed');
105+
}, this);
106+
}
105107

106108
this._container = container;
107109
return this._container;

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ map.addControl(L.control.basemaps({
9898
```
9999

100100

101+
102+
### Toggle Mode
103+
To enable toggling between 2 basemaps, simply provide only 2 basemaps.
104+
105+
See [toggle example](//consbio.github.io/Leaflet.Basemaps/examples/toggle.html).
106+
107+
108+
101109
## Credits:
102110
Developed and maintained with support from the [Peninsular Florida Landscape Conservation Cooperative](http://peninsularfloridalcc.org) and additional support from the [U.S. Forest Service Northwest Regional Climate Hub](http://www.fs.fed.us/climatechange/nrch/).
103111

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Leaflet.Basemaps",
3-
"version": "0.1.3",
3+
"version": "0.2.0",
44
"homepage": "https://github.com/consbio/Leaflet.Basemaps",
55
"authors": [
66
"Brendan Ward <bcward@consbio.org>"

examples/toggle.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head lang="en">
4+
<meta charset="UTF-8">
5+
<title>Leaflet Basemaps Control</title>
6+
<link rel="stylesheet" href="//unpkg.com/leaflet@1.0.0/dist/leaflet.css" />
7+
<link rel="stylesheet" href="../L.Control.Basemaps.css" />
8+
</head>
9+
<body>
10+
<script src="//unpkg.com/leaflet@1.0.0/dist/leaflet.js"></script>
11+
<script src="../L.Control.Basemaps.js"></script>
12+
<div id="map" style="position: absolute; top: 0; left:0; bottom:0; right: 0;"></div>
13+
14+
<script>
15+
var map = L.map('map').setView([44.07, -118.78], 5);
16+
17+
var basemaps = [
18+
L.tileLayer('//stamen-tiles-{s}.a.ssl.fastly.net/toner/{z}/{x}/{y}.png', {
19+
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
20+
subdomains: 'abcd',
21+
maxZoom: 20,
22+
minZoom: 0,
23+
label: 'Toner'
24+
}),
25+
L.tileLayer('//stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.png', {
26+
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
27+
subdomains: 'abcd',
28+
maxZoom: 16,
29+
minZoom: 1,
30+
label: 'Watercolor'
31+
})
32+
];
33+
34+
map.addControl(L.control.basemaps({
35+
basemaps: basemaps,
36+
tileX: 0,
37+
tileY: 0,
38+
tileZ: 1
39+
}));
40+
41+
</script>
42+
</body>
43+
</html>

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var minify = require('gulp-minify');
33

44

55
gulp.task('build', function () {
6-
gulp.src('L.Control.Basemaps.js')
6+
return gulp.src('L.Control.Basemaps.js')
77
.pipe(minify({noSource: true}))
88
.pipe(gulp.dest('./'))
99
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "leaflet-basemaps",
3-
"version": "0.1.3",
3+
"version": "0.2.0",
44
"description": "Basemaps Control for Leaflet",
55
"homepage": "http://github.com/consbio/Leaflet.Basemaps",
66
"author": {

0 commit comments

Comments
 (0)