Permalink
Browse files

Merge #1488: Make JSObserver work with Leaflet.

Fixes #1451.
  • Loading branch information...
agrif committed Oct 9, 2018
2 parents dc70d6d + 4efb9f2 commit e867221d8edcdfddfda5ca94b731db8d98c2c18f
@@ -15,6 +15,7 @@ overviewer.worldCtrl = null;
overviewer.layerCtrl = null;
overviewer.compass = null;
overviewer.coord_box = null;
overviewer.progress = null;
overviewer.current_world = null;
/// Records the current layer by name (if any) of each world
@@ -67,6 +67,48 @@ overviewer.util = {
return this.coord_box;
}
});
overviewer.progressClass = L.Control.extend({
options: {
position: 'bottomright'
},
initialize: function() {
this.progress = L.DomUtil.create("div", "progress");
this.progress.innerHTML = 'Current render progress';
this.progress.style.visibility = 'hidden';
},
update: function() {
fetch("progress.json")
.then(response => {
if (!response.ok) {
throw new Error('Response was not ok');
}
return response.json();
})
.then(data => {
this.progress.innerHTML = data.message;
if (data.update > 0) {
setTimeout(this.update.bind(this), data.update);
this.progress.style.visibility = '';
} else {
setTimeout(this.update.bind(this), 60000);
this.progress.innerHTML = 'Hidden - data.update < 0';
this.progress.style.visibility = 'hidden';
}
})
.catch(error => {
this.progress.innerHtml = 'Hidden - no data';
this.progress.style.visibility = 'hidden';
console.info('Error getting progress; hiding control', error);
});
},
onAdd: function() {
// Not all browsers may have this
if ('fetch' in window) {
setTimeout(this.update.bind(this), 0);
}
return this.progress;
}
});
overviewer.compassClass = L.Control.extend({
initialize: function(imagedict, options) {
L.Util.setOptions(this, options);
@@ -247,6 +289,7 @@ overviewer.util = {
overviewer.compass = new overviewer.compassClass(
overviewerConfig.CONST.image.compass);
overviewer.coord_box = new overviewer.coordBoxClass();
overviewer.progress = new overviewer.progressClass();
overviewerConfig.worlds.forEach(function(world_name, idx) {
@@ -258,6 +301,7 @@ overviewer.util = {
overviewer.compass.addTo(overviewer.map);
overviewer.worldCtrl.addTo(overviewer.map);
overviewer.coord_box.addTo(overviewer.map);
overviewer.progress.addTo(overviewer.map);
overviewer.map.on('mousemove', function(ev) {
overviewer.coord_box.render(ev.latlng);
@@ -165,7 +165,7 @@ div.worldcontrol select {
font-size: 1.2em;
}
.leaflet-container .coordbox {
.leaflet-container .coordbox, .leaflet-container .progress {
box-shadow: none;
font-size: 11px;
background: rgba(255, 255, 255, 0.7);
@@ -294,7 +294,7 @@ def update(self, current_value):
"""
self._current_value = current_value
if self._need_update():
refresh = max(1500*(time.time() - self.last_update_time), self.minrefresh) // 1
refresh = max(1500*(time.time() - max(self.start_time, self.last_update_time)), self.minrefresh) // 1
self.logfile.seek(0)
self.logfile.truncate()
if self.get_current_value():

0 comments on commit e867221

Please sign in to comment.