Only send bounds if they have changed

to close Issue #209
This commit is contained in:
Dave Conway-Jones 2022-10-26 17:17:22 +01:00
parent a56c276f33
commit 6236928ff5
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
4 changed files with 10 additions and 3 deletions

View File

@ -1,5 +1,6 @@
### Change Log for Node-RED Worldmap ### 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.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.29.0 - Change locate to be a toggle and add command (trackme) to set style. Issue #202

View File

@ -11,6 +11,7 @@ map web page for plotting "things" on.
### Updates ### Updates
- v2.30.1 - Don't resend bounds if not changed. Issue #209
- v2.30.0 - Add show/hide ruler option. PR #206 - 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.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 - v2.28.3 - Let button declaration be an array

View File

@ -1,12 +1,12 @@
{ {
"name": "node-red-contrib-web-worldmap", "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.", "description": "A Node-RED node to provide a web page of a world map for plotting things on.",
"dependencies": { "dependencies": {
"@turf/bezier-spline": "~6.5.0", "@turf/bezier-spline": "~6.5.0",
"cgi": "0.3.1", "cgi": "0.3.1",
"compression": "^1.7.4", "compression": "^1.7.4",
"express": "^4.18.1", "express": "^4.18.2",
"sockjs": "~0.3.24" "sockjs": "~0.3.24"
}, },
"bundledDependencies": [ "bundledDependencies": [

View File

@ -33,6 +33,7 @@ var drawingColour = "#910000";
var sendDrawing; var sendDrawing;
var colorControl; var colorControl;
var sendRoute; var sendRoute;
var oldBounds = {ne:{lat:0,lng:0},sw:{lat:0,lng:0}};
var iconSz = { var iconSz = {
"Team/Crew": 24, "Team/Crew": 24,
@ -669,12 +670,16 @@ map.on('zoomend', function() {
showMapCurrentZoom(); showMapCurrentZoom();
window.localStorage.setItem("lastzoom", map.getZoom()); window.localStorage.setItem("lastzoom", map.getZoom());
var b = map.getBounds(); 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() })); 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() { map.on('moveend', function() {
window.localStorage.setItem("lastpos",JSON.stringify(map.getCenter())); window.localStorage.setItem("lastpos",JSON.stringify(map.getCenter()));
var b = map.getBounds(); 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('locationfound', onLocationFound);
map.on('locationerror', onLocationError); map.on('locationerror', onLocationError);