commit 16615e2e4a3e4cb1ec40867d958b5bd12cde9cc0
parent ffa1a0e27ab62641eae7f843d2f55562df167306
Author: Sergej Orlov <wladimirych@gmail.com>
Date: Sun, 27 Nov 2016 23:36:00 +0300
[westra passes, geojson-ajax] replaced lazy xhr requests with normal ones
Diffstat:
2 files changed, 12 insertions(+), 14 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,5 @@
import L from 'leaflet';
-import {prepareXMLHttpRequestPromise} from 'lib/xhr-promise/xhr-promise';
+import {XMLHttpRequestPromise} from 'lib/xhr-promise/xhr-promise';
L.Layer.GeoJSONAjax = L.GeoJSON.extend({
options: {
@@ -9,10 +9,6 @@ L.Layer.GeoJSONAjax = L.GeoJSON.extend({
initialize: function(url, options) {
L.GeoJSON.prototype.initialize.call(this, null, options);
this.url = url;
- const {promise, send} = prepareXMLHttpRequestPromise(
- this.url, {responseType: 'json', timeout: this.options.requestTimeout});
- promise.then((xhr) => this.addData(xhr.response))
- this._loadData = send;
},
loadData: function() {
@@ -20,7 +16,10 @@ L.Layer.GeoJSONAjax = L.GeoJSON.extend({
return;
}
this._loadStarted = true;
- this._loadData();
+ const {promise} = XMLHttpRequestPromise(this.url,
+ {responseType: 'json', timeout: this.options.requestTimeout});
+ promise.then((xhr) => this.addData(xhr.response))
+
},
onAdd: function(map) {
diff --git a/src/lib/leaflet.layer.westraPasses/westraPassesMarkers.js b/src/lib/leaflet.layer.westraPasses/westraPassesMarkers.js
@@ -4,7 +4,7 @@ import openPopup from 'lib/popupWindow/popupWindow';
import escapeHtml from 'escape-html';
import {saveAs} from 'browser-filesaver';
import iconFromBackgroundImage from 'lib/iconFromBackgroundImage/iconFromBackgroundImage';
-import {prepareXMLHttpRequestPromise} from 'lib/xhr-promise/xhr-promise';
+import {XMLHttpRequestPromise} from 'lib/xhr-promise/xhr-promise';
const westraPasesMarkers = L.Layer.CanvasMarkers.extend({
@@ -16,12 +16,7 @@ const westraPasesMarkers = L.Layer.CanvasMarkers.extend({
initialize: function(baseUrl, options) {
L.Layer.CanvasMarkers.prototype.initialize.call(this, null, options);
this.on('markerclick', this.showPassDescription, this);
- // TODO: обработка ошибок, повторные запросы
- const {send, promise} = prepareXMLHttpRequestPromise(baseUrl + this.options.filePasses,
- {responseType: 'json', timeout: 30000}
- );
- promise.then((xhr) => this._loadMarkers(xhr));
- this.sendDataRequest = send;
+ this.url = baseUrl + this.options.filePasses;
},
loadData: function() {
@@ -29,7 +24,11 @@ const westraPasesMarkers = L.Layer.CanvasMarkers.extend({
return;
}
this._downloadStarted = true;
- this.sendDataRequest();
+ const {promise} = XMLHttpRequestPromise(this.url,
+ {responseType: 'json', timeout: 30000}
+ );
+ promise.then((xhr) => this._loadMarkers(xhr));
+
},
onAdd: function(map) {