BBOX vector source working
[gpl/argeo-suite.git] / js / src / geo / BboxVectorSource.js
diff --git a/js/src/geo/BboxVectorSource.js b/js/src/geo/BboxVectorSource.js
new file mode 100644 (file)
index 0000000..49606b1
--- /dev/null
@@ -0,0 +1,23 @@
+
+import VectorSource from 'ol/source/Vector.js';
+import { bbox } from 'ol/loadingstrategy';
+import { transformExtent } from 'ol/proj.js';
+
+export default class BboxVectorSource extends VectorSource {
+       constructor(options) {
+               super(BboxVectorSource.processOptions(options));
+       }
+
+       static processOptions(options) {
+               options.strategy = bbox;
+               options.url = function(extent, resolution, projection) {
+                       const proj = projection.getCode();
+                       var bbox = transformExtent(extent, proj, 'EPSG:4326');
+
+                       const baseUrl = options.baseUrl;
+                       const url = baseUrl + '&bbox=' + bbox.join(',');
+                       return url;
+               }
+               return options;
+       }
+}
\ No newline at end of file