nakarte

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

commit e655f9c0e97ef0ec706c4bd24e611e22b51911f3
parent f2a35a5a87da53b863b655f3bd7e4e0c36521980
Author: Sergej Orlov <wladimirych@gmail.com>
Date:   Sat, 18 Feb 2017 18:22:20 +0300

[elevation profile] handle server errors

Diffstat:
Msrc/lib/leaflet.control.elevation-profile/index.js | 28++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/lib/leaflet.control.elevation-profile/index.js b/src/lib/leaflet.control.elevation-profile/index.js @@ -3,6 +3,7 @@ import './elevation-profile.css'; import {fetch} from 'lib/xhr-promise'; import config from 'config'; import 'lib/leaflet.control.commons'; +import {formatXhrError, notify} from 'lib/notifications'; function createSvg(tagName, attributes, parent) { var element = document.createElementNS('http://www.w3.org/2000/svg', tagName); @@ -207,11 +208,15 @@ L.Control.ElevationProfile = L.Class.extend({ this.horizZoom = 1; this.dragStart = null; - this._getElevation(samples).then(function(values) { - self.values = values; - self.updateGraph(); - } - ); + this._getElevation(samples) + .then(function(values) { + self.values = values; + self.updateGraph(); + } + ) + .catch((e) => { + notify(e); + }); this.values = null; }, @@ -553,6 +558,9 @@ L.Control.ElevationProfile = L.Class.extend({ }, setCursorPosition: function(ind) { + if (!this._map || !this.values) { + return; + } var distance = this.options.samplingInterval * ind; distance = (distance / 1000).toFixed(2); var gradient = (this.values[Math.ceil(ind)] - this.values[Math.floor(ind)]) / this.options.samplingInterval; @@ -699,10 +707,11 @@ L.Control.ElevationProfile = L.Class.extend({ setupGraph: function() { - if (!this._map) { + if (!this._map || !this.values) { return; } + while (this.svg.hasChildNodes()) { this.svg.removeChild(this.svg.lastChild); } @@ -773,11 +782,10 @@ L.Control.ElevationProfile = L.Class.extend({ .then( function(xhr) { return parseResponse(xhr.responseText); - }, - function() { - alert('Failed to plot elevation profile, server error'); } - ); + ).catch((xhr) => { + throw new Error(formatXhrError(xhr, 'elevation data')) + }); }, onCloseButtonClick: function() { this.removeFrom(this._map);