From c52e093db8f17977ae9d88542f02eeecc8f77cf0 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 30 May 2023 11:04:10 +0200 Subject: [PATCH] Also expose direct map URL in the export panel cf #699 --- umap/static/umap/js/umap.controls.js | 27 +++++++++++++++------------ umap/static/umap/js/umap.js | 6 +++++- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index 8e35d0a1..7fda3a37 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -1231,7 +1231,7 @@ L.U.IframeExporter = L.Evented.extend({ return this.map }, - build: function () { + buildUrl: function () { var datalayers = [] if (this.options.viewCurrentFeature && this.map.currentFeature) { this.queryString.feature = this.map.currentFeature.getSlug() @@ -1246,17 +1246,20 @@ L.U.IframeExporter = L.Evented.extend({ } else { delete this.queryString.datalayers } - var currentView = this.options.currentView ? window.location.hash : '', - iframeUrl = - this.baseUrl + '?' + L.Util.buildQueryString(this.queryString) + currentView, - code = - '' + var currentView = this.options.currentView ? window.location.hash : '' + return this.baseUrl + '?' + L.Util.buildQueryString(this.queryString) + currentView + }, + + build: function () { + var iframeUrl = this.buildUrl() + var code = + '' if (this.options.includeFullScreenLink) { code += '

' + L._('See full screen') + '

' } diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index e60ef8ef..90f20170 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -732,7 +732,10 @@ L.U.Map.include({ var container = L.DomUtil.create('div', 'umap-share'), embedTitle = L.DomUtil.add('h4', '', container, L._('Embed the map')), iframe = L.DomUtil.create('textarea', 'umap-share-iframe', container), + urlTitle = L.DomUtil.add('h4', '', container, L._('Direct link')), + exportUrl = L.DomUtil.create('input', 'umap-share-url', container), option + exportUrl.type = 'text' var UIFields = [ ['dimensions.width', { handler: 'Input', label: L._('width') }], ['dimensions.height', { handler: 'Input', label: L._('height') }], @@ -766,6 +769,7 @@ L.U.Map.include({ var iframeExporter = new L.U.IframeExporter(this) var buildIframeCode = () => { iframe.innerHTML = iframeExporter.build() + exportUrl.value = window.location.protocol + iframeExporter.buildUrl() } buildIframeCode() var builder = new L.U.FormBuilder(iframeExporter, UIFields, { @@ -773,7 +777,7 @@ L.U.Map.include({ }) var iframeOptions = L.DomUtil.createFieldset( container, - L._('Iframe export options') + L._('Export options') ) iframeOptions.appendChild(builder.build()) if (this.options.shortUrl) {