diff --git a/biome.json b/biome.json
index 1d1b9435..fe1b09d4 100644
--- a/biome.json
+++ b/biome.json
@@ -13,8 +13,11 @@
"enabled": true,
"rules": {
"style": {
- "useBlockStatements": "warn",
+ "useBlockStatements": "off",
"noShoutyConstants": "warn"
+ },
+ "performance": {
+ "noDelete": "off"
}
}
},
diff --git a/umap/static/umap/js/modules/autocomplete.js b/umap/static/umap/js/modules/autocomplete.js
index 0c6972e7..8e4bfae2 100644
--- a/umap/static/umap/js/modules/autocomplete.js
+++ b/umap/static/umap/js/modules/autocomplete.js
@@ -250,7 +250,7 @@ export class BaseAjax extends BaseAutocomplete {
return
}
if (val === this.cache) return
- else this.cache = val
+ this.cache = val
val = val.toLowerCase()
const url = Util.template(this.url, { q: encodeURIComponent(val) })
this.handleResults(await this._search(url))
@@ -258,7 +258,7 @@ export class BaseAjax extends BaseAutocomplete {
async _search(url) {
const response = await this.request.get(url)
- if (response && response.ok) {
+ if (response?.ok) {
return await response.json()
}
}
diff --git a/umap/static/umap/js/modules/browser.js b/umap/static/umap/js/modules/browser.js
index 9a277a7f..db988d7e 100644
--- a/umap/static/umap/js/modules/browser.js
+++ b/umap/static/umap/js/modules/browser.js
@@ -63,8 +63,8 @@ export default class Browser {
addDataLayer(datalayer, parent) {
let className = `datalayer ${datalayer.getHidableClass()}`
if (this.mode !== 'layers') className += ' show-list'
- const container = DomUtil.create('div', className, parent),
- headline = DomUtil.create('h5', '', container)
+ const container = DomUtil.create('div', className, parent)
+ const headline = DomUtil.create('h5', '', container)
container.id = this.datalayerId(datalayer)
const ul = DomUtil.create('ul', '', container)
this.updateDatalayer(datalayer)
@@ -90,9 +90,9 @@ export default class Browser {
container.innerHTML = ''
datalayer.eachFeature((feature) => this.addFeature(feature, container))
- const total = datalayer.count(),
- current = container.querySelectorAll('li').length,
- count = total == current ? total : `${current}/${total}`
+ const total = datalayer.count()
+ const current = container.querySelectorAll('li').length
+ const count = total === current ? total : `${current}/${total}`
const counter = DomUtil.create('span', 'datalayer-counter', headline)
counter.textContent = `(${count})`
counter.title = translate(`Features in this layer: ${count}`)
diff --git a/umap/static/umap/js/modules/caption.js b/umap/static/umap/js/modules/caption.js
index a17a57e9..cf8c0de2 100644
--- a/umap/static/umap/js/modules/caption.js
+++ b/umap/static/umap/js/modules/caption.js
@@ -40,9 +40,9 @@ export default class Caption {
addDataLayer(datalayer, container) {
if (!datalayer.options.inCaption) return
- const p = DomUtil.create('p', 'datalayer-legend', container),
- legend = DomUtil.create('span', '', p),
- headline = DomUtil.create('strong', '', p)
+ const p = DomUtil.create('p', 'datalayer-legend', container)
+ const legend = DomUtil.create('span', '', p)
+ const headline = DomUtil.create('strong', '', p)
datalayer.onceLoaded(() => {
datalayer.renderLegend(legend)
if (datalayer.options.description) {
diff --git a/umap/static/umap/js/modules/dompurify.js b/umap/static/umap/js/modules/dompurify.js
index 74d75ed7..09e527ca 100644
--- a/umap/static/umap/js/modules/dompurify.js
+++ b/umap/static/umap/js/modules/dompurify.js
@@ -6,7 +6,6 @@ console.log(DOMPurifyInitializer)
export default function getPurify() {
if (typeof window === 'undefined') {
return DOMPurifyInitializer(new JSDOM('').window)
- } else {
- return DOMPurifyInitializer(window)
}
+ return DOMPurifyInitializer(window)
}
diff --git a/umap/static/umap/js/modules/facets.js b/umap/static/umap/js/modules/facets.js
index 47e266fe..6677b5f6 100644
--- a/umap/static/umap/js/modules/facets.js
+++ b/umap/static/umap/js/modules/facets.js
@@ -13,7 +13,7 @@ export default class Facets {
let selected
names.forEach((name) => {
- const type = defined[name]['type']
+ const type = defined[name].type
properties[name] = { type: type }
selected = this.selected[name] || {}
selected.type = type
@@ -28,17 +28,23 @@ export default class Facets {
datalayer.eachFeature((feature) => {
names.forEach((name) => {
let value = feature.properties[name]
- const type = defined[name]['type']
+ const type = defined[name].type
const parser = this.getParser(type)
value = parser(value)
switch (type) {
case 'date':
case 'datetime':
case 'number':
- if (!isNaN(value)) {
+ if (!Number.isNaN(value)) {
+ // Special cases where we want to be lousy when checking isNaN without
+ // coercing to a Number first because we handle multiple types.
+ // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/
+ // Reference/Global_Objects/Number/isNaN
+ // biome-ignore lint/suspicious/noGlobalIsNan: see above.
if (isNaN(properties[name].min) || properties[name].min > value) {
properties[name].min = value
}
+ // biome-ignore lint/suspicious/noGlobalIsNan: see above.
if (isNaN(properties[name].max) || properties[name].max < value) {
properties[name].max = value
}
@@ -58,7 +64,7 @@ export default class Facets {
isActive() {
for (const { type, min, max, choices } of Object.values(this.selected)) {
- if (min !== undefined || max != undefined || choices?.length) {
+ if (min !== undefined || max !== undefined || choices?.length) {
return true
}
}
@@ -73,7 +79,7 @@ export default class Facets {
const fields = names.map((name) => {
const criteria = facetProperties[name]
let handler = 'FacetSearchChoices'
- switch (criteria['type']) {
+ switch (criteria.type) {
case 'number':
handler = 'FacetSearchNumber'
break
@@ -84,7 +90,7 @@ export default class Facets {
handler = 'FacetSearchDateTime'
break
}
- const label = defined[name]['label']
+ const label = defined[name].label
return [
`selected.${name}`,
{
diff --git a/umap/static/umap/js/modules/help.js b/umap/static/umap/js/modules/help.js
index 580d97cd..fe0a8460 100644
--- a/umap/static/umap/js/modules/help.js
+++ b/umap/static/umap/js/modules/help.js
@@ -191,7 +191,7 @@ export default class Help {
const container = DomUtil.add('div')
DomUtil.createTitle(container, translate('Help'))
// Special dynamic case. Do we still think this dialog is usefull ?
- if (entries == 'edit') {
+ if (entries === 'edit') {
DomUtil.element({
tagName: 'div',
className: 'umap-help-entry',
diff --git a/umap/static/umap/js/modules/importer.js b/umap/static/umap/js/modules/importer.js
index cca11806..ba227fd9 100644
--- a/umap/static/umap/js/modules/importer.js
+++ b/umap/static/umap/js/modules/importer.js
@@ -179,12 +179,12 @@ export default class Importer {
this.format === 'umap' || !this.url
)
this.qs('[name=layer-name]').toggleAttribute('hidden', Boolean(this.layerId))
- this.qs('#clear').toggleAttribute('hidden', !Boolean(this.layerId))
+ this.qs('#clear').toggleAttribute('hidden', !this.layerId)
}
onFileChange(e) {
- let type = '',
- newType
+ let type = ''
+ let newType
for (const file of e.target.files) {
newType = U.Utils.detectFileType(file)
if (!type && newType) type = newType
diff --git a/umap/static/umap/js/modules/importers/geodatamine.js b/umap/static/umap/js/modules/importers/geodatamine.js
index 74c2819b..cfbef595 100644
--- a/umap/static/umap/js/modules/importers/geodatamine.js
+++ b/umap/static/umap/js/modules/importers/geodatamine.js
@@ -52,7 +52,7 @@ export class Importer {
container.innerHTML = TEMPLATE
const response = await importer.map.request.get(`${this.baseUrl}/themes`)
const select = container.querySelector('select')
- if (response && response.ok) {
+ if (response?.ok) {
const { themes } = await response.json()
themes.sort((a, b) => Utils.naturalSort(a['name:fr'], b['name:fr']))
for (const theme of themes) {
diff --git a/umap/static/umap/js/modules/orderable.js b/umap/static/umap/js/modules/orderable.js
index 60b36012..978dabf6 100644
--- a/umap/static/umap/js/modules/orderable.js
+++ b/umap/static/umap/js/modules/orderable.js
@@ -59,8 +59,8 @@ export default class Orderable {
const dst = this.findTarget(e.target)
if (!dst || dst === this.src) return
this.dst = dst
- const targetIndex = this.nodeIndex(this.dst),
- srcIndex = this.nodeIndex(this.src)
+ const targetIndex = this.nodeIndex(this.dst)
+ const srcIndex = this.nodeIndex(this.src)
if (targetIndex > srcIndex) this.parent.insertBefore(this.dst, this.src)
else this.parent.insertBefore(this.src, this.dst)
}
diff --git a/umap/static/umap/js/modules/rules.js b/umap/static/umap/js/modules/rules.js
index b3e06dd9..518339c1 100644
--- a/umap/static/umap/js/modules/rules.js
+++ b/umap/static/umap/js/modules/rules.js
@@ -49,7 +49,7 @@ class Rule {
}
not_equal(other) {
- return this.expected != other
+ return this.expected !== other
}
gt(other) {
@@ -71,9 +71,14 @@ class Rule {
break
}
}
- if (vars.length != 2) return
+ if (vars.length !== 2) return
this.key = vars[0]
this.expected = vars[1]
+ // Special cases where we want to be lousy when checking isNaN without
+ // coercing to a Number first because we handle multiple types.
+ // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/
+ // Reference/Global_Objects/Number/isNaN
+ // biome-ignore lint/suspicious/noGlobalIsNan: expected might not be a number.
if (!isNaN(this.expected)) this.cast = Number.parseFloat
else if (['true', 'false'].includes(this.expected)) this.cast = (v) => !!v
this.expected = this.cast(this.expected)
@@ -161,7 +166,7 @@ class Rule {
}
_delete() {
- this.map.rules.rules = this.map.rules.rules.filter((rule) => rule != this)
+ this.map.rules.rules = this.map.rules.rules.filter((rule) => rule !== this)
}
}
@@ -181,8 +186,8 @@ export default class Rules {
}
onReorder(src, dst, initialIndex, finalIndex) {
- const moved = this.rules.find((rule) => stamp(rule) == src.dataset.id)
- const reference = this.rules.find((rule) => stamp(rule) == dst.dataset.id)
+ const moved = this.rules.find((rule) => stamp(rule) === src.dataset.id)
+ const reference = this.rules.find((rule) => stamp(rule) === dst.dataset.id)
const movedIdx = this.rules.indexOf(moved)
let referenceIdx = this.rules.indexOf(reference)
const minIndex = Math.min(movedIdx, referenceIdx)
diff --git a/umap/static/umap/js/modules/sync/engine.js b/umap/static/umap/js/modules/sync/engine.js
index 6b672aa7..2eb97224 100644
--- a/umap/static/umap/js/modules/sync/engine.js
+++ b/umap/static/umap/js/modules/sync/engine.js
@@ -36,7 +36,7 @@ export class SyncEngine {
// This method is called by the transport layer on new messages
receive({ kind, ...payload }) {
- if (kind == 'operation') {
+ if (kind === 'operation') {
const updater = this._getUpdater(payload.subject, payload.metadata)
updater.applyMessage(payload)
} else {
diff --git a/umap/static/umap/js/modules/sync/updaters.js b/umap/static/umap/js/modules/sync/updaters.js
index faaf7920..4bd7ae51 100644
--- a/umap/static/umap/js/modules/sync/updaters.js
+++ b/umap/static/umap/js/modules/sync/updaters.js
@@ -88,13 +88,12 @@ export class FeatureUpdater extends BaseUpdater {
if (feature === undefined) {
console.error(`Unable to find feature with id = ${metadata.id}.`)
}
- switch (key) {
- case 'geometry':
- const datalayer = this.getDataLayerFromID(metadata.layerId)
- datalayer.geoJSONToLeaflet({ geometry: value, id: metadata.id, feature })
- default:
- this.updateObjectValue(feature, key, value)
- feature.datalayer.indexProperties(feature)
+ if (key === 'geometry') {
+ const datalayer = this.getDataLayerFromID(metadata.layerId)
+ datalayer.geoJSONToLeaflet({ geometry: value, id: metadata.id, feature })
+ } else {
+ this.updateObjectValue(feature, key, value)
+ feature.datalayer.indexProperties(feature)
}
feature.render([key])
diff --git a/umap/static/umap/js/modules/ui/tooltip.js b/umap/static/umap/js/modules/ui/tooltip.js
index eb95b809..feed1b5e 100644
--- a/umap/static/umap/js/modules/ui/tooltip.js
+++ b/umap/static/umap/js/modules/ui/tooltip.js
@@ -42,10 +42,10 @@ export default class Tooltip {
anchorAbsolute() {
this.container.className = ''
const left =
- this.parent.offsetLeft +
- this.parent.clientWidth / 2 -
- this.container.clientWidth / 2,
- top = this.parent.offsetTop + 75
+ this.parent.offsetLeft +
+ this.parent.clientWidth / 2 -
+ this.container.clientWidth / 2
+ const top = this.parent.offsetTop + 75
this.setPosition({ top: top, left: left })
}
diff --git a/umap/static/umap/js/modules/urls.js b/umap/static/umap/js/modules/urls.js
index ad834a65..171ca91b 100644
--- a/umap/static/umap/js/modules/urls.js
+++ b/umap/static/umap/js/modules/urls.js
@@ -10,9 +10,8 @@ export default class URLs {
if (this.urls.hasOwnProperty(urlName)) {
return template(this.urls[urlName], params)
- } else {
- throw `Unable to find a URL for route ${urlName}`
}
+ throw `Unable to find a URL for route ${urlName}`
}
// Update if map_id is passed, create otherwise.
diff --git a/umap/static/umap/js/modules/utils.js b/umap/static/umap/js/modules/utils.js
index c132f1a5..0af6d206 100644
--- a/umap/static/umap/js/modules/utils.js
+++ b/umap/static/umap/js/modules/utils.js
@@ -63,9 +63,8 @@ export function getImpactsFromSchema(fields, schema) {
export default function getPurify() {
if (typeof window === 'undefined') {
return DOMPurifyInitializer(new global.JSDOM('').window)
- } else {
- return DOMPurifyInitializer(window)
}
+ return DOMPurifyInitializer(window)
}
export function escapeHTML(s) {
@@ -114,7 +113,7 @@ export function escapeHTML(s) {
export function toHTML(r, options) {
if (!r) return ''
- const target = (options && options.target) || 'blank'
+ const target = options?.target || 'blank'
// unordered lists
r = r.replace(/^\*\* (.*)/gm, '
')
@@ -271,8 +270,8 @@ export function sortFeatures(features, sortKey, lang) {
const sortKeys = (sortKey || 'name').split(',')
const sort = (a, b, i) => {
- let sortKey = sortKeys[i],
- reverse = 1
+ let sortKey = sortKeys[i]
+ let reverse = 1
if (sortKey[0] === '-') {
reverse = -1
sortKey = sortKey.substring(1)
@@ -315,19 +314,19 @@ export function getBaseUrl() {
}
export function hasVar(value) {
- return typeof value === 'string' && value.indexOf('{') != -1
+ return typeof value === 'string' && value.indexOf('{') !== -1
}
export function isPath(value) {
- return value && value.length && value.startsWith('/')
+ return value?.length && value.startsWith('/')
}
export function isRemoteUrl(value) {
- return value && value.length && value.startsWith('http')
+ return value?.length && value.startsWith('http')
}
export function isDataImage(value) {
- return value && value.length && value.startsWith('data:image')
+ return value?.length && value.startsWith('data:image')
}
/**
@@ -349,15 +348,16 @@ export function normalize(s) {
// Vendorized from leaflet.utils
// https://github.com/Leaflet/Leaflet/blob/108c6717b70f57c63645498f9bd66b6677758786/src/core/Util.js#L132-L151
-var templateRe = /\{ *([\w_ -]+) *\}/g
+const templateRe = /\{ *([\w_ -]+) *\}/g
export function template(str, data) {
return str.replace(templateRe, (str, key) => {
- var value = data[key]
+ let value = data[key]
if (value === undefined) {
- throw new Error('No value provided for variable ' + str)
- } else if (typeof value === 'function') {
+ throw new Error(`No value provided for variable ${str}`)
+ }
+ if (typeof value === 'function') {
value = value(data)
}
return value
diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js
index dab12378..9b481139 100644
--- a/umap/static/umap/js/umap.controls.js
+++ b/umap/static/umap/js/umap.controls.js
@@ -434,9 +434,9 @@ U.MoreControls = L.Control.extend({
},
toggle: function () {
- const pos = this.getPosition(),
- corner = this._map._controlCorners[pos],
- className = 'umap-more-controls'
+ const pos = this.getPosition()
+ const corner = this._map._controlCorners[pos]
+ const className = 'umap-more-controls'
if (L.DomUtil.hasClass(corner, className)) L.DomUtil.removeClass(corner, className)
else L.DomUtil.addClass(corner, className)
},
@@ -454,10 +454,10 @@ U.PermanentCreditsControl = L.Control.extend({
onAdd: function () {
const paragraphContainer = L.DomUtil.create(
- 'div',
- 'umap-permanent-credits-container'
- ),
- creditsParagraph = L.DomUtil.create('p', '', paragraphContainer)
+ 'div',
+ 'umap-permanent-credits-container'
+ )
+ const creditsParagraph = L.DomUtil.create('p', '', paragraphContainer)
this.paragraphContainer = paragraphContainer
this.setCredits()
@@ -745,7 +745,7 @@ const ControlsMixin = {
L.DomUtil.createLink(
'umap-user',
rightContainer,
- L._(`My Dashboard ({username})`, {
+ L._('My Dashboard ({username})', {
username: this.options.user.name,
}),
this.options.user.url
@@ -832,10 +832,10 @@ const ControlsMixin = {
row.dataset.id = L.stamp(datalayer)
})
const onReorder = (src, dst, initialIndex, finalIndex) => {
- const layer = this.datalayers[src.dataset.id],
- other = this.datalayers[dst.dataset.id],
- minIndex = Math.min(layer.getRank(), other.getRank()),
- maxIndex = Math.max(layer.getRank(), other.getRank())
+ const layer = this.datalayers[src.dataset.id]
+ const other = this.datalayers[dst.dataset.id]
+ const minIndex = Math.min(layer.getRank(), other.getRank())
+ const maxIndex = Math.max(layer.getRank(), other.getRank())
if (finalIndex === 0) layer.bringToTop()
else if (finalIndex > initialIndex) layer.insertBefore(other)
else layer.insertAfter(other)
@@ -948,10 +948,10 @@ U.TileLayerChooser = L.Control.extend({
},
addTileLayerElement: function (tilelayer, options) {
- const selectedClass = this.map.hasLayer(tilelayer) ? 'selected' : '',
- el = L.DomUtil.create('li', selectedClass, this._tilelayers_container),
- img = L.DomUtil.create('img', '', el),
- name = L.DomUtil.create('div', '', el)
+ const selectedClass = this.map.hasLayer(tilelayer) ? 'selected' : ''
+ const el = L.DomUtil.create('li', selectedClass, this._tilelayers_container)
+ const img = L.DomUtil.create('img', '', el)
+ const name = L.DomUtil.create('div', '', el)
img.src = U.Utils.template(tilelayer.options.url_template, this.map.demoTileInfos)
img.loading = 'lazy'
name.textContent = tilelayer.options.name
@@ -961,7 +961,7 @@ U.TileLayerChooser = L.Control.extend({
function () {
this.map.selectTileLayer(tilelayer)
this.map._controls.tilelayers.setLayers()
- if (options && options.callback) options.callback(tilelayer)
+ if (options?.callback) options.callback(tilelayer)
},
this
)
@@ -982,8 +982,8 @@ U.AttributionControl = L.Control.Attribution.extend({
this._container.innerHTML = ''
const container = L.DomUtil.create('div', 'attribution-container', this._container)
container.innerHTML = credits
- const shortCredit = this._map.getOption('shortCredit'),
- captionMenus = this._map.getOption('captionMenus')
+ const shortCredit = this._map.getOption('shortCredit')
+ const captionMenus = this._map.getOption('captionMenus')
if (shortCredit) {
L.DomUtil.element({
tagName: 'span',
@@ -1310,7 +1310,7 @@ U.Editable = L.Editable.extend({
},
drawingTooltip: function (e) {
- if (e.layer instanceof L.Marker && e.type == 'editable:drawing:start') {
+ if (e.layer instanceof L.Marker && e.type === 'editable:drawing:start') {
this.map.tooltip.open({ content: L._('Click to add a marker') })
}
if (!(e.layer instanceof L.Polyline)) {
diff --git a/umap/static/umap/js/umap.core.js b/umap/static/umap/js/umap.core.js
index 4ae9e465..187c5830 100644
--- a/umap/static/umap/js/umap.core.js
+++ b/umap/static/umap/js/umap.core.js
@@ -27,8 +27,8 @@ L.Util.copyToClipboard = (textToCopy) => {
L.Util.queryString = (name, fallback) => {
const decode = (s) => decodeURIComponent(s.replace(/\+/g, ' '))
- const qs = window.location.search.slice(1).split('&'),
- qa = {}
+ const qs = window.location.search.slice(1).split('&')
+ const qa = {}
for (const i in qs) {
const key = qs[i].split('=')
if (!key) continue
@@ -49,12 +49,12 @@ L.Util.setFromQueryString = (options, name) => {
L.Util.setBooleanFromQueryString = (options, 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.setNumberFromQueryString = (options, name) => {
const value = +L.Util.queryString(name)
- if (!isNaN(value)) options[name] = value
+ if (!Number.isNaN(value)) options[name] = value
}
L.Util.setNullableBooleanFromQueryString = (options, name) => {
@@ -192,7 +192,7 @@ L.DomUtil.after = (target, el) => {
// convert colour in range 0-255 to the modifier used within luminance calculation
L.DomUtil.colourMod = (colour) => {
const sRGB = colour / 255
- let mod = Math.pow((sRGB + 0.055) / 1.055, 2.4)
+ let mod = ((sRGB + 0.055) / 1.055) ** 2.4
if (sRGB < 0.03928) mod = sRGB / 12.92
return mod
}
@@ -251,9 +251,9 @@ L.DomEvent.once = (el, types, fn, context) => {
L.LatLng.prototype.isValid = function () {
return (
- isFinite(this.lat) &&
+ Number.isFinite(this.lat) &&
Math.abs(this.lat) <= 90 &&
- isFinite(this.lng) &&
+ Number.isFinite(this.lng) &&
Math.abs(this.lng) <= 180
)
}
diff --git a/umap/static/umap/js/umap.datalayer.permissions.js b/umap/static/umap/js/umap.datalayer.permissions.js
index 5ff81302..d5a6a288 100644
--- a/umap/static/umap/js/umap.datalayer.permissions.js
+++ b/umap/static/umap/js/umap.datalayer.permissions.js
@@ -26,19 +26,19 @@ U.DataLayerPermissions = L.Class.extend({
edit: function (container) {
const fields = [
- [
- 'options.edit_status',
- {
- handler: 'IntSelect',
- label: L._('Who can edit "{layer}"', { layer: this.datalayer.getName() }),
- selectOptions: this.datalayer.map.options.datalayer_edit_statuses,
- },
- ],
+ [
+ 'options.edit_status',
+ {
+ handler: 'IntSelect',
+ label: L._('Who can edit "{layer}"', { layer: this.datalayer.getName() }),
+ selectOptions: this.datalayer.map.options.datalayer_edit_statuses,
+ },
],
- builder = new U.FormBuilder(this, fields, {
- className: 'umap-form datalayer-permissions',
- }),
- form = builder.build()
+ ]
+ const builder = new U.FormBuilder(this, fields, {
+ className: 'umap-form datalayer-permissions',
+ })
+ const form = builder.build()
container.appendChild(form)
},
diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js
index ba30c4fe..e4670255 100644
--- a/umap/static/umap/js/umap.features.js
+++ b/umap/static/umap/js/umap.features.js
@@ -90,7 +90,7 @@ U.FeatureMixin = {
preInit: () => {},
isReadOnly: function () {
- return this.datalayer && this.datalayer.isDataReadOnly()
+ return this.datalayer?.isDataReadOnly()
},
getSlug: function () {
@@ -414,7 +414,7 @@ U.FeatureMixin = {
},
_onClick: function (e) {
- if (this.map.measureTools && this.map.measureTools.enabled()) return
+ if (this.map.measureTools?.enabled()) return
this._popupHandlersAdded = true // Prevent leaflet from managing event
if (!this.map.editEnabled) {
this.view(e)
@@ -476,7 +476,7 @@ U.FeatureMixin = {
let items = ['-']
if (this.map.editedFeature !== this) {
items.push({
- text: L._('Edit this feature') + ' (⇧+Click)',
+ text: `${L._('Edit this feature')} (⇧+Click)`,
callback: this.edit,
context: this,
iconCls: 'umap-edit',
@@ -546,7 +546,7 @@ U.FeatureMixin = {
}
keys = keys.split(',')
for (let i = 0, value; i < keys.length; i++) {
- value = (this.properties[keys[i]] || '') + ''
+ value = `${this.properties[keys[i]] || ''}`
if (value.toLowerCase().indexOf(filter) !== -1) return true
}
return false
@@ -562,8 +562,8 @@ U.FeatureMixin = {
case 'date':
case 'datetime':
case 'number':
- if (!isNaN(min) && !isNaN(value) && min > value) return false
- if (!isNaN(max) && !isNaN(value) && max < value) return false
+ if (!Number.isNaN(min) && !Number.isNaN(value) && min > value) return false
+ if (!Number.isNaN(max) && !Number.isNaN(value) && max < value) return false
break
default:
value = value || L._('')
@@ -659,11 +659,7 @@ U.Marker = L.Marker.extend({
},
_onMouseOut: function () {
- if (
- this.dragging &&
- this.dragging._draggable &&
- !this.dragging._draggable._moving
- ) {
+ if (this.dragging?._draggable && !this.dragging._draggable._moving) {
// Do not disable if the mouse went out while dragging
this._disableDragging()
}
@@ -684,14 +680,14 @@ U.Marker = L.Marker.extend({
_disableDragging: function () {
if (this.map.editEnabled) {
- if (this.editor && this.editor.drawing) return // when creating a new marker, the mouse can trigger the mouseover/mouseout event
+ if (this.editor?.drawing) return // when creating a new marker, the mouse can trigger the mouseover/mouseout event
// do not listen to them
this.disableEdit()
}
},
_redraw: function () {
- if (this.datalayer && this.datalayer.isVisible()) {
+ if (this.datalayer?.isVisible()) {
this._initIcon()
this.update()
}
@@ -706,8 +702,8 @@ U.Marker = L.Marker.extend({
},
_getTooltipAnchor: function () {
- const anchor = this.options.icon.options.tooltipAnchor.clone(),
- direction = this.getOption('labelDirection')
+ const anchor = this.options.icon.options.tooltipAnchor.clone()
+ const direction = this.getOption('labelDirection')
if (direction === 'left') {
anchor.x *= -1
} else if (direction === 'bottom') {
@@ -862,7 +858,7 @@ U.PathMixin = {
},
_redraw: function () {
- if (this.datalayer && this.datalayer.isVisible()) {
+ if (this.datalayer?.isVisible()) {
this.setStyle()
this.resetTooltip()
}
@@ -876,14 +872,14 @@ U.PathMixin = {
// this.map.on('showmeasure', this.showMeasureTooltip, this);
// this.map.on('hidemeasure', this.removeTooltip, this);
this.parentClass.prototype.onAdd.call(this, map)
- if (this.editing && this.editing.enabled()) this.editing.addHooks()
+ if (this.editing?.enabled()) this.editing.addHooks()
this.resetTooltip()
},
onRemove: function (map) {
// this.map.off('showmeasure', this.showMeasureTooltip, this);
// this.map.off('hidemeasure', this.removeTooltip, this);
- if (this.editing && this.editing.enabled()) this.editing.removeHooks()
+ if (this.editing?.enabled()) this.editing.removeHooks()
U.FeatureMixin.onRemove.call(this, map)
},
@@ -905,7 +901,7 @@ U.PathMixin = {
},
_onMouseOver: function () {
- if (this.map.measureTools && this.map.measureTools.enabled()) {
+ if (this.map.measureTools?.enabled()) {
this.map.tooltip.open({ content: this.getMeasure(), anchor: this })
} else if (this.map.editEnabled && !this.map.editedFeature) {
this.map.tooltip.open({ content: L._('Click to edit'), anchor: this })
@@ -1151,11 +1147,11 @@ U.Polyline = L.Polyline.extend({
from.reverse()
toMerge = [from, to]
}
- const a = toMerge[0],
- b = toMerge[1],
- p1 = this.map.latLngToContainerPoint(a[a.length - 1]),
- p2 = this.map.latLngToContainerPoint(b[0]),
- tolerance = 5 // px on screen
+ const a = toMerge[0]
+ const b = toMerge[1]
+ const p1 = this.map.latLngToContainerPoint(a[a.length - 1])
+ const p2 = this.map.latLngToContainerPoint(b[0])
+ const tolerance = 5 // px on screen
if (Math.abs(p1.x - p2.x) <= tolerance && Math.abs(p1.y - p2.y) <= tolerance) {
a.pop()
}
@@ -1180,8 +1176,8 @@ U.Polyline = L.Polyline.extend({
},
getVertexActions: function (e) {
- const actions = U.FeatureMixin.getVertexActions.call(this, e),
- index = e.vertex.getIndex()
+ const actions = U.FeatureMixin.getVertexActions.call(this, e)
+ const index = e.vertex.getIndex()
if (index === 0 || index === e.vertex.getLastIndex())
actions.push(U.ContinueLineAction)
else actions.push(U.SplitLineAction)
@@ -1223,8 +1219,8 @@ U.Polygon = L.Polygon.extend({
},
getContextMenuEditItems: function (e) {
- const items = U.PathMixin.getContextMenuEditItems.call(this, e),
- shape = this.shapeAt(e.latlng)
+ const items = U.PathMixin.getContextMenuEditItems.call(this, e)
+ const shape = this.shapeAt(e.latlng)
// No multi and no holes.
if (shape && !this.isMulti() && (L.LineUtil.isFlat(shape) || shape.length === 1)) {
items.push({
diff --git a/umap/static/umap/js/umap.forms.js b/umap/static/umap/js/umap.forms.js
index 6a15e93e..0d698624 100644
--- a/umap/static/umap/js/umap.forms.js
+++ b/umap/static/umap/js/umap.forms.js
@@ -61,8 +61,8 @@ L.FormBuilder.Element.include({
get: function (own) {
if (!this.options.inheritable || own) return this.builder.getter(this.field)
- const path = this.field.split('.'),
- key = path[path.length - 1]
+ const path = this.field.split('.')
+ const key = path[path.length - 1]
return this.obj.getOption(key)
},
@@ -514,18 +514,13 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({
this
)
}
- const symbol = L.DomUtil.add(
- 'button',
- 'flat tab-symbols',
- this.tabs,
- L._('Symbol')
- ),
- char = L.DomUtil.add(
- 'button',
- 'flat tab-chars',
- this.tabs,
- L._('Emoji & Character')
- )
+ const symbol = L.DomUtil.add('button', 'flat tab-symbols', this.tabs, L._('Symbol'))
+ const char = L.DomUtil.add(
+ 'button',
+ 'flat tab-chars',
+ this.tabs,
+ L._('Emoji & Character')
+ )
url = L.DomUtil.add('button', 'flat tab-url', this.tabs, L._('URL'))
L.DomEvent.on(symbol, 'click', L.DomEvent.stop).on(
symbol,
@@ -571,15 +566,15 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({
},
addIconPreview: function (pictogram, parent) {
- const baseClass = 'umap-pictogram-choice',
- value = pictogram.src,
- search = U.Utils.normalize(this.searchInput.value),
- title = pictogram.attribution
- ? `${pictogram.name} — © ${pictogram.attribution}`
- : pictogram.name || pictogram.src
+ const baseClass = 'umap-pictogram-choice'
+ const value = pictogram.src
+ const search = U.Utils.normalize(this.searchInput.value)
+ const title = pictogram.attribution
+ ? `${pictogram.name} — © ${pictogram.attribution}`
+ : pictogram.name || pictogram.src
if (search && U.Utils.normalize(title).indexOf(search) === -1) return
- const className = value === this.value() ? `${baseClass} selected` : baseClass,
- container = L.DomUtil.create('div', className, parent)
+ const className = value === this.value() ? `${baseClass} selected` : baseClass
+ const container = L.DomUtil.create('div', className, parent)
U.Icon.makeIconElement(value, container)
container.title = title
L.DomEvent.on(
@@ -743,9 +738,9 @@ L.FormBuilder.FacetSearchChoices = L.FormBuilder.FacetSearchBase.extend({
this.container = L.DomUtil.create('fieldset', 'umap-facet', this.parentNode)
this.container.appendChild(this.label)
this.ul = L.DomUtil.create('ul', '', this.container)
- this.type = this.options.criteria['type']
+ this.type = this.options.criteria.type
- const choices = this.options.criteria['choices']
+ const choices = this.options.criteria.choices
choices.sort()
choices.forEach((value) => this.buildLi(value))
},
@@ -758,7 +753,7 @@ L.FormBuilder.FacetSearchChoices = L.FormBuilder.FacetSearchBase.extend({
input.type = this.type
input.name = `${this.type}_${this.name}`
- input.checked = this.get()['choices'].includes(value)
+ input.checked = this.get().choices.includes(value)
input.dataset.value = value
L.DomEvent.on(input, 'change', (e) => this.sync())
@@ -845,13 +840,13 @@ L.FormBuilder.MinMaxBase = L.FormBuilder.FacetSearchBase.extend({
isMinModified: function () {
const default_ = this.minInput.getAttribute('value')
const current = this.minInput.value
- return current != default_
+ return current !== default_
},
isMaxModified: function () {
const default_ = this.maxInput.getAttribute('value')
const current = this.maxInput.value
- return current != default_
+ return current !== default_
},
toJS: function () {
@@ -879,7 +874,7 @@ L.FormBuilder.FacetSearchDate = L.FormBuilder.MinMaxBase.extend({
prepareForHTML: function (value) {
// Value must be in local time
- if (isNaN(value)) return
+ if (Number.isNaN(value)) return
return this.toLocaleDateTime(value).toISOString().substr(0, 10)
},
@@ -891,7 +886,7 @@ L.FormBuilder.FacetSearchDateTime = L.FormBuilder.FacetSearchDate.extend({
prepareForHTML: function (value) {
// Value must be in local time
- if (isNaN(value)) return
+ if (Number.isNaN(value)) return
return this.toLocaleDateTime(value).toISOString().slice(0, -1)
},
})
diff --git a/umap/static/umap/js/umap.icon.js b/umap/static/umap/js/umap.icon.js
index b79114fa..b8de3668 100644
--- a/umap/static/umap/js/umap.icon.js
+++ b/umap/static/umap/js/umap.icon.js
@@ -12,7 +12,7 @@ U.Icon = L.DivIcon.extend({
options = L.Util.extend({}, default_options, options)
L.Icon.prototype.initialize.call(this, options)
this.feature = this.options.feature
- if (this.feature && this.feature.isReadOnly()) {
+ if (this.feature?.isReadOnly()) {
this.options.className += ' readonly'
}
},
@@ -27,7 +27,7 @@ U.Icon = L.DivIcon.extend({
_getIconUrl: function (name) {
let url
- if (this.feature && this.feature._getIconUrl(name)) {
+ if (this.feature?._getIconUrl(name)) {
url = this.feature._getIconUrl(name)
this._setRecent(url)
} else {
@@ -70,8 +70,8 @@ U.Icon.Default = U.Icon.extend({
_setIconStyles: function (img, name) {
U.Icon.prototype._setIconStyles.call(this, img, name)
- const color = this._getColor(),
- opacity = this._getOpacity()
+ const color = this._getColor()
+ const opacity = this._getOpacity()
this.elements.container.style.backgroundColor = color
this.elements.arrow.style.borderTopColor = color
this.elements.container.style.opacity = opacity
@@ -185,10 +185,10 @@ U.Icon.Cluster = L.DivIcon.extend({
},
createIcon: function () {
- const container = L.DomUtil.create('div', 'leaflet-marker-icon marker-cluster'),
- div = L.DomUtil.create('div', '', container),
- span = L.DomUtil.create('span', '', div),
- backgroundColor = this.datalayer.getColor()
+ const container = L.DomUtil.create('div', 'leaflet-marker-icon marker-cluster')
+ const div = L.DomUtil.create('div', '', container)
+ const span = L.DomUtil.create('span', '', div)
+ const backgroundColor = this.datalayer.getColor()
span.textContent = this.cluster.getChildCount()
div.style.backgroundColor = backgroundColor
return container
@@ -197,7 +197,7 @@ U.Icon.Cluster = L.DivIcon.extend({
computeTextColor: function (el) {
let color
const backgroundColor = this.datalayer.getColor()
- if (this.datalayer.options.cluster && this.datalayer.options.cluster.textColor) {
+ if (this.datalayer.options.cluster?.textColor) {
color = this.datalayer.options.cluster.textColor
}
return color || L.DomUtil.TextColorFromBackgroundColor(el, backgroundColor)
diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js
index 57efc650..3f3cda9b 100644
--- a/umap/static/umap/js/umap.js
+++ b/umap/static/umap/js/umap.js
@@ -99,11 +99,7 @@ U.Map = L.Map.extend({
}
// Retrocompat
- if (
- this.options.slideshow &&
- this.options.slideshow.delay &&
- this.options.slideshow.active === undefined
- ) {
+ if (this.options.slideshow?.delay && this.options.slideshow.active === undefined) {
this.options.slideshow.active = true
}
if (this.options.advancedFilterKey) {
@@ -211,8 +207,8 @@ U.Map = L.Map.extend({
},
initSyncEngine: async function () {
- if (this.options.websocketEnabled == false) return
- if (this.options.syncEnabled != true) {
+ if (this.options.websocketEnabled === false) return
+ if (this.options.syncEnabled !== true) {
this.sync.stop()
} else {
const ws_token_uri = this.urls.get('map_websocket_auth_token', {
@@ -414,9 +410,7 @@ U.Map = L.Map.extend({
},
renderControls: function () {
- const hasSlideshow = Boolean(
- this.options.slideshow && this.options.slideshow.active
- )
+ const hasSlideshow = Boolean(this.options.slideshow?.active)
const barEnabled = this.options.captionBar || hasSlideshow
document.body.classList.toggle('umap-caption-bar-enabled', barEnabled)
document.body.classList.toggle('umap-slideshow-enabled', hasSlideshow)
@@ -444,7 +438,9 @@ U.Map = L.Map.extend({
}
})
}
- let name, status, control
+ let name
+ let status
+ let control
for (let i = 0; i < this.HIDDABLE_CONTROLS.length; i++) {
name = this.HIDDABLE_CONTROLS[i]
status = this.getOption(`${name}Control`)
@@ -630,11 +626,7 @@ U.Map = L.Map.extend({
this.options.tilelayer.attribution = props.attribution
}
}
- if (
- this.options.tilelayer &&
- this.options.tilelayer.url_template &&
- this.options.tilelayer.attribution
- ) {
+ if (this.options.tilelayer?.url_template && this.options.tilelayer.attribution) {
this.customTilelayer = this.createTileLayer(this.options.tilelayer)
this.selectTileLayer(this.customTilelayer)
} else {
@@ -657,13 +649,13 @@ U.Map = L.Map.extend({
}
this.selected_tilelayer = tilelayer
if (
- !isNaN(this.selected_tilelayer.options.minZoom) &&
+ !Number.isNaN(this.selected_tilelayer.options.minZoom) &&
this.getZoom() < this.selected_tilelayer.options.minZoom
) {
this.setZoom(this.selected_tilelayer.options.minZoom)
}
if (
- !isNaN(this.selected_tilelayer.options.maxZoom) &&
+ !Number.isNaN(this.selected_tilelayer.options.maxZoom) &&
this.getZoom() > this.selected_tilelayer.options.maxZoom
) {
this.setZoom(this.selected_tilelayer.options.maxZoom)
@@ -760,11 +752,16 @@ U.Map = L.Map.extend({
},
handleLimitBounds: function () {
- const south = Number.parseFloat(this.options.limitBounds.south),
- west = Number.parseFloat(this.options.limitBounds.west),
- north = Number.parseFloat(this.options.limitBounds.north),
- east = Number.parseFloat(this.options.limitBounds.east)
- if (!isNaN(south) && !isNaN(west) && !isNaN(north) && !isNaN(east)) {
+ const south = Number.parseFloat(this.options.limitBounds.south)
+ const west = Number.parseFloat(this.options.limitBounds.west)
+ const north = Number.parseFloat(this.options.limitBounds.north)
+ const east = Number.parseFloat(this.options.limitBounds.east)
+ if (
+ !Number.isNaN(south) &&
+ !Number.isNaN(west) &&
+ !Number.isNaN(north) &&
+ !Number.isNaN(east)
+ ) {
const bounds = L.latLngBounds([
[south, west],
[north, east],
@@ -794,7 +791,7 @@ U.Map = L.Map.extend({
return L.Map.prototype.setMaxBounds.call(this, bounds)
},
- createDataLayer: function (options = {}, sync) {
+ createDataLayer: function (options = {}, sync = true) {
options.name = options.name || `${L._('Layer')} ${this.datalayers_index.length + 1}`
const datalayer = new U.DataLayer(this, options, sync)
@@ -809,7 +806,7 @@ U.Map = L.Map.extend({
datalayer.edit()
},
- getDefaultOption: (option) => U.SCHEMA[option] && U.SCHEMA[option].default,
+ getDefaultOption: (option) => U.SCHEMA[option]?.default,
getOption: function (option, feature) {
if (feature) {
@@ -884,7 +881,7 @@ U.Map = L.Map.extend({
importFromUrl: async function (uri) {
const response = await this.request.get(uri)
- if (response && response.ok) {
+ if (response?.ok) {
this.importRaw(await response.text())
}
},
@@ -1135,7 +1132,8 @@ U.Map = L.Map.extend({
// (edit and viewing)
// cf https://github.com/umap-project/umap/issues/585
defaultEditDataLayer: function () {
- let datalayer, fallback
+ let datalayer
+ let fallback
datalayer = this.lastUsedDataLayer
if (
datalayer &&
@@ -1161,7 +1159,7 @@ U.Map = L.Map.extend({
},
getDataLayerByUmapId: function (umap_id) {
- return this.findDataLayer((d) => d.umap_id == umap_id)
+ return this.findDataLayer((d) => d.umap_id === umap_id)
},
_editControls: function (container) {
@@ -1343,7 +1341,7 @@ U.Map = L.Map.extend({
handler: 'BlurInput',
helpText: `${L._('Supported scheme')}: http://{s}.domain.com/{z}/{x}/{y}.png`,
placeholder: 'url',
- helpText: L._('Background overlay url'),
+ label: L._('Background overlay url'),
type: 'url',
},
],
@@ -1600,11 +1598,11 @@ U.Map = L.Map.extend({
initCaptionBar: function () {
const container = L.DomUtil.create(
- 'div',
- 'umap-caption-bar',
- this._controlContainer
- ),
- name = L.DomUtil.create('h3', '', container)
+ 'div',
+ 'umap-caption-bar',
+ this._controlContainer
+ )
+ const name = L.DomUtil.create('h3', '', container)
L.DomEvent.disableClickPropagation(container)
this.permissions.addOwnerLink('span', container)
if (this.getOption('captionMenus')) {
@@ -1716,7 +1714,7 @@ U.Map = L.Map.extend({
},
})
}
- if (e && e.relatedTarget) {
+ if (e?.relatedTarget) {
if (e.relatedTarget.getContextMenuItems) {
items = items.concat(e.relatedTarget.getContextMenuItems(e))
}
diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js
index 6992a2f2..857befe0 100644
--- a/umap/static/umap/js/umap.layer.js
+++ b/umap/static/umap/js/umap.layer.js
@@ -67,7 +67,7 @@ U.Layer.Cluster = L.MarkerClusterGroup.extend({
},
iconCreateFunction: (cluster) => new U.Icon.Cluster(datalayer, cluster),
}
- if (this.datalayer.options.cluster && this.datalayer.options.cluster.radius) {
+ if (this.datalayer.options.cluster?.radius) {
options.maxClusterRadius = this.datalayer.options.cluster.radius
}
L.MarkerClusterGroup.prototype.initialize.call(this, options)
@@ -177,7 +177,7 @@ U.Layer.Choropleth = L.FeatureGroup.extend({
const values = []
this.datalayer.eachLayer((layer) => {
const value = this._getValue(layer)
- if (!isNaN(value)) values.push(value)
+ if (!Number.isNaN(value)) values.push(value)
})
return values
},
@@ -190,9 +190,9 @@ U.Layer.Choropleth = L.FeatureGroup.extend({
this.options.colors = []
return
}
- let mode = this.datalayer.options.choropleth.mode,
- classes = +this.datalayer.options.choropleth.classes || 5,
- breaks
+ const mode = this.datalayer.options.choropleth.mode
+ let classes = +this.datalayer.options.choropleth.classes || 5
+ let breaks
classes = Math.min(classes, values.length)
if (mode === 'manual') {
const manualBreaks = this.datalayer.options.choropleth.breaks
@@ -200,7 +200,7 @@ U.Layer.Choropleth = L.FeatureGroup.extend({
breaks = manualBreaks
.split(',')
.map((b) => +b)
- .filter((b) => !isNaN(b))
+ .filter((b) => !Number.isNaN(b))
}
} else if (mode === 'equidistant') {
breaks = ss.equalIntervalBreaks(values, classes)
@@ -243,7 +243,7 @@ U.Layer.Choropleth = L.FeatureGroup.extend({
addLayer: function (layer) {
// Do not add yet the layer to the map
// wait for datachanged event, so we want compute breaks once
- var id = this.getLayerId(layer)
+ const id = this.getLayerId(layer)
this._layers[id] = layer
return this
},
@@ -326,7 +326,9 @@ U.Layer.Choropleth = L.FeatureGroup.extend({
renderLegend: function (container) {
const parent = L.DomUtil.create('ul', '', container)
- let li, color, label
+ let li
+ let color
+ let label
this.options.breaks.slice(0, -1).forEach((limit, index) => {
li = L.DomUtil.create('li', '', parent)
@@ -358,12 +360,9 @@ U.Layer.Heat = L.HeatLayer.extend({
addLayer: function (layer) {
if (layer instanceof L.Marker) {
- let latlng = layer.getLatLng(),
- alt
- if (
- this.datalayer.options.heat &&
- this.datalayer.options.heat.intensityProperty
- ) {
+ let latlng = layer.getLatLng()
+ let alt
+ if (this.datalayer.options.heat?.intensityProperty) {
alt = Number.parseFloat(
layer.properties[this.datalayer.options.heat.intensityProperty || 0]
)
@@ -430,23 +429,23 @@ U.Layer.Heat = L.HeatLayer.extend({
if (!this._map) {
return
}
- var data = [],
- r = this._heat._r,
- size = this._map.getSize(),
- bounds = new L.Bounds(L.point([-r, -r]), size.add([r, r])),
- cellSize = r / 2,
- grid = [],
- panePos = this._map._getMapPanePos(),
- offsetX = panePos.x % cellSize,
- offsetY = panePos.y % cellSize,
- i,
- len,
- p,
- cell,
- x,
- y,
- j,
- len2
+ const data = []
+ const r = this._heat._r
+ const size = this._map.getSize()
+ const bounds = new L.Bounds(L.point([-r, -r]), size.add([r, r]))
+ const cellSize = r / 2
+ const grid = []
+ const panePos = this._map._getMapPanePos()
+ const offsetX = panePos.x % cellSize
+ const offsetY = panePos.y % cellSize
+ let i
+ let len
+ let p
+ let cell
+ let x
+ let y
+ let j
+ let len2
this._max = 1
@@ -455,7 +454,7 @@ U.Layer.Heat = L.HeatLayer.extend({
x = Math.floor((p.x - offsetX) / cellSize) + 2
y = Math.floor((p.y - offsetY) / cellSize) + 2
- var alt =
+ const alt =
this._latlngs[i].alt !== undefined
? this._latlngs[i].alt
: this._latlngs[i][2] !== undefined
@@ -567,11 +566,11 @@ U.DataLayer = L.Evented.extend({
this.options.remoteData = {}
}
// Retrocompat
- if (this.options.remoteData && this.options.remoteData.from) {
+ if (this.options.remoteData?.from) {
this.options.fromZoom = this.options.remoteData.from
delete this.options.remoteData.from
}
- if (this.options.remoteData && this.options.remoteData.to) {
+ if (this.options.remoteData?.to) {
this.options.toZoom = this.options.remoteData.to
delete this.options.remoteData.to
}
@@ -772,14 +771,14 @@ U.DataLayer = L.Evented.extend({
},
showAtZoom: function () {
- const from = Number.parseInt(this.options.fromZoom, 10),
- to = Number.parseInt(this.options.toZoom, 10),
- zoom = this.map.getZoom()
- return !((!isNaN(from) && zoom < from) || (!isNaN(to) && zoom > to))
+ const from = Number.parseInt(this.options.fromZoom, 10)
+ const to = Number.parseInt(this.options.toZoom, 10)
+ const zoom = this.map.getZoom()
+ return !((!Number.isNaN(from) && zoom < from) || (!Number.isNaN(to) && zoom > to))
},
hasDynamicData: function () {
- return !!(this.options.remoteData && this.options.remoteData.dynamic)
+ return !!this.options.remoteData?.dynamic
},
fetchRemoteData: async function (force) {
@@ -791,7 +790,7 @@ U.DataLayer = L.Evented.extend({
url = this.map.proxyUrl(url, this.options.remoteData.ttl)
}
const response = await this.map.request.get(url)
- if (response && response.ok) {
+ if (response?.ok) {
this.clear()
this.rawToGeoJSON(
await response.text(),
@@ -869,11 +868,7 @@ U.DataLayer = L.Evented.extend({
},
isRemoteLayer: function () {
- return Boolean(
- this.options.remoteData &&
- this.options.remoteData.url &&
- this.options.remoteData.format
- )
+ return Boolean(this.options.remoteData?.url && this.options.remoteData.format)
},
isClustered: function () {
@@ -961,7 +956,7 @@ U.DataLayer = L.Evented.extend({
// csv2geojson fallback to null geometries when it cannot determine
// lat or lon columns. This is valid geojson, but unwanted from a user
// point of view.
- if (result && result.features.length) {
+ if (result?.features.length) {
if (result.features[0].geometry === null) {
err = {
type: 'Error',
@@ -982,7 +977,7 @@ U.DataLayer = L.Evented.extend({
U.Alert.error(message, 10000)
console.error(err)
}
- if (result && result.features.length) {
+ if (result?.features.length) {
callback(result)
}
}
@@ -1017,7 +1012,7 @@ U.DataLayer = L.Evented.extend({
// GeoJSON features.
geojsonToFeatures: function (geojson, sync) {
if (!geojson) return
- const features = geojson instanceof Array ? geojson : geojson.features
+ const features = Array.isArray(geojson) ? geojson : geojson.features
let i
let len
@@ -1063,7 +1058,8 @@ U.DataLayer = L.Evented.extend({
} = {}) {
if (!geometry) return // null geometry is valid geojson.
const coords = geometry.coordinates
- let latlng, latlngs
+ let latlng
+ let latlngs
// Create a default geojson if none is provided
if (geojson === undefined) geojson = { type: 'Feature', geometry: geometry }
@@ -1162,7 +1158,7 @@ U.DataLayer = L.Evented.extend({
importFromUrl: async function (uri, type) {
uri = this.map.localizeUrl(uri)
const response = await this.map.request.get(uri)
- if (response && response.ok) {
+ if (response?.ok) {
this.importRaw(await response.text(), type)
}
},
@@ -1208,8 +1204,8 @@ U.DataLayer = L.Evented.extend({
const options = U.Utils.CopyJSON(this.options)
options.name = L._('Clone of {name}', { name: this.options.name })
delete options.id
- const geojson = U.Utils.CopyJSON(this._geojson),
- datalayer = this.map.createDataLayer(options)
+ const geojson = U.Utils.CopyJSON(this._geojson)
+ const datalayer = this.map.createDataLayer(options)
datalayer.fromGeoJSON(geojson)
return datalayer
},
@@ -1258,28 +1254,28 @@ U.DataLayer = L.Evented.extend({
if (!this.map.editEnabled || !this.isLoaded()) {
return
}
- const container = L.DomUtil.create('div', 'umap-layer-properties-container'),
- metadataFields = [
- 'options.name',
- 'options.description',
- ['options.type', { handler: 'LayerTypeChooser', label: L._('Type of layer') }],
- ['options.displayOnLoad', { label: L._('Display on load'), handler: 'Switch' }],
- [
- 'options.browsable',
- {
- label: L._('Data is browsable'),
- handler: 'Switch',
- helpEntries: 'browsable',
- },
- ],
- [
- 'options.inCaption',
- {
- label: L._('Show this layer in the caption'),
- handler: 'Switch',
- },
- ],
- ]
+ const container = L.DomUtil.create('div', 'umap-layer-properties-container')
+ const metadataFields = [
+ 'options.name',
+ 'options.description',
+ ['options.type', { handler: 'LayerTypeChooser', label: L._('Type of layer') }],
+ ['options.displayOnLoad', { label: L._('Display on load'), handler: 'Switch' }],
+ [
+ 'options.browsable',
+ {
+ label: L._('Data is browsable'),
+ handler: 'Switch',
+ helpEntries: 'browsable',
+ },
+ ],
+ [
+ 'options.inCaption',
+ {
+ label: L._('Show this layer in the caption'),
+ handler: 'Switch',
+ },
+ ],
+ ]
L.DomUtil.createTitle(container, L._('Layer properties'), 'icon-layers')
let builder = new U.FormBuilder(this, metadataFields, {
callback: function (e) {
@@ -1470,17 +1466,17 @@ U.DataLayer = L.Evented.extend({
},
getOption: function (option, feature) {
- if (this.layer && this.layer.getOption) {
+ if (this.layer?.getOption) {
const value = this.layer.getOption(option, feature)
if (typeof value !== 'undefined') return value
}
if (typeof this.getOwnOption(option) !== 'undefined') {
return this.getOwnOption(option)
- } else if (this.layer && this.layer.defaults && this.layer.defaults[option]) {
- return this.layer.defaults[option]
- } else {
- return this.map.getOption(option, feature)
}
+ if (this.layer?.defaults?.[option]) {
+ return this.layer.defaults[option]
+ }
+ return this.map.getOption(option, feature)
},
buildVersionsFieldset: async function (container) {
@@ -1562,7 +1558,7 @@ U.DataLayer = L.Evented.extend({
// Is this layer type browsable in theorie
isBrowsable: function () {
- return this.layer && this.layer.browsable
+ return this.layer?.browsable
},
// Is this layer browsable in theorie
@@ -1749,9 +1745,9 @@ U.DataLayer = L.Evented.extend({
// By default, it will we use the "name" property, which is also the one used as label in the features list.
// When map owner has configured another label or sort key, we try to be smart and search in the same keys.
if (this.map.options.filterKey) return this.map.options.filterKey
- else if (this.options.labelKey) return this.options.labelKey
- else if (this.map.options.sortKey) return this.map.options.sortKey
- else return 'name'
+ if (this.options.labelKey) return this.options.labelKey
+ if (this.map.options.sortKey) return this.map.options.sortKey
+ return 'name'
},
})
diff --git a/umap/static/umap/js/umap.permissions.js b/umap/static/umap/js/umap.permissions.js
index 86da5a59..42630301 100644
--- a/umap/static/umap/js/umap.permissions.js
+++ b/umap/static/umap/js/umap.permissions.js
@@ -35,7 +35,7 @@ U.MapPermissions = L.Class.extend({
return (
this.map.options.user &&
this.map.options.permissions.owner &&
- this.map.options.user.id == this.map.options.permissions.owner.id
+ this.map.options.user.id === this.map.options.permissions.owner.id
)
},
@@ -151,7 +151,7 @@ U.MapPermissions = L.Class.extend({
if (this.isOwner() || this.isAnonymousMap())
formData.append('edit_status', this.options.edit_status)
if (this.isOwner()) {
- formData.append('owner', this.options.owner && this.options.owner.id)
+ formData.append('owner', this.options.owner?.id)
formData.append('share_status', this.options.share_status)
}
const [data, response, error] = await this.map.server.post(
@@ -180,7 +180,7 @@ U.MapPermissions = L.Class.extend({
},
addOwnerLink: function (element, container) {
- if (this.options.owner && this.options.owner.name && this.options.owner.url) {
+ if (this.options.owner?.name && this.options.owner.url) {
const ownerContainer = L.DomUtil.add(
element,
'umap-map-owner',
diff --git a/umap/static/umap/js/umap.popup.js b/umap/static/umap/js/umap.popup.js
index 2912f169..411e14bd 100644
--- a/umap/static/umap/js/umap.popup.js
+++ b/umap/static/umap/js/umap.popup.js
@@ -14,8 +14,8 @@ U.Popup = L.Popup.extend({
},
format: function () {
- const mode = this.feature.getOption('popupTemplate') || 'Default',
- klass = U.PopupTemplate[mode] || U.PopupTemplate.Default
+ const mode = this.feature.getOption('popupTemplate') || 'Default'
+ const klass = U.PopupTemplate[mode] || U.PopupTemplate.Default
this.content = new klass(this.feature, this.container)
this.content.render()
const els = this.container.querySelectorAll('img,iframe')
@@ -125,12 +125,12 @@ U.PopupTemplate.Default = L.Class.extend({
renderFooter: function () {
if (this.feature.hasPopupFooter()) {
- const footer = L.DomUtil.create('ul', 'umap-popup-footer', this.container),
- previousLi = L.DomUtil.create('li', 'previous', footer),
- zoomLi = L.DomUtil.create('li', 'zoom', footer),
- nextLi = L.DomUtil.create('li', 'next', footer),
- next = this.feature.getNext(),
- prev = this.feature.getPrevious()
+ const footer = L.DomUtil.create('ul', 'umap-popup-footer', this.container)
+ const previousLi = L.DomUtil.create('li', 'previous', footer)
+ const zoomLi = L.DomUtil.create('li', 'zoom', footer)
+ const nextLi = L.DomUtil.create('li', 'next', footer)
+ const next = this.feature.getNext()
+ const prev = this.feature.getPrevious()
// Fixme: remove me when this is merged and released
// https://github.com/Leaflet/Leaflet/pull/9052
L.DomEvent.disableClickPropagation(footer)
@@ -240,8 +240,8 @@ U.PopupTemplate.GeoRSSLink = U.PopupTemplate.Default.extend({
},
renderBody: function () {
- const title = this.renderTitle(this),
- a = L.DomUtil.add('a')
+ const title = this.renderTitle(this)
+ const a = L.DomUtil.add('a')
a.href = this.feature.properties.link
a.target = '_blank'
a.appendChild(title)
@@ -323,7 +323,7 @@ U.PopupTemplate.OSM = U.PopupTemplate.Default.extend({
L.DomUtil.element('a', { href: `mailto:${email}`, textContent: email })
)
}
- const id = props['@id'] || props['id']
+ const id = props['@id'] || props.id
if (id) {
L.DomUtil.add(
'div',
diff --git a/umap/static/umap/js/umap.share.js b/umap/static/umap/js/umap.share.js
index dbd68710..a2ab6106 100644
--- a/umap/static/umap/js/umap.share.js
+++ b/umap/static/umap/js/umap.share.js
@@ -19,11 +19,11 @@ U.Share = L.Class.extend({
formatter: (map) => {
const table = []
map.eachFeature((feature) => {
- const row = feature.toGeoJSON()['properties'],
- center = feature.getCenter()
- delete row['_umap_options']
- row['Latitude'] = center.lat
- row['Longitude'] = center.lng
+ const row = feature.toGeoJSON().properties
+ const center = feature.getCenter()
+ delete row._umap_options
+ row.Latitude = center.lat
+ row.Longitude = center.lng
table.push(row)
})
return csv2geojson.dsv.csvFormat(table)
diff --git a/umap/static/umap/js/umap.slideshow.js b/umap/static/umap/js/umap.slideshow.js
index 54117a9e..0122c0fd 100644
--- a/umap/static/umap/js/umap.slideshow.js
+++ b/umap/static/umap/js/umap.slideshow.js
@@ -69,8 +69,8 @@ U.Slideshow = L.Class.extend({
timeSpinner: function () {
const time = Number.parseInt(this.options.delay, 10)
if (!time) return
- const css = `rotation ${time / 1000}s infinite linear`,
- spinners = document.querySelectorAll('.umap-slideshow-toolbox .play .spinner')
+ const css = `rotation ${time / 1000}s infinite linear`
+ const spinners = document.querySelectorAll('.umap-slideshow-toolbox .play .spinner')
for (let i = 0; i < spinners.length; i++) {
spinners[i].style.animation = css
spinners[i].style['-webkit-animation'] = css
@@ -138,11 +138,11 @@ U.Slideshow = L.Class.extend({
},
renderToolbox: function (container) {
- const box = L.DomUtil.create('ul', 'umap-slideshow-toolbox'),
- play = L.DomUtil.create('li', 'play', box),
- stop = L.DomUtil.create('li', 'stop', box),
- prev = L.DomUtil.create('li', 'prev', box),
- next = L.DomUtil.create('li', 'next', box)
+ const box = L.DomUtil.create('ul', 'umap-slideshow-toolbox')
+ const play = L.DomUtil.create('li', 'play', box)
+ const stop = L.DomUtil.create('li', 'stop', box)
+ const prev = L.DomUtil.create('li', 'prev', box)
+ const next = L.DomUtil.create('li', 'next', box)
L.DomUtil.create('div', 'spinner', play)
play.title = L._('Start slideshow')
stop.title = L._('Stop slideshow')
diff --git a/umap/static/umap/js/umap.tableeditor.js b/umap/static/umap/js/umap.tableeditor.js
index 021815c4..9fc2e1e3 100644
--- a/umap/static/umap/js/umap.tableeditor.js
+++ b/umap/static/umap/js/umap.tableeditor.js
@@ -15,10 +15,10 @@ U.TableEditor = L.Class.extend({
},
renderHeader: function (property) {
- const container = L.DomUtil.create('div', 'tcell', this.header),
- title = L.DomUtil.add('span', '', container, property),
- del = L.DomUtil.create('i', 'umap-delete', container),
- rename = L.DomUtil.create('i', 'umap-edit', container)
+ const container = L.DomUtil.create('div', 'tcell', this.header)
+ const title = L.DomUtil.add('span', '', container, property)
+ const del = L.DomUtil.create('i', 'umap-delete', container)
+ const rename = L.DomUtil.create('i', 'umap-edit', container)
del.title = L._('Delete this property on all the features')
rename.title = L._('Rename this property on all the features')
const doDelete = function () {