Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

Commit

Permalink
Feature: error messaging, param to disable mousezoom (#15)
Browse files Browse the repository at this point in the history
* Feature: display error message on failures

So things don't look "JS is dead" on failure.

* Improve documentation a bit

* Add disableZoomScroll option
  • Loading branch information
khawkins98 authored Aug 20, 2019
1 parent 7b537cb commit 4bf8034
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
43 changes: 41 additions & 2 deletions assets/map_scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ if (issetPolyfill(config.debugMetrics)) {
config.debugMetrics = true;
}

// error message display
config.hideErrorMessages = paraseParam('hideErrorMessages');
if (issetPolyfill(config.hideErrorMessages)) {
config.hideErrorMessages = true;
}

// passed zoom param
config.zoom = paraseParam('zoomLevel');
if (issetPolyfill(config.zoom)) {
Expand All @@ -95,6 +101,13 @@ if (issetPolyfill(config.lon)) {
if (!isNaN(config.lon)) initialLon = config.lon;
}

// optionally disable mouse wheel zooming
config.disableZoomScroll = paraseParam('disableZoomScroll');
if (issetPolyfill(config.disableZoomScroll)) {
config.disableZoomScroll = true;
map.scrollWheelZoom.disable();
}

// show sunrise and sunset
// http://joergdietrich.github.io/Leaflet.Terminator/
var daynightoverlay = L.terminator({className:'daynightoverlay'});
Expand Down Expand Up @@ -248,6 +261,26 @@ function scheduledNodeRemoval(targetClusterGroup,targetNode) {
}
}

// Show a user-friendly when data fetching fails
var errorMessageTimeout;
var errorFailCount = 0;
var errorDisplayThreshold = 2; // so we don't show every time a fail occurs

function showErrorMessage() {
errorFailCount++

if (errorFailCount >= errorDisplayThreshold && !(config.hideErrorMessages)) {
$('.modal--error').slideUp(); // ensure hidden to begin
clearTimeout(errorMessageTimeout); // ensure we're not already awaiting message to be cleared
$('.modal--error').slideDown('fast');
// show error message for length of http request lifespan
errorMessageTimeout = setTimeout(function(){ $('.modal--error').slideUp('slow'); }, lifeSpan);

errorFailCount = 0;
}

}

// loop to keep clusters updating
function runClusters() {
if (config.debugMetrics) { console.log(window.performance.memory); }
Expand Down Expand Up @@ -301,9 +334,15 @@ function runClusters() {
}
parseDate(data,offset);
},
error: function(jqXHR, textStatus){
error: function(jqXHR, textStatus) {

showErrorMessage();

if(jqXHR.status === 403) {
console.log('There was an error fetching list of users. Please try again later.');
}
if(textStatus === 'timeout') {
// console.log('Unable to get data source in a timely fashion',jqXHR);
console.log('Unable to get data source in a timely fashion');
if (Raven.isSetup()) {
Raven.captureMessage('Unable to get data source in a timely fashion', {
level: 'warning' // one of 'info', 'warning', or 'error'
Expand Down
12 changes: 10 additions & 2 deletions assets/map_styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ body.display-unified .leaflet-marker-icon div.markerClustersUniprot:hover,
body.display-unified .legend div.markerClustersPortals .legend-icon,
body.display-unified .legend div.markerClustersUniprot .legend-icon { background-color: rgba(168,200,19,.4); }



.modal {
background-color: #fff;
padding: 10px;
Expand All @@ -51,6 +49,16 @@ body.display-unified .legend div.markerClustersUniprot .legend-icon { background

.modal h4 { margin: 0 0 5px; }

.modal--error {
opacity: .9;
display: none;
border-radius: 5px;
box-shadow: 0 0 6px rgba(0,0,0,.4);
left: 50%;
margin-left: -25%;
top: -10px;
}

.description {
display: none;
bottom: 0%;
Expand Down
16 changes: 10 additions & 6 deletions live-data-map.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@
- disable the legend: live-data-map.html?hideLegend=true
- description block: live-data-map.html?description=true
You can throttle this for older devices with "?slimClient=true",
this will reduce the update frequency and trim some display options.
You can set an initial zoom level, lat, long:
You can set some other optional paramaters:
- zoomLevel=2 (2 is default)
- disableZoomScroll=false (false is default)
- lat=30 (30 is default)
- lon=-10.5 (-10.5 is default)
- slimClient=false (reduces performance for older devices by lowering update frequency and trim some display options; false is default)
- hideErrorMessages=false (false is default)
- debug=false (false is default)
The map and its asset URLs are subject to change, so please do not directly code the map into your web page.
Updates:
2017-01-23: Various timing optimisations and the ability to request a legend display
2016-12-14: Initial go-live
- See https://github.com/ebiwd/EMBL-EBI-Live-data-map/releases
Credits:
- Philip Lewis: Backend server log queries, first implementation (http://wwwdev.ebi.ac.uk/ebiwebtrafficmap/kmlvector.html)
- Ken Hawkins: Visual polish, various log optimisations, and MapBox-based implementation
Expand All @@ -94,6 +94,10 @@
<!-- <script src="https://cdn.ravenjs.com/3.17.0/raven.min.js" crossorigin="anonymous"></script> -->
<!-- <script>Raven.config('https://[email protected]/204881').install();</script> -->

<div class="modal modal--error">
<p class=""><strong>Retrying...</strong> Something went wrong while to fetch map data. Attempting to reconnect.</p>
</div>

<div id="map"></div>

<div id="legend" class="legend modal"></div>
Expand Down

0 comments on commit 4bf8034

Please sign in to comment.