Skip to content

Commit

Permalink
Add loading indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
stesie committed Mar 22, 2021
1 parent 1b60d9a commit 45b8b40
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
9 changes: 6 additions & 3 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,14 @@ input#trackname:focus:invalid {
/* map click/drag selects text in controls in Firefox because of display flex */
-moz-user-select: none;
}
.leaflet-control-container,
#message .alert {
.leaflet-control-container {
-moz-user-select: text;
}
#message {
#notification_jar .alert {
-moz-user-select: text;
margin-bottom: 10px;
}
#notification_jar {
position: absolute;
margin: 10px 46px; /* 10 + 26 + 10 */
z-index: 3001;
Expand Down
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,10 @@ <h4 class="modal-title" data-i18n="trackasroute.title">Load Track as Route</h4>

<div class="leaflet-sidebar-flex-row flexgrow">
<div id="map" class="leaflet-sidebar-map">
<div id="message"></div>
<div id="notification_jar">
<div id="message"></div>
<div id="overpass_loading_indicator"></div>
</div>
<div id="preview" hidden data-i18n="map.preview">Preview</div>
</div>

Expand Down
41 changes: 30 additions & 11 deletions js/LayersConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ BR.LayersConfig = L.Class.extend({

initialize: function (map) {
this._map = map;
this._overpassLoadingIndicator = new BR.Message('overpass_loading_indicator', { alert: false });
this._overpassActiveRequestCount = 0;

this._addLeafletProvidersLayers();
this._customizeLayers();
Expand Down Expand Up @@ -172,18 +174,35 @@ BR.LayersConfig = L.Class.extend({
return result;
},

_showOverpassLoadingIndicator: function () {
this._overpassActiveRequestCount++;
this._overpassLoadingIndicator.showInfo(i18next.t('layers.overpass-loading-indicator'));
},

_hideOverpassLoadingIndicator: function () {
if (--this._overpassActiveRequestCount === 0) {
this._overpassLoadingIndicator.hide();
}
},

createOverpassLayer: function (query) {
return new OverpassLayer({
overpassFrontend: this.overpassFrontend,
query: query,
minZoom: 12,
feature: {
title: '{{ tags.name }}',
body:
'<table class="overpass-tags">{% for k, v in tags %}{% if k[:5] != "addr:" %}<tr><th>{{ k }}</th><td>{% if k matches "/email/" %}<a href="mailto:{{ v }}">{{ v }}</a>{% elseif v matches "/^http/" %}<a href="{{ v }}">{{ v }}</a>{% elseif v matches "/^www/" %}<a href="http://{{ v }}">{{ v }}</a>{% else %}{{ v }}{% endif %}</td></tr>{% endif %}{% endfor %}</table>',
markerSymbol: null,
},
});
return Object.assign(
new OverpassLayer({
overpassFrontend: this.overpassFrontend,
query: query,
minZoom: 12,
feature: {
title: '{{ tags.name }}',
body:
'<table class="overpass-tags">{% for k, v in tags %}{% if k[:5] != "addr:" %}<tr><th>{{ k }}</th><td>{% if k matches "/email/" %}<a href="mailto:{{ v }}">{{ v }}</a>{% elseif v matches "/^http/" %}<a href="{{ v }}">{{ v }}</a>{% elseif v matches "/^www/" %}<a href="http://{{ v }}">{{ v }}</a>{% else %}{{ v }}{% endif %}</td></tr>{% endif %}{% endfor %}</table>',
markerSymbol: null,
},
}),
{
onLoadStart: this._showOverpassLoadingIndicator.bind(this),
onLoadEnd: this._hideOverpassLoadingIndicator.bind(this),
}
);
},

createLayer: function (layerData) {
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"custom-layer-url-label": "Custom layer URL/Query",
"customize": "Customize layers",
"opacity-slider": "Opacity slider",
"overpass-loading-indicator": "Running Overpass API query ...",
"remove-selection": "Remove selection"
},
"loadNogos": {
Expand Down

0 comments on commit 45b8b40

Please sign in to comment.