Merge pull request #3704 from AntonKhorev/leaflet-control-groups

Group map controls explicitly
This commit is contained in:
Andy Allan 2022-10-19 15:42:08 +01:00 committed by GitHub
commit 0917201893
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 68 deletions

View file

@ -2,6 +2,7 @@
//= require leaflet.sidebar //= require leaflet.sidebar
//= require leaflet.sidebar-pane //= require leaflet.sidebar-pane
//= require leaflet.locatecontrol/src/L.Control.Locate //= require leaflet.locatecontrol/src/L.Control.Locate
//= require leaflet.locate
//= require leaflet.layers //= require leaflet.layers
//= require leaflet.key //= require leaflet.key
//= require leaflet.note //= require leaflet.note
@ -98,62 +99,60 @@ $(document).ready(function () {
} }
}); });
var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
L.OSM.zoom({ position: position })
.addTo(map);
var locate = L.control.locate({
position: position,
icon: "icon geolocate",
iconLoading: "icon geolocate",
strings: {
title: I18n.t("javascripts.map.locate.title"),
popup: function (options) {
return I18n.t("javascripts.map.locate." + options.unit + "Popup", { count: options.distance });
}
}
}).addTo(map);
var locateContainer = locate.getContainer();
$(locateContainer)
.removeClass("leaflet-control-locate leaflet-bar")
.addClass("control-locate")
.children("a")
.attr("href", "#")
.removeClass("leaflet-bar-part leaflet-bar-part-single")
.addClass("control-button");
var sidebar = L.OSM.sidebar("#map-ui") var sidebar = L.OSM.sidebar("#map-ui")
.addTo(map); .addTo(map);
L.OSM.layers({ var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
position: position,
layers: map.baseLayers,
sidebar: sidebar
}).addTo(map);
L.OSM.key({ function addControlGroup(controls) {
position: position, controls.forEach(function (control) {
sidebar: sidebar control.addTo(map);
}).addTo(map); });
L.OSM.share({ var firstContainer = controls[0].getContainer();
"position": position, $(firstContainer).find(".control-button").first()
"sidebar": sidebar, .addClass("control-button-first");
"short": true
}).addTo(map);
L.OSM.note({ var lastContainer = controls[controls.length - 1].getContainer();
position: position, $(lastContainer).find(".control-button").last()
sidebar: sidebar .addClass("control-button-last");
}).addTo(map); }
L.OSM.query({ addControlGroup([
position: position, L.OSM.zoom({ position: position }),
sidebar: sidebar L.OSM.locate({ position: position })
}).addTo(map); ]);
addControlGroup([
L.OSM.layers({
position: position,
layers: map.baseLayers,
sidebar: sidebar
}),
L.OSM.key({
position: position,
sidebar: sidebar
}),
L.OSM.share({
"position": position,
"sidebar": sidebar,
"short": true
})
]);
addControlGroup([
L.OSM.note({
position: position,
sidebar: sidebar
})
]);
addControlGroup([
L.OSM.query({
position: position,
sidebar: sidebar
})
]);
L.control.scale() L.control.scale()
.addTo(map); .addTo(map);

View file

@ -0,0 +1,26 @@
L.OSM.locate = function (options) {
var control = L.control.locate(Object.assign({
icon: "icon geolocate",
iconLoading: "icon geolocate",
strings: {
title: I18n.t("javascripts.map.locate.title"),
popup: function (options) {
return I18n.t("javascripts.map.locate." + options.unit + "Popup", { count: options.distance });
}
}
}, options));
control.onAdd = function (map) {
var container = Object.getPrototypeOf(this).onAdd.apply(this, [map]);
$(container)
.removeClass("leaflet-control-locate leaflet-bar")
.addClass("control-locate")
.children("a")
.attr("href", "#")
.removeClass("leaflet-bar-part leaflet-bar-part-single")
.addClass("control-button");
return container;
};
return control;
};

View file

@ -358,8 +358,6 @@ body.small-nav {
width: 40px; width: 40px;
background-color: #333; background-color: #333;
background-color: rgba(0,0,0,.6); background-color: rgba(0,0,0,.6);
border-radius: 4px 0 0 4px;
margin-bottom: 10px;
outline: none; outline: none;
&:hover, &:hover,
@ -378,28 +376,20 @@ body.small-nav {
background-color: $vibrant-green; background-color: $vibrant-green;
} }
&-first {
border-start-start-radius: 4px;
}
&-last {
border-end-start-radius: 4px;
margin-bottom: 10px;
}
.icon { .icon {
margin: 10px; margin: 10px;
} }
} }
.leaflet-control .zoomin,
.control-layers .control-button {
margin-bottom: 0px;
border-radius: 4px 0 0 0;
}
.leaflet-control .zoomout,
.control-key .control-button {
margin-bottom: 0;
border-radius: 0;
}
.control-locate .control-button,
.control-share .control-button {
border-radius: 0 0 0 4px;
}
/* Rules for the sidebar and main map area */ /* Rules for the sidebar and main map area */
.map-layout { .map-layout {