Skip to content

Commit

Permalink
worldmap - consistent page reloads
Browse files Browse the repository at this point in the history
  • Loading branch information
vpithart authored and LarsMichelsen committed Aug 16, 2019
1 parent 8a16d01 commit 75d310e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Core:
* MKBI backend: Use "htmlcgi" URL/path for building links to the Checkmk GUI
(Aggregations used the base_url, which should not be used for user URLs)

Worldmap:
* Consistent page reloads: center + zoom of the map kept in URL

Frontend
* FIX: Fix creating users when mbstring extension is not available

Expand Down
20 changes: 17 additions & 3 deletions share/frontend/nagvis-js/js/ViewWorldmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,24 @@ var ViewWorldmap = ViewMap.extend({
detectRetina: true, // look nice on high resolution screens
maxZoom: 20,
})
}
}

g_map = L.map('map', {
markerZoomAnimation: false,
maxBounds: [ [-85,-180.0], [85,180.0] ],
minZoom: 2,
layers: [layers.map]
}).setView(getViewParam('worldmap_center').split(','), parseInt(getViewParam('worldmap_zoom')));

})

let restored_coordinates = window.location.hash.substr(1).split('/');
if (restored_coordinates.length === 3) {
// place the map view according to location hash (#lat/lon/zoom) - consistent page reloads
g_map.setView([restored_coordinates[1], restored_coordinates[0]], restored_coordinates[2]);
} else {
// or default (map-defined) view
g_map.setView(getViewParam('worldmap_center').split(','), parseInt(getViewParam('worldmap_zoom')));
}

if (layers.satellite)
L.control.layers(layers).addTo(g_map);

Expand Down Expand Up @@ -115,6 +125,10 @@ var ViewWorldmap = ViewMap.extend({
setViewParam('worldmap_zoom', g_map.getZoom());

this.render(); // re-render the whole map

// Put the new map view coords into URL (location) - consistent reloads
new_center = g_map.getCenter();
window.location.hash = `${new_center.lng}/${new_center.lat}/${g_map.getZoom()}`;
},

saveView: function() {
Expand Down

0 comments on commit 75d310e

Please sign in to comment.