//= require_self
//= require leaflet.sidebar
+//= require leaflet.sidebar-pane
//= require leaflet.locatecontrol/src/L.Control.Locate
//= require leaflet.layers
//= require leaflet.key
L.OSM.key = function (options) {
- var control = L.control(options);
+ var control = L.OSM.sidebarPane(options);
control.onAdd = function (map) {
var $container = $("<div>")
.on("click", toggle)
.appendTo($container);
- var $ui = $("<div>")
- .attr("class", "key-ui");
-
- $("<div>")
- .attr("class", "sidebar_heading")
- .appendTo($ui)
- .append(
- $("<button type='button' class='btn-close float-end mt-1'>")
- .attr("aria-label", I18n.t("javascripts.close"))
- .bind("click", toggle))
- .append(
- $("<h4>")
- .text(I18n.t("javascripts.key.title")));
+ var $ui = this.makeUI("key-ui", "javascripts.key.title", toggle);
var $section = $("<div>")
.attr("class", "section")
L.OSM.layers = function (options) {
- var control = L.control(options);
+ var control = L.OSM.sidebarPane(options);
control.onAdd = function (map) {
var layers = options.layers;
.on("click", toggle)
.appendTo($container);
- var $ui = $("<div>")
- .attr("class", "layers-ui");
-
- $("<div>")
- .attr("class", "sidebar_heading")
- .appendTo($ui)
- .append(
- $("<button type='button' class='btn-close float-end mt-1'>")
- .attr("aria-label", I18n.t("javascripts.close"))
- .bind("click", toggle))
- .append(
- $("<h4>")
- .text(I18n.t("javascripts.map.layers.header")));
+ var $ui = this.makeUI("layers-ui", "javascripts.map.layers.header", toggle);
var baseSection = $("<div>")
.attr("class", "section base-layers")
L.OSM.share = function (options) {
- var control = L.control(options),
+ var control = L.OSM.sidebarPane(options),
marker = L.marker([0, 0], { draggable: true }),
locationFilter = new L.LocationFilter({
enableButton: false,
.on("click", toggle)
.appendTo($container);
- var $ui = $("<div>")
- .attr("class", "share-ui");
-
- $("<div>")
- .attr("class", "sidebar_heading")
- .appendTo($ui)
- .append(
- $("<button type='button' class='btn-close float-end mt-1'>")
- .attr("aria-label", I18n.t("javascripts.close"))
- .bind("click", toggle))
- .append(
- $("<h4>")
- .text(I18n.t("javascripts.share.title")));
+ var $ui = this.makeUI("share-ui", "javascripts.share.title", toggle);
// Link / Embed
--- /dev/null
+L.OSM.sidebarPane = function (options) {
+ var control = L.control(options);
+
+ control.makeUI = function (uiClass, paneTitle, toggle) {
+ var $ui = $("<div>")
+ .attr("class", uiClass);
+
+ $("<div>")
+ .attr("class", "sidebar_heading")
+ .appendTo($ui)
+ .append(
+ $("<button type='button' class='btn-close float-end mt-1'>")
+ .attr("aria-label", I18n.t("javascripts.close"))
+ .bind("click", toggle))
+ .append(
+ $("<h4>")
+ .text(I18n.t(paneTitle)));
+
+ return $ui;
+ };
+
+ return control;
+};