diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index 4884304a..eaed1b82 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -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: { diff --git a/umap/static/umap/js/umap.core.js b/umap/static/umap/js/umap.core.js index a6201360..30aaa4cb 100644 --- a/umap/static/umap/js/umap.core.js +++ b/umap/static/umap/js/umap.core.js @@ -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'), diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index 4222ef49..6521c221 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -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()); diff --git a/umap/static/umap/map.css b/umap/static/umap/map.css index c57f4596..5939f335 100644 --- a/umap/static/umap/map.css +++ b/umap/static/umap/map.css @@ -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; + } } /* ****** */