Skip to content

Commit d4e4681

Browse files
committed
JS: Remove import from legacy
The legacy JS code does not have to contain `import` like modules. If we need some methods or classes in the legacy JS code, they have o be exposed.
1 parent 43bfeaf commit d4e4681

File tree

5 files changed

+14
-25
lines changed

5 files changed

+14
-25
lines changed

assets/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import executeJSFromServer from './modules/ExecuteJSFromServer.js';
3232

3333
import olDep from './dependencies/ol.js';
3434
import litHTMLDep from './dependencies/lit-html.js';
35+
import DOMPurify from 'dompurify';
3536
import proj4 from 'proj4';
3637

3738
/**
@@ -86,6 +87,7 @@ const definedCustomElements = () => {
8687
const initLizmapApp = () => {
8788
lizMap.ol = olDep;
8889
lizMap.litHTML = litHTMLDep;
90+
lizMap.DOMPurify = DOMPurify;
8991
lizMap.proj4 = proj4;
9092

9193
lizMap.events.on({

assets/src/legacy/atlas.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
* @license MPL-2.0
66
*/
77

8-
import DOMPurify from 'dompurify';
9-
import { getCenter } from 'ol/extent.js';
10-
118
(function () {
129

1310
lizMap.events.on({
@@ -204,7 +201,7 @@ import { getCenter } from 'ol/extent.js';
204201
}
205202
}
206203

207-
$('#liz-atlas-select').html(DOMPurify.sanitize(options));
204+
$('#liz-atlas-select').html(lizMap.DOMPurify.sanitize(options));
208205
// reset val
209206
$('#liz-atlas-select').val(val);
210207
// get popup
@@ -403,7 +400,7 @@ import { getCenter } from 'ol/extent.js';
403400
// Get Atlas home
404401
var home = getAtlasHome(lizAtlasConfig);
405402

406-
$("#atlas-content").html(DOMPurify.sanitize(home));
403+
$("#atlas-content").html(lizMap.DOMPurify.sanitize(home));
407404

408405
// Add events
409406
activateAtlasTrigger(lizAtlasConfig);
@@ -566,7 +563,7 @@ import { getCenter } from 'ol/extent.js';
566563
if (lizAtlasConfig['zoom']) {
567564
if (lizAtlasConfig['zoom'].toLowerCase() == 'center') {
568565
// center
569-
const center = getCenter(olFeature.getGeometry().getExtent());
566+
const center = lizMap.ol.extent.getCenter(olFeature.getGeometry().getExtent());
570567
lizMap.map.setCenter(center);
571568
}
572569
else {

assets/src/legacy/attributeTable.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* @license MPL-2.0
66
*/
77

8-
import DOMPurify from 'dompurify';
9-
108
var lizAttributeTable = function() {
119

1210
const intRegex = /^[0-9]+$/;
@@ -1927,7 +1925,7 @@ var lizAttributeTable = function() {
19271925
continue;
19281926
var prop = feat.properties[idx];
19291927
if (typeof prop == 'string') {
1930-
prop = DOMPurify.sanitize(prop, {
1928+
prop = lizMap.DOMPurify.sanitize(prop, {
19311929
ADD_ATTR: ['target']
19321930
});
19331931
}

assets/src/legacy/filter.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* @license MPL-2.0
66
*/
77

8-
import DOMPurify from 'dompurify';
9-
108
var lizLayerFilterTool = function () {
119

1210
lizMap.events.on({
@@ -528,7 +526,7 @@ var lizLayerFilterTool = function () {
528526
}
529527

530528
for (const feat of result) {
531-
globalThis['filterConfig'][field_item.order]['items'][DOMPurify.sanitize(feat['v'].toString())] = feat['c'];
529+
globalThis['filterConfig'][field_item.order]['items'][lizMap.DOMPurify.sanitize(feat['v'].toString())] = feat['c'];
532530
}
533531

534532
var dhtml = '';

assets/src/legacy/map.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
* @license MPL-2.0
99
*/
1010

11-
import { extend } from 'ol/extent.js';
12-
13-
import WFS from '../modules/WFS.js';
14-
import WMS from '../modules/WMS.js';
15-
import { Utils } from '../modules/Utils.js';
16-
1711
window.lizMap = function() {
1812
/**
1913
* PRIVATE Property: config
@@ -2082,7 +2076,7 @@ window.lizMap = function() {
20822076
// Download file
20832077
document.querySelectorAll('.exportLayer').forEach(el => el.disabled = true);
20842078
mAddMessage(lizDict['layer.export.started'], 'info', true).addClass('export-in-progress');
2085-
Utils.downloadFile(getFeatureUrlData['url'], getFeatureUrlData['options'], () => {
2079+
lizMap.mainLizmap.utils.downloadFile(getFeatureUrlData['url'], getFeatureUrlData['options'], () => {
20862080
document.querySelectorAll('.exportLayer').forEach(el => el.disabled = false);
20872081
document.querySelector('#message .export-in-progress button').click();
20882082
});
@@ -2301,7 +2295,7 @@ window.lizMap = function() {
23012295
types: aConfig['types']
23022296
};
23032297

2304-
const wfs = new WFS();
2298+
const wfs = new lizMap.mainLizmap.wfs();
23052299
wfs.getFeature(getFeatureUrlData['options']).then(data => {
23062300
aConfig['featureCrs'] = 'EPSG:4326';
23072301

@@ -2522,7 +2516,7 @@ window.lizMap = function() {
25222516

25232517
// Query the server
25242518
$.post(globalThis['lizUrls'].service, wmsOptions, function(data) {
2525-
aCallback(Utils.sanitizeGFIContent(data));
2519+
aCallback(lizMap.mainLizmap.utils.sanitizeGFIContent(data));
25262520
});
25272521
}
25282522

@@ -2596,7 +2590,7 @@ window.lizMap = function() {
25962590
// Query the server
25972591
$.post(globalThis['lizUrls'].service, wmsOptions, function(data) {
25982592
if (aCallback) {
2599-
aCallback(globalThis['lizUrls'].service, wmsOptions, Utils.sanitizeGFIContent(data));
2593+
aCallback(globalThis['lizUrls'].service, wmsOptions, lizMap.mainLizmap.utils.sanitizeGFIContent(data));
26002594
}
26012595
});
26022596
}
@@ -3249,7 +3243,7 @@ window.lizMap = function() {
32493243
if(layerName && filter){
32503244

32513245
// Feature extent
3252-
const wfs = new WFS();
3246+
const wfs = new lizMap.mainLizmap.wfs();
32533247
const wfsParams = {
32543248
TYPENAME: layerName,
32553249
EXP_FILTER: filter
@@ -3259,7 +3253,7 @@ window.lizMap = function() {
32593253

32603254
// Feature info
32613255
if(urlParameters.get('popup') === 'true'){
3262-
const wms = new WMS();
3256+
const wms = new lizMap.mainLizmap.wms();
32633257
const wmsParams = {
32643258
QUERY_LAYERS: layerName,
32653259
LAYERS: layerName,
@@ -3302,7 +3296,7 @@ window.lizMap = function() {
33023296

33033297
if(featuresExtent){
33043298
for (const feature of startupFeatures) {
3305-
featuresExtent = extend(featuresExtent, feature.bbox);
3299+
featuresExtent = lizMap.ol.extent.extend(featuresExtent, feature.bbox);
33063300
}
33073301
}
33083302

0 commit comments

Comments
 (0)