@opengeoweb/webmap 19.1.1 → 19.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js
CHANGED
|
@@ -1045,25 +1045,8 @@ var WMImage = /*#__PURE__*/function () {
|
|
|
1045
1045
|
_proto._setMaxAgeFromResponseHeaders = function _setMaxAgeFromResponseHeaders(response) {
|
|
1046
1046
|
this._maxAgeSeconds = WMImage._parseMaxAgeFromCacheControl(response.headers.get('cache-control'));
|
|
1047
1047
|
};
|
|
1048
|
-
_proto._updateMaxAgeFromUrl = function _updateMaxAgeFromUrl(url) {
|
|
1049
|
-
var _this3 = this;
|
|
1050
|
-
fetch(new Request(url), {
|
|
1051
|
-
method: 'GET',
|
|
1052
|
-
mode: 'cors',
|
|
1053
|
-
cache: 'default',
|
|
1054
|
-
headers: new Headers({
|
|
1055
|
-
Range: 'bytes=0-0'
|
|
1056
|
-
})
|
|
1057
|
-
}).then(function (response) {
|
|
1058
|
-
var _response$body;
|
|
1059
|
-
_this3._setMaxAgeFromResponseHeaders(response);
|
|
1060
|
-
void ((_response$body = response.body) == null ? void 0 : _response$body.cancel());
|
|
1061
|
-
})["catch"](function () {
|
|
1062
|
-
// Keep existing behaviour if headers are not readable.
|
|
1063
|
-
});
|
|
1064
|
-
};
|
|
1065
1048
|
_proto._getImageWithHeaders = function _getImageWithHeaders(url, headers) {
|
|
1066
|
-
var
|
|
1049
|
+
var _this3 = this;
|
|
1067
1050
|
var fetchHeaders = new Headers();
|
|
1068
1051
|
if (headers && headers.length > 0) {
|
|
1069
1052
|
for (var _iterator = _createForOfIteratorHelperLoose(headers), _step; !(_step = _iterator()).done;) {
|
|
@@ -1078,34 +1061,20 @@ var WMImage = /*#__PURE__*/function () {
|
|
|
1078
1061
|
cache: 'default'
|
|
1079
1062
|
};
|
|
1080
1063
|
var request = new Request(url);
|
|
1081
|
-
var arrayBufferToBase64 = function arrayBufferToBase64(buffer) {
|
|
1082
|
-
var binary = '';
|
|
1083
|
-
var bytes = [].slice.call(new Uint8Array(buffer));
|
|
1084
|
-
bytes.forEach(function (_byte) {
|
|
1085
|
-
binary += String.fromCharCode(_byte);
|
|
1086
|
-
});
|
|
1087
|
-
return window.btoa(binary);
|
|
1088
|
-
};
|
|
1089
1064
|
fetch(request, options).then(function (response) {
|
|
1090
|
-
|
|
1091
|
-
response.
|
|
1092
|
-
|
|
1093
|
-
var imageStr = arrayBufferToBase64(buffer);
|
|
1094
|
-
_this4.getElement().src = base64Flag + imageStr;
|
|
1065
|
+
_this3._setMaxAgeFromResponseHeaders(response);
|
|
1066
|
+
response.blob().then(function (imageBlob) {
|
|
1067
|
+
_this3.el.src = URL.createObjectURL(imageBlob);
|
|
1095
1068
|
})["catch"](function () {
|
|
1096
|
-
|
|
1097
|
-
|
|
1069
|
+
// Do not log errors, as they are not very useful and can better be inspected via the network console
|
|
1070
|
+
_this3._loadEvent(true);
|
|
1098
1071
|
});
|
|
1099
1072
|
})["catch"](function () {
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
debugLogger(DebugType.Error);
|
|
1103
|
-
}
|
|
1104
|
-
_this4._loadEvent(true);
|
|
1073
|
+
// Do not log errors, as they are not very useful and can better be inspected via the network consoles
|
|
1074
|
+
_this3._loadEvent(true);
|
|
1105
1075
|
});
|
|
1106
1076
|
};
|
|
1107
1077
|
_proto._load = function _load() {
|
|
1108
|
-
var _this$headers;
|
|
1109
1078
|
this._loadStartTime = getCurrentImageTime();
|
|
1110
1079
|
this._hasError = false;
|
|
1111
1080
|
if (this._isLoaded) {
|
|
@@ -1136,31 +1105,8 @@ var WMImage = /*#__PURE__*/function () {
|
|
|
1136
1105
|
this._loadEvent(false);
|
|
1137
1106
|
return;
|
|
1138
1107
|
}
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
this._getImageWithHeaders(this.srcToLoad, this.headers);
|
|
1142
|
-
} else if (this.randomize) {
|
|
1143
|
-
/* Do a standard img.src url request */
|
|
1144
|
-
this._maxAgeSeconds = null;
|
|
1145
|
-
var newSrc = this.srcToLoad;
|
|
1146
|
-
if (!this.srcToLoad.includes('?')) {
|
|
1147
|
-
newSrc += '?';
|
|
1148
|
-
newSrc += "random=" + Math.random();
|
|
1149
|
-
} else {
|
|
1150
|
-
try {
|
|
1151
|
-
var url = new URL(this.srcToLoad);
|
|
1152
|
-
url.searchParams.set('random', Math.random().toString());
|
|
1153
|
-
newSrc = url.toString();
|
|
1154
|
-
} catch (_unused) {
|
|
1155
|
-
console.warn('failed to randomize url');
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
this.getElement().src = newSrc;
|
|
1159
|
-
} else {
|
|
1160
|
-
// Keep the browser image loading path for rendering reliability.
|
|
1161
|
-
this.getElement().src = this.srcToLoad;
|
|
1162
|
-
this._updateMaxAgeFromUrl(this.srcToLoad);
|
|
1163
|
-
}
|
|
1108
|
+
/* Get an image which needs headers */
|
|
1109
|
+
this._getImageWithHeaders(this.srcToLoad, this.headers);
|
|
1164
1110
|
};
|
|
1165
1111
|
_proto._loadEvent = function _loadEvent(hasError) {
|
|
1166
1112
|
var _this$loadEventCallba;
|
|
@@ -1172,6 +1118,8 @@ var WMImage = /*#__PURE__*/function () {
|
|
|
1172
1118
|
this._srcLoaded = this.srcToLoad;
|
|
1173
1119
|
this._resolveAll();
|
|
1174
1120
|
(_this$loadEventCallba = this.loadEventCallback) == null || _this$loadEventCallba.call(this, this);
|
|
1121
|
+
// Free up memory
|
|
1122
|
+
URL.revokeObjectURL(this._srcLoaded);
|
|
1175
1123
|
};
|
|
1176
1124
|
_proto.getLoadDuration = function getLoadDuration() {
|
|
1177
1125
|
return this._loadDuration;
|
|
@@ -96,8 +96,7 @@ export default class WMImage {
|
|
|
96
96
|
forceReload(randomize?: boolean): void;
|
|
97
97
|
private static _parseMaxAgeFromCacheControl;
|
|
98
98
|
private _setMaxAgeFromResponseHeaders;
|
|
99
|
-
|
|
100
|
-
private _getImageWithHeaders;
|
|
99
|
+
_getImageWithHeaders(url: string, headers: WMHeader[]): void;
|
|
101
100
|
_load(): void;
|
|
102
101
|
_loadEvent(hasError: boolean): void;
|
|
103
102
|
getLoadDuration(): number | undefined;
|