import View from 'ol/View.js';
import OSM from 'ol/source/OSM.js';
import TileLayer from 'ol/layer/Tile.js';
-import { fromLonLat, getPointResolution } from 'ol/proj.js';
+import { fromLonLat, getPointResolution, transformExtent } from 'ol/proj.js';
import VectorSource from 'ol/source/Vector.js';
import Feature from 'ol/Feature.js';
import { Point } from 'ol/geom.js';
import MapPart from './MapPart.js';
+import { bbox } from 'ol/loadingstrategy';
+
/** OpenLayers implementation of MapPart. */
export default class OpenLayersMapPart extends MapPart {
/** The OpenLayers Map. */
// transition: 0,
// }),
],
- // view: new View({
- // center: [0, 0],
- // zoom: 2,
- // }),
+ // view: new View({
+ // projection: 'EPSG:4326',
+ // center: [0, 0],
+ // zoom: 2,
+ // }),
target: this.getMapName(),
});
+ //this.#map.getView().set('projection', 'EPSG:4326', true);
}
/* GEOGRAPHICAL METHODS */
});
vectorLayer.setStyle(olStyleFunction);
}
-}
\ No newline at end of file
+
+ //
+ // 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);
+ }
+}