Fix map local storage of zoom levels

and socket.io reconnect
This commit is contained in:
Dave Conway-Jones 2016-05-20 16:41:13 +01:00
parent 0fcfb24c9d
commit 8629f1f017
2 changed files with 16 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-contrib-web-worldmap", "name" : "node-red-contrib-web-worldmap",
"version" : "1.0.0", "version" : "1.0.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" : {
"express": "4.*", "express": "4.*",

View File

@ -138,11 +138,13 @@ function start() { // Create the websocket
ws.emit("worldmap",{action:"connected"}); ws.emit("worldmap",{action:"connected"});
}); });
//ws.onclose = function(evt) { ws.on('disconnect', function() {
ws.on('close', function() {
console.log("DISCONNECTED"); console.log("DISCONNECTED");
document.getElementById("foot").innerHTML = "<font color='#900'>"+ibmfoot+"</font>"; document.getElementById("foot").innerHTML = "<font color='#900'>"+ibmfoot+"</font>";
setTimeout(function() { start() }, 3000); // try to reconnect every 3 secs... bit fast ? socketConnectTimeInterval = setInterval(function () {
ws.socket.reconnect();
if (ws.socket.connected) { clearInterval(socketConnectTimeInterval); }
}, 3000);
}); });
ws.on('worldmapdata', function(data) { ws.on('worldmapdata', function(data) {
@ -159,11 +161,17 @@ function start() { // Create the websocket
start(); start();
if ( window.localStorage.hasOwnProperty("lastpos") ) { if ( window.localStorage.hasOwnProperty("lastpos") ) {
var sp = JSON.parse(localStorage.getItem("lastpos")); var sp = JSON.parse(window.localStorage.getItem("lastpos"));
startpos = [ sp.lat, sp.lng ]; startpos = [ sp.lat, sp.lng ];
} }
if ( window.localStorage.hasOwnProperty("lastzoom") ) { if ( window.localStorage.hasOwnProperty("lastzoom") ) {
startzoom = JSON.parse(localStorage.getItem("lastzoom")); startzoom = window.localStorage.getItem("lastzoom");
}
if ( window.localStorage.hasOwnProperty("clusterAt") ) {
clusterAt = window.localStorage.getItem("clusterAt");
}
if ( window.localStorage.hasOwnProperty("maxage") ) {
maxage = window.localStorage.getItem("maxage");
} }
// Create the Initial Map object. // Create the Initial Map object.
map = new L.map('map').setView(startpos, startzoom); map = new L.map('map').setView(startpos, startzoom);
@ -216,6 +224,8 @@ function doLock() {
window.localStorage.setItem("lastpos",JSON.stringify(map.getCenter())); window.localStorage.setItem("lastpos",JSON.stringify(map.getCenter()));
window.localStorage.setItem("lastzoom", map.getZoom()); window.localStorage.setItem("lastzoom", map.getZoom());
window.localStorage.setItem("lastlayer", baselayername); window.localStorage.setItem("lastlayer", baselayername);
window.localStorage.setItem("clusterAt", clusterAt);
window.localStorage.setItem("maxage", maxage);
console.log("Saved :",JSON.stringify(map.getCenter()),map.getZoom(),baselayername); console.log("Saved :",JSON.stringify(map.getCenter()),map.getZoom(),baselayername);
} }
map.setMaxBounds(mb); map.setMaxBounds(mb);