nakarte

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

commit 7900f7508c959a70e54940eb484119913fd8be4c
parent 51a8993c826ae8bd0cec2ae78602b6e17828a836
Author: Sergej Orlov <wladimirych@gmail.com>
Date:   Sat,  8 Jul 2017 02:19:43 +0300

[xhr-promise] workarounf for xhr.response_type=json not supported in IE

Diffstat:
Msrc/lib/leaflet.control.panoramas/lib/mapillary/index.js | 4++--
Msrc/lib/xhr-promise/index.js | 10++++++++++
2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/lib/leaflet.control.panoramas/lib/mapillary/index.js b/src/lib/leaflet.control.panoramas/lib/mapillary/index.js @@ -21,8 +21,8 @@ function getMapillary() { async function getPanoramaAtPos(latlng, searchRadiusMeters) { const url = `https://a.mapillary.com/v3/images?client_id=${config.mapillary}&closeto=${latlng.lng},${latlng.lat}&radius=${searchRadiusMeters}`; const resp = await fetch(url, {responseType: 'json', timeout: 10000}); - if (resp.status === 200 && resp.response.features.length) { - return {found: true, data: resp.response.features[0].properties.key}; + if (resp.status === 200 && resp.responseJSON.features.length) { + return {found: true, data: resp.responseJSON.features[0].properties.key}; } return {found: false}; } diff --git a/src/lib/xhr-promise/index.js b/src/lib/xhr-promise/index.js @@ -69,6 +69,16 @@ class XMLHttpRequestPromise { if (this.responseType === 'binarystring' && xhr.response && xhr.response.byteLength) { xhr.responseBinaryText = arrayBufferToString(xhr.response); } + // IE doesnot support responseType=json + if (this.responseType === 'json' && (typeof xhr.response) === 'string') { + try { + // xhr.response is readonly + xhr.responseJSON = JSON.parse(xhr.response); + } catch (e) { + } + } else { + xhr.responseJSON = xhr.response; + } if (this._isResponseSuccess(xhr)) { // console.log('success', this.url); this._resolve(xhr);