Permanent credits feature in the bottom left corner

This commit is contained in:
3st3ban3 2023-01-14 22:48:16 +01:00
parent d69f965f79
commit 57ba42061c
4 changed files with 64 additions and 3 deletions

View file

@ -434,6 +434,47 @@ L.U.MoreControls = L.Control.extend({
});
L.U.PermanentCreditsControl = L.Control.extend({
options: {
position: 'bottomleft'
},
initialize: function (map) {
this.map = map;
},
onAdd: function () {
var paragraphContainer = L.DomUtil.create('div', 'umap-permanent-credits-container'),
creditsParagraph = L.DomUtil.create('p', '', paragraphContainer);
this.paragraphContainer = paragraphContainer;
this.setCredits();
this.setBackground();
return paragraphContainer;
},
_update: function () {
this.setCredits();
this.setBackground();
},
setCredits: function () {
this.paragraphContainer.innerHTML = L.Util.toHTML(this.map.options.permanentCredit);
},
setBackground: function () {
if (this.map.options.permanentCreditBackground) {
this.paragraphContainer.style.backgroundColor = '#FFFFFFB0';
} else {
this.paragraphContainer.style.backgroundColor = '';
}
}
});
L.U.DataLayersControl = L.Control.extend({
options: {

View file

@ -452,6 +452,7 @@ L.U.Help = L.Class.extend({
fillColor: L._('Optional. Same as color if not set.'),
shortCredit: L._('Will be displayed in the bottom right corner of the map'),
longCredit: L._('Will be visible in the caption of the map'),
permanentCredit: L._('Will be permanently visible in the bottom left corner of the map'),
sortKey: L._('Property to use for sorting features'),
slugKey: L._('The name of the property to use as feature unique identifier.'),
filterKey: L._('Comma separated list of properties to use when filtering features'),

View file

@ -46,7 +46,8 @@ L.Map.mergeOptions({
slideshow: {},
clickable: true,
easing: true,
permissions: {}
permissions: {},
permanentCreditBackground: true,
});
L.U.Map.include({
@ -274,6 +275,7 @@ L.U.Map.include({
this._controls.measure = (new L.MeasureControl()).initHandler(this);
this._controls.more = new L.U.MoreControls();
this._controls.scale = L.control.scale();
if (this.options.permanentCredit) this.permanentCreditControl = (new L.U.PermanentCreditsControl(this)).addTo(this);
if (this.options.scrollWheelZoom) this.scrollWheelZoom.enable();
else this.scrollWheelZoom.disable();
this.renderControls();
@ -1076,6 +1078,8 @@ L.U.Map.include({
'labelInteractive',
'shortCredit',
'longCredit',
'permanentCredit',
'permanentCreditBackground',
'zoomControl',
'datalayersControl',
'searchControl',
@ -1379,10 +1383,14 @@ L.U.Map.include({
var creditsFields = [
['options.licence', {handler: 'LicenceChooser', label: L._('licence')}],
['options.shortCredit', {handler: 'Input', label: L._('Short credits'), helpEntries: ['shortCredit', 'textFormatting']}],
['options.longCredit', {handler: 'Textarea', label: L._('Long credits'), helpEntries: ['longCredit', 'textFormatting']}]
['options.longCredit', {handler: 'Textarea', label: L._('Long credits'), helpEntries: ['longCredit', 'textFormatting']}],
['options.permanentCredit', {handler: 'Textarea', label: L._('Permanent credits'), helpEntries: ['permanentCredit', 'textFormatting']}],
['options.permanentCreditBackground', {handler: 'Switch', label: L._('Permanent credits background')}]
];
var creditsBuilder = new L.U.FormBuilder(this, creditsFields, {
callback: function () {this._controls.attribution._update();},
callback: function () {
this._controls.attribution._update();
this.permanentCreditControl._update();},
callbackContext: this
});
credits.appendChild(creditsBuilder.build());

View file

@ -117,6 +117,12 @@ a.umap-control-text {
.leaflet-control-edit-enable a:hover {
background-color: #4d5759;
}
.umap-permanent-credits-container {
max-width: 20rem;
margin: 0!important;
padding: 0.5rem;
border-top-right-radius: 1rem;
}
@ -1366,6 +1372,11 @@ a.add-datalayer:hover,
.leaflet-control-layers-expanded {
margin-left: 10px;
}
.umap-permanent-credits-container {
max-width: 100%;
border-top-right-radius: 0;
}
}
/* ****** */