aboutsummaryrefslogtreecommitdiffstats
path: root/main.js
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2025-06-10 00:49:44 +0200
committerGuilhem Moulin <guilhem@fripost.org>2025-06-10 01:00:03 +0200
commit887c24b79489fc9403a98a039a9138e48fc147a7 (patch)
tree607a75e59f7d6592d14a85f42fcefc97d61ce27e /main.js
parent9922252612b81714ef6e01b46f4744352ca94adb (diff)
Consolidate comparison with undefined/null.
Replace `a === undefined || a === null` resp. `a !== undefined && a !== null` with `a == null` resp. `a != null`. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality . Relax also some `=== undefined` and `=== null` into `== null` when that makes sense.
Diffstat (limited to 'main.js')
-rw-r--r--main.js60
1 files changed, 30 insertions, 30 deletions
diff --git a/main.js b/main.js
index 1e0e828..dcf5592 100644
--- a/main.js
+++ b/main.js
@@ -539,9 +539,9 @@ if (window.location === window.parent.location) {
infoMetadataAccordions.forEach((x) => x.element.replaceChildren());
modal.show();
Promise.allSettled(Object.entries(mapLayers).map(function([grp,lyr]) {
- if (lyr !== null && lyr.getSource() instanceof VectorTile) {
+ if (lyr != null && lyr.getSource() instanceof VectorTile) {
const url = lyr.getSource().getUrls()[0];
- if (url === undefined || url.length <= 16 || url.substr(url.length - 16) !== '/{z}/{x}/{y}.pbf') {
+ if (url == null || url.length <= 16 || url.substr(url.length - 16) !== '/{z}/{x}/{y}.pbf') {
return new Promise(() => { throw new Error(`Invalid URL ${url}`); });
}
return fetch(url.substr(0, url.length - 16) + '/metadata.json')
@@ -571,12 +571,12 @@ if (window.location === window.parent.location) {
const last_updated = [];
x.items.forEach(function([groupname, _]) {
const layer_group = metadata[groupname];
- if (layer_group === undefined) {
+ if (layer_group == null) {
return;
}
if (!groupnames.has(groupname)) {
groupnames.add(groupname);
- if (layer_group.last_updated !== undefined) {
+ if (layer_group.last_updated != null) {
last_updated.push(layer_group.last_updated);
}
}
@@ -603,11 +603,11 @@ if (window.location === window.parent.location) {
x.items.forEach(function([groupname, layername]) {
/* for each source file associated with the accordion header, show copyright, license and timing information */
const layer_group = metadata[groupname];
- if (layer_group === undefined || layer_group.layers === undefined || layer_group.source_files === undefined) {
+ if (layer_group == null || layer_group.layers == null || layer_group.source_files == null) {
return;
}
const def = layer_group.layers[layername];
- if (def === undefined || def.source_files === undefined) {
+ if (def == null || def.source_files == null) {
return;
}
def.source_files.forEach(function(source_file) {
@@ -622,24 +622,24 @@ if (window.location === window.parent.location) {
ul.appendChild(li)
const h = document.createElement('h6');
li.appendChild(h)
- if (x.description !== undefined && x.description !== null) {
+ if (x.description != null) {
const t = document.createTextNode(x.description);
h.appendChild(t);
}
- if (x.copyright !== undefined && x.copyright !== null) {
+ if (x.copyright != null) {
const p = document.createElement('p');
li.appendChild(p)
const t = document.createTextNode(x.copyright);
p.appendChild(t);
}
- if (x.license !== undefined && x.license !== null) {
+ if (x.license != null) {
const p = document.createElement('p');
li.appendChild(p)
p.appendChild(document.createTextNode('Licensvillkor: '));
const t = document.createTextNode(x.license.name);
- if (x.license.url === undefined || x.license.url === null) {
+ if (x.license.url == null) {
p.appendChild(t);
} else {
const a = document.createElement('a');
@@ -650,7 +650,7 @@ if (window.location === window.parent.location) {
}
}
- if (x.product_url !== undefined && x.product_url !== null) {
+ if (x.product_url != null) {
const p = document.createElement('p');
li.appendChild(p)
const t = document.createTextNode('Produktlänk ');
@@ -664,7 +664,7 @@ if (window.location === window.parent.location) {
p.appendChild(a);
}
- if (x.last_modified !== undefined && x.last_modified !== null) {
+ if (x.last_modified != null) {
const p = document.createElement('p');
p.classList.add('small', 'text-muted');
li.appendChild(p);
@@ -673,7 +673,7 @@ if (window.location === window.parent.location) {
p.appendChild(i);
p.appendChild(document.createTextNode(' '));
const t0 = document.createTextNode('Källfil');
- if (x.url === undefined || x.url === null) {
+ if (x.url == null) {
p.appendChild(t0);
} else {
const a = document.createElement('a');
@@ -2720,7 +2720,7 @@ const layers = {
['Senaste beslutsdatum', 'SEN_BESLUT'],
['Rättsakt', 'LEGAL_ACT'],
['Länk', 'LINK', { fn: function(v) {
- if (v === undefined || v === null || v === '') {
+ if (v == null || v === '') {
return;
}
const a = document.createElement('a');
@@ -2832,7 +2832,7 @@ const layers = {
['Namn', 'NAMN'],
['Skyddstyp', 'SKYDDSTYP'],
['Länk', 'LINK', { fn: function(v) {
- if (v === undefined || v === null || v === '') {
+ if (v == null || v === '') {
return;
}
const a = document.createElement('a');
@@ -2980,7 +2980,7 @@ const layers = {
['Avtalat datum', 'AvtalatDatum'],
['Areal', 'geom_area', { fn: 'area' }],
['Länk', 'Url', { fn: function(v) {
- if (v === undefined || v === null || v === '') {
+ if (v == null || v === '') {
return;
}
const a = document.createElement('a');
@@ -3052,7 +3052,7 @@ const layers = {
['Nyckelord #3 som beskriver objektet', 'Beskrivn3'],
['Areal', 'geom_area', { fn: 'area' }],
['Länk', 'Url', { fn: function(v) {
- if (v === undefined || v === null || v === '') {
+ if (v == null || v === '') {
return;
}
const a = document.createElement('a');
@@ -3129,7 +3129,7 @@ const layers = {
['Nyckelord #8 som beskriver objektet', 'Beskrivn8'],
['Areal', 'geom_area', { fn: 'area' }],
['Länk', 'Url', { fn: function(v) {
- if (v === undefined || v === null || v === '') {
+ if (v == null || v === '') {
return;
}
const a = document.createElement('a');
@@ -3194,7 +3194,7 @@ const layers = {
['Inkom datum', 'InkomDatum'],
['Areal', 'geom_area', { fn: 'area' }],
['Länk', 'Url', { fn: function(v) {
- if (v === undefined || v === null || v === '') {
+ if (v == null || v === '') {
return;
}
const a = document.createElement('a');
@@ -3275,7 +3275,7 @@ const layers = {
['Ansvarig myndighet', 'Ansvmynd'],
['Areal', 'geom_area', { fn: 'area' }],
['Länk', 'Url', { fn: function(v) {
- if (v === undefined || v === null || v === '') {
+ if (v == null || v === '') {
return;
}
const a = document.createElement('a');
@@ -3403,7 +3403,7 @@ const layers = {
['Skydd', 'SKYDD'],
['Ämnesområde', 'AMNESOMRAD'],
['Beskrivning', 'BESKRIVNIN', { fn: function(v) {
- if (v === undefined || v === null || !(v.startsWith('http://') || v.startsWith('https://'))) {
+ if (v == null || !(v.startsWith('http://') || v.startsWith('https://'))) {
return v;
}
const a = document.createElement('a');
@@ -4538,7 +4538,7 @@ const [mapLayers, featureOverlayLayer] = (function() {
[width/2, parent_height/2]
),
};
- let canvas = null, render = null;
+ let canvas, render;
(Array.isArray(elem.layer) ? elem.layer : [elem.layer])
.forEach(function(layer) {
/* add symbols for each layer */
@@ -4548,7 +4548,7 @@ const [mapLayers, featureOverlayLayer] = (function() {
return;
}
const legend = layers[layer].legend || {};
- if (canvas === null || !legend.reuse_canvas) {
+ if (canvas == null || !legend.reuse_canvas) {
canvas = document.createElement('canvas');
div.appendChild(canvas);
render = toContext(canvas.getContext('2d'),
@@ -4691,14 +4691,14 @@ const infoMetadataAccordions = [];
}
});
const kskog = mapLayers['kskog'];
- if (kskog !== undefined && kskog !== null) {
+ if (kskog != null) {
/* XXX unfortunately calling .setStyle() makes the layer blink */
kskog.setStyle({ color: ['palette', ['band', 1], kskog_palette ] });
}
Object.entries(result).forEach(function([lyr, visible]) {
const v = mapLayers[lyr];
- if (v !== undefined && v !== null) {
+ if (v != null) {
//console.log(lyr, visible);
v.setVisible(visible);
}
@@ -4723,7 +4723,7 @@ const infoMetadataAccordions = [];
if (event.target.checked) {
layerList.forEach(function(lyr) {
const l = mapLayers[lyr.split('.', 1)[0]];
- if (l === undefined || l === null) {
+ if (l == null) {
return; /* keep unexisting layers (eg WebGL layers on a system without WebGL support) unselectable */
}
styles[lyr] = layers[lyr].style;
@@ -4742,7 +4742,7 @@ const infoMetadataAccordions = [];
layerList
.map((l) => l.split('.', 1)[0])
- .filter((v, i, arr) => mapLayers[v] !== undefined && mapLayers[v] !== null && arr.indexOf(v) === i)
+ .filter((v, i, arr) => mapLayers[v] != null && arr.indexOf(v) === i)
.forEach((l) => mapLayers[l].getSource().changed());
searchParams.set('layers', layersParams.join(' '));
@@ -5011,7 +5011,7 @@ const infoMetadataAccordions = [];
});
const updateFeatureOverlayLayer = function(layer_group, layer, id) {
const lyr = mapLayers[layer_group];
- if (lyr === undefined) {
+ if (lyr == null) {
return;
}
const urls = lyr.getSource().getUrls();
@@ -5161,7 +5161,7 @@ const infoMetadataAccordions = [];
v = opts.fn(v);
}
}
- if (v === undefined || v === null) {
+ if (v == null) {
v = document.createTextNode('');
} else if (!(v instanceof HTMLElement)) {
if (typeof(v) === 'number' && opts.unit !== undefined) {
@@ -5263,7 +5263,7 @@ const infoMetadataAccordions = [];
}, {
hitTolerance: 5,
checkWrapped: false,
- layerFilter: (l) => l !== null && l.get('layerGroup') !== undefined,
+ layerFilter: (l) => l.get('layerGroup') != null,
});
if (fetch_body.length === 0) {