From 2d905bd0481fafd22eda019369f30bb7c82eba22 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 24 Sep 2024 10:24:50 +0200 Subject: [PATCH] chore: use GeoRSStoGeoJSON as ES module --- package.json | 2 +- umap/static/umap/js/modules/formatter.js | 5 +- .../georsstogeojson/GeoRSSToGeoJSON.js | 199 ++++++++++-------- umap/templates/umap/js.html | 2 - 4 files changed, 119 insertions(+), 89 deletions(-) diff --git a/package.json b/package.json index 6b1e0522..c5c4c835 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "colorbrewer": "^1.5.6", "csv2geojson": "5.1.2", "dompurify": "^3.0.11", - "georsstogeojson": "^0.1.0", + "georsstogeojson": "^0.2.0", "jsdom": "^24.0.0", "leaflet": "1.9.4", "leaflet-contextmenu": "^1.4.0", diff --git a/umap/static/umap/js/modules/formatter.js b/umap/static/umap/js/modules/formatter.js index 99677e0f..4f1059ed 100644 --- a/umap/static/umap/js/modules/formatter.js +++ b/umap/static/umap/js/modules/formatter.js @@ -1,4 +1,4 @@ -/* Uses globals for: csv2geojson, osmtogeojson, GeoRSSToGeoJSON (not available as ESM) */ +/* Uses globals for: csv2geojson, osmtogeojson (not available as ESM) */ import { translate } from './i18n.js' export const EXPORT_FORMATS = { @@ -115,7 +115,8 @@ export class Formatter { } async fromGeoRSS(str) { - return GeoRSSToGeoJSON(this.toDom(str)) + const GeoRSSToGeoJSON = await import('../../vendors/georsstogeojson/GeoRSSToGeoJSON.js') + return GeoRSSToGeoJSON.parse(this.toDom(str)) } toDom(x) { diff --git a/umap/static/umap/vendors/georsstogeojson/GeoRSSToGeoJSON.js b/umap/static/umap/vendors/georsstogeojson/GeoRSSToGeoJSON.js index 560f0bb5..4fa2e1bc 100644 --- a/umap/static/umap/vendors/georsstogeojson/GeoRSSToGeoJSON.js +++ b/umap/static/umap/vendors/georsstogeojson/GeoRSSToGeoJSON.js @@ -1,89 +1,120 @@ -var GeoRSSToGeoJSON = function (dom, options) { +export function parse(dom, options) { + const g = { + type: 'FeatureCollection', + features: [], + } - function get(x, y) { return x.getElementsByTagName(y); } - function get1(x, y) { var n = get(x, y); return n.length ? n[0] : null; } - function norm(el) { if (el.normalize) { el.normalize(); } return el; } - function nodeVal(x) { if (x) {norm(x);} return x && x.firstChild && x.firstChild.nodeValue; } - function attr(x, y) { return x.getAttribute(y); } - - var g = { - type: 'FeatureCollection', - features: [] - }; - - function geom (node) { - - function p(c) {return parseFloat(c);} - function r(c) {return c.reverse().map(p);} // we have latlon we want lonlat - function e(f) {var _=[]; for (var i=0; i -