+
+ //
+ // BBOX
+ //
+ applyBboxStrategy(layerName) {
+ const layer = this.getLayerByName(layerName);
+ const vectorSource = layer.getSource();
+ const baseUrl = vectorSource.getUrl();
+ if (typeof baseUrl === 'function')
+ throw new Error('A strategy was already applied to layer ' + layerName);
+
+ const loadFunction = function(extent, resolution, projection, success, failure) {
+
+ const proj = projection.getCode();
+ var bbox = transformExtent(extent, proj, 'EPSG:4326');
+
+ const url = baseUrl + '&' +
+ 'bbox=' + bbox.join(',') ;
+// 'bbox=' + extent.join(',') + ',' + proj;
+ const xhr = new XMLHttpRequest();
+ xhr.open('GET', url);
+ const onError = function() {
+ vectorSource.removeLoadedExtent(extent);
+ failure();
+ }
+ xhr.onerror = onError;
+ xhr.onload = function() {
+ if (xhr.status == 200) {
+ const features = vectorSource.getFormat().readFeatures(xhr.responseText);
+ vectorSource.addFeatures(features);
+ success(features);
+ } else {
+ onError();
+ }
+ }
+ xhr.send();
+ }
+
+ vectorSource.setLoader(loadFunction);
+ }
+}