Apply Lebab for let/const conversions

As far as I understand, it default to `let` in these cases because the tool cannot figure out if a `const` is possible. It has to be checked manually:

```
./node_modules/lebab/bin/index.js --replace "umap/static/umap/js/*.js" --transform let
umap/static/umap/js/umap.xhr.js:
228:  warning  Unable to transform var  (let)
umap/static/umap/js/umap.ui.js:
83:  warning  Unable to transform var  (let)
umap/static/umap/js/umap.slideshow.js:
15:  warning  Unable to transform var  (let)
83:  warning  Unable to transform var  (let)
umap/static/umap/js/umap.popup.js:
100:  warning  Unable to transform var  (let)
umap/static/umap/js/umap.permissions.js:
14:  warning  Unable to transform var  (let)
umap/static/umap/js/umap.layer.js:
195:  warning  Unable to transform var  (let)
436:  warning  Unable to transform var  (let)
568:  warning  Unable to transform var  (let)
584:  warning  Unable to transform var  (let)
989:  warning  Unable to transform var  (let)
1088:  warning  Unable to transform var  (let)
1098:  warning  Unable to transform var  (let)
umap/static/umap/js/umap.js:
124:  warning  Unable to transform var  (let)
223:  warning  Unable to transform var  (let)
343:  warning  Unable to transform var  (let)
376:  warning  Unable to transform var  (let)
406:  warning  Unable to transform var  (let)
849:  warning  Unable to transform var  (let)
732:  warning  Unable to transform var  (let)
948:  warning  Unable to transform var  (let)
959:  warning  Unable to transform var  (let)
878:  warning  Unable to transform var  (let)
1085:  warning  Unable to transform var  (let)
umap/static/umap/js/umap.icon.js:
145:  warning  Unable to transform var  (let)
184:  warning  Unable to transform var  (let)
umap/static/umap/js/umap.forms.js:
453:  warning  Unable to transform var  (let)
umap/static/umap/js/umap.features.js:
15:  warning  Unable to transform var  (let)
101:  warning  Unable to transform var  (let)
143:  warning  Unable to transform var  (let)
373:  warning  Unable to transform var  (let)
429:  warning  Unable to transform var  (let)
890:  warning  Unable to transform var  (let)
949:  warning  Unable to transform var  (let)
umap/static/umap/js/umap.core.js:
149:  warning  Unable to transform var  (let)
175:  warning  Unable to transform var  (let)
umap/static/umap/js/umap.controls.js:
665:  warning  Unable to transform var  (let)
876:  warning  Unable to transform var  (let)
1249:  warning  Unable to transform var  (let)
```
This commit is contained in:
David Larlet 2023-05-22 10:13:45 -04:00
parent 99b2bfb811
commit 56ce9ae22c
No known key found for this signature in database
15 changed files with 703 additions and 662 deletions

View file

@ -60,6 +60,7 @@ pretty: ## Apply PrettierJS to all JS files (or specified `filepath`)
lebab: ## Convert JS `filepath` to modern syntax with Lebab, then prettify lebab: ## Convert JS `filepath` to modern syntax with Lebab, then prettify
./node_modules/lebab/bin/index.js --replace ${filepath} --transform arrow,arrow-return ./node_modules/lebab/bin/index.js --replace ${filepath} --transform arrow,arrow-return
./node_modules/lebab/bin/index.js --replace ${filepath} --transform let
$(MAKE) pretty filepath=${filepath} $(MAKE) pretty filepath=${filepath}
lebab-all: $(jsdir)* ## Convert all JS files to modern syntax with Lebab + prettify lebab-all: $(jsdir)* ## Convert all JS files to modern syntax with Lebab + prettify

View file

