From 6236928ff5d1fa390179ec5dc0890ab7d90aac49 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Wed, 26 Oct 2022 17:17:22 +0100 Subject: [PATCH] Only send bounds if they have changed to close Issue #209 --- CHANGELOG.md | 1 + README.md | 1 + package.json | 4 ++-- worldmap/worldmap.js | 7 ++++++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8222dd5..3f78c48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### Change Log for Node-RED Worldmap + - v2.30.1 - Don't resend bounds if not changed. Issue #209 - v2.30.0 - Add show/hide ruler option. PR #206 - v2.29.0 - Change locate to be a toggle and add command (trackme) to set style. Issue #202 diff --git a/README.md b/README.md index 117dd18..3229ca3 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ map web page for plotting "things" on. ### Updates +- v2.30.1 - Don't resend bounds if not changed. Issue #209 - v2.30.0 - Add show/hide ruler option. PR #206 - v2.29.0 - Change locate to be a toggle and add command (trackme) to set style. Issue #202 - v2.28.3 - Let button declaration be an array diff --git a/package.json b/package.json index 0dec60b..ee1813b 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "node-red-contrib-web-worldmap", - "version": "2.29.0", + "version": "2.30.1", "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", "cgi": "0.3.1", "compression": "^1.7.4", - "express": "^4.18.1", + "express": "^4.18.2", "sockjs": "~0.3.24" }, "bundledDependencies": [ diff --git a/worldmap/worldmap.js b/worldmap/worldmap.js index 77f1a1e..1699909 100644 --- a/worldmap/worldmap.js +++ b/worldmap/worldmap.js @@ -33,6 +33,7 @@ var drawingColour = "#910000"; var sendDrawing; var colorControl; var sendRoute; +var oldBounds = {ne:{lat:0,lng:0},sw:{lat:0,lng:0}}; var iconSz = { "Team/Crew": 24, @@ -669,12 +670,16 @@ map.on('zoomend', function() { showMapCurrentZoom(); window.localStorage.setItem("lastzoom", map.getZoom()); var b = map.getBounds(); + oldBounds = {sw:{lat:b._southWest.lat,lng:b._southWest.lng},ne:{lat:b._northEast.lat,lng:b._northEast.lng}}; ws.send(JSON.stringify({action:"bounds", south:b._southWest.lat, west:b._southWest.lng, north:b._northEast.lat, east:b._northEast.lng, zoom:map.getZoom() })); }); map.on('moveend', function() { window.localStorage.setItem("lastpos",JSON.stringify(map.getCenter())); var b = map.getBounds(); - ws.send(JSON.stringify({action:"bounds", south:b._southWest.lat, west:b._southWest.lng, north:b._northEast.lat, east:b._northEast.lng, zoom:map.getZoom() })); + if (b._southWest.lat !== oldBounds.sw.lat && b._southWest.lng !== oldBounds.sw.lng && b._northEast.lat !== oldBounds.ne.lat && b._northEast.lng !== oldBounds.ne.lng) { + ws.send(JSON.stringify({action:"bounds", south:b._southWest.lat, west:b._southWest.lng, north:b._northEast.lat, east:b._northEast.lng, zoom:map.getZoom() })); + oldBounds = {sw:{lat:b._southWest.lat,lng:b._southWest.lng},ne:{lat:b._northEast.lat,lng:b._northEast.lng}}; + } }); map.on('locationfound', onLocationFound); map.on('locationerror', onLocationError);