From 21e56f9afbc7cf44c75332d73e4beb046a5d2346 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Sat, 26 Aug 2023 18:00:56 +0100 Subject: [PATCH] Fixup more kml markup and geojson drag drop --- CHANGELOG.md | 1 + README.md | 1 + package.json | 2 +- worldmap/leaflet/leaflet-kmz.js | 37 ++++++++++++++++++++++++++------- worldmap/worldmap.js | 6 +++++- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21cd3ee..6c0379f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### Change Log for Node-RED Worldmap + - v2.42.2 - More KML and GEOJson drag drop fixes - v2.42.1 - Remove extraneous debug logging, fix KMZ icons - v2.42.0 - Add handling for TAK type spots, waypoints, alerts, sensors. Better KML/KMZ handling. - v2.41.0 - Bump leaflet libs to latest stable (1.9.4) diff --git a/README.md b/README.md index 6bac28d..b33abf0 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Feel free to [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D% ### Updates +- v2.42.2 - More KML and GEOJson drag drop fixes - v2.42.1 - Remove extraneous debug logging, fix KMZ icons - v2.42.0 - Add handling for TAK type spots, waypoints, alerts, sensors. Better KML/KMZ handling. - v2.41.0 - Bump leaflet libs to latest stable (1.9.4) diff --git a/package.json b/package.json index 9ac10b6..a999b90 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-contrib-web-worldmap", - "version": "2.42.1", + "version": "2.42.2", "description": "A Node-RED node to provide a web page of a world map for plotting things on.", "dependencies": { "@turf/bezier-spline": "~6.5.0", diff --git a/worldmap/leaflet/leaflet-kmz.js b/worldmap/leaflet/leaflet-kmz.js index d9e3e4b..1b09389 100644 --- a/worldmap/leaflet/leaflet-kmz.js +++ b/worldmap/leaflet/leaflet-kmz.js @@ -140,6 +140,9 @@ text = new TextDecoder(encoding[1]).decode(data); } } + else { + text = text.substr(text.indexOf('<')); + } return text ? (new DOMParser()).parseFromString(text, 'text/xml') : document.implementation.createDocument(null, "kml");} function unzip(folder) { @@ -265,6 +268,7 @@ // TODO: handle L.svg renderer within the L.KMZMarker class? }, style: (feature) => { + // console.log("FEATSTYLE",feature) var styles = {}; var prop = feature.properties; @@ -289,16 +293,18 @@ return styles; }, onEachFeature: (feature, layer) => { - if (!this.options.ballon) return; + // console.log("POP",feature.properties) + //if (!this.options.ballon) return; var prop = feature.properties; - var name = prop.name || ""; - var desc = prop.description || ""; + var name = (prop.name || "").trim(); + var desc = (prop.description || "").trim(); + var p = '
'; if (name || desc) { - if (this.options.bindPopup) { - layer.bindPopup('
' + '' + name + '' + '
' + desc + '
'); - } + // if (this.options.bindPopup) { + // p += '' + name + '' + '
' + desc + '
'; + // } if (this.options.bindTooltip) { layer.bindTooltip('' + name + '', { direction: 'auto', @@ -306,6 +312,22 @@ }); } } + + var u = {}; + if (prop.FeaturePlatformId) { u.FeaturePlatformId = prop.FeaturePlatformId; } + if (prop.FeatureAddress) { u.FeatureAddress = prop.FeatureAddress; } + if (prop.SymbolSpecification) { u.Symbol = prop.SymbolSpecification; } + if (prop.Speed) { u.Speed = prop.Speed; } + if (prop.FeatureLastModified) { u.LastUpdate = prop.FeatureLastModified; } + if (u.LastUpdate) { u.LastUpdate = (new Date(u.LastUpdate*1000)).toISOString(); } + + Object.entries(u).forEach(([key, value]) => { + p += ''+key+' : '+value+'
'; + }); + p += ''; + if (p !== '
') { + layer.bindPopup(p); + } }, interactive: this.options.interactive, }); @@ -426,5 +448,4 @@ Object.defineProperty(exports, '__esModule', { value: true }); -}))); -//# sourceMappingURL=leaflet-kmz-src.js.map \ No newline at end of file +}))); \ No newline at end of file diff --git a/worldmap/worldmap.js b/worldmap/worldmap.js index 38da4e2..318d9b4 100644 --- a/worldmap/worldmap.js +++ b/worldmap/worldmap.js @@ -257,6 +257,10 @@ var readFile = function(file) { console.log("ZIP FILE",file); } } + else if (file.type.indexOf('geo+json') !== -1 ) { + data = JSON.parse(data); + doGeojson(file.name,data,"geojson"); + } else { try { data = JSON.parse(data); @@ -2874,7 +2878,7 @@ function doCommand(cmd) { // handle any incoming GEOJSON directly - may style badly function doGeojson(n,g,l,o) { - // console.log("GEOJSON",n,g,l,o) + // console.log("GEOJSON",n,g,l,o) // name,geojson,layer,options var lay = l ?? g.name ?? "unknown"; // if (!basemaps[lay]) { var opt = { style: function(feature) {