diff --git a/umap/static/umap/js/modules/global.js b/umap/static/umap/js/modules/global.js index 62f3cbbc..90bd180f 100644 --- a/umap/static/umap/js/modules/global.js +++ b/umap/static/umap/js/modules/global.js @@ -1,12 +1,12 @@ import URLs from './urls.js' import Browser from './browser.js' import * as Utils from './utils.js' +import SCHEMA from './schema.js' import { Request, ServerRequest, RequestError, HTTPError, NOKError } from './request.js' // Import modules and export them to the global scope. // For the not yet module-compatible JS out there. -// Copy the leaflet module, it's expected by leaflet plugins to be writeable. window.U = { URLs, Request, @@ -16,4 +16,5 @@ window.U = { NOKError, Browser, Utils, + SCHEMA, } diff --git a/umap/static/umap/js/modules/schema.js b/umap/static/umap/js/modules/schema.js new file mode 100644 index 00000000..db3075ca --- /dev/null +++ b/umap/static/umap/js/modules/schema.js @@ -0,0 +1,62 @@ +import { translate } from './i18n.js' + +const SCHEMA = { + zoom: { type: undefined }, + scrollWheelZoom: { type: Boolean }, + scaleControl: { type: Boolean }, + moreControl: { type: Boolean }, + miniMap: { type: Boolean }, + displayPopupFooter: { type: undefined }, + onLoadPanel: { type: String }, + defaultView: { type: String }, + name: { type: String, label: translate('name') }, + description: { type: String }, + licence: { type: undefined }, + tilelayer: { type: undefined }, + overlay: { type: undefined }, + limitBounds: { type: undefined }, + color: { type: String }, + iconClass: { type: String }, + iconUrl: { type: String }, + smoothFactor: { type: undefined }, + iconOpacity: { type: undefined }, + opacity: { type: undefined }, + weight: { type: undefined }, + fill: { type: undefined }, + fillColor: { type: undefined }, + fillOpacity: { type: undefined }, + dashArray: { type: undefined }, + popupShape: { type: String }, + popupTemplate: { type: String }, + popupContentTemplate: { type: String }, + zoomTo: { type: Number }, + captionBar: { type: Boolean }, + captionMenus: { type: Boolean }, + slideshow: { type: undefined }, + sortKey: { type: undefined }, + labelKey: { type: String }, + filterKey: { type: undefined }, + facetKey: { type: undefined }, + slugKey: { type: undefined }, + showLabel: { type: 'NullableBoolean' }, + labelDirection: { type: undefined }, + labelInteractive: { type: undefined }, + outlinkTarget: { type: undefined }, + shortCredit: { type: undefined }, + longCredit: { type: undefined }, + permanentCredit: { type: undefined }, + permanentCreditBackground: { type: undefined }, + zoomControl: { type: 'NullableBoolean' }, + datalayersControl: { type: 'NullableBoolean' }, + searchControl: { type: 'NullableBoolean' }, + locateControl: { type: 'NullableBoolean' }, + fullscreenControl: { type: 'NullableBoolean' }, + editinosmControl: { type: 'NullableBoolean' }, + embedControl: { type: 'NullableBoolean' }, + measureControl: { type: 'NullableBoolean' }, + tilelayersControl: { type: 'NullableBoolean' }, + starControl: { type: 'NullableBoolean' }, + easing: { type: undefined }, +} + +export default { SCHEMA } diff --git a/umap/static/umap/js/umap.forms.js b/umap/static/umap/js/umap.forms.js index 2d28a026..7834b499 100644 --- a/umap/static/umap/js/umap.forms.js +++ b/umap/static/umap/js/umap.forms.js @@ -1276,6 +1276,9 @@ U.FormBuilder = L.FormBuilder.extend({ initialize: function (obj, fields, options) { this.map = obj.map || obj.getMap() + for (const [key, schema] of Object.entries(U.SCHEMA)) { + this.defaultOptions[key] = this.defaultOptions[key] || schema + } L.FormBuilder.prototype.initialize.call(this, obj, fields, options) this.on('finish', this.finish) }, diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index bc73784b..c503c418 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -57,64 +57,6 @@ L.Map.mergeOptions({ U.Map = L.Map.extend({ includes: [ControlsMixin], - editableOptions: { - zoom: undefined, - scrollWheelZoom: Boolean, - scaleControl: Boolean, - moreControl: Boolean, - miniMap: Boolean, - displayPopupFooter: undefined, - onLoadPanel: String, - defaultView: String, - name: String, - description: String, - licence: undefined, - tilelayer: undefined, - overlay: undefined, - limitBounds: undefined, - color: String, - iconClass: String, - iconUrl: String, - smoothFactor: undefined, - iconOpacity: undefined, - opacity: undefined, - weight: undefined, - fill: undefined, - fillColor: undefined, - fillOpacity: undefined, - dashArray: undefined, - popupShape: String, - popupTemplate: String, - popupContentTemplate: String, - zoomTo: Number, - captionBar: Boolean, - captionMenus: Boolean, - slideshow: undefined, - sortKey: undefined, - labelKey: String, - filterKey: undefined, - facetKey: undefined, - slugKey: undefined, - showLabel: 'NullableBoolean', - labelDirection: undefined, - labelInteractive: undefined, - outlinkTarget: undefined, - shortCredit: undefined, - longCredit: undefined, - permanentCredit: undefined, - permanentCreditBackground: undefined, - zoomControl: 'NullableBoolean', - datalayersControl: 'NullableBoolean', - searchControl: 'NullableBoolean', - locateControl: 'NullableBoolean', - fullscreenControl: 'NullableBoolean', - editinosmControl: 'NullableBoolean', - embedControl: 'NullableBoolean', - measureControl: 'NullableBoolean', - tilelayersControl: 'NullableBoolean', - starControl: 'NullableBoolean', - easing: undefined, - }, initialize: function (el, geojson) { // Locale name (pt_PT, en_US…) @@ -329,7 +271,7 @@ U.Map = L.Map.extend({ // FIXME retrocompat L.Util.setBooleanFromQueryString(options, 'displayDataBrowserOnLoad') L.Util.setBooleanFromQueryString(options, 'displayCaptionOnLoad') - for (const [key, type] of Object.entries(this.editableOptions)) { + for (const [key, { type }] of Object.entries(U.SCHEMA)) { switch (type) { case Boolean: L.Util.setBooleanFromQueryString(options, key) @@ -904,7 +846,7 @@ U.Map = L.Map.extend({ let mustReindex = false - for (const option of Object.keys(this.editableOptions)) { + for (const option of Object.keys(U.SCHEMA)) { if (typeof importedData.properties[option] !== 'undefined') { this.options[option] = importedData.properties[option] if (option === 'sortKey') mustReindex = true @@ -1033,7 +975,7 @@ U.Map = L.Map.extend({ exportOptions: function () { const properties = {} - for (const option of Object.keys(this.editableOptions)) { + for (const option of Object.keys(U.SCHEMA)) { if (typeof this.options[option] !== 'undefined') { properties[option] = this.options[option] }