@ -12,10 +12,10 @@ L.U.AutoComplete = L.Class.extend({
initialize: function (el, options) { initialize: function (el, options) {
this.el = el this.el = el
var ui = new L.U.UI(document.querySelector('header')) const ui = new L.U.UI(document.querySelector('header'))
this.xhr = new L.U.Xhr(ui) this.xhr = new L.U.Xhr(ui)
L.setOptions(this, options) L.setOptions(this, options)
var CURRENT = null let CURRENT = null
try { try {
Object.defineProperty(this, 'CURRENT', { Object.defineProperty(this, 'CURRENT', {
get: function () { get: function () {
@ -59,11 +59,11 @@ L.U.AutoComplete = L.Class.extend({
}, },
resizeContainer: function () { resizeContainer: function () {
var l = this.getLeft(this.input) const l = this.getLeft(this.input)
var t = this.getTop(this.input) + this.input.offsetHeight const t = this.getTop(this.input) + this.input.offsetHeight
this.container.style.left = l + 'px' this.container.style.left = l + 'px'
this.container.style.top = t + 'px' this.container.style.top = t + 'px'
var width = this.options.width ? this.options.width : this.input.offsetWidth - 2 const width = this.options.width ? this.options.width : this.input.offsetWidth - 2
this.container.style.width = width + 'px' this.container.style.width = width + 'px'
}, },
@ -111,7 +111,7 @@ L.U.AutoComplete = L.Class.extend({
}, },
onKeyUp: function (e) { onKeyUp: function (e) {
var special = [ const special = [
L.U.Keys.TAB, L.U.Keys.TAB,
L.U.Keys.ENTER, L.U.Keys.ENTER,
L.U.Keys.LEFT, L.U.Keys.LEFT,
@ -159,7 +159,7 @@ L.U.AutoComplete = L.Class.extend({
}, },
search: function () { search: function () {
var val = this.input.value const val = this.input.value
if (val.length < this.options.minChar) { if (val.length < this.options.minChar) {
this.clear() this.clear()
return return
@ -176,9 +176,9 @@ L.U.AutoComplete = L.Class.extend({
}, },
createResult: function (item) { createResult: function (item) {
var el = L.DomUtil.element('li', {}, this.container) const el = L.DomUtil.element('li', {}, this.container)
el.textContent = item.label el.textContent = item.label
var result = { const result = {
item: item, item: item,
el: el, el: el,
} }
@ -203,7 +203,7 @@ L.U.AutoComplete = L.Class.extend({
}, },
resultToIndex: function (result) { resultToIndex: function (result) {
var out = null let out = null
this.forEach(this.RESULTS, (item, index) => { this.forEach(this.RESULTS, (item, index) => {
if (item.item.value == result.item.value) { if (item.item.value == result.item.value) {
out = index out = index
@ -233,7 +233,7 @@ L.U.AutoComplete = L.Class.extend({
}, },
getLeft: function (el) { getLeft: function (el) {
var tmp = el.offsetLeft let tmp = el.offsetLeft
el = el.offsetParent el = el.offsetParent
while (el) { while (el) {
tmp += el.offsetLeft tmp += el.offsetLeft
@ -243,7 +243,7 @@ L.U.AutoComplete = L.Class.extend({
}, },
getTop: function (el) { getTop: function (el) {
var tmp = el.offsetTop let tmp = el.offsetTop
el = el.offsetParent el = el.offsetParent
while (el) { while (el) {
tmp += el.offsetTop tmp += el.offsetTop
@ -291,9 +291,9 @@ L.U.AutoComplete.Ajax.SelectMultiple = L.U.AutoComplete.Ajax.extend({
}, },
displaySelected: function (result) { displaySelected: function (result) {
var result_el = L.DomUtil.element('li', {}, this.selected_container) const result_el = L.DomUtil.element('li', {}, this.selected_container)
result_el.textContent = result.item.label result_el.textContent = result.item.label
var close = L.DomUtil.element('span', { className: 'close' }, result_el) const close = L.DomUtil.element('span', { className: 'close' }, result_el)
close.textContent = '×' close.textContent = '×'
L.DomEvent.on( L.DomEvent.on(
close, close,
@ -317,9 +317,9 @@ L.U.AutoComplete.Ajax.Select = L.U.AutoComplete.Ajax.extend({
}, },
displaySelected: function (result) { displaySelected: function (result) {
var result_el = L.DomUtil.element('div', {}, this.selected_container) const result_el = L.DomUtil.element('div', {}, this.selected_container)
result_el.textContent = result.item.label result_el.textContent = result.item.label
var close = L.DomUtil.element('span', { className: 'close' }, result_el) const close = L.DomUtil.element('span', { className: 'close' }, result_el)
close.textContent = '×' close.textContent = '×'
this.input.style.display = 'none' this.input.style.display = 'none'
L.DomEvent.on( L.DomEvent.on(

View file

@ -302,7 +302,7 @@ L.U.DrawToolbar = L.Toolbar.Control.extend({
}, },
redraw: function () { redraw: function () {
var container = this._control.getContainer() const container = this._control.getContainer()
container.innerHTML = '' container.innerHTML = ''
this.appendToContainer(container) this.appendToContainer(container)
}, },
@ -314,7 +314,10 @@ L.U.EditControl = L.Control.extend({
}, },
onAdd: function (map) { onAdd: function (map) {
var container = L.DomUtil.create('div', 'leaflet-control-edit-enable umap-control'), const container = L.DomUtil.create(
'div',
'leaflet-control-edit-enable umap-control'
),
edit = L.DomUtil.create('a', '', container) edit = L.DomUtil.create('a', '', container)
edit.href = '#' edit.href = '#'
edit.title = L._('Enable editing') + ' (Ctrl+E)' edit.title = L._('Enable editing') + ' (Ctrl+E)'
@ -336,9 +339,9 @@ L.Control.Embed = L.Control.extend({
}, },
onAdd: function (map) { onAdd: function (map) {
var container = L.DomUtil.create('div', 'leaflet-control-embed umap-control') const container = L.DomUtil.create('div', 'leaflet-control-embed umap-control')
var link = L.DomUtil.create('a', '', container) const link = L.DomUtil.create('a', '', container)
link.href = '#' link.href = '#'
link.title = L._('Embed and share this map') link.title = L._('Embed and share this map')
@ -356,7 +359,7 @@ L.U.MoreControls = L.Control.extend({
}, },
onAdd: function () { onAdd: function () {
var container = L.DomUtil.create('div', ''), const container = L.DomUtil.create('div', ''),
more = L.DomUtil.create('a', 'umap-control-more umap-control-text', container), more = L.DomUtil.create('a', 'umap-control-more umap-control-text', container),
less = L.DomUtil.create('a', 'umap-control-less umap-control-text', container) less = L.DomUtil.create('a', 'umap-control-less umap-control-text', container)
more.href = '#' more.href = '#'
@ -373,7 +376,7 @@ L.U.MoreControls = L.Control.extend({
}, },
toggle: function () { toggle: function () {
var pos = this.getPosition(), const pos = this.getPosition(),
corner = this._map._controlCorners[pos], corner = this._map._controlCorners[pos],
className = 'umap-more-controls' className = 'umap-more-controls'
if (L.DomUtil.hasClass(corner, className)) L.DomUtil.removeClass(corner, className) if (L.DomUtil.hasClass(corner, className)) L.DomUtil.removeClass(corner, className)
@ -392,7 +395,7 @@ L.U.PermanentCreditsControl = L.Control.extend({
}, },
onAdd: function () { onAdd: function () {
var paragraphContainer = L.DomUtil.create( const paragraphContainer = L.DomUtil.create(
'div', 'div',
'umap-permanent-credits-container' 'umap-permanent-credits-container'
), ),
@ -435,7 +438,7 @@ L.U.DataLayersControl = L.Control.extend({
}, },
_initLayout: function (map) { _initLayout: function (map) {
var container = (this._container = L.DomUtil.create( const container = (this._container = L.DomUtil.create(
'div', 'div',
'leaflet-control-browse umap-control' 'leaflet-control-browse umap-control'
)), )),
@ -446,11 +449,11 @@ L.U.DataLayersControl = L.Control.extend({
actions actions
) )
var link = L.DomUtil.create('a', 'umap-browse-link', actions) const link = L.DomUtil.create('a', 'umap-browse-link', actions)
link.href = '#' link.href = '#'
link.title = link.textContent = L._('Browse data') link.title = link.textContent = L._('Browse data')
var toggle = L.DomUtil.create('a', 'umap-browse-toggle', container) const toggle = L.DomUtil.create('a', 'umap-browse-toggle', container)
toggle.href = '#' toggle.href = '#'
toggle.title = L._('See data layers') toggle.title = L._('See data layers')
@ -524,7 +527,7 @@ L.U.DataLayersControl = L.Control.extend({
}, },
addDataLayer: function (container, datalayer, draggable) { addDataLayer: function (container, datalayer, draggable) {
var datalayerLi = L.DomUtil.create('li', '', container) const datalayerLi = L.DomUtil.create('li', '', container)
if (draggable) if (draggable)
L.DomUtil.element( L.DomUtil.element(
'i', 'i',
@ -532,7 +535,7 @@ L.U.DataLayersControl = L.Control.extend({
datalayerLi datalayerLi
) )
datalayer.renderToolbox(datalayerLi) datalayer.renderToolbox(datalayerLi)
var title = L.DomUtil.add( const title = L.DomUtil.add(
'span', 'span',
'layer-title', 'layer-title',
datalayerLi, datalayerLi,
@ -546,21 +549,21 @@ L.U.DataLayersControl = L.Control.extend({
}, },
newDataLayer: function () { newDataLayer: function () {
var datalayer = this.map.createDataLayer({}) const datalayer = this.map.createDataLayer({})
datalayer.edit() datalayer.edit()
}, },
openPanel: function () { openPanel: function () {
if (!this.map.editEnabled) return if (!this.map.editEnabled) return
var container = L.DomUtil.create('ul', 'umap-browse-datalayers') const container = L.DomUtil.create('ul', 'umap-browse-datalayers')
this.map.eachDataLayerReverse(function (datalayer) { this.map.eachDataLayerReverse(function (datalayer) {
this.addDataLayer(container, datalayer, true) this.addDataLayer(container, datalayer, true)
}, this) }, this)
var orderable = new L.U.Orderable(container) const orderable = new L.U.Orderable(container)
orderable.on( orderable.on(
'drop', 'drop',
function (e) { function (e) {
var layer = this.map.datalayers[e.src.dataset.id], const layer = this.map.datalayers[e.src.dataset.id],
other = this.map.datalayers[e.dst.dataset.id], other = this.map.datalayers[e.dst.dataset.id],
minIndex = Math.min(e.initialIndex, e.finalIndex) minIndex = Math.min(e.initialIndex, e.finalIndex)
if (e.finalIndex === 0) layer.bringToTop() if (e.finalIndex === 0) layer.bringToTop()
@ -574,7 +577,7 @@ L.U.DataLayersControl = L.Control.extend({
this this
) )
var bar = L.DomUtil.create('div', 'button-bar', container), const bar = L.DomUtil.create('div', 'button-bar', container),
add = L.DomUtil.create('a', 'show-on-edit block add-datalayer button', bar) add = L.DomUtil.create('a', 'show-on-edit block add-datalayer button', bar)
add.href = '#' add.href = '#'
add.textContent = add.title = L._('Add a layer') add.textContent = add.title = L._('Add a layer')
@ -592,7 +595,7 @@ L.U.DataLayersControl = L.Control.extend({
L.U.DataLayer.include({ L.U.DataLayer.include({
renderToolbox: function (container) { renderToolbox: function (container) {
var toggle = L.DomUtil.create('i', 'layer-toggle', container), const toggle = L.DomUtil.create('i', 'layer-toggle', container),
zoomTo = L.DomUtil.create('i', 'layer-zoom_to', container), zoomTo = L.DomUtil.create('i', 'layer-zoom_to', container),
edit = L.DomUtil.create('i', 'layer-edit show-on-edit', container), edit = L.DomUtil.create('i', 'layer-edit show-on-edit', container),
table = L.DomUtil.create('i', 'layer-table-edit show-on-edit', container), table = L.DomUtil.create('i', 'layer-table-edit show-on-edit', container),
@ -631,23 +634,23 @@ L.U.DataLayer.include({
}, },
propagateRemote: function () { propagateRemote: function () {
var els = this.getHidableElements() const els = this.getHidableElements()
for (var i = 0; i < els.length; i++) { for (let i = 0; i < els.length; i++) {
L.DomUtil.classIf(els[i], 'remotelayer', this.isRemoteLayer()) L.DomUtil.classIf(els[i], 'remotelayer', this.isRemoteLayer())
} }
}, },
propagateHide: function () { propagateHide: function () {
var els = this.getHidableElements() const els = this.getHidableElements()
for (var i = 0; i < els.length; i++) { for (let i = 0; i < els.length; i++) {
L.DomUtil.addClass(els[i], 'off') L.DomUtil.addClass(els[i], 'off')
} }
}, },
propagateShow: function () { propagateShow: function () {
this.onceLoaded(function () { this.onceLoaded(function () {
var els = this.getHidableElements() const els = this.getHidableElements()
for (var i = 0; i < els.length; i++) { for (let i = 0; i < els.length; i++) {
L.DomUtil.removeClass(els[i], 'off') L.DomUtil.removeClass(els[i], 'off')
} }
}, this) }, this)
@ -662,27 +665,31 @@ L.U.DataLayer.addInitHook(function () {
L.U.Map.include({ L.U.Map.include({
_openBrowser: function () { _openBrowser: function () {
var browserContainer = L.DomUtil.create('div', 'umap-browse-data'), const browserContainer = L.DomUtil.create('div', 'umap-browse-data')
title = L.DomUtil.add(
const title = L.DomUtil.add(
'h3', 'h3',
'umap-browse-title', 'umap-browse-title',
browserContainer, browserContainer,
this.options.name this.options.name
), )
filter = L.DomUtil.create('input', '', browserContainer),
filterValue = '', const filter = L.DomUtil.create('input', '', browserContainer)
featuresContainer = L.DomUtil.create( let filterValue = ''
const featuresContainer = L.DomUtil.create(
'div', 'div',
'umap-browse-features', 'umap-browse-features',
browserContainer browserContainer
), )
filterKeys = this.getFilterKeys()
const filterKeys = this.getFilterKeys()
filter.type = 'text' filter.type = 'text'
filter.placeholder = L._('Filter…') filter.placeholder = L._('Filter…')
filter.value = this.options.filter || '' filter.value = this.options.filter || ''
var addFeature = (feature) => { const addFeature = (feature) => {
var feature_li = L.DomUtil.create('li', feature.getClassName() + ' feature'), const feature_li = L.DomUtil.create('li', feature.getClassName() + ' feature'),
zoom_to = L.DomUtil.create('i', 'feature-zoom_to', feature_li), zoom_to = L.DomUtil.create('i', 'feature-zoom_to', feature_li),
edit = L.DomUtil.create('i', 'show-on-edit feature-edit', feature_li), edit = L.DomUtil.create('i', 'show-on-edit feature-edit', feature_li),
color = L.DomUtil.create('i', 'feature-color', feature_li), color = L.DomUtil.create('i', 'feature-color', feature_li),
@ -726,8 +733,8 @@ L.U.Map.include({
return feature_li return feature_li
} }
var append = (datalayer) => { const append = (datalayer) => {
var container = L.DomUtil.create( const container = L.DomUtil.create(
'div', 'div',
datalayer.getHidableClass(), datalayer.getHidableClass(),
featuresContainer featuresContainer
@ -736,10 +743,10 @@ L.U.Map.include({
container.id = 'browse_data_datalayer_' + datalayer.umap_id container.id = 'browse_data_datalayer_' + datalayer.umap_id
datalayer.renderToolbox(headline) datalayer.renderToolbox(headline)
L.DomUtil.add('span', '', headline, datalayer.options.name) L.DomUtil.add('span', '', headline, datalayer.options.name)
var ul = L.DomUtil.create('ul', '', container) const ul = L.DomUtil.create('ul', '', container)
L.DomUtil.classIf(container, 'off', !datalayer.isVisible()) L.DomUtil.classIf(container, 'off', !datalayer.isVisible())
var build = () => { const build = () => {
ul.innerHTML = '' ul.innerHTML = ''
datalayer.eachFeature((feature) => { datalayer.eachFeature((feature) => {
if ( if (
@ -762,14 +769,14 @@ L.U.Map.include({
}) })
} }
var appendAll = function () { const appendAll = function () {
this.options.filter = filterValue = filter.value this.options.filter = filterValue = filter.value
featuresContainer.innerHTML = '' featuresContainer.innerHTML = ''
this.eachBrowsableDataLayer((datalayer) => { this.eachBrowsableDataLayer((datalayer) => {
append(datalayer) append(datalayer)
}) })
} }
var resetLayers = function () { const resetLayers = function () {
this.eachBrowsableDataLayer((datalayer) => { this.eachBrowsableDataLayer((datalayer) => {
datalayer.resetLayer(true) datalayer.resetLayer(true)
}) })
@ -777,16 +784,16 @@ L.U.Map.include({
L.bind(appendAll, this)() L.bind(appendAll, this)()
L.DomEvent.on(filter, 'input', appendAll, this) L.DomEvent.on(filter, 'input', appendAll, this)
L.DomEvent.on(filter, 'input', resetLayers, this) L.DomEvent.on(filter, 'input', resetLayers, this)
var link = L.DomUtil.create('li', '') const link = L.DomUtil.create('li', '')
L.DomUtil.create('i', 'umap-icon-16 umap-caption', link) L.DomUtil.create('i', 'umap-icon-16 umap-caption', link)
var label = L.DomUtil.create('span', '', link) const label = L.DomUtil.create('span', '', link)
label.textContent = label.title = L._('About') label.textContent = label.title = L._('About')
L.DomEvent.on(link, 'click', this.displayCaption, this) L.DomEvent.on(link, 'click', this.displayCaption, this)
this.ui.openPanel({ data: { html: browserContainer }, actions: [link] }) this.ui.openPanel({ data: { html: browserContainer }, actions: [link] })
}, },
_openFilter: function () { _openFilter: function () {
var filterContainer = L.DomUtil.create('div', 'umap-filter-data'), const filterContainer = L.DomUtil.create('div', 'umap-filter-data'),
title = L.DomUtil.add( title = L.DomUtil.add(
'h3', 'h3',
'umap-filter-title', 'umap-filter-title',
@ -800,8 +807,8 @@ L.U.Map.include({
), ),
advancedFilterKeys = this.getAdvancedFilterKeys() advancedFilterKeys = this.getAdvancedFilterKeys()
var advancedFiltersFull = {} const advancedFiltersFull = {}
var filtersAlreadyLoaded = true let filtersAlreadyLoaded = true
if (!this.getMap().options.advancedFilters) { if (!this.getMap().options.advancedFilters) {
this.getMap().options.advancedFilters = {} this.getMap().options.advancedFilters = {}
filtersAlreadyLoaded = false filtersAlreadyLoaded = false
@ -824,8 +831,8 @@ L.U.Map.include({
}) })
}) })
var addPropertyValue = function (property, value) { const addPropertyValue = function (property, value) {
var property_li = L.DomUtil.create('li', ''), const property_li = L.DomUtil.create('li', ''),
filter_check = L.DomUtil.create('input', '', property_li), filter_check = L.DomUtil.create('input', '', property_li),
filter_label = L.DomUtil.create('label', '', property_li) filter_label = L.DomUtil.create('label', '', property_li)
filter_check.type = 'checkbox' filter_check.type = 'checkbox'
@ -841,8 +848,8 @@ L.U.Map.include({
filter_check, filter_check,
'change', 'change',
function (e) { function (e) {
var property = e.srcElement.dataset.property const property = e.srcElement.dataset.property
var value = e.srcElement.dataset.value const value = e.srcElement.dataset.value
if (e.srcElement.checked) { if (e.srcElement.checked) {
this.getMap().options.advancedFilters[property].push(value) this.getMap().options.advancedFilters[property].push(value)
} else { } else {
@ -858,15 +865,15 @@ L.U.Map.include({
return property_li return property_li
} }
var addProperty = function (property) { const addProperty = function (property) {
var container = L.DomUtil.create( const container = L.DomUtil.create(
'div', 'div',
'property-container', 'property-container',
propertiesContainer propertiesContainer
), ),
headline = L.DomUtil.add('h5', '', container, property) headline = L.DomUtil.add('h5', '', container, property)
var ul = L.DomUtil.create('ul', '', container) const ul = L.DomUtil.create('ul', '', container)
var orderedValues = advancedFiltersFull[property] const orderedValues = advancedFiltersFull[property]
orderedValues.sort() orderedValues.sort()
orderedValues.forEach((value) => { orderedValues.forEach((value) => {
ul.appendChild(L.bind(addPropertyValue, this)(property, value)) ul.appendChild(L.bind(addPropertyValue, this)(property, value))
@ -874,7 +881,7 @@ L.U.Map.include({
} }
var filterFeatures = function () { var filterFeatures = function () {
var noResults = true let noResults = true
this.eachDataLayer((datalayer) => { this.eachDataLayer((datalayer) => {
datalayer.eachFeature(function (feature) { datalayer.eachFeature(function (feature) {
feature.properties.isVisible = true feature.properties.isVisible = true
@ -913,9 +920,9 @@ L.U.Map.include({
L.bind(addProperty, this)(property) L.bind(addProperty, this)(property)
}) })
var link = L.DomUtil.create('li', '') const link = L.DomUtil.create('li', '')
L.DomUtil.create('i', 'umap-icon-16 umap-caption', link) L.DomUtil.create('i', 'umap-icon-16 umap-caption', link)
var label = L.DomUtil.create('span', '', link) const label = L.DomUtil.create('span', '', link)
label.textContent = label.title = L._('About') label.textContent = label.title = L._('About')
L.DomEvent.on(link, 'click', this.displayCaption, this) L.DomEvent.on(link, 'click', this.displayCaption, this)
this.ui.openPanel({ data: { html: filterContainer }, actions: [link] }) this.ui.openPanel({ data: { html: filterContainer }, actions: [link] })
@ -933,9 +940,9 @@ L.U.TileLayerControl = L.Control.extend({
}, },
onAdd: function () { onAdd: function () {
var container = L.DomUtil.create('div', 'leaflet-control-tilelayers umap-control') const container = L.DomUtil.create('div', 'leaflet-control-tilelayers umap-control')
var link = L.DomUtil.create('a', '', container) const link = L.DomUtil.create('a', '', container)
link.href = '#' link.href = '#'
link.title = L._('Change map background') link.title = L._('Change map background')
@ -970,7 +977,7 @@ L.U.TileLayerControl = L.Control.extend({
}, },
addTileLayerElement: function (tilelayer, options) { addTileLayerElement: function (tilelayer, options) {
var selectedClass = this.map.hasLayer(tilelayer) ? 'selected' : '', const selectedClass = this.map.hasLayer(tilelayer) ? 'selected' : '',
el = L.DomUtil.create('li', selectedClass, this._tilelayers_container), el = L.DomUtil.create('li', selectedClass, this._tilelayers_container),
img = L.DomUtil.create('img', '', el), img = L.DomUtil.create('img', '', el),
name = L.DomUtil.create('div', '', el) name = L.DomUtil.create('div', '', el)
@ -1006,14 +1013,14 @@ L.U.AttributionControl = L.Control.Attribution.extend({
) )
} }
if (this._map.options.captionMenus) { if (this._map.options.captionMenus) {
var link = L.DomUtil.add('a', '', this._container, ' — ' + L._('About')) const link = L.DomUtil.add('a', '', this._container, ' — ' + L._('About'))
L.DomEvent.on(link, 'click', L.DomEvent.stop) L.DomEvent.on(link, 'click', L.DomEvent.stop)
.on(link, 'click', this._map.displayCaption, this._map) .on(link, 'click', this._map.displayCaption, this._map)
.on(link, 'dblclick', L.DomEvent.stop) .on(link, 'dblclick', L.DomEvent.stop)
} }
if (window.top === window.self && this._map.options.captionMenus) { if (window.top === window.self && this._map.options.captionMenus) {
// We are not in iframe mode // We are not in iframe mode
var home = L.DomUtil.add('a', '', this._container, ' — ' + L._('Home')) const home = L.DomUtil.add('a', '', this._container, ' — ' + L._('Home'))
home.href = '/' home.href = '/'
} }
}, },
@ -1025,8 +1032,8 @@ L.U.StarControl = L.Control.extend({
}, },
onAdd: function (map) { onAdd: function (map) {
var status = map.options.starred ? ' starred' : '' const status = map.options.starred ? ' starred' : ''
var container = L.DomUtil.create( const container = L.DomUtil.create(
'div', 'div',
'leaflet-control-star umap-control' + status 'leaflet-control-star umap-control' + status
), ),
@ -1053,8 +1060,8 @@ L.U.Search = L.PhotonSearch.extend({
}, },
formatResult: function (feature, el) { formatResult: function (feature, el) {
var self = this const self = this
var tools = L.DomUtil.create('span', 'search-result-tools', el), const tools = L.DomUtil.create('span', 'search-result-tools', el),
zoom = L.DomUtil.create('i', 'feature-zoom_to', tools), zoom = L.DomUtil.create('i', 'feature-zoom_to', tools),
edit = L.DomUtil.create('i', 'feature-edit show-on-edit', tools) edit = L.DomUtil.create('i', 'feature-edit show-on-edit', tools)
zoom.title = L._('Zoom to this place') zoom.title = L._('Zoom to this place')
@ -1067,8 +1074,8 @@ L.U.Search = L.PhotonSearch.extend({
}) })
L.DomEvent.on(edit, 'mousedown', (e) => { L.DomEvent.on(edit, 'mousedown', (e) => {
L.DomEvent.stop(e) L.DomEvent.stop(e)
var datalayer = self.map.defaultDataLayer() const datalayer = self.map.defaultDataLayer()
var layer = datalayer.geojsonToFeatures(feature) const layer = datalayer.geojsonToFeatures(feature)
layer.isDirty = true layer.isDirty = true
layer.edit() layer.edit()
}) })
@ -1076,7 +1083,7 @@ L.U.Search = L.PhotonSearch.extend({
}, },
zoomToFeature: function (feature) { zoomToFeature: function (feature) {
var zoom = Math.max(this.map.getZoom(), 16) // Never unzoom. const zoom = Math.max(this.map.getZoom(), 16) // Never unzoom.
this.map.setView( this.map.setView(
[feature.geometry.coordinates[1], feature.geometry.coordinates[0]], [feature.geometry.coordinates[1], feature.geometry.coordinates[0]],
zoom zoom
@ -1095,11 +1102,11 @@ L.U.SearchControl = L.Control.extend({
}, },
onAdd: function (map) { onAdd: function (map) {
var container = L.DomUtil.create('div', 'leaflet-control-search umap-control'), const container = L.DomUtil.create('div', 'leaflet-control-search umap-control'),
self = this self = this
L.DomEvent.disableClickPropagation(container) L.DomEvent.disableClickPropagation(container)
var link = L.DomUtil.create('a', '', container) const link = L.DomUtil.create('a', '', container)
link.href = '#' link.href = '#'
link.title = L._('Search a place name') link.title = L._('Search a place name')
L.DomEvent.on(link, 'click', (e) => { L.DomEvent.on(link, 'click', (e) => {
@ -1110,19 +1117,19 @@ L.U.SearchControl = L.Control.extend({
}, },
openPanel: function (map) { openPanel: function (map) {
var options = { const options = {
limit: 10, limit: 10,
noResultLabel: L._('No results'), noResultLabel: L._('No results'),
} }
if (map.options.photonUrl) options.url = map.options.photonUrl if (map.options.photonUrl) options.url = map.options.photonUrl
var container = L.DomUtil.create('div', '') const container = L.DomUtil.create('div', '')
var title = L.DomUtil.create('h3', '', container) const title = L.DomUtil.create('h3', '', container)
title.textContent = L._('Search location') title.textContent = L._('Search location')
var input = L.DomUtil.create('input', 'photon-input', container) const input = L.DomUtil.create('input', 'photon-input', container)
var resultsContainer = L.DomUtil.create('div', 'photon-autocomplete', container) const resultsContainer = L.DomUtil.create('div', 'photon-autocomplete', container)
this.search = new L.U.Search(map, input, options) this.search = new L.U.Search(map, input, options)
var id = Math.random() const id = Math.random()
this.search.on('ajax:send', () => { this.search.on('ajax:send', () => {
map.fire('dataloading', { id: id }) map.fire('dataloading', { id: id })
}) })
@ -1144,7 +1151,7 @@ L.Control.MiniMap.include({
}, },
onMainMapBaseLayerChange: function (e) { onMainMapBaseLayerChange: function (e) {
var layer = this._cloneLayer(e.layer) const layer = this._cloneLayer(e.layer)
if (this._miniMap.hasLayer(this._layer)) { if (this._miniMap.hasLayer(this._layer)) {
this._miniMap.removeLayer(this._layer) this._miniMap.removeLayer(this._layer)
} }
@ -1232,7 +1239,7 @@ L.U.IframeExporter = L.Evented.extend({
}, },
buildUrl: function () { buildUrl: function () {
var datalayers = [] const datalayers = []
if (this.options.viewCurrentFeature && this.map.currentFeature) { if (this.options.viewCurrentFeature && this.map.currentFeature) {
this.queryString.feature = this.map.currentFeature.getSlug() this.queryString.feature = this.map.currentFeature.getSlug()
} }
@ -1246,13 +1253,13 @@ L.U.IframeExporter = L.Evented.extend({
} else { } else {
delete this.queryString.datalayers delete this.queryString.datalayers
} }
var currentView = this.options.currentView ? window.location.hash : '' const currentView = this.options.currentView ? window.location.hash : ''
return this.baseUrl + '?' + L.Util.buildQueryString(this.queryString) + currentView return this.baseUrl + '?' + L.Util.buildQueryString(this.queryString) + currentView
}, },
build: function () { build: function () {
var iframeUrl = this.buildUrl() const iframeUrl = this.buildUrl()
var code = const code =
'<iframe width="' + '<iframe width="' +
this.dimensions.width + this.dimensions.width +
'" height="' + '" height="' +
@ -1286,7 +1293,7 @@ L.U.Editable = L.Editable.extend({
if (this.map.editedFeature !== e.layer) e.layer.edit(e) if (this.map.editedFeature !== e.layer) e.layer.edit(e)
}) })
this.on('editable:editing', (e) => { this.on('editable:editing', (e) => {
var layer = e.layer const layer = e.layer
layer.isDirty = true layer.isDirty = true
if (layer._tooltip && layer.isTooltipOpen()) { if (layer._tooltip && layer.isTooltipOpen()) {
layer._tooltip.setLatLng(layer.getCenter()) layer._tooltip.setLatLng(layer.getCenter())
@ -1294,7 +1301,7 @@ L.U.Editable = L.Editable.extend({
} }
}) })
this.on('editable:vertex:ctrlclick', (e) => { this.on('editable:vertex:ctrlclick', (e) => {
var index = e.vertex.getIndex() const index = e.vertex.getIndex()
if (index === 0 || (index === e.vertex.getLastIndex() && e.vertex.continue)) if (index === 0 || (index === e.vertex.getLastIndex() && e.vertex.continue))
e.vertex.continue() e.vertex.continue()
}) })
@ -1309,7 +1316,7 @@ L.U.Editable = L.Editable.extend({
}, },
createPolygon: function (latlngs) { createPolygon: function (latlngs) {
var polygon = new L.U.Polygon(this.map, latlngs) const polygon = new L.U.Polygon(this.map, latlngs)
return polygon return polygon
}, },
@ -1319,7 +1326,7 @@ L.U.Editable = L.Editable.extend({
connectCreatedToMap: function (layer) { connectCreatedToMap: function (layer) {
// Overrided from Leaflet.Editable // Overrided from Leaflet.Editable
var datalayer = this.map.defaultDataLayer() const datalayer = this.map.defaultDataLayer()
datalayer.addLayer(layer) datalayer.addLayer(layer)
layer.isDirty = true layer.isDirty = true
return layer return layer
@ -1334,8 +1341,8 @@ L.U.Editable = L.Editable.extend({
return return
} }
var content let content
var measure let measure
if (e.layer.editor._drawnLatLngs) { if (e.layer.editor._drawnLatLngs) {
// when drawing (a Polyline or Polygon) // when drawing (a Polyline or Polygon)
if (!e.layer.editor._drawnLatLngs.length) { if (!e.layer.editor._drawnLatLngs.length) {
@ -1346,7 +1353,7 @@ L.U.Editable = L.Editable.extend({
content = L._('Click to start drawing a line') content = L._('Click to start drawing a line')
} }
} else { } else {
var tmpLatLngs = e.layer.editor._drawnLatLngs.slice() const tmpLatLngs = e.layer.editor._drawnLatLngs.slice()
tmpLatLngs.push(e.latlng) tmpLatLngs.push(e.latlng)
measure = e.layer.getMeasure(tmpLatLngs) measure = e.layer.getMeasure(tmpLatLngs)

View file

@ -8,11 +8,11 @@ L.U.Map = L.Map.extend({})
* Utils * Utils
*/ */
L.Util.queryString = (name, fallback) => { L.Util.queryString = (name, fallback) => {
var decode = (s) => decodeURIComponent(s.replace(/\+/g, ' ')) const decode = (s) => decodeURIComponent(s.replace(/\+/g, ' '))
var qs = window.location.search.slice(1).split('&'), const qs = window.location.search.slice(1).split('&'),
qa = {} qa = {}
for (var i in qs) { for (const i in qs) {
var key = qs[i].split('=') const key = qs[i].split('=')
if (!key) continue if (!key) continue
qa[decode(key[0])] = key[1] ? decode(key[1]) : 1 qa[decode(key[0])] = key[1] ? decode(key[1]) : 1
} }
@ -20,21 +20,21 @@ L.Util.queryString = (name, fallback) => {
} }
L.Util.booleanFromQueryString = (name) => { L.Util.booleanFromQueryString = (name) => {
var value = L.Util.queryString(name) const value = L.Util.queryString(name)
return value === '1' || value === 'true' return value === '1' || value === 'true'
} }
L.Util.setFromQueryString = (options, name) => { L.Util.setFromQueryString = (options, name) => {
var value = L.Util.queryString(name) const value = L.Util.queryString(name)
if (typeof value !== 'undefined') options[name] = value if (typeof value !== 'undefined') options[name] = value
} }
L.Util.setBooleanFromQueryString = (options, name) => { L.Util.setBooleanFromQueryString = (options, name) => {
var value = L.Util.queryString(name) const value = L.Util.queryString(name)
if (typeof value !== 'undefined') options[name] = value == '1' || value == 'true' if (typeof value !== 'undefined') options[name] = value == '1' || value == 'true'
} }
L.Util.setNullableBooleanFromQueryString = (options, name) => { L.Util.setNullableBooleanFromQueryString = (options, name) => {
var value = L.Util.queryString(name) let value = L.Util.queryString(name)
if (typeof value !== 'undefined') { if (typeof value !== 'undefined') {
if (value === 'null') value = null if (value === 'null') value = null
else if (value === '0' || value === 'false') value = false else if (value === '0' || value === 'false') value = false
@ -48,10 +48,10 @@ L.Util.escapeHTML = (s) => {
} }
L.Util.toHTML = (r) => { L.Util.toHTML = (r) => {
if (!r) return '' if (!r) return ''
var ii let ii
// detect newline format // detect newline format
var newline = r.indexOf('\r\n') != -1 ? '\r\n' : r.indexOf('\n') != -1 ? '\n' : '' const newline = r.indexOf('\r\n') != -1 ? '\r\n' : r.indexOf('\n') != -1 ? '\n' : ''
// Escape tags // Escape tags
r = r.replace(/</gm, '&lt;') r = r.replace(/</gm, '&lt;')
@ -114,7 +114,7 @@ L.Util.toHTML = (r) => {
L.Util.isObject = (what) => typeof what === 'object' && what !== null L.Util.isObject = (what) => typeof what === 'object' && what !== null
L.Util.CopyJSON = (geojson) => JSON.parse(JSON.stringify(geojson)) L.Util.CopyJSON = (geojson) => JSON.parse(JSON.stringify(geojson))
L.Util.detectFileType = (f) => { L.Util.detectFileType = (f) => {
var filename = f.name ? escape(f.name.toLowerCase()) : '' const filename = f.name ? escape(f.name.toLowerCase()) : ''
function ext(_) { function ext(_) {
return filename.indexOf(_) !== -1 return filename.indexOf(_) !== -1
} }
@ -135,8 +135,8 @@ L.Util.usableOption = (options, option) =>
L.Util.greedyTemplate = (str, data, ignore) => { L.Util.greedyTemplate = (str, data, ignore) => {
function getValue(data, path) { function getValue(data, path) {
var value = data let value = data
for (var i = 0; i < path.length; i++) { for (let i = 0; i < path.length; i++) {
value = value[path[i]] value = value[path[i]]
if (value === undefined) break if (value === undefined) break
} }
@ -146,13 +146,13 @@ L.Util.greedyTemplate = (str, data, ignore) => {
return str.replace( return str.replace(
/\{ *([\w_\:\.\|]+)(?:\|("[^"]*"))? *\}/g, /\{ *([\w_\:\.\|]+)(?:\|("[^"]*"))? *\}/g,
(str, key, staticFallback) => { (str, key, staticFallback) => {
var vars = key.split('|'), const vars = key.split('|')
value, let value
path let path
if (staticFallback !== undefined) { if (staticFallback !== undefined) {
vars.push(staticFallback) vars.push(staticFallback)
} }
for (var i = 0; i < vars.length; i++) { for (let i = 0; i < vars.length; i++) {
path = vars[i] path = vars[i]
if (path.startsWith('"') && path.endsWith('"')) if (path.startsWith('"') && path.endsWith('"'))
value = path.substring(1, path.length - 1) // static default value. value = path.substring(1, path.length - 1) // static default value.
@ -169,13 +169,13 @@ L.Util.greedyTemplate = (str, data, ignore) => {
} }
L.Util.sortFeatures = (features, sortKey) => { L.Util.sortFeatures = (features, sortKey) => {
var sortKeys = (sortKey || 'name').split(',') const sortKeys = (sortKey || 'name').split(',')
var sort = (a, b, i) => { const sort = (a, b, i) => {
var sortKey = sortKeys[i], const sortKey = sortKeys[i]
score, let score
valA = a.properties[sortKey] || '', const valA = a.properties[sortKey] || ''
valB = b.properties[sortKey] || '' const valB = b.properties[sortKey] || ''
if (!valA) { if (!valA) {
score = -1 score = -1
} else if (!valB) { } else if (!valB) {
@ -203,8 +203,8 @@ L.Util.flattenCoordinates = (coords) => {
} }
L.Util.buildQueryString = (params) => { L.Util.buildQueryString = (params) => {
var query_string = [] const query_string = []
for (var key in params) { for (const key in params) {
query_string.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key])) query_string.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key]))
} }
return query_string.join('&') return query_string.join('&')
@ -213,7 +213,7 @@ L.Util.buildQueryString = (params) => {
L.Util.getBaseUrl = () => '//' + window.location.host + window.location.pathname L.Util.getBaseUrl = () => '//' + window.location.host + window.location.pathname
L.DomUtil.add = (tagName, className, container, content) => { L.DomUtil.add = (tagName, className, container, content) => {
var el = L.DomUtil.create(tagName, className, container) const el = L.DomUtil.create(tagName, className, container)
if (content) { if (content) {
if (content.nodeType && content.nodeType === 1) { if (content.nodeType && content.nodeType === 1) {
el.appendChild(content) el.appendChild(content)
@ -226,9 +226,9 @@ L.DomUtil.add = (tagName, className, container, content) => {
L.DomUtil.createFieldset = (container, legend, options) => { L.DomUtil.createFieldset = (container, legend, options) => {
options = options || {} options = options || {}
var fieldset = L.DomUtil.create('div', 'fieldset toggle', container) const fieldset = L.DomUtil.create('div', 'fieldset toggle', container)
var legendEl = L.DomUtil.add('h5', 'legend style_options_toggle', fieldset, legend) const legendEl = L.DomUtil.add('h5', 'legend style_options_toggle', fieldset, legend)
var fieldsEl = L.DomUtil.add('div', 'fields with-transition', fieldset) const fieldsEl = L.DomUtil.add('div', 'fields with-transition', fieldset)
L.DomEvent.on(legendEl, 'click', function () { L.DomEvent.on(legendEl, 'click', function () {
if (L.DomUtil.hasClass(fieldset, 'on')) { if (L.DomUtil.hasClass(fieldset, 'on')) {
L.DomUtil.removeClass(fieldset, 'on') L.DomUtil.removeClass(fieldset, 'on')
@ -246,8 +246,8 @@ L.DomUtil.classIf = (el, className, bool) => {
} }
L.DomUtil.element = (what, attrs, parent) => { L.DomUtil.element = (what, attrs, parent) => {
var el = document.createElement(what) const el = document.createElement(what)
for (var attr in attrs) { for (const attr in attrs) {
el[attr] = attrs[attr] el[attr] = attrs[attr]
} }
if (typeof parent !== 'undefined') { if (typeof parent !== 'undefined') {
@ -269,11 +269,11 @@ L.DomUtil.after = (target, el) => {
L.DomUtil.RGBRegex = /rgb *\( *([0-9]{1,3}) *, *([0-9]{1,3}) *, *([0-9]{1,3}) *\)/ L.DomUtil.RGBRegex = /rgb *\( *([0-9]{1,3}) *, *([0-9]{1,3}) *, *([0-9]{1,3}) *\)/
L.DomUtil.TextColorFromBackgroundColor = (el) => { L.DomUtil.TextColorFromBackgroundColor = (el) => {
var out = '#000000' let out = '#000000'
if (!window.getComputedStyle) { if (!window.getComputedStyle) {
return out return out
} }
var rgb = window.getComputedStyle(el).getPropertyValue('background-color') let rgb = window.getComputedStyle(el).getPropertyValue('background-color')
rgb = L.DomUtil.RGBRegex.exec(rgb) rgb = L.DomUtil.RGBRegex.exec(rgb)
if (!rgb || rgb.length !== 4) { if (!rgb || rgb.length !== 4) {
return out return out
@ -288,13 +288,13 @@ L.DomEvent.once = (el, types, fn, context) => {
// cf https://github.com/Leaflet/Leaflet/pull/3528#issuecomment-134551575 // cf https://github.com/Leaflet/Leaflet/pull/3528#issuecomment-134551575
if (typeof types === 'object') { if (typeof types === 'object') {
for (var type in types) { for (const type in types) {
L.DomEvent.once(el, type, types[type], fn) L.DomEvent.once(el, type, types[type], fn)
} }
return L.DomEvent return L.DomEvent
} }
var handler = L.bind(() => { const handler = L.bind(() => {
L.DomEvent.off(el, types, fn, context).off(el, types, handler, context) L.DomEvent.off(el, types, fn, context).off(el, types, handler, context)
}, L.DomEvent) }, L.DomEvent)
@ -336,17 +336,17 @@ L.U.Help = L.Class.extend({
'umap-help-box with-transition dark', 'umap-help-box with-transition dark',
document.body document.body
) )
var closeLink = L.DomUtil.create('a', 'umap-close-link', this.box) const closeLink = L.DomUtil.create('a', 'umap-close-link', this.box)
closeLink.href = '#' closeLink.href = '#'
L.DomUtil.add('i', 'umap-close-icon', closeLink) L.DomUtil.add('i', 'umap-close-icon', closeLink)
var label = L.DomUtil.create('span', '', closeLink) const label = L.DomUtil.create('span', '', closeLink)
label.title = label.textContent = L._('Close') label.title = label.textContent = L._('Close')
this.content = L.DomUtil.create('div', 'umap-help-content', this.box) this.content = L.DomUtil.create('div', 'umap-help-content', this.box)
L.DomEvent.on(closeLink, 'click', this.hide, this) L.DomEvent.on(closeLink, 'click', this.hide, this)
}, },
onKeyDown: function (e) { onKeyDown: function (e) {
var key = e.keyCode, const key = e.keyCode,
ESC = 27 ESC = 27
if (key === ESC) { if (key === ESC) {
this.hide() this.hide()
@ -355,7 +355,7 @@ L.U.Help = L.Class.extend({
show: function () { show: function () {
this.content.innerHTML = '' this.content.innerHTML = ''
for (var i = 0, name; i < arguments.length; i++) { for (let i = 0, name; i < arguments.length; i++) {
name = arguments[i] name = arguments[i]
L.DomUtil.add('div', 'umap-help-entry', this.content, this.resolve(name)) L.DomUtil.add('div', 'umap-help-entry', this.content, this.resolve(name))
} }
@ -375,14 +375,14 @@ L.U.Help = L.Class.extend({
}, },
button: function (container, entries) { button: function (container, entries) {
var helpButton = L.DomUtil.create('a', 'umap-help-button', container) const helpButton = L.DomUtil.create('a', 'umap-help-button', container)
helpButton.href = '#' helpButton.href = '#'
if (entries) { if (entries) {
L.DomEvent.on(helpButton, 'click', L.DomEvent.stop).on( L.DomEvent.on(helpButton, 'click', L.DomEvent.stop).on(
helpButton, helpButton,
'click', 'click',
function (e) { function (e) {
var args = typeof entries === 'string' ? [entries] : entries const args = typeof entries === 'string' ? [entries] : entries
this.show.apply(this, args) this.show.apply(this, args)
}, },
this this
@ -392,26 +392,26 @@ L.U.Help = L.Class.extend({
}, },
edit: function () { edit: function () {
var container = L.DomUtil.create('div', ''), const container = L.DomUtil.create('div', ''),
self = this, self = this,
title = L.DomUtil.create('h3', '', container), title = L.DomUtil.create('h3', '', container),
actionsContainer = L.DomUtil.create('ul', 'umap-edit-actions', container) actionsContainer = L.DomUtil.create('ul', 'umap-edit-actions', container)
var addAction = (action) => { const addAction = (action) => {
var actionContainer = L.DomUtil.add('li', '', actionsContainer) const actionContainer = L.DomUtil.add('li', '', actionsContainer)
L.DomUtil.add('i', action.options.className, actionContainer), L.DomUtil.add('i', action.options.className, actionContainer),
L.DomUtil.add('span', '', actionContainer, action.options.tooltip) L.DomUtil.add('span', '', actionContainer, action.options.tooltip)
L.DomEvent.on(actionContainer, 'click', action.addHooks, action) L.DomEvent.on(actionContainer, 'click', action.addHooks, action)
L.DomEvent.on(actionContainer, 'click', self.hide, self) L.DomEvent.on(actionContainer, 'click', self.hide, self)
} }
title.textContent = L._('Where do we go from here?') title.textContent = L._('Where do we go from here?')
for (var id in this.map.helpMenuActions) { for (const id in this.map.helpMenuActions) {
addAction(this.map.helpMenuActions[id]) addAction(this.map.helpMenuActions[id])
} }
return container return container
}, },
importFormats: function () { importFormats: function () {
var container = L.DomUtil.create('div') const container = L.DomUtil.create('div')
L.DomUtil.add('h3', '', container, 'GeojSON') L.DomUtil.add('h3', '', container, 'GeojSON')
L.DomUtil.add('p', '', container, L._('All properties are imported.')) L.DomUtil.add('p', '', container, L._('All properties are imported.'))
L.DomUtil.add('h3', '', container, 'GPX') L.DomUtil.add('h3', '', container, 'GPX')
@ -438,7 +438,7 @@ L.U.Help = L.Class.extend({
}, },
textFormatting: function () { textFormatting: function () {
var container = L.DomUtil.create('div'), const container = L.DomUtil.create('div'),
title = L.DomUtil.add('h3', '', container, L._('Text formatting')), title = L.DomUtil.add('h3', '', container, L._('Text formatting')),
elements = L.DomUtil.create('ul', '', container) elements = L.DomUtil.create('ul', '', container)
L.DomUtil.add('li', '', elements, L._('*simple star for italic*')) L.DomUtil.add('li', '', elements, L._('*simple star for italic*'))
@ -480,7 +480,7 @@ L.U.Help = L.Class.extend({
}, },
dynamicProperties: function () { dynamicProperties: function () {
var container = L.DomUtil.create('div') const container = L.DomUtil.create('div')
L.DomUtil.add('h3', '', container, L._('Dynamic properties')) L.DomUtil.add('h3', '', container, L._('Dynamic properties'))
L.DomUtil.add( L.DomUtil.add(
'p', 'p',
@ -544,7 +544,7 @@ L.U.Orderable = L.Evented.extend({
this.src = null this.src = null
this.dst = null this.dst = null
this.els = this.parent.querySelectorAll(this.options.selector) this.els = this.parent.querySelectorAll(this.options.selector)
for (var i = 0; i < this.els.length; i++) this.makeDraggable(this.els[i]) for (let i = 0; i < this.els.length; i++) this.makeDraggable(this.els[i])
}, },
makeDraggable: function (node) { makeDraggable: function (node) {
@ -586,10 +586,10 @@ L.U.Orderable = L.Evented.extend({
onDragEnter: function (e) { onDragEnter: function (e) {
// e.target is the current hover target. // e.target is the current hover target.
var dst = this.findTarget(e.target) const dst = this.findTarget(e.target)
if (!dst || dst === this.src) return if (!dst || dst === this.src) return
this.dst = dst this.dst = dst
var targetIndex = this.nodeIndex(this.dst), const targetIndex = this.nodeIndex(this.dst),
srcIndex = this.nodeIndex(this.src) srcIndex = this.nodeIndex(this.src)
if (targetIndex > srcIndex) this.parent.insertBefore(this.dst, this.src) if (targetIndex > srcIndex) this.parent.insertBefore(this.dst, this.src)
else this.parent.insertBefore(this.src, this.dst) else this.parent.insertBefore(this.src, this.dst)

View file

@ -12,8 +12,8 @@ L.U.FeatureMixin = {
if (options.geojson) { if (options.geojson) {
this.populate(options.geojson) this.populate(options.geojson)
} }
var isDirty = false, let isDirty = false
self = this const self = this
try { try {
Object.defineProperty(this, 'isDirty', { Object.defineProperty(this, 'isDirty', {
get: function () { get: function () {
@ -60,7 +60,7 @@ L.U.FeatureMixin = {
view: function (e) { view: function (e) {
if (this.map.editEnabled) return if (this.map.editEnabled) return
var outlink = this.properties._umap_options.outlink, const outlink = this.properties._umap_options.outlink,
target = this.properties._umap_options.outlinkTarget target = this.properties._umap_options.outlinkTarget
if (outlink) { if (outlink) {
switch (target) { switch (target) {
@ -71,7 +71,7 @@ L.U.FeatureMixin = {
window.top.location = outlink window.top.location = outlink
break break
default: default:
var win = window.open(this.properties._umap_options.outlink) const win = window.open(this.properties._umap_options.outlink)
} }
return return
} }
@ -89,18 +89,18 @@ L.U.FeatureMixin = {
edit: function (e) { edit: function (e) {
if (!this.map.editEnabled || this.isReadOnly()) return if (!this.map.editEnabled || this.isReadOnly()) return
var container = L.DomUtil.create('div', 'umap-datalayer-container') const container = L.DomUtil.create('div', 'umap-datalayer-container')
var builder = new L.U.FormBuilder(this, ['datalayer'], { let builder = new L.U.FormBuilder(this, ['datalayer'], {
callback: function () { callback: function () {
this.edit(e) this.edit(e)
}, // removeLayer step will close the edit panel, let's reopen it }, // removeLayer step will close the edit panel, let's reopen it
}) })
container.appendChild(builder.build()) container.appendChild(builder.build())
var properties = [], const properties = []
property let property
for (var i = 0; i < this.datalayer._propertiesIndex.length; i++) { for (let i = 0; i < this.datalayer._propertiesIndex.length; i++) {
property = this.datalayer._propertiesIndex[i] property = this.datalayer._propertiesIndex[i]
if (L.Util.indexOf(['name', 'description'], property) !== -1) { if (L.Util.indexOf(['name', 'description'], property) !== -1) {
continue continue
@ -116,7 +116,7 @@ L.U.FeatureMixin = {
}) })
container.appendChild(builder.build()) container.appendChild(builder.build())
this.appendEditFieldsets(container) this.appendEditFieldsets(container)
var advancedActions = L.DomUtil.createFieldset(container, L._('Advanced actions')) const advancedActions = L.DomUtil.createFieldset(container, L._('Advanced actions'))
this.getAdvancedEditActions(advancedActions) this.getAdvancedEditActions(advancedActions)
this.map.ui.openPanel({ data: { html: container }, className: 'dark' }) this.map.ui.openPanel({ data: { html: container }, className: 'dark' })
this.map.editedFeature = this this.map.editedFeature = this
@ -124,7 +124,7 @@ L.U.FeatureMixin = {
}, },
getAdvancedEditActions: function (container) { getAdvancedEditActions: function (container) {
var deleteLink = L.DomUtil.create('a', 'button umap-delete', container) const deleteLink = L.DomUtil.create('a', 'button umap-delete', container)
deleteLink.href = '#' deleteLink.href = '#'
deleteLink.textContent = L._('Delete') deleteLink.textContent = L._('Delete')
L.DomEvent.on( L.DomEvent.on(
@ -139,30 +139,33 @@ L.U.FeatureMixin = {
}, },
appendEditFieldsets: function (container) { appendEditFieldsets: function (container) {
var optionsFields = this.getShapeOptions() const optionsFields = this.getShapeOptions()
var builder = new L.U.FormBuilder(this, optionsFields, { var builder = new L.U.FormBuilder(this, optionsFields, {
id: 'umap-feature-shape-properties', id: 'umap-feature-shape-properties',
callback: this._redraw, callback: this._redraw,
}) })
var shapeProperties = L.DomUtil.createFieldset(container, L._('Shape properties')) const shapeProperties = L.DomUtil.createFieldset(container, L._('Shape properties'))
shapeProperties.appendChild(builder.build()) shapeProperties.appendChild(builder.build())
var advancedOptions = this.getAdvancedOptions() const advancedOptions = this.getAdvancedOptions()
var builder = new L.U.FormBuilder(this, advancedOptions, { var builder = new L.U.FormBuilder(this, advancedOptions, {
id: 'umap-feature-advanced-properties', id: 'umap-feature-advanced-properties',
callback: this._redraw, callback: this._redraw,
}) })
var advancedProperties = L.DomUtil.createFieldset( const advancedProperties = L.DomUtil.createFieldset(
container, container,
L._('Advanced properties') L._('Advanced properties')
) )
advancedProperties.appendChild(builder.build()) advancedProperties.appendChild(builder.build())
var interactionOptions = this.getInteractionOptions() const interactionOptions = this.getInteractionOptions()
builder = new L.U.FormBuilder(this, interactionOptions, { builder = new L.U.FormBuilder(this, interactionOptions, {
callback: this._redraw, callback: this._redraw,
}) })
var popupFieldset = L.DomUtil.createFieldset(container, L._('Interaction options')) const popupFieldset = L.DomUtil.createFieldset(
container,
L._('Interaction options')
)
popupFieldset.appendChild(builder.build()) popupFieldset.appendChild(builder.build())
}, },
@ -180,7 +183,7 @@ L.U.FeatureMixin = {
getDisplayName: function (fallback) { getDisplayName: function (fallback) {
if (fallback === undefined) fallback = this.datalayer.options.name if (fallback === undefined) fallback = this.datalayer.options.name
var key = this.getOption('labelKey') || 'name' const key = this.getOption('labelKey') || 'name'
// Variables mode. // Variables mode.
if (key.indexOf('{') != -1) if (key.indexOf('{') != -1)
return L.Util.greedyTemplate(key, this.extendedProperties()) return L.Util.greedyTemplate(key, this.extendedProperties())
@ -196,12 +199,12 @@ L.U.FeatureMixin = {
}, },
getPopupClass: function () { getPopupClass: function () {
var old = this.getOption('popupTemplate') // Retrocompat. const old = this.getOption('popupTemplate') // Retrocompat.
return L.U.Popup[this.getOption('popupShape') || old] || L.U.Popup return L.U.Popup[this.getOption('popupShape') || old] || L.U.Popup
}, },
attachPopup: function () { attachPopup: function () {
var Class = this.getPopupClass() const Class = this.getPopupClass()
this.bindPopup(new Class(this)) this.bindPopup(new Class(this))
}, },
@ -258,7 +261,7 @@ L.U.FeatureMixin = {
}, },
getOption: function (option, fallback) { getOption: function (option, fallback) {
var value = fallback let value = fallback
if (typeof this.staticOptions[option] !== 'undefined') { if (typeof this.staticOptions[option] !== 'undefined') {
value = this.staticOptions[option] value = this.staticOptions[option]
} else if (L.Util.usableOption(this.properties._umap_options, option)) { } else if (L.Util.usableOption(this.properties._umap_options, option)) {
@ -273,11 +276,11 @@ L.U.FeatureMixin = {
zoomTo: function (e) { zoomTo: function (e) {
e = e || {} e = e || {}
var easing = e.easing !== undefined ? e.easing : this.map.options.easing const easing = e.easing !== undefined ? e.easing : this.map.options.easing
if (easing) { if (easing) {
this.map.flyTo(this.getCenter(), this.getBestZoom()) this.map.flyTo(this.getCenter(), this.getBestZoom())
} else { } else {
var latlng = e.latlng || this.getCenter() const latlng = e.latlng || this.getCenter()
this.map.setView(latlng, this.getBestZoom() || this.map.getZoom()) this.map.setView(latlng, this.getBestZoom() || this.map.getZoom())
} }
if (e.callback) e.callback.call(this) if (e.callback) e.callback.call(this)
@ -296,7 +299,7 @@ L.U.FeatureMixin = {
}, },
cloneProperties: function () { cloneProperties: function () {
var properties = L.extend({}, this.properties) const properties = L.extend({}, this.properties)
properties._umap_options = L.extend({}, properties._umap_options) properties._umap_options = L.extend({}, properties._umap_options)
if (Object.keys && Object.keys(properties._umap_options).length === 0) { if (Object.keys && Object.keys(properties._umap_options).length === 0) {
delete properties._umap_options // It can make a difference on big data sets delete properties._umap_options // It can make a difference on big data sets
@ -315,7 +318,7 @@ L.U.FeatureMixin = {
}, },
toGeoJSON: function () { toGeoJSON: function () {
var geojson = this.parentClass.prototype.toGeoJSON.call(this) const geojson = this.parentClass.prototype.toGeoJSON.call(this)
geojson.properties = this.cloneProperties() geojson.properties = this.cloneProperties()
delete geojson.properties._storage_options delete geojson.properties._storage_options
return geojson return geojson
@ -356,7 +359,7 @@ L.U.FeatureMixin = {
_showContextMenu: function (e) { _showContextMenu: function (e) {
L.DomEvent.stop(e) L.DomEvent.stop(e)
var pt = this.map.mouseEventToContainerPoint(e.originalEvent) const pt = this.map.mouseEventToContainerPoint(e.originalEvent)
e.relatedTarget = this e.relatedTarget = this
this.map.contextmenu.showAt(pt, e) this.map.contextmenu.showAt(pt, e)
}, },
@ -370,8 +373,8 @@ L.U.FeatureMixin = {
}, },
getContextMenuItems: function (e) { getContextMenuItems: function (e) {
var permalink = this.getPermalink(), const permalink = this.getPermalink()
items = [] let items = []
if (permalink) if (permalink)
items.push({ items.push({
text: L._('Permalink'), text: L._('Permalink'),
@ -386,7 +389,7 @@ L.U.FeatureMixin = {
}, },
getContextMenuEditItems: function () { getContextMenuEditItems: function () {
var items = ['-'] let items = ['-']
if (this.map.editedFeature !== this) { if (this.map.editedFeature !== this) {
items.push({ items.push({
text: L._('Edit this feature'), text: L._('Edit this feature'),
@ -426,13 +429,15 @@ L.U.FeatureMixin = {
}, },
resetTooltip: function () { resetTooltip: function () {
var displayName = this.getDisplayName(null), const displayName = this.getDisplayName(null)
showLabel = this.getOption('showLabel'), let showLabel = this.getOption('showLabel')
oldLabelHover = this.getOption('labelHover'), const oldLabelHover = this.getOption('labelHover')
options = {
const options = {
direction: this.getOption('labelDirection'), direction: this.getOption('labelDirection'),
interactive: this.getOption('labelInteractive'), interactive: this.getOption('labelInteractive'),
} }
if (oldLabelHover && showLabel) showLabel = null // Retrocompat. if (oldLabelHover && showLabel) showLabel = null // Retrocompat.
options.permanent = showLabel === true options.permanent = showLabel === true
this.unbindTooltip() this.unbindTooltip()
@ -442,7 +447,7 @@ L.U.FeatureMixin = {
matchFilter: function (filter, keys) { matchFilter: function (filter, keys) {
filter = filter.toLowerCase() filter = filter.toLowerCase()
for (var i = 0; i < keys.length; i++) { for (let i = 0; i < keys.length; i++) {
if ((this.properties[keys[i]] || '').toLowerCase().indexOf(filter) !== -1) if ((this.properties[keys[i]] || '').toLowerCase().indexOf(filter) !== -1)
return true return true
} }
@ -465,7 +470,7 @@ L.U.FeatureMixin = {
}, },
clone: function () { clone: function () {
var layer = this.datalayer.geojsonToFeatures(this.toGeoJSON()) const layer = this.datalayer.geojsonToFeatures(this.toGeoJSON())
layer.isDirty = true layer.isDirty = true
layer.edit() layer.edit()
return layer return layer
@ -573,7 +578,7 @@ L.U.Marker = L.Marker.extend({
}, },
getIcon: function () { getIcon: function () {
var Class = L.U.Icon[this.getIconClass()] || L.U.Icon.Default const Class = L.U.Icon[this.getIconClass()] || L.U.Icon.Default
return new Class(this.map, { feature: this }) return new Class(this.map, { feature: this })
}, },
@ -599,11 +604,11 @@ L.U.Marker = L.Marker.extend({
appendEditFieldsets: function (container) { appendEditFieldsets: function (container) {
L.U.FeatureMixin.appendEditFieldsets.call(this, container) L.U.FeatureMixin.appendEditFieldsets.call(this, container)
var coordinatesOptions = [ const coordinatesOptions = [
['_latlng.lat', { handler: 'FloatInput', label: L._('Latitude') }], ['_latlng.lat', { handler: 'FloatInput', label: L._('Latitude') }],
['_latlng.lng', { handler: 'FloatInput', label: L._('Longitude') }], ['_latlng.lng', { handler: 'FloatInput', label: L._('Longitude') }],
] ]
var builder = new L.U.FormBuilder(this, coordinatesOptions, { const builder = new L.U.FormBuilder(this, coordinatesOptions, {
callback: function () { callback: function () {
if (!this._latlng.isValid()) if (!this._latlng.isValid())
return this.map.ui.alert({ return this.map.ui.alert({
@ -615,7 +620,7 @@ L.U.Marker = L.Marker.extend({
}, },
callbackContext: this, callbackContext: this,
}) })
var fieldset = L.DomUtil.createFieldset(container, L._('Coordinates')) const fieldset = L.DomUtil.createFieldset(container, L._('Coordinates'))
fieldset.appendChild(builder.build()) fieldset.appendChild(builder.build())
}, },
@ -629,7 +634,7 @@ L.U.Marker = L.Marker.extend({
}, },
isOnScreen: function () { isOnScreen: function () {
var bounds = this.map.getBounds() const bounds = this.map.getBounds()
return bounds.contains(this._latlng) return bounds.contains(this._latlng)
}, },
@ -696,8 +701,8 @@ L.U.PathMixin = {
setStyle: function (options) { setStyle: function (options) {
options = options || {} options = options || {}
var option let option
for (var idx in this.styleOptions) { for (const idx in this.styleOptions) {
option = this.styleOptions[idx] option = this.styleOptions[idx]
options[option] = this.getOption(option) options[option] = this.getOption(option)
} }
@ -759,7 +764,7 @@ L.U.PathMixin = {
}, },
transferShape: function (at, to) { transferShape: function (at, to) {
var shape = this.enableEdit().deleteShapeAt(at) const shape = this.enableEdit().deleteShapeAt(at)
this.disableEdit() this.disableEdit()
if (!shape) return if (!shape) return
to.enableEdit().appendShape(shape) to.enableEdit().appendShape(shape)
@ -768,11 +773,11 @@ L.U.PathMixin = {
isolateShape: function (at) { isolateShape: function (at) {
if (!this.isMulti()) return if (!this.isMulti()) return
var shape = this.enableEdit().deleteShapeAt(at) const shape = this.enableEdit().deleteShapeAt(at)
this.disableEdit() this.disableEdit()
if (!shape) return if (!shape) return
var properties = this.cloneProperties() const properties = this.cloneProperties()
var other = new (this instanceof L.U.Polyline ? L.U.Polyline : L.U.Polygon)( const other = new (this instanceof L.U.Polyline ? L.U.Polyline : L.U.Polygon)(
this.map, this.map,
shape, shape,
{ geojson: { properties: properties } } { geojson: { properties: properties } }
@ -783,7 +788,7 @@ L.U.PathMixin = {
}, },
getContextMenuItems: function (e) { getContextMenuItems: function (e) {
var items = L.U.FeatureMixin.getContextMenuItems.call(this, e) let items = L.U.FeatureMixin.getContextMenuItems.call(this, e)
items.push({ items.push({
text: L._('Display measure'), text: L._('Display measure'),
callback: function () { callback: function () {
@ -798,7 +803,7 @@ L.U.PathMixin = {
}, },
getContextMenuMultiItems: function (e) { getContextMenuMultiItems: function (e) {
var items = [ const items = [
'-', '-',
{ {
text: L._('Remove shape from the multi'), text: L._('Remove shape from the multi'),
@ -808,7 +813,7 @@ L.U.PathMixin = {
context: this, context: this,
}, },
] ]
var shape = this.shapeAt(e.latlng) const shape = this.shapeAt(e.latlng)
if (this._latlngs.indexOf(shape) > 0) { if (this._latlngs.indexOf(shape) > 0) {
items.push({ items.push({
text: L._('Make main shape'), text: L._('Make main shape'),
@ -823,7 +828,7 @@ L.U.PathMixin = {
}, },
getContextMenuEditItems: function (e) { getContextMenuEditItems: function (e) {
var items = L.U.FeatureMixin.getContextMenuEditItems.call(this, e) const items = L.U.FeatureMixin.getContextMenuEditItems.call(this, e)
if ( if (
this.map.editedFeature && this.map.editedFeature &&
this.isSameClass(this.map.editedFeature) && this.isSameClass(this.map.editedFeature) &&
@ -850,7 +855,7 @@ L.U.PathMixin = {
}, },
getInplaceToolbarActions: function (e) { getInplaceToolbarActions: function (e) {
var items = L.U.FeatureMixin.getInplaceToolbarActions.call(this, e) const items = L.U.FeatureMixin.getInplaceToolbarActions.call(this, e)
if (this.isMulti()) { if (this.isMulti()) {
items.push(L.U.DeleteShapeAction) items.push(L.U.DeleteShapeAction)
items.push(L.U.ExtractShapeFromMultiAction) items.push(L.U.ExtractShapeFromMultiAction)
@ -859,7 +864,7 @@ L.U.PathMixin = {
}, },
isOnScreen: function () { isOnScreen: function () {
var bounds = this.map.getBounds() const bounds = this.map.getBounds()
return bounds.overlaps(this.getBounds()) return bounds.overlaps(this.getBounds())
}, },
} }
@ -882,14 +887,14 @@ L.U.Polyline = L.Polyline.extend({
}, },
getMeasure: function (shape) { getMeasure: function (shape) {
var length = L.GeoUtil.lineLength(this.map, shape || this._defaultShape()) const length = L.GeoUtil.lineLength(this.map, shape || this._defaultShape())
return L.GeoUtil.readableDistance(length, this.map.measureTools.getMeasureUnit()) return L.GeoUtil.readableDistance(length, this.map.measureTools.getMeasureUnit())
}, },
getContextMenuEditItems: function (e) { getContextMenuEditItems: function (e) {
var items = L.U.PathMixin.getContextMenuEditItems.call(this, e), const items = L.U.PathMixin.getContextMenuEditItems.call(this, e)
vertexClicked = e.vertex, const vertexClicked = e.vertex
index let index
if (!this.isMulti()) { if (!this.isMulti()) {
items.push({ items.push({
text: L._('Transform to polygon'), text: L._('Transform to polygon'),
@ -917,7 +922,7 @@ L.U.Polyline = L.Polyline.extend({
}, },
getContextMenuMultiItems: function (e) { getContextMenuMultiItems: function (e) {
var items = L.U.PathMixin.getContextMenuMultiItems.call(this, e) const items = L.U.PathMixin.getContextMenuMultiItems.call(this, e)
items.push({ items.push({
text: L._('Merge lines'), text: L._('Merge lines'),
callback: this.mergeShapes, callback: this.mergeShapes,
@ -927,34 +932,34 @@ L.U.Polyline = L.Polyline.extend({
}, },
toPolygon: function () { toPolygon: function () {
var geojson = this.toGeoJSON() const geojson = this.toGeoJSON()
geojson.geometry.type = 'Polygon' geojson.geometry.type = 'Polygon'
geojson.geometry.coordinates = [ geojson.geometry.coordinates = [
L.Util.flattenCoordinates(geojson.geometry.coordinates), L.Util.flattenCoordinates(geojson.geometry.coordinates),
] ]
var polygon = this.datalayer.geojsonToFeatures(geojson) const polygon = this.datalayer.geojsonToFeatures(geojson)
polygon.edit() polygon.edit()
this.del() this.del()
}, },
getAdvancedEditActions: function (container) { getAdvancedEditActions: function (container) {
L.U.FeatureMixin.getAdvancedEditActions.call(this, container) L.U.FeatureMixin.getAdvancedEditActions.call(this, container)
var toPolygon = L.DomUtil.create('a', 'button umap-to-polygon', container) const toPolygon = L.DomUtil.create('a', 'button umap-to-polygon', container)
toPolygon.href = '#' toPolygon.href = '#'
toPolygon.textContent = L._('Transform to polygon') toPolygon.textContent = L._('Transform to polygon')
L.DomEvent.on(toPolygon, 'click', this.toPolygon, this) L.DomEvent.on(toPolygon, 'click', this.toPolygon, this)
}, },
_mergeShapes: function (from, to) { _mergeShapes: function (from, to) {
var toLeft = to[0], const toLeft = to[0]
toRight = to[to.length - 1], const toRight = to[to.length - 1]
fromLeft = from[0], const fromLeft = from[0]
fromRight = from[from.length - 1], const fromRight = from[from.length - 1]
l2ldistance = toLeft.distanceTo(fromLeft), const l2ldistance = toLeft.distanceTo(fromLeft)
l2rdistance = toLeft.distanceTo(fromRight), const l2rdistance = toLeft.distanceTo(fromRight)
r2ldistance = toRight.distanceTo(fromLeft), const r2ldistance = toRight.distanceTo(fromLeft)
r2rdistance = toRight.distanceTo(fromRight), const r2rdistance = toRight.distanceTo(fromRight)
toMerge let toMerge
if (l2rdistance < Math.min(l2ldistance, r2ldistance, r2rdistance)) { if (l2rdistance < Math.min(l2ldistance, r2ldistance, r2rdistance)) {
toMerge = [from, to] toMerge = [from, to]
} else if (r2ldistance < Math.min(l2ldistance, l2rdistance, r2rdistance)) { } else if (r2ldistance < Math.min(l2ldistance, l2rdistance, r2rdistance)) {
@ -966,7 +971,7 @@ L.U.Polyline = L.Polyline.extend({
from.reverse() from.reverse()
toMerge = [from, to] toMerge = [from, to]
} }
var a = toMerge[0], const a = toMerge[0],
b = toMerge[1], b = toMerge[1],
p1 = this.map.latLngToContainerPoint(a[a.length - 1]), p1 = this.map.latLngToContainerPoint(a[a.length - 1]),
p2 = this.map.latLngToContainerPoint(b[0]), p2 = this.map.latLngToContainerPoint(b[0]),
@ -979,7 +984,7 @@ L.U.Polyline = L.Polyline.extend({
mergeShapes: function () { mergeShapes: function () {
if (!this.isMulti()) return if (!this.isMulti()) return
var latlngs = this.getLatLngs() const latlngs = this.getLatLngs()
if (!latlngs.length) return if (!latlngs.length) return
while (latlngs.length > 1) { while (latlngs.length > 1) {
latlngs.splice(0, 2, this._mergeShapes(latlngs[1], latlngs[0])) latlngs.splice(0, 2, this._mergeShapes(latlngs[1], latlngs[0]))
@ -995,7 +1000,7 @@ L.U.Polyline = L.Polyline.extend({
}, },
getVertexActions: function (e) { getVertexActions: function (e) {
var actions = L.U.FeatureMixin.getVertexActions.call(this, e), const actions = L.U.FeatureMixin.getVertexActions.call(this, e),
index = e.vertex.getIndex() index = e.vertex.getIndex()
if (index === 0 || index === e.vertex.getLastIndex()) if (index === 0 || index === e.vertex.getLastIndex())
actions.push(L.U.ContinueLineAction) actions.push(L.U.ContinueLineAction)
@ -1017,7 +1022,7 @@ L.U.Polygon = L.Polygon.extend({
}, },
getShapeOptions: function () { getShapeOptions: function () {
var options = L.U.PathMixin.getShapeOptions() const options = L.U.PathMixin.getShapeOptions()
options.push( options.push(
'properties._umap_options.stroke', 'properties._umap_options.stroke',
'properties._umap_options.fill', 'properties._umap_options.fill',
@ -1028,7 +1033,7 @@ L.U.Polygon = L.Polygon.extend({
}, },
getInteractionOptions: function () { getInteractionOptions: function () {
var options = [ const options = [
[ [
'properties._umap_options.interactive', 'properties._umap_options.interactive',
{ {
@ -1056,12 +1061,12 @@ L.U.Polygon = L.Polygon.extend({
}, },
getMeasure: function (shape) { getMeasure: function (shape) {
var area = L.GeoUtil.geodesicArea(shape || this._defaultShape()) const area = L.GeoUtil.geodesicArea(shape || this._defaultShape())
return L.GeoUtil.readableArea(area, this.map.measureTools.getMeasureUnit()) return L.GeoUtil.readableArea(area, this.map.measureTools.getMeasureUnit())
}, },
getContextMenuEditItems: function (e) { getContextMenuEditItems: function (e) {
var items = L.U.PathMixin.getContextMenuEditItems.call(this, e), const items = L.U.PathMixin.getContextMenuEditItems.call(this, e),
shape = this.shapeAt(e.latlng) shape = this.shapeAt(e.latlng)
// No multi and no holes. // No multi and no holes.
if (shape && !this.isMulti() && (L.LineUtil.isFlat(shape) || shape.length === 1)) { if (shape && !this.isMulti() && (L.LineUtil.isFlat(shape) || shape.length === 1)) {
@ -1084,19 +1089,19 @@ L.U.Polygon = L.Polygon.extend({
}, },
toPolyline: function () { toPolyline: function () {
var geojson = this.toGeoJSON() const geojson = this.toGeoJSON()
geojson.geometry.type = 'LineString' geojson.geometry.type = 'LineString'
geojson.geometry.coordinates = L.Util.flattenCoordinates( geojson.geometry.coordinates = L.Util.flattenCoordinates(
geojson.geometry.coordinates geojson.geometry.coordinates
) )
var polyline = this.datalayer.geojsonToFeatures(geojson) const polyline = this.datalayer.geojsonToFeatures(geojson)
polyline.edit() polyline.edit()
this.del() this.del()
}, },
getAdvancedEditActions: function (container) { getAdvancedEditActions: function (container) {
L.U.FeatureMixin.getAdvancedEditActions.call(this, container) L.U.FeatureMixin.getAdvancedEditActions.call(this, container)
var toPolyline = L.DomUtil.create('a', 'button umap-to-polyline', container) const toPolyline = L.DomUtil.create('a', 'button umap-to-polyline', container)
toPolyline.href = '#' toPolyline.href = '#'
toPolyline.textContent = L._('Transform to lines') toPolyline.textContent = L._('Transform to lines')
L.DomEvent.on(toPolyline, 'click', this.toPolyline, this) L.DomEvent.on(toPolyline, 'click', this.toPolyline, this)
@ -1112,7 +1117,7 @@ L.U.Polygon = L.Polygon.extend({
}, },
getInplaceToolbarActions: function (e) { getInplaceToolbarActions: function (e) {
var items = L.U.PathMixin.getInplaceToolbarActions.call(this, e) const items = L.U.PathMixin.getInplaceToolbarActions.call(this, e)
items.push(L.U.CreateHoleAction) items.push(L.U.CreateHoleAction)
return items return items
}, },

View file

@ -7,7 +7,7 @@ L.FormBuilder.Element.include({
this.form this.form
) )
} }
var className = 'formbox' let className = 'formbox'
if (this.options.inheritable) { if (this.options.inheritable) {
className += className +=
this.get(true) === undefined ? ' inheritable undefined' : ' inheritable ' this.get(true) === undefined ? ' inheritable undefined' : ' inheritable '
@ -16,8 +16,8 @@ L.FormBuilder.Element.include({
this.wrapper = L.DomUtil.create('div', className, this.form) this.wrapper = L.DomUtil.create('div', className, this.form)
this.header = L.DomUtil.create('div', 'header', this.wrapper) this.header = L.DomUtil.create('div', 'header', this.wrapper)
if (this.options.inheritable) { if (this.options.inheritable) {
var undefine = L.DomUtil.add('a', 'button undefine', this.header, L._('clear')) const undefine = L.DomUtil.add('a', 'button undefine', this.header, L._('clear'))
var define = L.DomUtil.add('a', 'button define', this.header, L._('define')) const define = L.DomUtil.add('a', 'button define', this.header, L._('define'))
L.DomEvent.on( L.DomEvent.on(
define, define,
'click', 'click',
@ -60,7 +60,7 @@ L.FormBuilder.Element.include({
get: function (own) { get: function (own) {
if (!this.options.inheritable || own) return this.builder.getter(this.field) if (!this.options.inheritable || own) return this.builder.getter(this.field)
var path = this.field.split('.'), const path = this.field.split('.'),
key = path[path.length - 1] key = path[path.length - 1]
return this.obj.getOption(key) return this.obj.getOption(key)
}, },
@ -72,7 +72,7 @@ L.FormBuilder.Element.include({
if (this.options.helpEntries) if (this.options.helpEntries)
this.builder.map.help.button(this.label, this.options.helpEntries) this.builder.map.help.button(this.label, this.options.helpEntries)
else if (this.options.helpTooltip) { else if (this.options.helpTooltip) {
var info = L.DomUtil.create('i', 'info', this.label) const info = L.DomUtil.create('i', 'info', this.label)
L.DomEvent.on( L.DomEvent.on(
info, info,
'mouseover', 'mouseover',
@ -278,7 +278,7 @@ L.FormBuilder.ColorPicker = L.FormBuilder.Input.extend({
this.extendedContainer this.extendedContainer
) )
this.container.style.display = 'none' this.container.style.display = 'none'
for (var idx in this.colors) { for (const idx in this.colors) {
this.addColor(this.colors[idx]) this.addColor(this.colors[idx])
} }
this.spreadColor() this.spreadColor()
@ -295,7 +295,7 @@ L.FormBuilder.ColorPicker = L.FormBuilder.Input.extend({
}, },
onBlur: function () { onBlur: function () {
var self = this, const self = this,
closePicker = () => { closePicker = () => {
self.container.style.display = 'none' self.container.style.display = 'none'
} }
@ -314,9 +314,9 @@ L.FormBuilder.ColorPicker = L.FormBuilder.Input.extend({
}, },
addColor: function (colorName) { addColor: function (colorName) {
var span = L.DomUtil.create('span', '', this.container) const span = L.DomUtil.create('span', '', this.container)
span.style.backgroundColor = span.title = colorName span.style.backgroundColor = span.title = colorName
var updateColorInput = function () { const updateColorInput = function () {
this.input.value = colorName this.input.value = colorName
this.sync() this.sync()
this.container.style.display = 'none' this.container.style.display = 'none'
@ -384,8 +384,8 @@ L.FormBuilder.LayerTypeChooser = L.FormBuilder.Select.extend({
L.FormBuilder.SlideshowDelay = L.FormBuilder.IntSelect.extend({ L.FormBuilder.SlideshowDelay = L.FormBuilder.IntSelect.extend({
getOptions: function () { getOptions: function () {
var options = [] const options = []
for (var i = 1; i < 30; i++) { for (let i = 1; i < 30; i++) {
options.push([i * 1000, L._('{delay} seconds', { delay: i })]) options.push([i * 1000, L._('{delay} seconds', { delay: i })])
} }
return options return options
@ -394,7 +394,7 @@ L.FormBuilder.SlideshowDelay = L.FormBuilder.IntSelect.extend({
L.FormBuilder.DataLayerSwitcher = L.FormBuilder.Select.extend({ L.FormBuilder.DataLayerSwitcher = L.FormBuilder.Select.extend({
getOptions: function () { getOptions: function () {
var options = [] const options = []
this.builder.map.eachDataLayerReverse((datalayer) => { this.builder.map.eachDataLayerReverse((datalayer) => {
if (datalayer.isLoaded() && !datalayer.isRemoteLayer() && datalayer.canBrowse()) { if (datalayer.isLoaded() && !datalayer.isRemoteLayer() && datalayer.canBrowse()) {
options.push([L.stamp(datalayer), datalayer.getName()]) options.push([L.stamp(datalayer), datalayer.getName()])
@ -450,10 +450,10 @@ L.FormBuilder.LabelDirection = L.FormBuilder.Select.extend({
L.FormBuilder.LicenceChooser = L.FormBuilder.Select.extend({ L.FormBuilder.LicenceChooser = L.FormBuilder.Select.extend({
getOptions: function () { getOptions: function () {
var licences = [], const licences = []
licencesList = this.builder.obj.options.licences, const licencesList = this.builder.obj.options.licences
licence let licence
for (var i in licencesList) { for (const i in licencesList) {
licence = licencesList[i] licence = licencesList[i]
licences.push([i, licence.name]) licences.push([i, licence.name])
} }
@ -477,7 +477,7 @@ L.FormBuilder.NullableBoolean = L.FormBuilder.Select.extend({
], ],
toJS: function () { toJS: function () {
var value = this.value() let value = this.value()
switch (value) { switch (value) {
case 'true': case 'true':
case true: case true:
@ -498,7 +498,7 @@ L.FormBuilder.BlurInput.include({
build: function () { build: function () {
this.options.className = 'blur' this.options.className = 'blur'
L.FormBuilder.Input.prototype.build.call(this) L.FormBuilder.Input.prototype.build.call(this)
var button = L.DomUtil.create('span', 'button blur-button') const button = L.DomUtil.create('span', 'button blur-button')
L.DomUtil.after(this.input, button) L.DomUtil.after(this.input, button)
}, },
}) })
@ -536,7 +536,7 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({
if (this.value() && this.value().indexOf('{') === -1) { if (this.value() && this.value().indexOf('{') === -1) {
// Do not try to render URL with variables // Do not try to render URL with variables
if (this.isUrl()) { if (this.isUrl()) {
var img = L.DomUtil.create( const img = L.DomUtil.create(
'img', 'img',
'', '',
L.DomUtil.create('div', 'umap-icon-choice', this.buttonsContainer) L.DomUtil.create('div', 'umap-icon-choice', this.buttonsContainer)
@ -544,7 +544,7 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({
img.src = this.value() img.src = this.value()
L.DomEvent.on(img, 'click', this.fetchIconList, this) L.DomEvent.on(img, 'click', this.fetchIconList, this)
} else { } else {
var el = L.DomUtil.create( const el = L.DomUtil.create(
'span', 'span',
'', '',
L.DomUtil.create('div', 'umap-icon-choice', this.buttonsContainer) L.DomUtil.create('div', 'umap-icon-choice', this.buttonsContainer)
@ -565,7 +565,7 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({
}, },
addIconPreview: function (pictogram) { addIconPreview: function (pictogram) {
var baseClass = 'umap-icon-choice', const baseClass = 'umap-icon-choice',
value = pictogram.src, value = pictogram.src,
className = value === this.value() ? baseClass + ' selected' : baseClass, className = value === this.value() ? baseClass + ' selected' : baseClass,
container = L.DomUtil.create('div', className, this.pictogramsContainer), container = L.DomUtil.create('div', className, this.pictogramsContainer),
@ -600,10 +600,10 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({
buildIconList: function (data) { buildIconList: function (data) {
this.pictogramsContainer.innerHTML = '' this.pictogramsContainer.innerHTML = ''
this.buttonsContainer.innerHTML = '' this.buttonsContainer.innerHTML = ''
for (var idx in data.pictogram_list) { for (const idx in data.pictogram_list) {
this.addIconPreview(data.pictogram_list[idx]) this.addIconPreview(data.pictogram_list[idx])
} }
var cancelButton = L.DomUtil.create('a', '', this.pictogramsContainer) const cancelButton = L.DomUtil.create('a', '', this.pictogramsContainer)
cancelButton.textContent = L._('Cancel') cancelButton.textContent = L._('Cancel')
cancelButton.href = '#' cancelButton.href = '#'
cancelButton.style.display = 'block' cancelButton.style.display = 'block'
@ -617,7 +617,7 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({
}, },
this this
) )
var customButton = L.DomUtil.create('a', '', this.pictogramsContainer) const customButton = L.DomUtil.create('a', '', this.pictogramsContainer)
customButton.textContent = L._('Set symbol') customButton.textContent = L._('Set symbol')
customButton.href = '#' customButton.href = '#'
customButton.style.display = 'block' customButton.style.display = 'block'
@ -642,8 +642,8 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({
}, },
unselectAll: function (container) { unselectAll: function (container) {
var els = container.querySelectorAll('div.selected') const els = container.querySelectorAll('div.selected')
for (var el in els) { for (const el in els) {
if (els.hasOwnProperty(el)) L.DomUtil.removeClass(els[el], 'selected') if (els.hasOwnProperty(el)) L.DomUtil.removeClass(els[el], 'selected')
} }
}, },
@ -668,7 +668,7 @@ L.FormBuilder.Switch = L.FormBuilder.CheckBox.extend({
this.label = L.DomUtil.create('label', '', this.input.parentNode) this.label = L.DomUtil.create('label', '', this.input.parentNode)
else this.input.parentNode.appendChild(this.label) else this.input.parentNode.appendChild(this.label)
L.DomUtil.addClass(this.input.parentNode, 'with-switch') L.DomUtil.addClass(this.input.parentNode, 'with-switch')
var id = (this.builder.options.id || Date.now()) + '.' + this.name const id = (this.builder.options.id || Date.now()) + '.' + this.name
this.label.setAttribute('for', id) this.label.setAttribute('for', id)
L.DomUtil.addClass(this.input, 'switch') L.DomUtil.addClass(this.input, 'switch')
this.input.id = id this.input.id = id
@ -680,12 +680,12 @@ L.FormBuilder.MultiChoice = L.FormBuilder.Element.extend({
className: 'umap-multiplechoice', className: 'umap-multiplechoice',
clear: function () { clear: function () {
var checked = this.container.querySelector('input[type="radio"]:checked') const checked = this.container.querySelector('input[type="radio"]:checked')
if (checked) checked.checked = false if (checked) checked.checked = false
}, },
fetch: function () { fetch: function () {
var value = (this.backup = this.toHTML()) let value = (this.backup = this.toHTML())
if (!this.container.querySelector('input[type="radio"][value="' + value + '"]')) if (!this.container.querySelector('input[type="radio"][value="' + value + '"]'))
value = this.default value = this.default
this.container.querySelector( this.container.querySelector(
@ -694,7 +694,7 @@ L.FormBuilder.MultiChoice = L.FormBuilder.Element.extend({
}, },
value: function () { value: function () {
var checked = this.container.querySelector('input[type="radio"]:checked') const checked = this.container.querySelector('input[type="radio"]:checked')
if (checked) return checked.value if (checked) return checked.value
}, },
@ -703,25 +703,25 @@ L.FormBuilder.MultiChoice = L.FormBuilder.Element.extend({
}, },
build: function () { build: function () {
var choices = this.getChoices() const choices = this.getChoices()
this.container = L.DomUtil.create( this.container = L.DomUtil.create(
'div', 'div',
this.className + ' by' + choices.length, this.className + ' by' + choices.length,
this.parentNode this.parentNode
) )
for (var i = 0; i < choices.length; i++) { for (let i = 0; i < choices.length; i++) {
this.addChoice(choices[i][0], choices[i][1], i) this.addChoice(choices[i][0], choices[i][1], i)
} }
this.fetch() this.fetch()
}, },
addChoice: function (value, label, counter) { addChoice: function (value, label, counter) {
var input = L.DomUtil.create('input', '', this.container) const input = L.DomUtil.create('input', '', this.container)
label = L.DomUtil.add('label', '', this.container, label) label = L.DomUtil.add('label', '', this.container, label)
input.type = 'radio' input.type = 'radio'
input.name = this.name input.name = this.name
input.value = value input.value = value
var id = Date.now() + '.' + this.name + '.' + counter const id = Date.now() + '.' + this.name + '.' + counter
label.setAttribute('for', id) label.setAttribute('for', id)
input.id = id input.id = id
L.DomEvent.on(input, 'change', this.sync, this) L.DomEvent.on(input, 'change', this.sync, this)
@ -732,7 +732,7 @@ L.FormBuilder.TernaryChoices = L.FormBuilder.MultiChoice.extend({
default: 'null', default: 'null',
toJS: function () { toJS: function () {
var value = this.value() let value = this.value()
switch (value) { switch (value) {
case 'true': case 'true':
case true: case true:
@ -776,7 +776,7 @@ L.FormBuilder.DataLayersControl = L.FormBuilder.ControlChoice.extend({
], ],
toJS: function () { toJS: function () {
var value = this.value() let value = this.value()
if (value !== 'expanded') if (value !== 'expanded')
value = L.FormBuilder.ControlChoice.prototype.toJS.call(this) value = L.FormBuilder.ControlChoice.prototype.toJS.call(this)
return value return value
@ -803,15 +803,15 @@ L.FormBuilder.Range = L.FormBuilder.Input.extend({
}, },
buildHelpText: function () { buildHelpText: function () {
var datalist = L.DomUtil.create( const datalist = L.DomUtil.create(
'datalist', 'datalist',
'umap-field-datalist', 'umap-field-datalist',
this.getHelpTextParent() this.getHelpTextParent()
) )
datalist.id = `range-${this.options.label || this.name}` datalist.id = `range-${this.options.label || this.name}`
this.input.setAttribute('list', datalist.id) this.input.setAttribute('list', datalist.id)
var options = '' let options = ''
for (var i = this.options.min; i <= this.options.max; i += this.options.step) { for (let i = this.options.min; i <= this.options.max; i += this.options.step) {
options += `<option value="${i.toPrecision(2)}" label="${i.toPrecision( options += `<option value="${i.toPrecision(2)}" label="${i.toPrecision(
2 2
)}"></option>` )}"></option>`
@ -822,12 +822,12 @@ L.FormBuilder.Range = L.FormBuilder.Input.extend({
L.FormBuilder.ManageOwner = L.FormBuilder.Element.extend({ L.FormBuilder.ManageOwner = L.FormBuilder.Element.extend({
build: function () { build: function () {
var options = { const options = {
className: 'edit-owner', className: 'edit-owner',
on_select: L.bind(this.onSelect, this), on_select: L.bind(this.onSelect, this),
} }
this.autocomplete = new L.U.AutoComplete.Ajax.Select(this.parentNode, options) this.autocomplete = new L.U.AutoComplete.Ajax.Select(this.parentNode, options)
var owner = this.toHTML() const owner = this.toHTML()
if (owner) if (owner)
this.autocomplete.displaySelected({ this.autocomplete.displaySelected({
item: { value: owner.id, label: owner.name }, item: { value: owner.id, label: owner.name },
@ -850,7 +850,7 @@ L.FormBuilder.ManageOwner = L.FormBuilder.Element.extend({
L.FormBuilder.ManageEditors = L.FormBuilder.Element.extend({ L.FormBuilder.ManageEditors = L.FormBuilder.Element.extend({
build: function () { build: function () {
var options = { const options = {
className: 'edit-editors', className: 'edit-editors',
on_select: L.bind(this.onSelect, this), on_select: L.bind(this.onSelect, this),
on_unselect: L.bind(this.onUnselect, this), on_unselect: L.bind(this.onUnselect, this),
@ -861,7 +861,7 @@ L.FormBuilder.ManageEditors = L.FormBuilder.Element.extend({
) )
this._values = this.toHTML() this._values = this.toHTML()
if (this._values) if (this._values)
for (var i = 0; i < this._values.length; i++) for (let i = 0; i < this._values.length; i++)
this.autocomplete.displaySelected({ this.autocomplete.displaySelected({
item: { value: this._values[i].id, label: this._values[i].name }, item: { value: this._values[i].id, label: this._values[i].name },
}) })
@ -881,7 +881,7 @@ L.FormBuilder.ManageEditors = L.FormBuilder.Element.extend({
}, },
onUnselect: function (choice) { onUnselect: function (choice) {
var index = this._values.findIndex((item) => item.id === choice.item.value) const index = this._values.findIndex((item) => item.id === choice.item.value)
if (index !== -1) { if (index !== -1) {
this._values.splice(index, 1) this._values.splice(index, 1)
this.set() this.set()

View file

@ -1,7 +1,7 @@
L.U.Icon = L.DivIcon.extend({ L.U.Icon = L.DivIcon.extend({
initialize: function (map, options) { initialize: function (map, options) {
this.map = map this.map = map
var default_options = { const default_options = {
iconSize: null, // Made in css iconSize: null, // Made in css
iconUrl: this.map.getDefaultOption('iconUrl'), iconUrl: this.map.getDefaultOption('iconUrl'),
feature: null, feature: null,
@ -15,7 +15,7 @@ L.U.Icon = L.DivIcon.extend({
}, },
_getIconUrl: function (name) { _getIconUrl: function (name) {
var url let url
if (this.feature && this.feature._getIconUrl(name)) if (this.feature && this.feature._getIconUrl(name))
url = this.feature._getIconUrl(name) url = this.feature._getIconUrl(name)
else url = this.options[name + 'Url'] else url = this.options[name + 'Url']
@ -23,7 +23,7 @@ L.U.Icon = L.DivIcon.extend({
}, },
_getColor: function () { _getColor: function () {
var color let color
if (this.feature) color = this.feature.getOption('color') if (this.feature) color = this.feature.getOption('color')
else if (this.options.color) color = this.options.color else if (this.options.color) color = this.options.color
else color = this.map.getDefaultOption('color') else color = this.map.getDefaultOption('color')
@ -49,7 +49,7 @@ L.U.Icon.Default = L.U.Icon.extend({
}, },
_setColor: function () { _setColor: function () {
var color = this._getColor() const color = this._getColor()
this.elements.container.style.backgroundColor = color this.elements.container.style.backgroundColor = color
this.elements.arrow.style.borderTopColor = color this.elements.arrow.style.borderTopColor = color
}, },
@ -63,7 +63,7 @@ L.U.Icon.Default = L.U.Icon.extend({
this.elements.main this.elements.main
) )
this.elements.arrow = L.DomUtil.create('div', 'icon_arrow', this.elements.main) this.elements.arrow = L.DomUtil.create('div', 'icon_arrow', this.elements.main)
var src = this._getIconUrl('icon') const src = this._getIconUrl('icon')
if (src) { if (src) {
// An url. // An url.
if ( if (
@ -86,7 +86,7 @@ L.U.Icon.Default = L.U.Icon.extend({
L.U.Icon.Circle = L.U.Icon.extend({ L.U.Icon.Circle = L.U.Icon.extend({
initialize: function (map, options) { initialize: function (map, options) {
var default_options = { const default_options = {
iconAnchor: new L.Point(6, 6), iconAnchor: new L.Point(6, 6),
popupAnchor: new L.Point(0, -6), popupAnchor: new L.Point(0, -6),
tooltipAnchor: new L.Point(6, 0), tooltipAnchor: new L.Point(6, 0),
@ -142,8 +142,8 @@ L.U.Icon.Ball = L.U.Icon.Default.extend({
}, },
_setColor: function () { _setColor: function () {
var color = this._getColor('color'), const color = this._getColor('color')
background let background
if (L.Browser.ielt9) { if (L.Browser.ielt9) {
background = color background = color
} else if (L.Browser.webkit) { } else if (L.Browser.webkit) {
@ -159,7 +159,7 @@ L.U.Icon.Ball = L.U.Icon.Default.extend({
}, },
}) })
var _CACHE_COLOR = {} const _CACHE_COLOR = {}
L.U.Icon.Cluster = L.DivIcon.extend({ L.U.Icon.Cluster = L.DivIcon.extend({
options: { options: {
iconSize: [40, 40], iconSize: [40, 40],
@ -171,7 +171,7 @@ L.U.Icon.Cluster = L.DivIcon.extend({
}, },
createIcon: function () { createIcon: function () {
var container = L.DomUtil.create('div', 'leaflet-marker-icon marker-cluster'), const container = L.DomUtil.create('div', 'leaflet-marker-icon marker-cluster'),
div = L.DomUtil.create('div', '', container), div = L.DomUtil.create('div', '', container),
span = L.DomUtil.create('span', '', div), span = L.DomUtil.create('span', '', div),
backgroundColor = this.datalayer.getColor() backgroundColor = this.datalayer.getColor()
@ -181,8 +181,8 @@ L.U.Icon.Cluster = L.DivIcon.extend({
}, },
computeTextColor: function (el) { computeTextColor: function (el) {
var color, let color
backgroundColor = this.datalayer.getColor() const backgroundColor = this.datalayer.getColor()
if (this.datalayer.options.cluster && this.datalayer.options.cluster.textColor) { if (this.datalayer.options.cluster && this.datalayer.options.cluster.textColor) {
color = this.datalayer.options.cluster.textColor color = this.datalayer.options.cluster.textColor
} }

View file

@ -68,12 +68,12 @@ L.U.Map.include({
L.setLocale(geojson.properties.locale) L.setLocale(geojson.properties.locale)
// Don't let default autocreation of controls // Don't let default autocreation of controls
var zoomControl = const zoomControl =
typeof geojson.properties.zoomControl !== 'undefined' typeof geojson.properties.zoomControl !== 'undefined'
? geojson.properties.zoomControl ? geojson.properties.zoomControl
: true : true
geojson.properties.zoomControl = false geojson.properties.zoomControl = false
var fullscreenControl = const fullscreenControl =
typeof geojson.properties.fullscreenControl !== 'undefined' typeof geojson.properties.fullscreenControl !== 'undefined'
? geojson.properties.fullscreenControl ? geojson.properties.fullscreenControl
: true : true
@ -105,7 +105,7 @@ L.U.Map.include({
L.Util.setBooleanFromQueryString(this.options, 'displayCaptionOnLoad') L.Util.setBooleanFromQueryString(this.options, 'displayCaptionOnLoad')
L.Util.setBooleanFromQueryString(this.options, 'captionBar') L.Util.setBooleanFromQueryString(this.options, 'captionBar')
L.Util.setBooleanFromQueryString(this.options, 'captionMenus') L.Util.setBooleanFromQueryString(this.options, 'captionMenus')
for (var i = 0; i < this.HIDDABLE_CONTROLS.length; i++) { for (let i = 0; i < this.HIDDABLE_CONTROLS.length; i++) {
L.Util.setNullableBooleanFromQueryString( L.Util.setNullableBooleanFromQueryString(
this.options, this.options,
this.HIDDABLE_CONTROLS[i] + 'Control' this.HIDDABLE_CONTROLS[i] + 'Control'
@ -121,8 +121,8 @@ L.U.Map.include({
if (L.Browser.ielt9) this.options.allowEdit = false // TODO include ie9 if (L.Browser.ielt9) this.options.allowEdit = false // TODO include ie9
var editedFeature = null, let editedFeature = null
self = this const self = this
try { try {
Object.defineProperty(this, 'editedFeature', { Object.defineProperty(this, 'editedFeature', {
get: function () { get: function () {
@ -188,7 +188,7 @@ L.U.Map.include({
this this
) )
var isDirty = false // global status let isDirty = false // global status
try { try {
Object.defineProperty(this, 'isDirty', { Object.defineProperty(this, 'isDirty', {
get: function () { get: function () {
@ -217,11 +217,11 @@ L.U.Map.include({
this._default_extent = true this._default_extent = true
this.options.name = L._('Untitled map') this.options.name = L._('Untitled map')
this.options.allowEdit = true this.options.allowEdit = true
var datalayer = this.createDataLayer() const datalayer = this.createDataLayer()
datalayer.connectToMap() datalayer.connectToMap()
this.enableEdit() this.enableEdit()
var dataUrl = L.Util.queryString('dataUrl', null), let dataUrl = L.Util.queryString('dataUrl', null)
dataFormat = L.Util.queryString('dataFormat', 'geojson') const dataFormat = L.Util.queryString('dataFormat', 'geojson')
if (dataUrl) { if (dataUrl) {
dataUrl = decodeURIComponent(dataUrl) dataUrl = decodeURIComponent(dataUrl)
dataUrl = this.localizeUrl(dataUrl) dataUrl = this.localizeUrl(dataUrl)
@ -257,7 +257,7 @@ L.U.Map.include({
}) })
window.onbeforeunload = (e) => { window.onbeforeunload = (e) => {
var msg = L._('You have unsaved changes.') const msg = L._('You have unsaved changes.')
if (self.isDirty) { if (self.isDirty) {
e.returnValue = msg e.returnValue = msg
return msg return msg
@ -277,7 +277,7 @@ L.U.Map.include({
new L.U.DrawToolbar({ map: this }).addTo(this) new L.U.DrawToolbar({ map: this }).addTo(this)
var editActions = [ const editActions = [
L.U.ImportAction, L.U.ImportAction,
L.U.EditPropertiesAction, L.U.EditPropertiesAction,
L.U.ChangeTileLayerAction, L.U.ChangeTileLayerAction,
@ -356,7 +356,7 @@ L.U.Map.include({
} }
}) })
} }
var name, status, control let name, status, control
for (var i = 0; i < this.HIDDABLE_CONTROLS.length; i++) { for (var i = 0; i < this.HIDDABLE_CONTROLS.length; i++) {
name = this.HIDDABLE_CONTROLS[i] name = this.HIDDABLE_CONTROLS[i]
status = this.options[name + 'Control'] status = this.options[name + 'Control']
@ -373,26 +373,26 @@ L.U.Map.include({
}, },
initDatalayers: function () { initDatalayers: function () {
var toload = (dataToload = seen = this.options.datalayers.length), let toload = (dataToload = seen = this.options.datalayers.length)
self = this, const self = this
datalayer let datalayer
var loaded = () => { const loaded = () => {
self.datalayersLoaded = true self.datalayersLoaded = true
self.fire('datalayersloaded') self.fire('datalayersloaded')
} }
var decrementToLoad = () => { const decrementToLoad = () => {
toload-- toload--
if (toload === 0) loaded() if (toload === 0) loaded()
} }
var dataLoaded = () => { const dataLoaded = () => {
self.dataLoaded = true self.dataLoaded = true
self.fire('dataloaded') self.fire('dataloaded')
} }
var decrementDataToLoad = () => { const decrementDataToLoad = () => {
dataToload-- dataToload--
if (dataToload === 0) dataLoaded() if (dataToload === 0) dataLoaded()
} }
for (var j = 0; j < this.options.datalayers.length; j++) { for (let j = 0; j < this.options.datalayers.length; j++) {
datalayer = this.createDataLayer(this.options.datalayers[j]) datalayer = this.createDataLayer(this.options.datalayers[j])
if (datalayer.displayedOnLoad()) datalayer.onceLoaded(decrementToLoad) if (datalayer.displayedOnLoad()) datalayer.onceLoaded(decrementToLoad)
else decrementToLoad() else decrementToLoad()
@ -403,10 +403,10 @@ L.U.Map.include({
}, },
indexDatalayers: function () { indexDatalayers: function () {
var panes = this.getPane('overlayPane'), const panes = this.getPane('overlayPane')
pane let pane
this.datalayers_index = [] this.datalayers_index = []
for (var i = 0; i < panes.children.length; i++) { for (let i = 0; i < panes.children.length; i++) {
pane = panes.children[i] pane = panes.children[i]
if (!pane.dataset || !pane.dataset.id) continue if (!pane.dataset || !pane.dataset.id) continue
this.datalayers_index.push(this.datalayers[pane.dataset.id]) this.datalayers_index.push(this.datalayers[pane.dataset.id])
@ -458,8 +458,8 @@ L.U.Map.include({
}, },
initShortcuts: function () { initShortcuts: function () {
var globalShortcuts = function (e) { const globalShortcuts = function (e) {
var key = e.keyCode, const key = e.keyCode,
modifierKey = e.ctrlKey || e.metaKey modifierKey = e.ctrlKey || e.metaKey
/* Generic shortcuts */ /* Generic shortcuts */
@ -527,7 +527,7 @@ L.U.Map.include({
initTileLayers: function () { initTileLayers: function () {
this.tilelayers = [] this.tilelayers = []
for (var i in this.options.tilelayers) { for (const i in this.options.tilelayers) {
if (this.options.tilelayers.hasOwnProperty(i)) { if (this.options.tilelayers.hasOwnProperty(i)) {
this.tilelayers.push(this.createTileLayer(this.options.tilelayers[i])) this.tilelayers.push(this.createTileLayer(this.options.tilelayers[i]))
if ( if (
@ -592,8 +592,8 @@ L.U.Map.include({
}, },
eachTileLayer: function (method, context) { eachTileLayer: function (method, context) {
var urls = [] const urls = []
for (var i in this.tilelayers) { for (const i in this.tilelayers) {
if (this.tilelayers.hasOwnProperty(i)) { if (this.tilelayers.hasOwnProperty(i)) {
method.call(context, this.tilelayers[i]) method.call(context, this.tilelayers[i])
urls.push(this.tilelayers[i]._url) urls.push(this.tilelayers[i]._url)
@ -610,7 +610,7 @@ L.U.Map.include({
setOverlay: function () { setOverlay: function () {
if (!this.options.overlay || !this.options.overlay.url_template) return if (!this.options.overlay || !this.options.overlay.url_template) return
var overlay = this.createTileLayer(this.options.overlay) const overlay = this.createTileLayer(this.options.overlay)
try { try {
this.addLayer(overlay) this.addLayer(overlay)
if (this.overlay) this.removeLayer(this.overlay) if (this.overlay) this.removeLayer(this.overlay)
@ -649,12 +649,12 @@ L.U.Map.include({
}, },
handleLimitBounds: function () { handleLimitBounds: function () {
var south = parseFloat(this.options.limitBounds.south), const south = parseFloat(this.options.limitBounds.south),
west = parseFloat(this.options.limitBounds.west), west = parseFloat(this.options.limitBounds.west),
north = parseFloat(this.options.limitBounds.north), north = parseFloat(this.options.limitBounds.north),
east = parseFloat(this.options.limitBounds.east) east = parseFloat(this.options.limitBounds.east)
if (!isNaN(south) && !isNaN(west) && !isNaN(north) && !isNaN(east)) { if (!isNaN(south) && !isNaN(west) && !isNaN(north) && !isNaN(east)) {
var bounds = L.latLngBounds([ const bounds = L.latLngBounds([
[south, west], [south, west],
[north, east], [north, east],
]) ])
@ -715,7 +715,7 @@ L.U.Map.include({
}, },
updateTileLayers: function () { updateTileLayers: function () {
var self = this, const self = this,
callback = (tilelayer) => { callback = (tilelayer) => {
self.options.tilelayer = tilelayer.toJSON() self.options.tilelayer = tilelayer.toJSON()
self.isDirty = true self.isDirty = true
@ -729,14 +729,14 @@ L.U.Map.include({
}, },
renderShareBox: function () { renderShareBox: function () {
var container = L.DomUtil.create('div', 'umap-share'), const container = L.DomUtil.create('div', 'umap-share')
embedTitle = L.DomUtil.add('h4', '', container, L._('Embed the map')), const embedTitle = L.DomUtil.add('h4', '', container, L._('Embed the map'))
iframe = L.DomUtil.create('textarea', 'umap-share-iframe', container), const iframe = L.DomUtil.create('textarea', 'umap-share-iframe', container)
urlTitle = L.DomUtil.add('h4', '', container, L._('Direct link')), const urlTitle = L.DomUtil.add('h4', '', container, L._('Direct link'))
exportUrl = L.DomUtil.create('input', 'umap-share-url', container), const exportUrl = L.DomUtil.create('input', 'umap-share-url', container)
option let option
exportUrl.type = 'text' exportUrl.type = 'text'
var UIFields = [ const UIFields = [
['dimensions.width', { handler: 'Input', label: L._('width') }], ['dimensions.width', { handler: 'Input', label: L._('width') }],
['dimensions.height', { handler: 'Input', label: L._('height') }], ['dimensions.height', { handler: 'Input', label: L._('height') }],
[ [
@ -763,47 +763,44 @@ L.U.Map.include({
'queryString.captionBar', 'queryString.captionBar',
'queryString.captionMenus', 'queryString.captionMenus',
] ]
for (var i = 0; i < this.HIDDABLE_CONTROLS.length; i++) { for (let i = 0; i < this.HIDDABLE_CONTROLS.length; i++) {
UIFields.push('queryString.' + this.HIDDABLE_CONTROLS[i] + 'Control') UIFields.push('queryString.' + this.HIDDABLE_CONTROLS[i] + 'Control')
} }
var iframeExporter = new L.U.IframeExporter(this) const iframeExporter = new L.U.IframeExporter(this)
var buildIframeCode = () => { const buildIframeCode = () => {
iframe.innerHTML = iframeExporter.build() iframe.innerHTML = iframeExporter.build()
exportUrl.value = window.location.protocol + iframeExporter.buildUrl() exportUrl.value = window.location.protocol + iframeExporter.buildUrl()
} }
buildIframeCode() buildIframeCode()
var builder = new L.U.FormBuilder(iframeExporter, UIFields, { const builder = new L.U.FormBuilder(iframeExporter, UIFields, {
callback: buildIframeCode, callback: buildIframeCode,
}) })
var iframeOptions = L.DomUtil.createFieldset( const iframeOptions = L.DomUtil.createFieldset(container, L._('Export options'))
container,
L._('Export options')
)
iframeOptions.appendChild(builder.build()) iframeOptions.appendChild(builder.build())
if (this.options.shortUrl) { if (this.options.shortUrl) {
L.DomUtil.create('hr', '', container) L.DomUtil.create('hr', '', container)
L.DomUtil.add('h4', '', container, L._('Short URL')) L.DomUtil.add('h4', '', container, L._('Short URL'))
var shortUrl = L.DomUtil.create('input', 'umap-short-url', container) const shortUrl = L.DomUtil.create('input', 'umap-short-url', container)
shortUrl.type = 'text' shortUrl.type = 'text'
shortUrl.value = this.options.shortUrl shortUrl.value = this.options.shortUrl
} }
L.DomUtil.create('hr', '', container) L.DomUtil.create('hr', '', container)
L.DomUtil.add('h4', '', container, L._('Download data')) L.DomUtil.add('h4', '', container, L._('Download data'))
var typeInput = L.DomUtil.create('select', '', container) const typeInput = L.DomUtil.create('select', '', container)
typeInput.name = 'format' typeInput.name = 'format'
var exportCaveat = L.DomUtil.add( const exportCaveat = L.DomUtil.add(
'small', 'small',
'help-text', 'help-text',
container, container,
L._('Only visible features will be downloaded.') L._('Only visible features will be downloaded.')
) )
exportCaveat.id = 'export_caveat_text' exportCaveat.id = 'export_caveat_text'
var toggleCaveat = () => { const toggleCaveat = () => {
if (typeInput.value === 'umap') exportCaveat.style.display = 'none' if (typeInput.value === 'umap') exportCaveat.style.display = 'none'
else exportCaveat.style.display = 'inherit' else exportCaveat.style.display = 'inherit'
} }
L.DomEvent.on(typeInput, 'change', toggleCaveat) L.DomEvent.on(typeInput, 'change', toggleCaveat)
var types = { const types = {
geojson: { geojson: {
formatter: function (map) { formatter: function (map) {
return JSON.stringify(map.toGeoJSON(), null, 2) return JSON.stringify(map.toGeoJSON(), null, 2)
@ -835,7 +832,7 @@ L.U.Map.include({
selected: true, selected: true,
}, },
} }
for (var key in types) { for (const key in types) {
if (types.hasOwnProperty(key)) { if (types.hasOwnProperty(key)) {
option = L.DomUtil.create('option', '', typeInput) option = L.DomUtil.create('option', '', typeInput)
option.value = key option.value = key
@ -844,19 +841,19 @@ L.U.Map.include({
} }
} }
toggleCaveat() toggleCaveat()
var download = L.DomUtil.create('a', 'button', container) const download = L.DomUtil.create('a', 'button', container)
download.textContent = L._('Download data') download.textContent = L._('Download data')
L.DomEvent.on( L.DomEvent.on(
download, download,
'click', 'click',
function () { function () {
var type = types[typeInput.value], const type = types[typeInput.value]
content = type.formatter(this), const content = type.formatter(this)
name = this.options.name || 'data' let name = this.options.name || 'data'
name = name.replace(/[^a-z0-9]/gi, '_').toLowerCase() name = name.replace(/[^a-z0-9]/gi, '_').toLowerCase()
download.download = name + type.ext download.download = name + type.ext
window.URL = window.URL || window.webkitURL window.URL = window.URL || window.webkitURL
var blob = new Blob([content], { type: type.filetype }) const blob = new Blob([content], { type: type.filetype })
download.href = window.URL.createObjectURL(blob) download.href = window.URL.createObjectURL(blob)
}, },
this this
@ -865,13 +862,13 @@ L.U.Map.include({
}, },
toGeoJSON: function () { toGeoJSON: function () {
var features = [] let features = []
this.eachDataLayer((datalayer) => { this.eachDataLayer((datalayer) => {
if (datalayer.isVisible()) { if (datalayer.isVisible()) {
features = features.concat(datalayer.featuresToGeoJSON()) features = features.concat(datalayer.featuresToGeoJSON())
} }
}) })
var geojson = { const geojson = {
type: 'FeatureCollection', type: 'FeatureCollection',
features: features, features: features,
} }
@ -879,21 +876,21 @@ L.U.Map.include({
}, },
importPanel: function () { importPanel: function () {
var container = L.DomUtil.create('div', 'umap-upload'), const container = L.DomUtil.create('div', 'umap-upload')
title = L.DomUtil.create('h4', '', container), const title = L.DomUtil.create('h4', '', container)
presetBox = L.DomUtil.create('div', 'formbox', container), const presetBox = L.DomUtil.create('div', 'formbox', container)
presetSelect = L.DomUtil.create('select', '', presetBox), const presetSelect = L.DomUtil.create('select', '', presetBox)
fileBox = L.DomUtil.create('div', 'formbox', container), const fileBox = L.DomUtil.create('div', 'formbox', container)
fileInput = L.DomUtil.create('input', '', fileBox), const fileInput = L.DomUtil.create('input', '', fileBox)
urlInput = L.DomUtil.create('input', '', container), const urlInput = L.DomUtil.create('input', '', container)
rawInput = L.DomUtil.create('textarea', '', container), const rawInput = L.DomUtil.create('textarea', '', container)
typeLabel = L.DomUtil.create('label', '', container), const typeLabel = L.DomUtil.create('label', '', container)
layerLabel = L.DomUtil.create('label', '', container), const layerLabel = L.DomUtil.create('label', '', container)
clearLabel = L.DomUtil.create('label', '', container), const clearLabel = L.DomUtil.create('label', '', container)
submitInput = L.DomUtil.create('input', '', container), const submitInput = L.DomUtil.create('input', '', container)
map = this, const map = this
option, let option
types = ['geojson', 'csv', 'gpx', 'kml', 'osm', 'georss', 'umap'] const types = ['geojson', 'csv', 'gpx', 'kml', 'osm', 'georss', 'umap']
title.textContent = L._('Import data') title.textContent = L._('Import data')
fileInput.type = 'file' fileInput.type = 'file'
fileInput.multiple = 'multiple' fileInput.multiple = 'multiple'
@ -902,21 +899,21 @@ L.U.Map.include({
submitInput.className = 'button' submitInput.className = 'button'
typeLabel.textContent = L._('Choose the format of the data to import') typeLabel.textContent = L._('Choose the format of the data to import')
this.help.button(typeLabel, 'importFormats') this.help.button(typeLabel, 'importFormats')
var typeInput = L.DomUtil.create('select', '', typeLabel) const typeInput = L.DomUtil.create('select', '', typeLabel)
typeInput.name = 'format' typeInput.name = 'format'
layerLabel.textContent = L._('Choose the layer to import in') layerLabel.textContent = L._('Choose the layer to import in')
var layerInput = L.DomUtil.create('select', '', layerLabel) const layerInput = L.DomUtil.create('select', '', layerLabel)
layerInput.name = 'datalayer' layerInput.name = 'datalayer'
urlInput.type = 'text' urlInput.type = 'text'
urlInput.placeholder = L._('Provide an URL here') urlInput.placeholder = L._('Provide an URL here')
rawInput.placeholder = L._('Paste your data here') rawInput.placeholder = L._('Paste your data here')
clearLabel.textContent = L._('Replace layer content') clearLabel.textContent = L._('Replace layer content')
var clearFlag = L.DomUtil.create('input', '', clearLabel) const clearFlag = L.DomUtil.create('input', '', clearLabel)
clearFlag.type = 'checkbox' clearFlag.type = 'checkbox'
clearFlag.name = 'clear' clearFlag.name = 'clear'
this.eachDataLayerReverse((datalayer) => { this.eachDataLayerReverse((datalayer) => {
if (datalayer.isLoaded() && !datalayer.isRemoteLayer()) { if (datalayer.isLoaded() && !datalayer.isRemoteLayer()) {
var id = L.stamp(datalayer) const id = L.stamp(datalayer)
option = L.DomUtil.create('option', '', layerInput) option = L.DomUtil.create('option', '', layerInput)
option.value = id option.value = id
option.textContent = datalayer.options.name option.textContent = datalayer.options.name
@ -932,14 +929,14 @@ L.U.Map.include({
{ value: '', textContent: L._('Choose the data format') }, { value: '', textContent: L._('Choose the data format') },
typeInput typeInput
) )
for (var i = 0; i < types.length; i++) { for (let i = 0; i < types.length; i++) {
option = L.DomUtil.create('option', '', typeInput) option = L.DomUtil.create('option', '', typeInput)
option.value = option.textContent = types[i] option.value = option.textContent = types[i]
} }
if (this.options.importPresets.length) { if (this.options.importPresets.length) {
var noPreset = L.DomUtil.create('option', '', presetSelect) const noPreset = L.DomUtil.create('option', '', presetSelect)
noPreset.value = noPreset.textContent = L._('Choose a preset') noPreset.value = noPreset.textContent = L._('Choose a preset')
for (var j = 0; j < this.options.importPresets.length; j++) { for (let j = 0; j < this.options.importPresets.length; j++) {
option = L.DomUtil.create('option', '', presetSelect) option = L.DomUtil.create('option', '', presetSelect)
option.value = this.options.importPresets[j].url option.value = this.options.importPresets[j].url
option.textContent = this.options.importPresets[j].label option.textContent = this.options.importPresets[j].label
@ -948,10 +945,10 @@ L.U.Map.include({
presetBox.style.display = 'none' presetBox.style.display = 'none'
} }
var submit = function () { const submit = function () {
var type = typeInput.value, let type = typeInput.value
layerId = layerInput[layerInput.selectedIndex].value, const layerId = layerInput[layerInput.selectedIndex].value
layer let layer
if (type === 'umap') { if (type === 'umap') {
this.once('postsync', function () { this.once('postsync', function () {
this.setView(this.latLng(this.options.center), this.options.zoom) this.setView(this.latLng(this.options.center), this.options.zoom)
@ -961,7 +958,7 @@ L.U.Map.include({
if (layer && clearFlag.checked) layer.empty() if (layer && clearFlag.checked) layer.empty()
if (fileInput.files.length) { if (fileInput.files.length) {
var file var file
for (var i = 0, file; (file = fileInput.files[i]); i++) { for (let i = 0, file; (file = fileInput.files[i]); i++) {
type = type || L.Util.detectFileType(file) type = type || L.Util.detectFileType(file)
if (!type) { if (!type) {
this.ui.alert({ this.ui.alert({
@ -975,7 +972,7 @@ L.U.Map.include({
if (type === 'umap') { if (type === 'umap') {
this.importFromFile(file, 'umap') this.importFromFile(file, 'umap')
} else { } else {
var importLayer = layer let importLayer = layer
if (!layer) importLayer = this.createDataLayer({ name: file.name }) if (!layer) importLayer = this.createDataLayer({ name: file.name })
importLayer.importFromFile(file, type) importLayer.importFromFile(file, type)
} }
@ -1007,9 +1004,9 @@ L.U.Map.include({
fileInput, fileInput,
'change', 'change',
(e) => { (e) => {
var type = '', let type = '',
newType newType
for (var i = 0; i < e.target.files.length; i++) { for (let i = 0; i < e.target.files.length; i++) {
newType = L.Util.detectFileType(e.target.files[i]) newType = L.Util.detectFileType(e.target.files[i])
if (!type && newType) type = newType if (!type && newType) type = newType
if (type && newType !== type) { if (type && newType !== type) {
@ -1025,12 +1022,12 @@ L.U.Map.include({
}, },
importRaw: function (rawData) { importRaw: function (rawData) {
var importedData = JSON.parse(rawData) const importedData = JSON.parse(rawData)
var mustReindex = false let mustReindex = false
for (var i = 0; i < this.editableOptions.length; i++) { for (let i = 0; i < this.editableOptions.length; i++) {
var option = this.editableOptions[i] const option = this.editableOptions[i]
if (typeof importedData.properties[option] !== 'undefined') { if (typeof importedData.properties[option] !== 'undefined') {
this.options[option] = importedData.properties[option] this.options[option] = importedData.properties[option]
if (option === 'sortKey') mustReindex = true if (option === 'sortKey') mustReindex = true
@ -1038,9 +1035,9 @@ L.U.Map.include({
} }
if (importedData.geometry) this.options.center = this.latLng(importedData.geometry) if (importedData.geometry) this.options.center = this.latLng(importedData.geometry)
var self = this const self = this
importedData.layers.forEach((geojson) => { importedData.layers.forEach((geojson) => {
var dataLayer = self.createDataLayer() const dataLayer = self.createDataLayer()
dataLayer.fromUmapGeoJSON(geojson) dataLayer.fromUmapGeoJSON(geojson)
}) })
@ -1056,11 +1053,11 @@ L.U.Map.include({
}, },
importFromFile: function (file) { importFromFile: function (file) {
var reader = new FileReader() const reader = new FileReader()
reader.readAsText(file) reader.readAsText(file)
var self = this const self = this
reader.onload = (e) => { reader.onload = (e) => {
var rawData = e.target.result const rawData = e.target.result
try { try {
self.importRaw(rawData) self.importRaw(rawData)
} catch (e) { } catch (e) {
@ -1086,17 +1083,17 @@ L.U.Map.include({
}, },
displayCaption: function () { displayCaption: function () {
var container = L.DomUtil.create('div', 'umap-caption'), const container = L.DomUtil.create('div', 'umap-caption')
title = L.DomUtil.create('h3', '', container) let title = L.DomUtil.create('h3', '', container)
title.textContent = this.options.name title.textContent = this.options.name
this.permissions.addOwnerLink('h5', container) this.permissions.addOwnerLink('h5', container)
if (this.options.description) { if (this.options.description) {
var description = L.DomUtil.create('div', 'umap-map-description', container) const description = L.DomUtil.create('div', 'umap-map-description', container)
description.innerHTML = L.Util.toHTML(this.options.description) description.innerHTML = L.Util.toHTML(this.options.description)
} }
var datalayerContainer = L.DomUtil.create('div', 'datalayer-container', container) const datalayerContainer = L.DomUtil.create('div', 'datalayer-container', container)
this.eachVisibleDataLayer((datalayer) => { this.eachVisibleDataLayer((datalayer) => {
var p = L.DomUtil.create('p', '', datalayerContainer), const p = L.DomUtil.create('p', '', datalayerContainer),
color = L.DomUtil.create('span', 'datalayer-color', p), color = L.DomUtil.create('span', 'datalayer-color', p),
headline = L.DomUtil.create('strong', '', p), headline = L.DomUtil.create('strong', '', p),
description = L.DomUtil.create('span', '', p) description = L.DomUtil.create('span', '', p)
@ -1109,7 +1106,7 @@ L.U.Map.include({
datalayer.renderToolbox(headline) datalayer.renderToolbox(headline)
L.DomUtil.add('span', '', headline, datalayer.options.name + ' ') L.DomUtil.add('span', '', headline, datalayer.options.name + ' ')
}) })
var creditsContainer = L.DomUtil.create('div', 'credits-container', container), const creditsContainer = L.DomUtil.create('div', 'credits-container', container),
credits = L.DomUtil.createFieldset(creditsContainer, L._('Credits')) credits = L.DomUtil.createFieldset(creditsContainer, L._('Credits'))
title = L.DomUtil.add('h5', '', credits, L._('User content credits')) title = L.DomUtil.add('h5', '', credits, L._('User content credits'))
if (this.options.shortCredit || this.options.longCredit) { if (this.options.shortCredit || this.options.longCredit) {
@ -1121,7 +1118,7 @@ L.U.Map.include({
) )
} }
if (this.options.licence) { if (this.options.licence) {
var licence = L.DomUtil.add( const licence = L.DomUtil.add(
'p', 'p',
'', '',
credits, credits,
@ -1135,13 +1132,13 @@ L.U.Map.include({
L.DomUtil.create('hr', '', credits) L.DomUtil.create('hr', '', credits)
title = L.DomUtil.create('h5', '', credits) title = L.DomUtil.create('h5', '', credits)
title.textContent = L._('Map background credits') title.textContent = L._('Map background credits')
var tilelayerCredit = L.DomUtil.create('p', '', credits), const tilelayerCredit = L.DomUtil.create('p', '', credits),
name = L.DomUtil.create('strong', '', tilelayerCredit), name = L.DomUtil.create('strong', '', tilelayerCredit),
attribution = L.DomUtil.create('span', '', tilelayerCredit) attribution = L.DomUtil.create('span', '', tilelayerCredit)
name.textContent = this.selected_tilelayer.options.name + ' ' name.textContent = this.selected_tilelayer.options.name + ' '
attribution.innerHTML = this.selected_tilelayer.getAttribution() attribution.innerHTML = this.selected_tilelayer.getAttribution()
L.DomUtil.create('hr', '', credits) L.DomUtil.create('hr', '', credits)
var umapCredit = L.DomUtil.create('p', '', credits), const umapCredit = L.DomUtil.create('p', '', credits),
urls = { urls = {
leaflet: 'http://leafletjs.com', leaflet: 'http://leafletjs.com',
django: 'https://www.djangoproject.com', django: 'https://www.djangoproject.com',
@ -1151,16 +1148,16 @@ L.U.Map.include({
'Powered by <a href="{leaflet}">Leaflet</a> and <a href="{django}">Django</a>, glued by <a href="{umap}">uMap project</a>.', 'Powered by <a href="{leaflet}">Leaflet</a> and <a href="{django}">Django</a>, glued by <a href="{umap}">uMap project</a>.',
urls urls
) )
var browser = L.DomUtil.create('li', '') const browser = L.DomUtil.create('li', '')
L.DomUtil.create('i', 'umap-icon-16 umap-list', browser) L.DomUtil.create('i', 'umap-icon-16 umap-list', browser)
var labelBrowser = L.DomUtil.create('span', '', browser) const labelBrowser = L.DomUtil.create('span', '', browser)
labelBrowser.textContent = labelBrowser.title = L._('Browse data') labelBrowser.textContent = labelBrowser.title = L._('Browse data')
L.DomEvent.on(browser, 'click', this.openBrowser, this) L.DomEvent.on(browser, 'click', this.openBrowser, this)
var actions = [browser] const actions = [browser]
if (this.options.advancedFilterKey) { if (this.options.advancedFilterKey) {
var filter = L.DomUtil.create('li', '') const filter = L.DomUtil.create('li', '')
L.DomUtil.create('i', 'umap-icon-16 umap-add', filter) L.DomUtil.create('i', 'umap-icon-16 umap-add', filter)
var labelFilter = L.DomUtil.create('span', '', filter) const labelFilter = L.DomUtil.create('span', '', filter)
labelFilter.textContent = labelFilter.title = L._('Select data') labelFilter.textContent = labelFilter.title = L._('Select data')
L.DomEvent.on(filter, 'click', this.openFilter, this) L.DomEvent.on(filter, 'click', this.openFilter, this)
actions.push(filter) actions.push(filter)
@ -1169,13 +1166,13 @@ L.U.Map.include({
}, },
eachDataLayer: function (method, context) { eachDataLayer: function (method, context) {
for (var i = 0; i < this.datalayers_index.length; i++) { for (let i = 0; i < this.datalayers_index.length; i++) {
method.call(context, this.datalayers_index[i]) method.call(context, this.datalayers_index[i])
} }
}, },
eachDataLayerReverse: function (method, context, filter) { eachDataLayerReverse: function (method, context, filter) {
for (var i = this.datalayers_index.length - 1; i >= 0; i--) { for (let i = this.datalayers_index.length - 1; i >= 0; i--) {
if (filter && !filter.call(context, this.datalayers_index[i])) continue if (filter && !filter.call(context, this.datalayers_index[i])) continue
method.call(context, this.datalayers_index[i]) method.call(context, this.datalayers_index[i])
} }
@ -1190,7 +1187,7 @@ L.U.Map.include({
}, },
findDataLayer: function (method, context) { findDataLayer: function (method, context) {
for (var i = this.datalayers_index.length - 1; i >= 0; i--) { for (let i = this.datalayers_index.length - 1; i >= 0; i--) {
if (method.call(context, this.datalayers_index[i])) if (method.call(context, this.datalayers_index[i]))
return this.datalayers_index[i] return this.datalayers_index[i]
} }
@ -1297,8 +1294,8 @@ L.U.Map.include({
], ],
exportOptions: function () { exportOptions: function () {
var properties = {} const properties = {}
for (var i = this.editableOptions.length - 1; i >= 0; i--) { for (let i = this.editableOptions.length - 1; i >= 0; i--) {
if (typeof this.options[this.editableOptions[i]] !== 'undefined') { if (typeof this.options[this.editableOptions[i]] !== 'undefined') {
properties[this.editableOptions[i]] = this.options[this.editableOptions[i]] properties[this.editableOptions[i]] = this.options[this.editableOptions[i]]
} }
@ -1307,7 +1304,7 @@ L.U.Map.include({
}, },
serialize: function () { serialize: function () {
var umapfile = { const umapfile = {
type: 'umap', type: 'umap',
uri: window.location.href, uri: window.location.href,
properties: this.exportOptions(), properties: this.exportOptions(),
@ -1325,13 +1322,13 @@ L.U.Map.include({
save: function () { save: function () {
if (!this.isDirty) return if (!this.isDirty) return
if (this._default_extent) this.updateExtent() if (this._default_extent) this.updateExtent()
var geojson = { const geojson = {
type: 'Feature', type: 'Feature',
geometry: this.geometry(), geometry: this.geometry(),
properties: this.exportOptions(), properties: this.exportOptions(),
} }
this.backup() this.backup()
var formData = new FormData() const formData = new FormData()
formData.append('name', this.options.name) formData.append('name', this.options.name)
formData.append('center', JSON.stringify(this.geometry())) formData.append('center', JSON.stringify(this.geometry()))
formData.append('settings', JSON.stringify(geojson)) formData.append('settings', JSON.stringify(geojson))
@ -1339,7 +1336,7 @@ L.U.Map.include({
data: formData, data: formData,
context: this, context: this,
callback: function (data) { callback: function (data) {
var duration = 3000 let duration = 3000
if (!this.options.umap_id) { if (!this.options.umap_id) {
duration = 100000 // we want a longer message at map creation (TODO UGLY) duration = 100000 // we want a longer message at map creation (TODO UGLY)
this.options.umap_id = data.id this.options.umap_id = data.id
@ -1403,7 +1400,7 @@ L.U.Map.include({
geometry: function () { geometry: function () {
/* Return a GeoJSON geometry Object */ /* Return a GeoJSON geometry Object */
var latlng = this.latLng(this.options.center || this.getCenter()) const latlng = this.latLng(this.options.center || this.getCenter())
return { return {
type: 'Point', type: 'Point',
coordinates: [latlng.lng, latlng.lat], coordinates: [latlng.lng, latlng.lat],
@ -1411,7 +1408,7 @@ L.U.Map.include({
}, },
defaultDataLayer: function () { defaultDataLayer: function () {
var datalayer, fallback let datalayer, fallback
datalayer = this.lastUsedDataLayer datalayer = this.lastUsedDataLayer
if ( if (
datalayer && datalayer &&
@ -1441,8 +1438,8 @@ L.U.Map.include({
}, },
_editControls: function (container) { _editControls: function (container) {
var UIFields = [] let UIFields = []
for (var i = 0; i < this.HIDDABLE_CONTROLS.length; i++) { for (let i = 0; i < this.HIDDABLE_CONTROLS.length; i++) {
UIFields.push('options.' + this.HIDDABLE_CONTROLS[i] + 'Control') UIFields.push('options.' + this.HIDDABLE_CONTROLS[i] + 'Control')
} }
UIFields = UIFields.concat([ UIFields = UIFields.concat([
@ -1462,7 +1459,7 @@ L.U.Map.include({
}, },
callbackContext: this, callbackContext: this,
}) })
var controlsOptions = L.DomUtil.createFieldset( const controlsOptions = L.DomUtil.createFieldset(
container, container,
L._('User interface options') L._('User interface options')
) )
@ -1470,7 +1467,7 @@ L.U.Map.include({
}, },
_editShapeProperties: function (container) { _editShapeProperties: function (container) {
var shapeOptions = [ const shapeOptions = [
'options.color', 'options.color',
'options.iconClass', 'options.iconClass',
'options.iconUrl', 'options.iconUrl',
@ -1488,7 +1485,7 @@ L.U.Map.include({
}) })
}, },
}) })
var defaultShapeProperties = L.DomUtil.createFieldset( const defaultShapeProperties = L.DomUtil.createFieldset(
container, container,
L._('Default shape properties') L._('Default shape properties')
) )
@ -1496,7 +1493,7 @@ L.U.Map.include({
}, },
_editDefaultProperties: function (container) { _editDefaultProperties: function (container) {
var optionsFields = [ const optionsFields = [
'options.smoothFactor', 'options.smoothFactor',
'options.dashArray', 'options.dashArray',
'options.zoomTo', 'options.zoomTo',
@ -1552,7 +1549,7 @@ L.U.Map.include({
}) })
}, },
}) })
var defaultProperties = L.DomUtil.createFieldset( const defaultProperties = L.DomUtil.createFieldset(
container, container,
L._('Default properties') L._('Default properties')
) )
@ -1560,7 +1557,7 @@ L.U.Map.include({
}, },
_editInteractionsProperties: function (container) { _editInteractionsProperties: function (container) {
var popupFields = [ const popupFields = [
'options.popupShape', 'options.popupShape',
'options.popupTemplate', 'options.popupTemplate',
'options.popupContentTemplate', 'options.popupContentTemplate',
@ -1581,7 +1578,7 @@ L.U.Map.include({
}) })
}, },
}) })
var popupFieldset = L.DomUtil.createFieldset( const popupFieldset = L.DomUtil.createFieldset(
container, container,
L._('Default interaction options') L._('Default interaction options')
) )
@ -1592,7 +1589,7 @@ L.U.Map.include({
if (!L.Util.isObject(this.options.tilelayer)) { if (!L.Util.isObject(this.options.tilelayer)) {
this.options.tilelayer = {} this.options.tilelayer = {}
} }
var tilelayerFields = [ const tilelayerFields = [
[ [
'options.tilelayer.name', 'options.tilelayer.name',
{ handler: 'BlurInput', placeholder: L._('display name') }, { handler: 'BlurInput', placeholder: L._('display name') },
@ -1619,7 +1616,10 @@ L.U.Map.include({
], ],
['options.tilelayer.tms', { handler: 'Switch', label: L._('TMS format') }], ['options.tilelayer.tms', { handler: 'Switch', label: L._('TMS format') }],
] ]
var customTilelayer = L.DomUtil.createFieldset(container, L._('Custom background')) const customTilelayer = L.DomUtil.createFieldset(
container,
L._('Custom background')
)
builder = new L.U.FormBuilder(this, tilelayerFields, { builder = new L.U.FormBuilder(this, tilelayerFields, {
callback: this.initTileLayers, callback: this.initTileLayers,
callbackContext: this, callbackContext: this,
@ -1631,7 +1631,7 @@ L.U.Map.include({
if (!L.Util.isObject(this.options.overlay)) { if (!L.Util.isObject(this.options.overlay)) {
this.options.overlay = {} this.options.overlay = {}
} }
var overlayFields = [ const overlayFields = [
[ [
'options.overlay.url_template', 'options.overlay.url_template',
{ {
@ -1659,7 +1659,7 @@ L.U.Map.include({
], ],
['options.overlay.tms', { handler: 'Switch', label: L._('TMS format') }], ['options.overlay.tms', { handler: 'Switch', label: L._('TMS format') }],
] ]
var overlay = L.DomUtil.createFieldset(container, L._('Custom overlay')) const overlay = L.DomUtil.createFieldset(container, L._('Custom overlay'))
builder = new L.U.FormBuilder(this, overlayFields, { builder = new L.U.FormBuilder(this, overlayFields, {
callback: this.initTileLayers, callback: this.initTileLayers,
callbackContext: this, callbackContext: this,
@ -1671,8 +1671,8 @@ L.U.Map.include({
if (!L.Util.isObject(this.options.limitBounds)) { if (!L.Util.isObject(this.options.limitBounds)) {
this.options.limitBounds = {} this.options.limitBounds = {}
} }
var limitBounds = L.DomUtil.createFieldset(container, L._('Limit bounds')) const limitBounds = L.DomUtil.createFieldset(container, L._('Limit bounds'))
var boundsFields = [ const boundsFields = [
[ [
'options.limitBounds.south', 'options.limitBounds.south',
{ handler: 'BlurFloatInput', placeholder: L._('max South') }, { handler: 'BlurFloatInput', placeholder: L._('max South') },
@ -1690,13 +1690,13 @@ L.U.Map.include({
{ handler: 'BlurFloatInput', placeholder: L._('max East') }, { handler: 'BlurFloatInput', placeholder: L._('max East') },
], ],
] ]
var boundsBuilder = new L.U.FormBuilder(this, boundsFields, { const boundsBuilder = new L.U.FormBuilder(this, boundsFields, {
callback: this.handleLimitBounds, callback: this.handleLimitBounds,
callbackContext: this, callbackContext: this,
}) })
limitBounds.appendChild(boundsBuilder.build()) limitBounds.appendChild(boundsBuilder.build())
var boundsButtons = L.DomUtil.create('div', 'button-bar half', limitBounds) const boundsButtons = L.DomUtil.create('div', 'button-bar half', limitBounds)
var setCurrentButton = L.DomUtil.add( const setCurrentButton = L.DomUtil.add(
'a', 'a',
'button', 'button',
boundsButtons, boundsButtons,
@ -1707,7 +1707,7 @@ L.U.Map.include({
setCurrentButton, setCurrentButton,
'click', 'click',
function () { function () {
var bounds = this.getBounds() const bounds = this.getBounds()
this.options.limitBounds.south = L.Util.formatNum(bounds.getSouth()) this.options.limitBounds.south = L.Util.formatNum(bounds.getSouth())
this.options.limitBounds.west = L.Util.formatNum(bounds.getWest()) this.options.limitBounds.west = L.Util.formatNum(bounds.getWest())
this.options.limitBounds.north = L.Util.formatNum(bounds.getNorth()) this.options.limitBounds.north = L.Util.formatNum(bounds.getNorth())
@ -1718,7 +1718,7 @@ L.U.Map.include({
}, },
this this
) )
var emptyBounds = L.DomUtil.add('a', 'button', boundsButtons, L._('Empty')) const emptyBounds = L.DomUtil.add('a', 'button', boundsButtons, L._('Empty'))
emptyBounds.href = '#' emptyBounds.href = '#'
L.DomEvent.on( L.DomEvent.on(
emptyBounds, emptyBounds,
@ -1737,8 +1737,8 @@ L.U.Map.include({
}, },
_editSlideshow: function (container) { _editSlideshow: function (container) {
var slideshow = L.DomUtil.createFieldset(container, L._('Slideshow')) const slideshow = L.DomUtil.createFieldset(container, L._('Slideshow'))
var slideshowFields = [ const slideshowFields = [
[ [
'options.slideshow.active', 'options.slideshow.active',
{ handler: 'Switch', label: L._('Activate slideshow mode') }, { handler: 'Switch', label: L._('Activate slideshow mode') },
@ -1759,11 +1759,11 @@ L.U.Map.include({
{ handler: 'Switch', label: L._('Autostart when map is loaded') }, { handler: 'Switch', label: L._('Autostart when map is loaded') },
], ],
] ]
var slideshowHandler = function () { const slideshowHandler = function () {
this.slideshow.setOptions(this.options.slideshow) this.slideshow.setOptions(this.options.slideshow)
this.renderControls() this.renderControls()
} }
var slideshowBuilder = new L.U.FormBuilder(this, slideshowFields, { const slideshowBuilder = new L.U.FormBuilder(this, slideshowFields, {
callback: slideshowHandler, callback: slideshowHandler,
callbackContext: this, callbackContext: this,
}) })
@ -1771,8 +1771,8 @@ L.U.Map.include({
}, },
_editCredits: function (container) { _editCredits: function (container) {
var credits = L.DomUtil.createFieldset(container, L._('Credits')) const credits = L.DomUtil.createFieldset(container, L._('Credits'))
var creditsFields = [ const creditsFields = [
['options.licence', { handler: 'LicenceChooser', label: L._('licence') }], ['options.licence', { handler: 'LicenceChooser', label: L._('licence') }],
[ [
'options.shortCredit', 'options.shortCredit',
@ -1803,7 +1803,7 @@ L.U.Map.include({
{ handler: 'Switch', label: L._('Permanent credits background') }, { handler: 'Switch', label: L._('Permanent credits background') },
], ],
] ]
var creditsBuilder = new L.U.FormBuilder(this, creditsFields, { const creditsBuilder = new L.U.FormBuilder(this, creditsFields, {
callback: this.renderControls, callback: this.renderControls,
callbackContext: this, callbackContext: this,
}) })
@ -1811,23 +1811,23 @@ L.U.Map.include({
}, },
_advancedActions: function (container) { _advancedActions: function (container) {
var advancedActions = L.DomUtil.createFieldset(container, L._('Advanced actions')) const advancedActions = L.DomUtil.createFieldset(container, L._('Advanced actions'))
var advancedButtons = L.DomUtil.create('div', 'button-bar half', advancedActions) const advancedButtons = L.DomUtil.create('div', 'button-bar half', advancedActions)
var del = L.DomUtil.create('a', 'button umap-delete', advancedButtons) const del = L.DomUtil.create('a', 'button umap-delete', advancedButtons)
del.href = '#' del.href = '#'
del.textContent = L._('Delete') del.textContent = L._('Delete')
L.DomEvent.on(del, 'click', L.DomEvent.stop).on(del, 'click', this.del, this) L.DomEvent.on(del, 'click', L.DomEvent.stop).on(del, 'click', this.del, this)
var clone = L.DomUtil.create('a', 'button umap-clone', advancedButtons) const clone = L.DomUtil.create('a', 'button umap-clone', advancedButtons)
clone.href = '#' clone.href = '#'
clone.textContent = L._('Clone') clone.textContent = L._('Clone')
clone.title = L._('Clone this map') clone.title = L._('Clone this map')
L.DomEvent.on(clone, 'click', L.DomEvent.stop).on(clone, 'click', this.clone, this) L.DomEvent.on(clone, 'click', L.DomEvent.stop).on(clone, 'click', this.clone, this)
var empty = L.DomUtil.create('a', 'button umap-empty', advancedButtons) const empty = L.DomUtil.create('a', 'button umap-empty', advancedButtons)
empty.href = '#' empty.href = '#'
empty.textContent = L._('Empty') empty.textContent = L._('Empty')
empty.title = L._('Delete all layers') empty.title = L._('Delete all layers')
L.DomEvent.on(empty, 'click', L.DomEvent.stop).on(empty, 'click', this.empty, this) L.DomEvent.on(empty, 'click', L.DomEvent.stop).on(empty, 'click', this.empty, this)
var download = L.DomUtil.create('a', 'button umap-download', advancedButtons) const download = L.DomUtil.create('a', 'button umap-download', advancedButtons)
download.href = '#' download.href = '#'
download.textContent = L._('Download') download.textContent = L._('Download')
download.title = L._('Open download panel') download.title = L._('Open download panel')
@ -1841,12 +1841,12 @@ L.U.Map.include({
edit: function () { edit: function () {
if (!this.editEnabled) return if (!this.editEnabled) return
var container = L.DomUtil.create('div', 'umap-edit-container'), const container = L.DomUtil.create('div', 'umap-edit-container'),
metadataFields = ['options.name', 'options.description'], metadataFields = ['options.name', 'options.description'],
title = L.DomUtil.create('h4', '', container) title = L.DomUtil.create('h4', '', container)
title.textContent = L._('Edit map properties') title.textContent = L._('Edit map properties')
var builder = new L.U.FormBuilder(this, metadataFields) const builder = new L.U.FormBuilder(this, metadataFields)
var form = builder.build() const form = builder.build()
container.appendChild(form) container.appendChild(form)
this._editControls(container) this._editControls(container)
this._editShapeProperties(container) this._editShapeProperties(container)
@ -1881,15 +1881,24 @@ L.U.Map.include({
}, },
initCaptionBar: function () { initCaptionBar: function () {
var container = L.DomUtil.create('div', 'umap-caption-bar', this._controlContainer), const container = L.DomUtil.create(
'div',
'umap-caption-bar',
this._controlContainer
),
name = L.DomUtil.create('h3', '', container) name = L.DomUtil.create('h3', '', container)
L.DomEvent.disableClickPropagation(container) L.DomEvent.disableClickPropagation(container)
this.permissions.addOwnerLink('span', container) this.permissions.addOwnerLink('span', container)
if (this.options.captionMenus) { if (this.options.captionMenus) {
var about = L.DomUtil.add('a', 'umap-about-link', container, ' — ' + L._('About')) const about = L.DomUtil.add(
'a',
'umap-about-link',
container,
' — ' + L._('About')
)
about.href = '#' about.href = '#'
L.DomEvent.on(about, 'click', this.displayCaption, this) L.DomEvent.on(about, 'click', this.displayCaption, this)
var browser = L.DomUtil.add( const browser = L.DomUtil.add(
'a', 'a',
'umap-open-browser-link', 'umap-open-browser-link',
container, container,
@ -1903,7 +1912,7 @@ L.U.Map.include({
this this
) )
if (this.options.advancedFilterKey) { if (this.options.advancedFilterKey) {
var filter = L.DomUtil.add( const filter = L.DomUtil.add(
'a', 'a',
'umap-open-filter-link', 'umap-open-filter-link',
container, container,
@ -1918,7 +1927,7 @@ L.U.Map.include({
) )
} }
} }
var setName = function () { const setName = function () {
name.textContent = this.getDisplayName() name.textContent = this.getDisplayName()
} }
L.bind(setName, this)() L.bind(setName, this)()
@ -1929,7 +1938,7 @@ L.U.Map.include({
}, },
initEditBar: function () { initEditBar: function () {
var container = L.DomUtil.create( const container = L.DomUtil.create(
'div', 'div',
'umap-main-edit-toolbox with-transition dark', 'umap-main-edit-toolbox with-transition dark',
this._controlContainer this._controlContainer
@ -1943,15 +1952,19 @@ L.U.Map.include({
L.DomEvent.on(name, 'click', this.edit, this) L.DomEvent.on(name, 'click', this.edit, this)
this.on('postsync', L.bind(setName, this)) this.on('postsync', L.bind(setName, this))
this.help.button(title, 'edit') this.help.button(title, 'edit')
var save = L.DomUtil.create('a', 'leaflet-control-edit-save button', container) const save = L.DomUtil.create('a', 'leaflet-control-edit-save button', container)
save.href = '#' save.href = '#'
save.title = L._('Save current edits') + ' (Ctrl+S)' save.title = L._('Save current edits') + ' (Ctrl+S)'
save.textContent = L._('Save') save.textContent = L._('Save')
var cancel = L.DomUtil.create('a', 'leaflet-control-edit-cancel button', container) const cancel = L.DomUtil.create(
'a',
'leaflet-control-edit-cancel button',
container
)
cancel.href = '#' cancel.href = '#'
cancel.title = L._('Cancel edits') cancel.title = L._('Cancel edits')
cancel.textContent = L._('Cancel') cancel.textContent = L._('Cancel')
var disable = L.DomUtil.create('a', 'leaflet-control-edit-disable', container) const disable = L.DomUtil.create('a', 'leaflet-control-edit-disable', container)
disable.href = '#' disable.href = '#'
disable.title = disable.textContent = L._('Disable editing') disable.title = disable.textContent = L._('Disable editing')
@ -2001,7 +2014,7 @@ L.U.Map.include({
del: function () { del: function () {
if (confirm(L._('Are you sure you want to delete this map?'))) { if (confirm(L._('Are you sure you want to delete this map?'))) {
var url = L.Util.template(this.options.urls.map_delete, { const url = L.Util.template(this.options.urls.map_delete, {
map_id: this.options.umap_id, map_id: this.options.umap_id,
}) })
this.post(url) this.post(url)
@ -2012,7 +2025,7 @@ L.U.Map.include({
if ( if (
confirm(L._('Are you sure you want to clone this map and all its datalayers?')) confirm(L._('Are you sure you want to clone this map and all its datalayers?'))
) { ) {
var url = L.Util.template(this.options.urls.map_clone, { const url = L.Util.template(this.options.urls.map_clone, {
map_id: this.options.umap_id, map_id: this.options.umap_id,
}) })
this.post(url) this.post(url)
@ -2053,7 +2066,7 @@ L.U.Map.include({
}, },
setContextMenuItems: function (e) { setContextMenuItems: function (e) {
var items = [] let items = []
if (this._zoom !== this.getMaxZoom()) { if (this._zoom !== this.getMaxZoom()) {
items.push({ items.push({
text: L._('Zoom in'), text: L._('Zoom in'),
@ -2149,9 +2162,9 @@ L.U.Map.include({
}, },
openExternalRouting: function (e) { openExternalRouting: function (e) {
var url = this.options.urls.routing const url = this.options.urls.routing
if (url) { if (url) {
var params = { const params = {
lat: e.latlng.lat, lat: e.latlng.lat,
lng: e.latlng.lng, lng: e.latlng.lng,
locale: L.locale, locale: L.locale,
@ -2167,7 +2180,7 @@ L.U.Map.include({
}, },
getGeoContext: function () { getGeoContext: function () {
var context = { const context = {
bbox: this.getBounds().toBBoxString(), bbox: this.getBounds().toBBoxString(),
north: this.getBounds().getNorthEast().lat, north: this.getBounds().getNorthEast().lat,
east: this.getBounds().getNorthEast().lng, east: this.getBounds().getNorthEast().lng,
@ -2199,7 +2212,7 @@ L.U.Map.include({
}, },
closeInplaceToolbar: function () { closeInplaceToolbar: function () {
var toolbar = this._toolbars[L.Toolbar.Popup._toolbar_class_id] const toolbar = this._toolbars[L.Toolbar.Popup._toolbar_class_id]
if (toolbar) toolbar.remove() if (toolbar) toolbar.remove()
}, },

View file

@ -28,7 +28,7 @@ L.U.MarkerCluster = L.MarkerCluster.extend({
_initIcon: function () { _initIcon: function () {
L.MarkerCluster.prototype._initIcon.call(this) L.MarkerCluster.prototype._initIcon.call(this)
var div = this._icon.querySelector('div') const div = this._icon.querySelector('div')
// Compute text color only when icon is added to the DOM. // Compute text color only when icon is added to the DOM.
div.style.color = this._iconObj.computeTextColor(div) div.style.color = this._iconObj.computeTextColor(div)
}, },
@ -40,7 +40,7 @@ L.U.Layer.Cluster = L.MarkerClusterGroup.extend({
initialize: function (datalayer) { initialize: function (datalayer) {
this.datalayer = datalayer this.datalayer = datalayer
var options = { const options = {
polygonOptions: { polygonOptions: {
color: this.datalayer.getColor(), color: this.datalayer.getColor(),
}, },
@ -103,7 +103,7 @@ L.U.Layer.Heat = L.HeatLayer.extend({
addLayer: function (layer) { addLayer: function (layer) {
if (layer instanceof L.Marker) { if (layer instanceof L.Marker) {
var latlng = layer.getLatLng(), let latlng = layer.getLatLng(),
alt alt
if ( if (
this.datalayer.options.heat && this.datalayer.options.heat &&
@ -192,9 +192,9 @@ L.U.DataLayer = L.Evented.extend({
this.pane.dataset.id = L.stamp(this) this.pane.dataset.id = L.stamp(this)
this.renderer = L.svg({ pane: this.pane }) this.renderer = L.svg({ pane: this.pane })
var isDirty = false, let isDirty = false
isDeleted = false, let isDeleted = false
self = this const self = this
try { try {
Object.defineProperty(this, 'isDirty', { Object.defineProperty(this, 'isDirty', {
get: function () { get: function () {
@ -267,13 +267,13 @@ L.U.DataLayer = L.Evented.extend({
resetLayer: function (force) { resetLayer: function (force) {
if (this.layer && this.options.type === this.layer._type && !force) return if (this.layer && this.options.type === this.layer._type && !force) return
var visible = this.isVisible() const visible = this.isVisible()
if (this.layer) this.layer.clearLayers() if (this.layer) this.layer.clearLayers()
// delete this.layer? // delete this.layer?
if (visible) this.map.removeLayer(this.layer) if (visible) this.map.removeLayer(this.layer)
var Class = L.U.Layer[this.options.type] || L.U.Layer.Default const Class = L.U.Layer[this.options.type] || L.U.Layer.Default
this.layer = new Class(this) this.layer = new Class(this)
var filterKeys = this.map.getFilterKeys(), const filterKeys = this.map.getFilterKeys(),
filter = this.map.options.filter filter = this.map.options.filter
this.eachLayer(function (layer) { this.eachLayer(function (layer) {
if (filter && !layer.matchFilter(filter, filterKeys)) return if (filter && !layer.matchFilter(filter, filterKeys)) return
@ -284,7 +284,7 @@ L.U.DataLayer = L.Evented.extend({
}, },
eachLayer: function (method, context) { eachLayer: function (method, context) {
for (var i in this._layers) { for (const i in this._layers) {
method.call(context || this, this._layers[i]) method.call(context || this, this._layers[i])
} }
return this return this
@ -292,7 +292,7 @@ L.U.DataLayer = L.Evented.extend({
eachFeature: function (method, context) { eachFeature: function (method, context) {
if (this.layer && this.layer.canBrowse) { if (this.layer && this.layer.canBrowse) {
for (var i = 0; i < this._index.length; i++) { for (let i = 0; i < this._index.length; i++) {
method.call(context || this, this._layers[this._index[i]]) method.call(context || this, this._layers[this._index[i]])
} }
} }
@ -342,18 +342,18 @@ L.U.DataLayer = L.Evented.extend({
}, },
reindex: function () { reindex: function () {
var features = [] const features = []
this.eachFeature((feature) => features.push(feature)) this.eachFeature((feature) => features.push(feature))
L.Util.sortFeatures(features, this.map.getOption('sortKey')) L.Util.sortFeatures(features, this.map.getOption('sortKey'))
this._index = [] this._index = []
for (var i = 0; i < features.length; i++) { for (let i = 0; i < features.length; i++) {
this._index.push(L.Util.stamp(features[i])) this._index.push(L.Util.stamp(features[i]))
} }
}, },
fetchRemoteData: function () { fetchRemoteData: function () {
if (!this.isRemoteLayer()) return if (!this.isRemoteLayer()) return
var from = parseInt(this.options.remoteData.from, 10), const from = parseInt(this.options.remoteData.from, 10),
to = parseInt(this.options.remoteData.to, 10) to = parseInt(this.options.remoteData.to, 10)
if ( if (
(!isNaN(from) && this.map.getZoom() < from) || (!isNaN(from) && this.map.getZoom() < from) ||
@ -364,7 +364,7 @@ L.U.DataLayer = L.Evented.extend({
} }
if (!this.options.remoteData.dynamic && this.hasDataLoaded()) return if (!this.options.remoteData.dynamic && this.hasDataLoaded()) return
if (!this.isVisible()) return if (!this.isVisible()) return
var url = this.map.localizeUrl(this.options.remoteData.url) let url = this.map.localizeUrl(this.options.remoteData.url)
if (this.options.remoteData.proxy) if (this.options.remoteData.proxy)
url = this.map.proxyUrl(url, this.options.remoteData.ttl) url = this.map.proxyUrl(url, this.options.remoteData.ttl)
this.map.ajax({ this.map.ajax({
@ -423,7 +423,7 @@ L.U.DataLayer = L.Evented.extend({
}, },
connectToMap: function () { connectToMap: function () {
var id = L.stamp(this) const id = L.stamp(this)
if (!this.map.datalayers[id]) { if (!this.map.datalayers[id]) {
this.map.datalayers[id] = this this.map.datalayers[id] = this
if (L.Util.indexOf(this.map.datalayers_index, this) === -1) if (L.Util.indexOf(this.map.datalayers_index, this) === -1)
@ -433,11 +433,13 @@ L.U.DataLayer = L.Evented.extend({
}, },
_dataUrl: function () { _dataUrl: function () {
var template = this.map.options.urls.datalayer_view, const template = this.map.options.urls.datalayer_view
url = L.Util.template(template, {
let url = L.Util.template(template, {
pk: this.umap_id, pk: this.umap_id,
map_id: this.map.options.umap_id, map_id: this.map.options.umap_id,
}) })
// No browser cache for owners/editors. // No browser cache for owners/editors.
if (this.map.options.allowEdit) url = url + '?' + Date.now() if (this.map.options.allowEdit) url = url + '?' + Date.now()
return url return url
@ -456,7 +458,7 @@ L.U.DataLayer = L.Evented.extend({
}, },
addLayer: function (feature) { addLayer: function (feature) {
var id = L.stamp(feature) const id = L.stamp(feature)
feature.connectToDataLayer(this) feature.connectToDataLayer(this)
this._index.push(id) this._index.push(id)
this._layers[id] = feature this._layers[id] = feature
@ -467,7 +469,7 @@ L.U.DataLayer = L.Evented.extend({
}, },
removeLayer: function (feature) { removeLayer: function (feature) {
var id = L.stamp(feature) const id = L.stamp(feature)
feature.disconnectFromDataLayer(this) feature.disconnectFromDataLayer(this)
this._index.splice(this._index.indexOf(id), 1) this._index.splice(this._index.indexOf(id), 1)
delete this._layers[id] delete this._layers[id]
@ -477,7 +479,7 @@ L.U.DataLayer = L.Evented.extend({
}, },
indexProperties: function (feature) { indexProperties: function (feature) {
for (var i in feature.properties) for (const i in feature.properties)
if (typeof feature.properties[i] !== 'object') this.indexProperty(i) if (typeof feature.properties[i] !== 'object') this.indexProperty(i)
}, },
@ -489,7 +491,7 @@ L.U.DataLayer = L.Evented.extend({
}, },
deindexProperty: function (name) { deindexProperty: function (name) {
var idx = this._propertiesIndex.indexOf(name) const idx = this._propertiesIndex.indexOf(name)
if (idx !== -1) this._propertiesIndex.splice(idx, 1) if (idx !== -1) this._propertiesIndex.splice(idx, 1)
}, },
@ -509,7 +511,7 @@ L.U.DataLayer = L.Evented.extend({
}, },
rawToGeoJSON: function (c, type, callback) { rawToGeoJSON: function (c, type, callback) {
var toDom = (x) => new DOMParser().parseFromString(x, 'text/xml') const toDom = (x) => new DOMParser().parseFromString(x, 'text/xml')
// TODO add a duck typing guessType // TODO add a duck typing guessType
if (type === 'csv') { if (type === 'csv') {
@ -521,7 +523,7 @@ L.U.DataLayer = L.Evented.extend({
}, },
(err, result) => { (err, result) => {
if (err) { if (err) {
var message let message
if (err.type === 'Error') { if (err.type === 'Error') {
message = err.message message = err.message
} else { } else {
@ -545,7 +547,7 @@ L.U.DataLayer = L.Evented.extend({
} else if (type === 'kml') { } else if (type === 'kml') {
callback(toGeoJSON.kml(toDom(c))) callback(toGeoJSON.kml(toDom(c)))
} else if (type === 'osm') { } else if (type === 'osm') {
var d let d
try { try {
d = JSON.parse(c) d = JSON.parse(c)
} catch (e) { } catch (e) {
@ -554,7 +556,7 @@ L.U.DataLayer = L.Evented.extend({
callback(osmtogeojson(d, { flatProperties: true })) callback(osmtogeojson(d, { flatProperties: true }))
} else if (type === 'geojson') { } else if (type === 'geojson') {
try { try {
var gj = JSON.parse(c) const gj = JSON.parse(c)
callback(gj) callback(gj)
} catch (err) { } catch (err) {
this.map.ui.alert({ content: 'Invalid JSON file: ' + err }) this.map.ui.alert({ content: 'Invalid JSON file: ' + err })
@ -565,11 +567,11 @@ L.U.DataLayer = L.Evented.extend({
geojsonToFeatures: function (geojson) { geojsonToFeatures: function (geojson) {
if (!geojson) return if (!geojson) return
var features = geojson instanceof Array ? geojson : geojson.features, const features = geojson instanceof Array ? geojson : geojson.features
i, let i
len, let len
latlng, let latlng
latlngs let latlngs
if (features) { if (features) {
L.Util.sortFeatures(features, this.map.getOption('sortKey')) L.Util.sortFeatures(features, this.map.getOption('sortKey'))
@ -579,11 +581,11 @@ L.U.DataLayer = L.Evented.extend({
return this return this
} }
var geometry = geojson.type === 'Feature' ? geojson.geometry : geojson const geometry = geojson.type === 'Feature' ? geojson.geometry : geojson
if (!geometry) return // null geometry is valid geojson. if (!geometry) return // null geometry is valid geojson.
var coords = geometry.coordinates, const coords = geometry.coordinates
layer, let layer
tmp let tmp
switch (geometry.type) { switch (geometry.type) {
case 'Point': case 'Point':
@ -655,13 +657,13 @@ L.U.DataLayer = L.Evented.extend({
}, },
importFromFiles: function (files, type) { importFromFiles: function (files, type) {
for (var i = 0, f; (f = files[i]); i++) { for (let i = 0, f; (f = files[i]); i++) {
this.importFromFile(f, type) this.importFromFile(f, type)
} }
}, },
importFromFile: function (f, type) { importFromFile: function (f, type) {
var reader = new FileReader() const reader = new FileReader()
type = type || L.Util.detectFileType(f) type = type || L.Util.detectFileType(f)
reader.readAsText(f) reader.readAsText(f)
reader.onload = (e) => this.importRaw(e.target.result, type) reader.onload = (e) => this.importRaw(e.target.result, type)
@ -731,10 +733,10 @@ L.U.DataLayer = L.Evented.extend({
}, },
clone: function () { clone: function () {
var options = L.Util.CopyJSON(this.options) const options = L.Util.CopyJSON(this.options)
options.name = L._('Clone of {name}', { name: this.options.name }) options.name = L._('Clone of {name}', { name: this.options.name })
delete options.id delete options.id
var geojson = L.Util.CopyJSON(this._geojson), const geojson = L.Util.CopyJSON(this._geojson),
datalayer = this.map.createDataLayer(options) datalayer = this.map.createDataLayer(options)
datalayer.fromGeoJSON(geojson) datalayer.fromGeoJSON(geojson)
return datalayer return datalayer
@ -779,7 +781,7 @@ L.U.DataLayer = L.Evented.extend({
if (!this.map.editEnabled || !this.isLoaded()) { if (!this.map.editEnabled || !this.isLoaded()) {
return return
} }
var container = L.DomUtil.create('div', 'umap-layer-properties-container'), const container = L.DomUtil.create('div', 'umap-layer-properties-container'),
metadataFields = [ metadataFields = [
'options.name', 'options.name',
'options.description', 'options.description',
@ -794,8 +796,8 @@ L.U.DataLayer = L.Evented.extend({
}, },
], ],
] ]
var title = L.DomUtil.add('h3', '', container, L._('Layer properties')) const title = L.DomUtil.add('h3', '', container, L._('Layer properties'))
var builder = new L.U.FormBuilder(this, metadataFields, { let builder = new L.U.FormBuilder(this, metadataFields, {
callback: function (e) { callback: function (e) {
this.map.updateDatalayersControl() this.map.updateDatalayersControl()
if (e.helper.field === 'options.type') { if (e.helper.field === 'options.type') {
@ -806,7 +808,7 @@ L.U.DataLayer = L.Evented.extend({
}) })
container.appendChild(builder.build()) container.appendChild(builder.build())
var shapeOptions = [ let shapeOptions = [
'options.color', 'options.color',
'options.iconClass', 'options.iconClass',
'options.iconUrl', 'options.iconUrl',
@ -820,7 +822,7 @@ L.U.DataLayer = L.Evented.extend({
shapeOptions = shapeOptions.concat(this.layer.getEditableOptions()) shapeOptions = shapeOptions.concat(this.layer.getEditableOptions())
var redrawCallback = function (field) { const redrawCallback = function (field) {
this.hide() this.hide()
this.layer.postUpdate(field) this.layer.postUpdate(field)
this.show() this.show()
@ -830,10 +832,10 @@ L.U.DataLayer = L.Evented.extend({
id: 'datalayer-advanced-properties', id: 'datalayer-advanced-properties',
callback: redrawCallback, callback: redrawCallback,
}) })
var shapeProperties = L.DomUtil.createFieldset(container, L._('Shape properties')) const shapeProperties = L.DomUtil.createFieldset(container, L._('Shape properties'))
shapeProperties.appendChild(builder.build()) shapeProperties.appendChild(builder.build())
var optionsFields = [ let optionsFields = [
'options.smoothFactor', 'options.smoothFactor',
'options.dashArray', 'options.dashArray',
'options.zoomTo', 'options.zoomTo',
@ -846,13 +848,13 @@ L.U.DataLayer = L.Evented.extend({
id: 'datalayer-advanced-properties', id: 'datalayer-advanced-properties',
callback: redrawCallback, callback: redrawCallback,
}) })
var advancedProperties = L.DomUtil.createFieldset( const advancedProperties = L.DomUtil.createFieldset(
container, container,
L._('Advanced properties') L._('Advanced properties')
) )
advancedProperties.appendChild(builder.build()) advancedProperties.appendChild(builder.build())
var popupFields = [ const popupFields = [
'options.popupShape', 'options.popupShape',
'options.popupTemplate', 'options.popupTemplate',
'options.popupContentTemplate', 'options.popupContentTemplate',
@ -861,13 +863,16 @@ L.U.DataLayer = L.Evented.extend({
'options.labelInteractive', 'options.labelInteractive',
] ]
builder = new L.U.FormBuilder(this, popupFields, { callback: redrawCallback }) builder = new L.U.FormBuilder(this, popupFields, { callback: redrawCallback })
var popupFieldset = L.DomUtil.createFieldset(container, L._('Interaction options')) const popupFieldset = L.DomUtil.createFieldset(
container,
L._('Interaction options')
)
popupFieldset.appendChild(builder.build()) popupFieldset.appendChild(builder.build())
if (!L.Util.isObject(this.options.remoteData)) { if (!L.Util.isObject(this.options.remoteData)) {
this.options.remoteData = {} this.options.remoteData = {}
} }
var remoteDataFields = [ const remoteDataFields = [
[ [
'options.remoteData.url', 'options.remoteData.url',
{ handler: 'Url', label: L._('Url'), helpEntries: 'formatURL' }, { handler: 'Url', label: L._('Url'), helpEntries: 'formatURL' },
@ -905,15 +910,15 @@ L.U.DataLayer = L.Evented.extend({
]) ])
} }
var remoteDataContainer = L.DomUtil.createFieldset(container, L._('Remote data')) const remoteDataContainer = L.DomUtil.createFieldset(container, L._('Remote data'))
builder = new L.U.FormBuilder(this, remoteDataFields) builder = new L.U.FormBuilder(this, remoteDataFields)
remoteDataContainer.appendChild(builder.build()) remoteDataContainer.appendChild(builder.build())
if (this.map.options.urls.datalayer_versions) this.buildVersionsFieldset(container) if (this.map.options.urls.datalayer_versions) this.buildVersionsFieldset(container)
var advancedActions = L.DomUtil.createFieldset(container, L._('Advanced actions')) const advancedActions = L.DomUtil.createFieldset(container, L._('Advanced actions'))
var advancedButtons = L.DomUtil.create('div', 'button-bar half', advancedActions) const advancedButtons = L.DomUtil.create('div', 'button-bar half', advancedActions)
var deleteLink = L.DomUtil.create( const deleteLink = L.DomUtil.create(
'a', 'a',
'button delete_datalayer_button umap-delete', 'button delete_datalayer_button umap-delete',
advancedButtons advancedButtons
@ -930,7 +935,7 @@ L.U.DataLayer = L.Evented.extend({
this this
) )
if (!this.isRemoteLayer()) { if (!this.isRemoteLayer()) {
var emptyLink = L.DomUtil.create('a', 'button umap-empty', advancedButtons) const emptyLink = L.DomUtil.create('a', 'button umap-empty', advancedButtons)
emptyLink.textContent = L._('Empty') emptyLink.textContent = L._('Empty')
emptyLink.href = '#' emptyLink.href = '#'
L.DomEvent.on(emptyLink, 'click', L.DomEvent.stop).on( L.DomEvent.on(emptyLink, 'click', L.DomEvent.stop).on(
@ -940,20 +945,20 @@ L.U.DataLayer = L.Evented.extend({
this this
) )
} }
var cloneLink = L.DomUtil.create('a', 'button umap-clone', advancedButtons) const cloneLink = L.DomUtil.create('a', 'button umap-clone', advancedButtons)
cloneLink.textContent = L._('Clone') cloneLink.textContent = L._('Clone')
cloneLink.href = '#' cloneLink.href = '#'
L.DomEvent.on(cloneLink, 'click', L.DomEvent.stop).on( L.DomEvent.on(cloneLink, 'click', L.DomEvent.stop).on(
cloneLink, cloneLink,
'click', 'click',
function () { function () {
var datalayer = this.clone() const datalayer = this.clone()
datalayer.edit() datalayer.edit()
}, },
this this
) )
if (this.umap_id) { if (this.umap_id) {
var download = L.DomUtil.create('a', 'button umap-download', advancedButtons) const download = L.DomUtil.create('a', 'button umap-download', advancedButtons)
download.textContent = L._('Download') download.textContent = L._('Download')
download.href = this._dataUrl() download.href = this._dataUrl()
download.target = '_blank' download.target = '_blank'
@ -967,12 +972,12 @@ L.U.DataLayer = L.Evented.extend({
}, },
buildVersionsFieldset: function (container) { buildVersionsFieldset: function (container) {
var appendVersion = function (data) { const appendVersion = function (data) {
var date = new Date(parseInt(data.at, 10)) const date = new Date(parseInt(data.at, 10))
var content = const content =
date.toLocaleDateString(L.locale) + ' (' + parseInt(data.size) / 1000 + 'Kb)' date.toLocaleDateString(L.locale) + ' (' + parseInt(data.size) / 1000 + 'Kb)'
var el = L.DomUtil.create('div', 'umap-datalayer-version', versionsContainer) const el = L.DomUtil.create('div', 'umap-datalayer-version', versionsContainer)
var a = L.DomUtil.create('a', '', el) const a = L.DomUtil.create('a', '', el)
L.DomUtil.add('span', '', el, content) L.DomUtil.add('span', '', el, content)
a.href = '#' a.href = '#'
a.title = L._('Restore this version') a.title = L._('Restore this version')
@ -990,7 +995,7 @@ L.U.DataLayer = L.Evented.extend({
callback: function () { callback: function () {
this.map.xhr.get(this.getVersionsUrl(), { this.map.xhr.get(this.getVersionsUrl(), {
callback: function (data) { callback: function (data) {
for (var i = 0; i < data.versions.length; i++) { for (let i = 0; i < data.versions.length; i++) {
appendVersion.call(this, data.versions[i]) appendVersion.call(this, data.versions[i])
} }
}, },
@ -1018,7 +1023,7 @@ L.U.DataLayer = L.Evented.extend({
}, },
featuresToGeoJSON: function () { featuresToGeoJSON: function () {
var features = [] const features = []
this.eachLayer((layer) => features.push(layer.toGeoJSON())) this.eachLayer((layer) => features.push(layer.toGeoJSON()))
return features return features
}, },
@ -1041,7 +1046,7 @@ L.U.DataLayer = L.Evented.extend({
zoomTo: function () { zoomTo: function () {
if (!this.isVisible()) return if (!this.isVisible()) return
var bounds = this.layer.getBounds() const bounds = this.layer.getBounds()
if (bounds.isValid()) this.map.fitBounds(bounds) if (bounds.isValid()) this.map.fitBounds(bounds)
}, },
@ -1063,12 +1068,12 @@ L.U.DataLayer = L.Evented.extend({
getFeatureByIndex: function (index) { getFeatureByIndex: function (index) {
if (index === -1) index = this._index.length - 1 if (index === -1) index = this._index.length - 1
var id = this._index[index] const id = this._index[index]
return this._layers[id] return this._layers[id]
}, },
getNextFeature: function (feature) { getNextFeature: function (feature) {
var id = this._index.indexOf(L.stamp(feature)), const id = this._index.indexOf(L.stamp(feature)),
nextId = this._index[id + 1] nextId = this._index[id + 1]
return nextId ? this._layers[nextId] : this.getNextBrowsable().getFeatureByIndex(0) return nextId ? this._layers[nextId] : this.getNextBrowsable().getFeatureByIndex(0)
}, },
@ -1077,7 +1082,7 @@ L.U.DataLayer = L.Evented.extend({
if (this._index <= 1) { if (this._index <= 1) {
return null return null
} }
var id = this._index.indexOf(L.stamp(feature)), const id = this._index.indexOf(L.stamp(feature)),
previousId = this._index[id - 1] previousId = this._index[id - 1]
return previousId return previousId
? this._layers[previousId] ? this._layers[previousId]
@ -1085,9 +1090,9 @@ L.U.DataLayer = L.Evented.extend({
}, },
getPreviousBrowsable: function () { getPreviousBrowsable: function () {
var id = this.getRank(), let id = this.getRank()
next, let next
index = this.map.datalayers_index const index = this.map.datalayers_index
while (((id = index[++id] ? id : 0), (next = index[id]))) { while (((id = index[++id] ? id : 0), (next = index[id]))) {
if (next === this || (next.allowBrowse() && next.hasData())) break if (next === this || (next.allowBrowse() && next.hasData())) break
} }
@ -1095,9 +1100,9 @@ L.U.DataLayer = L.Evented.extend({
}, },
getNextBrowsable: function () { getNextBrowsable: function () {
var id = this.getRank(), let id = this.getRank()
prev, let prev
index = this.map.datalayers_index const index = this.map.datalayers_index
while (((id = index[--id] ? id : index.length - 1), (prev = index[id]))) { while (((id = index[--id] ? id : index.length - 1), (prev = index[id]))) {
if (prev === this || (prev.allowBrowse() && prev.hasData())) break if (prev === this || (prev.allowBrowse() && prev.hasData())) break
} }
@ -1129,13 +1134,13 @@ L.U.DataLayer = L.Evented.extend({
if (!this.isLoaded()) { if (!this.isLoaded()) {
return return
} }
var geojson = this.umapGeoJSON() const geojson = this.umapGeoJSON()
var formData = new FormData() const formData = new FormData()
formData.append('name', this.options.name) formData.append('name', this.options.name)
formData.append('display_on_load', !!this.options.displayOnLoad) formData.append('display_on_load', !!this.options.displayOnLoad)
formData.append('rank', this.getRank()) formData.append('rank', this.getRank())
// Filename support is shaky, don't do it for now. // Filename support is shaky, don't do it for now.
var blob = new Blob([JSON.stringify(geojson)], { type: 'application/json' }) const blob = new Blob([JSON.stringify(geojson)], { type: 'application/json' })
formData.append('geojson', blob) formData.append('geojson', blob)
this.map.post(this.getSaveUrl(), { this.map.post(this.getSaveUrl(), {
data: formData, data: formData,
@ -1159,7 +1164,7 @@ L.U.DataLayer = L.Evented.extend({
}, },
saveDelete: function () { saveDelete: function () {
var callback = function () { const callback = function () {
this.isDirty = false this.isDirty = false
this.map.continueSaving() this.map.continueSaving()
} }
@ -1180,7 +1185,7 @@ L.U.DataLayer = L.Evented.extend({
tableEdit: function () { tableEdit: function () {
if (this.isRemoteLayer() || !this.isVisible()) return if (this.isRemoteLayer() || !this.isVisible()) return
var editor = new L.U.TableEditor(this) const editor = new L.U.TableEditor(this)
editor.edit() editor.edit()
}, },
}) })

View file

@ -11,8 +11,8 @@ L.U.MapPermissions = L.Class.extend({
initialize: function (map) { initialize: function (map) {
this.setOptions(map.options.permissions) this.setOptions(map.options.permissions)
this.map = map this.map = map
var isDirty = false, let isDirty = false
self = this const self = this
try { try {
Object.defineProperty(this, 'isDirty', { Object.defineProperty(this, 'isDirty', {
get: function () { get: function () {
@ -54,12 +54,12 @@ L.U.MapPermissions = L.Class.extend({
content: L._('Please save the map first'), content: L._('Please save the map first'),
level: 'info', level: 'info',
}) })
var container = L.DomUtil.create('div', 'permissions-panel'), const container = L.DomUtil.create('div', 'permissions-panel'),
fields = [], fields = [],
title = L.DomUtil.create('h4', '', container) title = L.DomUtil.create('h4', '', container)
if (this.isAnonymousMap()) { if (this.isAnonymousMap()) {
if (this.options.anonymous_edit_url) { if (this.options.anonymous_edit_url) {
var helpText = L._('Secret edit link is:<br>{link}', { const helpText = L._('Secret edit link is:<br>{link}', {
link: this.options.anonymous_edit_url, link: this.options.anonymous_edit_url,
}) })
fields.push([ fields.push([
@ -101,15 +101,18 @@ L.U.MapPermissions = L.Class.extend({
]) ])
} }
title.textContent = L._('Update permissions') title.textContent = L._('Update permissions')
var builder = new L.U.FormBuilder(this, fields) const builder = new L.U.FormBuilder(this, fields)
var form = builder.build() const form = builder.build()
container.appendChild(form) container.appendChild(form)
if (this.isAnonymousMap() && this.map.options.user) { if (this.isAnonymousMap() && this.map.options.user) {
// We have a user, and this user has come through here, so they can edit the map, so let's allow to own the map. // We have a user, and this user has come through here, so they can edit the map, so let's allow to own the map.
// Note: real check is made on the back office anyway. // Note: real check is made on the back office anyway.
var advancedActions = L.DomUtil.createFieldset(container, L._('Advanced actions')) const advancedActions = L.DomUtil.createFieldset(
var advancedButtons = L.DomUtil.create('div', 'button-bar', advancedActions) container,
var download = L.DomUtil.create('a', 'button', advancedButtons) L._('Advanced actions')
)
const advancedButtons = L.DomUtil.create('div', 'button-bar', advancedActions)
const download = L.DomUtil.create('a', 'button', advancedButtons)
download.href = '#' download.href = '#'
download.textContent = L._('Attach the map to my account') download.textContent = L._('Attach the map to my account')
L.DomEvent.on(download, 'click', L.DomEvent.stop).on( L.DomEvent.on(download, 'click', L.DomEvent.stop).on(
@ -138,10 +141,10 @@ L.U.MapPermissions = L.Class.extend({
save: function () { save: function () {
if (!this.isDirty) return this.map.continueSaving() if (!this.isDirty) return this.map.continueSaving()
var formData = new FormData() const formData = new FormData()
if (!this.isAnonymousMap() && this.options.editors) { if (!this.isAnonymousMap() && this.options.editors) {
var editors = this.options.editors.map((u) => u.id) const editors = this.options.editors.map((u) => u.id)
for (var i = 0; i < this.options.editors.length; i++) for (let i = 0; i < this.options.editors.length; i++)
formData.append('editors', this.options.editors[i].id) formData.append('editors', this.options.editors[i].id)
} }
if (this.isOwner() || this.isAnonymousMap()) if (this.isOwner() || this.isAnonymousMap())
@ -175,7 +178,7 @@ L.U.MapPermissions = L.Class.extend({
addOwnerLink: function (element, container) { addOwnerLink: function (element, container) {
if (this.options.owner && this.options.owner.name && this.options.owner.url) { if (this.options.owner && this.options.owner.name && this.options.owner.url) {
var ownerContainer = L.DomUtil.add( const ownerContainer = L.DomUtil.add(
element, element,
'umap-map-owner', 'umap-map-owner',
container, container,

View file

@ -14,12 +14,12 @@ L.U.Popup = L.Popup.extend({
}, },
format: function () { format: function () {
var mode = this.feature.getOption('popupTemplate') || 'Default', const mode = this.feature.getOption('popupTemplate') || 'Default',
klass = L.U.PopupTemplate[mode] || L.U.PopupTemplate.Default klass = L.U.PopupTemplate[mode] || L.U.PopupTemplate.Default
this.content = new klass(this.feature, this.container) this.content = new klass(this.feature, this.container)
this.content.render() this.content.render()
var els = this.container.querySelectorAll('img,iframe') const els = this.container.querySelectorAll('img,iframe')
for (var i = 0; i < els.length; i++) { for (let i = 0; i < els.length; i++) {
this.onElementLoaded(els[i]) this.onElementLoaded(els[i])
} }
if (!els.length && this.container.textContent.replace('\n', '') === '') { if (!els.length && this.container.textContent.replace('\n', '') === '') {
@ -55,9 +55,9 @@ L.U.Popup.Panel = L.U.Popup.extend({
}, },
allButton: function () { allButton: function () {
var button = L.DomUtil.create('li', '') const button = L.DomUtil.create('li', '')
L.DomUtil.create('i', 'umap-icon-16 umap-list', button) L.DomUtil.create('i', 'umap-icon-16 umap-list', button)
var label = L.DomUtil.create('span', '', button) const label = L.DomUtil.create('span', '', button)
label.textContent = label.title = L._('See all') label.textContent = label.title = L._('See all')
L.DomEvent.on(button, 'click', this.feature.map.openBrowser, this.feature.map) L.DomEvent.on(button, 'click', this.feature.map.openBrowser, this.feature.map)
return button return button
@ -97,11 +97,11 @@ L.U.PopupTemplate.Default = L.Class.extend({
renderTitle: function () {}, renderTitle: function () {},
renderBody: function () { renderBody: function () {
var template = this.feature.getOption('popupContentTemplate'), const template = this.feature.getOption('popupContentTemplate')
container = L.DomUtil.create('div', 'umap-popup-container'), const container = L.DomUtil.create('div', 'umap-popup-container')
content = '', let content = ''
properties, let properties
center let center
properties = this.feature.extendedProperties() properties = this.feature.extendedProperties()
// Resolve properties inside description // Resolve properties inside description
properties.description = L.Util.greedyTemplate( properties.description = L.Util.greedyTemplate(
@ -116,7 +116,7 @@ L.U.PopupTemplate.Default = L.Class.extend({
renderFooter: function () { renderFooter: function () {
if (this.feature.hasPopupFooter()) { if (this.feature.hasPopupFooter()) {
var footerContainer = L.DomUtil.create( const footerContainer = L.DomUtil.create(
'div', 'div',
'umap-footer-container', 'umap-footer-container',
this.container this.container
@ -154,9 +154,9 @@ L.U.PopupTemplate.Default = L.Class.extend({
}, },
render: function () { render: function () {
var title = this.renderTitle() const title = this.renderTitle()
if (title) this.container.appendChild(title) if (title) this.container.appendChild(title)
var body = this.renderBody() const body = this.renderBody()
if (body) L.DomUtil.add('div', 'umap-popup-content', this.container, body) if (body) L.DomUtil.add('div', 'umap-popup-content', this.container, body)
this.renderFooter() this.renderFooter()
}, },
@ -164,7 +164,7 @@ L.U.PopupTemplate.Default = L.Class.extend({
L.U.PopupTemplate.BaseWithTitle = L.U.PopupTemplate.Default.extend({ L.U.PopupTemplate.BaseWithTitle = L.U.PopupTemplate.Default.extend({
renderTitle: function () { renderTitle: function () {
var title let title
if (this.feature.getDisplayName()) { if (this.feature.getDisplayName()) {
title = L.DomUtil.create('h3', 'popup-title') title = L.DomUtil.create('h3', 'popup-title')
title.textContent = this.feature.getDisplayName() title.textContent = this.feature.getDisplayName()
@ -182,15 +182,15 @@ L.U.PopupTemplate.Table = L.U.PopupTemplate.BaseWithTitle.extend({
}, },
addRow: function (container, key, value) { addRow: function (container, key, value) {
var tr = L.DomUtil.create('tr', '', container) const tr = L.DomUtil.create('tr', '', container)
L.DomUtil.add('th', '', tr, key) L.DomUtil.add('th', '', tr, key)
L.DomUtil.add('td', '', tr, this.formatRow(key, value)) L.DomUtil.add('td', '', tr, this.formatRow(key, value))
}, },
renderBody: function () { renderBody: function () {
var table = L.DomUtil.create('table') const table = L.DomUtil.create('table')
for (var key in this.feature.properties) { for (const key in this.feature.properties) {
if (typeof this.feature.properties[key] === 'object' || key === 'name') continue if (typeof this.feature.properties[key] === 'object' || key === 'name') continue
// TODO, manage links (url, mailto, wikipedia...) // TODO, manage links (url, mailto, wikipedia...)
this.addRow(table, key, L.Util.escapeHTML(this.feature.properties[key]).trim()) this.addRow(table, key, L.Util.escapeHTML(this.feature.properties[key]).trim())
@ -207,11 +207,11 @@ L.U.PopupTemplate.GeoRSSImage = L.U.PopupTemplate.BaseWithTitle.extend({
}, },
renderBody: function () { renderBody: function () {
var container = L.DomUtil.create('a') const container = L.DomUtil.create('a')
container.href = this.feature.properties.link container.href = this.feature.properties.link
container.target = '_blank' container.target = '_blank'
if (this.feature.properties.img) { if (this.feature.properties.img) {
var img = L.DomUtil.create('img', '', container) const img = L.DomUtil.create('img', '', container)
img.src = this.feature.properties.img img.src = this.feature.properties.img
// Sadly, we are unable to override this from JS the clean way // Sadly, we are unable to override this from JS the clean way
// See https://github.com/Leaflet/Leaflet/commit/61d746818b99d362108545c151a27f09d60960ee#commitcomment-6061847 // See https://github.com/Leaflet/Leaflet/commit/61d746818b99d362108545c151a27f09d60960ee#commitcomment-6061847
@ -229,7 +229,7 @@ L.U.PopupTemplate.GeoRSSLink = L.U.PopupTemplate.Default.extend({
}, },
renderBody: function () { renderBody: function () {
var title = this.renderTitle(this), const title = this.renderTitle(this),
a = L.DomUtil.add('a') a = L.DomUtil.add('a')
a.href = this.feature.properties.link a.href = this.feature.properties.link
a.target = '_blank' a.target = '_blank'

View file

@ -12,13 +12,16 @@ L.U.Slideshow = L.Class.extend({
this.setOptions(options) this.setOptions(options)
this.map = map this.map = map
this._id = null this._id = null
var current = null, // current feature
self = this let // current feature
current = null
const self = this
try { try {
Object.defineProperty(this, 'current', { Object.defineProperty(this, 'current', {
get: function () { get: function () {
if (!current) { if (!current) {
var datalayer = this.defaultDatalayer() const datalayer = this.defaultDatalayer()
if (datalayer) current = datalayer.getFeatureByIndex(0) if (datalayer) current = datalayer.getFeatureByIndex(0)
} }
return current return current
@ -66,11 +69,11 @@ L.U.Slideshow = L.Class.extend({
}, },
timeSpinner: function () { timeSpinner: function () {
var time = parseInt(this.options.delay, 10) const time = parseInt(this.options.delay, 10)
if (!time) return if (!time) return
var css = 'rotation ' + time / 1000 + 's infinite linear', const css = 'rotation ' + time / 1000 + 's infinite linear',
spinners = document.querySelectorAll('.umap-slideshow-toolbox .play .spinner') spinners = document.querySelectorAll('.umap-slideshow-toolbox .play .spinner')
for (var i = 0; i < spinners.length; i++) { for (let i = 0; i < spinners.length; i++) {
spinners[i].style.animation = css spinners[i].style.animation = css
spinners[i].style['-webkit-animation'] = css spinners[i].style['-webkit-animation'] = css
spinners[i].style['-moz-animation'] = css spinners[i].style['-moz-animation'] = css
@ -80,10 +83,11 @@ L.U.Slideshow = L.Class.extend({
resetSpinners: function () { resetSpinners: function () {
// Make that animnation is coordinated with user actions // Make that animnation is coordinated with user actions
var spinners = document.querySelectorAll('.umap-slideshow-toolbox .play .spinner'), const spinners = document.querySelectorAll('.umap-slideshow-toolbox .play .spinner')
el,
newOne let el
for (var i = 0; i < spinners.length; i++) { let newOne
for (let i = 0; i < spinners.length; i++) {
el = spinners[i] el = spinners[i]
newOne = el.cloneNode(true) newOne = el.cloneNode(true)
el.parentNode.replaceChild(newOne, el) el.parentNode.replaceChild(newOne, el)
@ -136,7 +140,7 @@ L.U.Slideshow = L.Class.extend({
}, },
renderToolbox: function (container) { renderToolbox: function (container) {
var box = L.DomUtil.create('ul', 'umap-slideshow-toolbox'), const box = L.DomUtil.create('ul', 'umap-slideshow-toolbox'),
play = L.DomUtil.create('li', 'play', box), play = L.DomUtil.create('li', 'play', box),
stop = L.DomUtil.create('li', 'stop', box), stop = L.DomUtil.create('li', 'stop', box),
prev = L.DomUtil.create('li', 'prev', box), prev = L.DomUtil.create('li', 'prev', box),
@ -146,7 +150,7 @@ L.U.Slideshow = L.Class.extend({
stop.title = L._('Stop slideshow') stop.title = L._('Stop slideshow')
next.title = L._('Zoom to the next') next.title = L._('Zoom to the next')
prev.title = L._('Zoom to the previous') prev.title = L._('Zoom to the previous')
var toggle = function () { const toggle = function () {
if (this._id) this.pause() if (this._id) this.pause()
else this.play() else this.play()
} }

View file

@ -9,19 +9,19 @@ L.U.TableEditor = L.Class.extend({
renderHeaders: function () { renderHeaders: function () {
this.header.innerHTML = '' this.header.innerHTML = ''
for (var i = 0; i < this.properties.length; i++) { for (let i = 0; i < this.properties.length; i++) {
this.renderHeader(this.properties[i]) this.renderHeader(this.properties[i])
} }
}, },
renderHeader: function (property) { renderHeader: function (property) {
var container = L.DomUtil.create('div', 'tcell', this.header), const container = L.DomUtil.create('div', 'tcell', this.header),
title = L.DomUtil.add('span', '', container, property), title = L.DomUtil.add('span', '', container, property),
del = L.DomUtil.create('i', 'umap-delete', container), del = L.DomUtil.create('i', 'umap-delete', container),
rename = L.DomUtil.create('i', 'umap-edit', container) rename = L.DomUtil.create('i', 'umap-edit', container)
del.title = L._('Delete this property on all the features') del.title = L._('Delete this property on all the features')
rename.title = L._('Rename this property on all the features') rename.title = L._('Rename this property on all the features')
var doDelete = function () { const doDelete = function () {
if ( if (
confirm( confirm(
L._('Are you sure you want to delete this property on all the features?') L._('Are you sure you want to delete this property on all the features?')
@ -35,8 +35,11 @@ L.U.TableEditor = L.Class.extend({
this.edit() this.edit()
} }
} }
var doRename = function () { const doRename = function () {
var newName = prompt(L._('Please enter the new name of this property'), property) const newName = prompt(
L._('Please enter the new name of this property'),
property
)
if (!newName || !this.validateName(newName)) return if (!newName || !this.validateName(newName)) return
this.datalayer.eachLayer((feature) => { this.datalayer.eachLayer((feature) => {
feature.renameProperty(property, newName) feature.renameProperty(property, newName)
@ -51,7 +54,7 @@ L.U.TableEditor = L.Class.extend({
}, },
renderRow: function (feature) { renderRow: function (feature) {
var builder = new L.U.FormBuilder(feature, this.field_properties, { const builder = new L.U.FormBuilder(feature, this.field_properties, {
id: 'umap-feature-properties_' + L.stamp(feature), id: 'umap-feature-properties_' + L.stamp(feature),
className: 'trow', className: 'trow',
callback: feature.resetTooltip, callback: feature.resetTooltip,
@ -66,7 +69,7 @@ L.U.TableEditor = L.Class.extend({
this.properties.splice(this.properties.indexOf('description'), 1) this.properties.splice(this.properties.indexOf('description'), 1)
this.properties.sort() this.properties.sort()
this.field_properties = [] this.field_properties = []
for (var i = 0; i < this.properties.length; i++) { for (let i = 0; i < this.properties.length; i++) {
this.field_properties.push([ this.field_properties.push([
'properties.' + this.properties[i], 'properties.' + this.properties[i],
{ wrapper: 'div', wrapperClass: 'tcell' }, { wrapper: 'div', wrapperClass: 'tcell' },
@ -90,24 +93,24 @@ L.U.TableEditor = L.Class.extend({
}, },
edit: function () { edit: function () {
var id = 'tableeditor:edit' const id = 'tableeditor:edit'
this.datalayer.map.fire('dataloading', { id: id }) this.datalayer.map.fire('dataloading', { id: id })
this.compileProperties() this.compileProperties()
this.renderHeaders() this.renderHeaders()
this.body.innerHTML = '' this.body.innerHTML = ''
this.datalayer.eachLayer(this.renderRow, this) this.datalayer.eachLayer(this.renderRow, this)
var addButton = L.DomUtil.create('li', 'add-property') const addButton = L.DomUtil.create('li', 'add-property')
L.DomUtil.create('i', 'umap-icon-16 umap-add', addButton) L.DomUtil.create('i', 'umap-icon-16 umap-add', addButton)
var label = L.DomUtil.create('span', '', addButton) const label = L.DomUtil.create('span', '', addButton)
label.textContent = label.title = L._('Add a new property') label.textContent = label.title = L._('Add a new property')
var addProperty = function () { const addProperty = function () {
var newName = prompt(L._('Please enter the name of the property')) const newName = prompt(L._('Please enter the name of the property'))
if (!newName || !this.validateName(newName)) return if (!newName || !this.validateName(newName)) return
this.datalayer.indexProperty(newName) this.datalayer.indexProperty(newName)
this.edit() this.edit()
} }
L.DomEvent.on(addButton, 'click', addProperty, this) L.DomEvent.on(addButton, 'click', addProperty, this)
var className = const className =
this.properties.length > 2 this.properties.length > 2
? 'umap-table-editor fullwidth dark' ? 'umap-table-editor fullwidth dark'
: 'umap-table-editor dark' : 'umap-table-editor dark'

View file

@ -31,17 +31,17 @@ L.U.UI = L.Evented.extend({
// by previous ui processes... // by previous ui processes...
this.resetPanelClassName() this.resetPanelClassName()
this._panel.innerHTML = '' this._panel.innerHTML = ''
var actionsContainer = L.DomUtil.create('ul', 'toolbox', this._panel) const actionsContainer = L.DomUtil.create('ul', 'toolbox', this._panel)
var body = L.DomUtil.create('div', 'body', this._panel) const body = L.DomUtil.create('div', 'body', this._panel)
if (e.data.html.nodeType && e.data.html.nodeType === 1) if (e.data.html.nodeType && e.data.html.nodeType === 1)
body.appendChild(e.data.html) body.appendChild(e.data.html)
else body.innerHTML = e.data.html else body.innerHTML = e.data.html
var closeLink = L.DomUtil.create('li', 'umap-close-link', actionsContainer) const closeLink = L.DomUtil.create('li', 'umap-close-link', actionsContainer)
L.DomUtil.add('i', 'umap-close-icon', closeLink) L.DomUtil.add('i', 'umap-close-icon', closeLink)
var label = L.DomUtil.create('span', '', closeLink) const label = L.DomUtil.create('span', '', closeLink)
label.title = label.textContent = L._('Close') label.title = label.textContent = L._('Close')
if (e.actions) { if (e.actions) {
for (var i = 0; i < e.actions.length; i++) { for (let i = 0; i < e.actions.length; i++) {
actionsContainer.appendChild(e.actions[i]) actionsContainer.appendChild(e.actions[i])
} }
} }
@ -75,17 +75,17 @@ L.U.UI = L.Evented.extend({
}, },
popAlert: function (e) { popAlert: function (e) {
var self = this const self = this
if (!e) { if (!e) {
if (this.ALERTS.length) e = this.ALERTS.pop() if (this.ALERTS.length) e = this.ALERTS.pop()
else return else return
} }
var timeoutID, let timeoutID
level_class = e.level && e.level == 'info' ? 'info' : 'error' const level_class = e.level && e.level == 'info' ? 'info' : 'error'
this._alert.innerHTML = '' this._alert.innerHTML = ''
L.DomUtil.addClass(this.parent, 'umap-alert') L.DomUtil.addClass(this.parent, 'umap-alert')
L.DomUtil.addClass(this._alert, level_class) L.DomUtil.addClass(this._alert, level_class)
var close = function () { const close = function () {
if (timeoutID !== this.ALERT_ID) { if (timeoutID !== this.ALERT_ID) {
return return
} // Another alert has been forced } // Another alert has been forced
@ -95,10 +95,10 @@ L.U.UI = L.Evented.extend({
if (timeoutID) window.clearTimeout(timeoutID) if (timeoutID) window.clearTimeout(timeoutID)
this.popAlert() this.popAlert()
} }
var closeLink = L.DomUtil.create('a', 'umap-close-link', this._alert) const closeLink = L.DomUtil.create('a', 'umap-close-link', this._alert)
closeLink.href = '#' closeLink.href = '#'
L.DomUtil.add('i', 'umap-close-icon', closeLink) L.DomUtil.add('i', 'umap-close-icon', closeLink)
var label = L.DomUtil.create('span', '', closeLink) const label = L.DomUtil.create('span', '', closeLink)
label.title = label.textContent = L._('Close') label.title = label.textContent = L._('Close')
L.DomEvent.on(closeLink, 'click', L.DomEvent.stop).on( L.DomEvent.on(closeLink, 'click', L.DomEvent.stop).on(
closeLink, closeLink,
@ -108,8 +108,8 @@ L.U.UI = L.Evented.extend({
) )
L.DomUtil.add('div', '', this._alert, e.content) L.DomUtil.add('div', '', this._alert, e.content)
if (e.actions) { if (e.actions) {
var action, el let action, el
for (var i = 0; i < e.actions.length; i++) { for (let i = 0; i < e.actions.length; i++) {
action = e.actions[i] action = e.actions[i]
el = L.DomUtil.element('a', { className: 'umap-action' }, this._alert) el = L.DomUtil.element('a', { className: 'umap-action' }, this._alert)
el.href = '#' el.href = '#'
@ -132,7 +132,7 @@ L.U.UI = L.Evented.extend({
tooltip: function (e) { tooltip: function (e) {
this.TOOLTIP_ID = Math.random() this.TOOLTIP_ID = Math.random()
var id = this.TOOLTIP_ID const id = this.TOOLTIP_ID
L.DomUtil.addClass(this.parent, 'umap-tooltip') L.DomUtil.addClass(this.parent, 'umap-tooltip')
if (e.anchor && e.position === 'top') this.anchorTooltipTop(e.anchor) if (e.anchor && e.position === 'top') this.anchorTooltipTop(e.anchor)
else if (e.anchor && e.position === 'left') this.anchorTooltipLeft(e.anchor) else if (e.anchor && e.position === 'left') this.anchorTooltipLeft(e.anchor)
@ -148,7 +148,7 @@ L.U.UI = L.Evented.extend({
anchorTooltipAbsolute: function () { anchorTooltipAbsolute: function () {
this._tooltip.className = '' this._tooltip.className = ''
var left = const left =
this.parent.offsetLeft + this.parent.offsetLeft +
this.parent.clientWidth / 2 - this.parent.clientWidth / 2 -
this._tooltip.clientWidth / 2, this._tooltip.clientWidth / 2,
@ -158,7 +158,7 @@ L.U.UI = L.Evented.extend({
anchorTooltipTop: function (el) { anchorTooltipTop: function (el) {
this._tooltip.className = 'tooltip-top' this._tooltip.className = 'tooltip-top'
var coords = this.getPosition(el) const coords = this.getPosition(el)
this.setTooltipPosition({ this.setTooltipPosition({
left: coords.left - 10, left: coords.left - 10,
bottom: this.getDocHeight() - coords.top + 11, bottom: this.getDocHeight() - coords.top + 11,
@ -167,7 +167,7 @@ L.U.UI = L.Evented.extend({
anchorTooltipLeft: function (el) { anchorTooltipLeft: function (el) {
this._tooltip.className = 'tooltip-left' this._tooltip.className = 'tooltip-left'
var coords = this.getPosition(el) const coords = this.getPosition(el)
this.setTooltipPosition({ this.setTooltipPosition({
top: coords.top, top: coords.top,
right: document.documentElement.offsetWidth - coords.left + 11, right: document.documentElement.offsetWidth - coords.left + 11,
@ -196,7 +196,7 @@ L.U.UI = L.Evented.extend({
}, },
getDocHeight: function () { getDocHeight: function () {
var D = document const D = document
return Math.max( return Math.max(
D.body.scrollHeight, D.body.scrollHeight,
D.documentElement.scrollHeight, D.documentElement.scrollHeight,

View file

@ -4,7 +4,7 @@ L.U.Xhr = L.Evented.extend({
}, },
_wrapper: function () { _wrapper: function () {
var wrapper let wrapper
if (window.XMLHttpRequest === undefined) { if (window.XMLHttpRequest === undefined) {
wrapper = () => { wrapper = () => {
try { try {
@ -24,11 +24,11 @@ L.U.Xhr = L.Evented.extend({
}, },
_ajax: function (settings) { _ajax: function (settings) {
var xhr = this._wrapper(), const xhr = this._wrapper(),
id = Math.random(), id = Math.random(),
self = this self = this
this.fire('dataloading', { id: id }) this.fire('dataloading', { id: id })
var loaded = () => { const loaded = () => {
self.fire('dataload', { id: id }) self.fire('dataload', { id: id })
} }
@ -53,7 +53,7 @@ L.U.Xhr = L.Evented.extend({
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest') xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
} }
if (settings.headers) { if (settings.headers) {
for (var name in settings.headers) { for (const name in settings.headers) {
xhr.setRequestHeader(name, settings.headers[name]) xhr.setRequestHeader(name, settings.headers[name])
} }
} }
@ -68,10 +68,10 @@ L.U.Xhr = L.Evented.extend({
level: 'error', level: 'error',
}) })
} else if (xhr.status === 412) { } else if (xhr.status === 412) {
var msg = L._( const msg = L._(
'Woops! Someone else seems to have edited the data. You can save anyway, but this will erase the changes made by others.' 'Woops! Someone else seems to have edited the data. You can save anyway, but this will erase the changes made by others.'
) )
var actions = [ const actions = [
{ {
label: L._('Save anyway'), label: L._('Save anyway'),
callback: function () { callback: function () {
@ -111,20 +111,20 @@ L.U.Xhr = L.Evented.extend({
// supports only JSON as response data type // supports only JSON as response data type
_json: function (verb, uri, options) { _json: function (verb, uri, options) {
var args = arguments, const args = arguments,
self = this self = this
var default_options = { const default_options = {
async: true, async: true,
callback: null, callback: null,
responseType: 'text', responseType: 'text',
data: null, data: null,
listen_form: null, // optional form to listen in default callback listen_form: null, // optional form to listen in default callback
} }
var settings = L.Util.extend({}, default_options, options) const settings = L.Util.extend({}, default_options, options)
if (verb === 'POST') { if (verb === 'POST') {
// find a way not to make this django specific // find a way not to make this django specific
var token = document.cookie.replace( const token = document.cookie.replace(
/(?:(?:^|.*;\s*)csrftoken\s*\=\s*([^;]*).*$)|^.*$/, /(?:(?:^|.*;\s*)csrftoken\s*\=\s*([^;]*).*$)|^.*$/,
'$1' '$1'
) )
@ -134,8 +134,8 @@ L.U.Xhr = L.Evented.extend({
} }
} }
var callback = function (responseText, response) { const callback = function (responseText, response) {
var data let data
try { try {
data = JSON.parse(responseText) data = JSON.parse(responseText)
} catch (err) { } catch (err) {
@ -180,8 +180,8 @@ L.U.Xhr = L.Evented.extend({
submit_form: function (form_id, options) { submit_form: function (form_id, options) {
if (typeof options === 'undefined') options = {} if (typeof options === 'undefined') options = {}
var form = L.DomUtil.get(form_id) const form = L.DomUtil.get(form_id)
var formData = new FormData(form) const formData = new FormData(form)
if (options.extraFormData) formData.append(options.extraFormData) if (options.extraFormData) formData.append(options.extraFormData)
options.data = formData options.data = formData
this.post(form.action, options) this.post(form.action, options)
@ -189,7 +189,7 @@ L.U.Xhr = L.Evented.extend({
}, },
listen_form: function (form_id, options) { listen_form: function (form_id, options) {
var form = L.DomUtil.get(form_id), const form = L.DomUtil.get(form_id),
self = this self = this
if (!form) return if (!form) return
L.DomEvent.on(form, 'submit', L.DomEvent.stopPropagation) L.DomEvent.on(form, 'submit', L.DomEvent.stopPropagation)
@ -200,7 +200,7 @@ L.U.Xhr = L.Evented.extend({
}, },
listen_link: function (link_id, options) { listen_link: function (link_id, options) {
var link = L.DomUtil.get(link_id), const link = L.DomUtil.get(link_id),
self = this self = this
if (link) { if (link) {
L.DomEvent.on(link, 'click', L.DomEvent.stop).on(link, 'click', () => { L.DomEvent.on(link, 'click', L.DomEvent.stop).on(link, 'click', () => {
@ -215,7 +215,7 @@ L.U.Xhr = L.Evented.extend({
default_callback: function (data, options) { default_callback: function (data, options) {
// default callback, to avoid boilerplate // default callback, to avoid boilerplate
if (data.redirect) { if (data.redirect) {
var newPath = data.redirect const newPath = data.redirect
if (window.location.pathname == newPath) if (window.location.pathname == newPath)
window.location.reload() // Keep the hash, so the current view window.location.reload() // Keep the hash, so the current view
else window.location = newPath else window.location = newPath
@ -225,8 +225,8 @@ L.U.Xhr = L.Evented.extend({
} else if (data.error) { } else if (data.error) {
this.ui.alert({ content: data.error, level: 'error' }) this.ui.alert({ content: data.error, level: 'error' })
} else if (data.html) { } else if (data.html) {
var ui_options = { data: data }, const ui_options = { data: data }
listen_options let listen_options
if (options.className) ui_options.className = options.className if (options.className) ui_options.className = options.className
this.ui.openPanel(ui_options) this.ui.openPanel(ui_options)
// To low boilerplate, if there is a form, listen it // To low boilerplate, if there is a form, listen it
@ -236,7 +236,7 @@ L.U.Xhr = L.Evented.extend({
this.listen_form(options.listen_form.id, listen_options) this.listen_form(options.listen_form.id, listen_options)
} }
if (options.listen_link) { if (options.listen_link) {
for (var i = 0, l = options.listen_link.length; i < l; i++) { for (let i = 0, l = options.listen_link.length; i < l; i++) {
// Listen link again // Listen link again
listen_options = L.Util.extend({}, options, options.listen_link[i].options) listen_options = L.Util.extend({}, options, options.listen_link[i].options)
this.listen_link(options.listen_link[i].id, listen_options) this.listen_link(options.listen_link[i].id, listen_options)
@ -251,13 +251,13 @@ L.U.Xhr = L.Evented.extend({
login: function (data, args) { login: function (data, args) {
// data.html: login form // data.html: login form
// args: args of the first _json call, to call again at process end // args: args of the first _json call, to call again at process end
var self = this const self = this
var proceed = () => { const proceed = () => {
self.ui.closePanel() self.ui.closePanel()
if (typeof args !== 'undefined') self._json.apply(self, args) if (typeof args !== 'undefined') self._json.apply(self, args)
else self.default_callback(data, {}) else self.default_callback(data, {})
} }
var ask_for_login = (data) => { const ask_for_login = (data) => {
self.ui.openPanel({ data: data, className: 'login-panel' }) self.ui.openPanel({ data: data, className: 'login-panel' })
self.listen_form('login_form', { self.listen_form('login_form', {
callback: function (data) { callback: function (data) {
@ -266,12 +266,12 @@ L.U.Xhr = L.Evented.extend({
}, },
}) })
// Auth links // Auth links
var links = document.getElementsByClassName('umap-login-popup') const links = document.getElementsByClassName('umap-login-popup')
Object.keys(links).forEach((el) => { Object.keys(links).forEach((el) => {
var link = links[el] const link = links[el]
L.DomEvent.on(link, 'click', L.DomEvent.stop).on(link, 'click', () => { L.DomEvent.on(link, 'click', L.DomEvent.stop).on(link, 'click', () => {
self.ui.closePanel() self.ui.closePanel()
var win = window.open(link.href) const win = window.open(link.href)
window.umap_proceed = () => { window.umap_proceed = () => {
proceed() proceed()
win.close() win.close()