Create Leaflet sidebar pane control with header writer fn
This commit is contained in:
parent
cd5b793dca
commit
8a02bd67d9
5 changed files with 30 additions and 42 deletions
|
@ -1,5 +1,6 @@
|
||||||
//= require_self
|
//= require_self
|
||||||
//= require leaflet.sidebar
|
//= require leaflet.sidebar
|
||||||
|
//= require leaflet.sidebar-pane
|
||||||
//= require leaflet.locatecontrol/src/L.Control.Locate
|
//= require leaflet.locatecontrol/src/L.Control.Locate
|
||||||
//= require leaflet.layers
|
//= require leaflet.layers
|
||||||
//= require leaflet.key
|
//= require leaflet.key
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
L.OSM.key = function (options) {
|
L.OSM.key = function (options) {
|
||||||
var control = L.control(options);
|
var control = L.OSM.sidebarPane(options);
|
||||||
|
|
||||||
control.onAdd = function (map) {
|
control.onAdd = function (map) {
|
||||||
var $container = $("<div>")
|
var $container = $("<div>")
|
||||||
|
@ -12,19 +12,7 @@ L.OSM.key = function (options) {
|
||||||
.on("click", toggle)
|
.on("click", toggle)
|
||||||
.appendTo($container);
|
.appendTo($container);
|
||||||
|
|
||||||
var $ui = $("<div>")
|
var $ui = this.makeUI("key-ui", "javascripts.key.title", toggle);
|
||||||
.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 $section = $("<div>")
|
var $section = $("<div>")
|
||||||
.attr("class", "section")
|
.attr("class", "section")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
L.OSM.layers = function (options) {
|
L.OSM.layers = function (options) {
|
||||||
var control = L.control(options);
|
var control = L.OSM.sidebarPane(options);
|
||||||
|
|
||||||
control.onAdd = function (map) {
|
control.onAdd = function (map) {
|
||||||
var layers = options.layers;
|
var layers = options.layers;
|
||||||
|
@ -15,19 +15,7 @@ L.OSM.layers = function (options) {
|
||||||
.on("click", toggle)
|
.on("click", toggle)
|
||||||
.appendTo($container);
|
.appendTo($container);
|
||||||
|
|
||||||
var $ui = $("<div>")
|
var $ui = this.makeUI("layers-ui", "javascripts.map.layers.header", toggle);
|
||||||
.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 baseSection = $("<div>")
|
var baseSection = $("<div>")
|
||||||
.attr("class", "section base-layers")
|
.attr("class", "section base-layers")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
L.OSM.share = function (options) {
|
L.OSM.share = function (options) {
|
||||||
var control = L.control(options),
|
var control = L.OSM.sidebarPane(options),
|
||||||
marker = L.marker([0, 0], { draggable: true }),
|
marker = L.marker([0, 0], { draggable: true }),
|
||||||
locationFilter = new L.LocationFilter({
|
locationFilter = new L.LocationFilter({
|
||||||
enableButton: false,
|
enableButton: false,
|
||||||
|
@ -18,19 +18,7 @@ L.OSM.share = function (options) {
|
||||||
.on("click", toggle)
|
.on("click", toggle)
|
||||||
.appendTo($container);
|
.appendTo($container);
|
||||||
|
|
||||||
var $ui = $("<div>")
|
var $ui = this.makeUI("share-ui", "javascripts.share.title", toggle);
|
||||||
.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")));
|
|
||||||
|
|
||||||
// Link / Embed
|
// Link / Embed
|
||||||
|
|
||||||
|
|
23
app/assets/javascripts/leaflet.sidebar-pane.js
Normal file
23
app/assets/javascripts/leaflet.sidebar-pane.js
Normal 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;
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue