nakarte

Source code of https://map.sikmir.ru (fork)
git clone git://git.sikmir.ru/nakarte
Log | Files | Refs | LICENSE

commit 6a81888228bd48450985e171274c8fec5e32f7b3
parent 16615e2e4a3e4cb1ec40867d958b5bd12cde9cc0
Author: Sergej Orlov <wladimirych@gmail.com>
Date:   Sun, 27 Nov 2016 23:53:44 +0300

[westra passes] show message if data download failed

Diffstat:
Msrc/lib/leaflet.layer.geojson-ajax/geojson-ajax.js | 5+++--
Msrc/lib/leaflet.layer.westraPasses/westraPassesMarkers.js | 5++++-
Asrc/lib/notifications/notifications.js | 16++++++++++++++++
3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/lib/leaflet.layer.geojson-ajax/geojson-ajax.js b/src/lib/leaflet.layer.geojson-ajax/geojson-ajax.js @@ -1,5 +1,6 @@ import L from 'leaflet'; import {XMLHttpRequestPromise} from 'lib/xhr-promise/xhr-promise'; +import {notifyXhrError} from 'lib/notifications/notifications'; L.Layer.GeoJSONAjax = L.GeoJSON.extend({ options: { @@ -18,8 +19,8 @@ L.Layer.GeoJSONAjax = L.GeoJSON.extend({ this._loadStarted = true; const {promise} = XMLHttpRequestPromise(this.url, {responseType: 'json', timeout: this.options.requestTimeout}); - promise.then((xhr) => this.addData(xhr.response)) - + promise.then((xhr) => this.addData(xhr.response), + (xhr) => notifyXhrError(xhr, `GeoJSON data from ${this.url}`)) }, onAdd: function(map) { diff --git a/src/lib/leaflet.layer.westraPasses/westraPassesMarkers.js b/src/lib/leaflet.layer.westraPasses/westraPassesMarkers.js @@ -5,6 +5,7 @@ import escapeHtml from 'escape-html'; import {saveAs} from 'browser-filesaver'; import iconFromBackgroundImage from 'lib/iconFromBackgroundImage/iconFromBackgroundImage'; import {XMLHttpRequestPromise} from 'lib/xhr-promise/xhr-promise'; +import {notifyXhrError} from 'lib/notifications/notifications'; const westraPasesMarkers = L.Layer.CanvasMarkers.extend({ @@ -27,7 +28,9 @@ const westraPasesMarkers = L.Layer.CanvasMarkers.extend({ const {promise} = XMLHttpRequestPromise(this.url, {responseType: 'json', timeout: 30000} ); - promise.then((xhr) => this._loadMarkers(xhr)); + promise.then((xhr) => this._loadMarkers(xhr), + (xhr) => notifyXhrError(xhr, 'westra passes data') + ); }, diff --git a/src/lib/notifications/notifications.js b/src/lib/notifications/notifications.js @@ -0,0 +1,15 @@ +function notify(message, level) { + window.alert(message); +} + +function prompt(message, value) { + return window.prompt(message, value); +} + +function notifyXhrError(xhr, whatWasDownloading, level) { + const reason = xhr.status === 0 ? 'network error' : `server response is ${xhr.status}`; + const message = `Failed to download ${whatWasDownloading}: ${reason}`; + notify(message, level); +} + +export {notify, prompt, notifyXhrError}; +\ No newline at end of file