Create Leaflet sidebar pane control with header writer fn

This commit is contained in:
Anton Khorev 2022-08-27 20:33:44 +03:00
parent cd5b793dca
commit 8a02bd67d9
5 changed files with 30 additions and 42 deletions

View file

@ -1,5 +1,6 @@
//= require_self
//= require leaflet.sidebar
//= require leaflet.sidebar-pane
//= require leaflet.locatecontrol/src/L.Control.Locate
//= require leaflet.layers
//= require leaflet.key

View file

@ -1,5 +1,5 @@
L.OSM.key = function (options) {
var control = L.control(options);
var control = L.OSM.sidebarPane(options);
control.onAdd = function (map) {
var $container = $("<div>")
@ -12,19 +12,7 @@ L.OSM.key = function (options) {
.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")

View file

@ -1,5 +1,5 @@
L.OSM.layers = function (options) {
var control = L.control(options);
var control = L.OSM.sidebarPane(options);
control.onAdd = function (map) {
var layers = options.layers;
@ -15,19 +15,7 @@ L.OSM.layers = function (options) {
.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")

View file

@ -1,5 +1,5 @@
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,
@ -18,19 +18,7 @@ L.OSM.share = function (options) {
.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

View file

@ -0,0 +1,23 @@
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;
};