--- /dev/null
+
+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
import Map from 'ol/Map.js';
import View from 'ol/View.js';
-import OSM from 'ol/source/OSM.js';
-import TileLayer from 'ol/layer/Tile.js';
-import { fromLonLat, getPointResolution, transformExtent } from 'ol/proj.js';
+import { fromLonLat, getPointResolution } 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. */
super(mapName);
this.#map = new Map({
layers: [
- // new TileLayer({
- // source: new SentinelCloudless(),
- // }),
- // new TileLayer({
- // source: new OSM(),
- // opacity: 0.4,
- // transition: 0,
- // }),
],
// view: new View({
// projection: 'EPSG:4326',
vectorLayer.setStyle(olStyleFunction);
}
- //
- // 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);
- }
}
import OpenLayersMapPart from './OpenLayersMapPart.js';
+import BboxVectorSource from './BboxVectorSource.js';
import SentinelCloudless from './SentinelCloudless.js';
import Map from 'ol/Map.js';
import VectorSource from 'ol/source/Vector.js';
import VectorLayer from 'ol/layer/Vector.js';
import GeoJSON from 'ol/format/GeoJSON.js';
-import {bbox} from 'ol/loadingstrategy';
// PSEUDO PACKAGE
if (typeof globalThis.argeo === 'undefined')
// PUBLIC CLASSES
globalThis.argeo.app.geo.OpenLayersMapPart = OpenLayersMapPart;
+globalThis.argeo.app.geo.BboxVectorSource = BboxVectorSource;
globalThis.argeo.app.geo.SentinelCloudless = SentinelCloudless;
globalThis.argeo.tp.ol.Map = Map;
globalThis.argeo.tp.ol.VectorSource = VectorSource;
globalThis.argeo.tp.ol.VectorLayer = VectorLayer;
globalThis.argeo.tp.ol.GeoJSON = GeoJSON;
-globalThis.argeo.tp.ol.bbox = bbox;
"use strict";
--- /dev/null
+package org.argeo.app.geo.ux;
+
+import org.argeo.app.ol.FeatureFormat;
+import org.argeo.app.ol.VectorSource;
+
+public class BboxVectorSource extends VectorSource {
+
+ public BboxVectorSource(Object... args) {
+ super(args);
+ }
+
+ public BboxVectorSource(String baseUrl, FeatureFormat format) {
+ setFormat(format);
+ setBaseUrl(baseUrl);
+ }
+
+ @Override
+ public String getJsPackage() {
+ return AbstractGeoJsObject.JS_PACKAGE;
+ }
+
+ public void setBaseUrl(String baseUrl) {
+ doSetValue(null, "baseUrl", baseUrl);
+ }
+
+}
import org.argeo.app.ol.VectorLayer;
import org.argeo.app.ux.js.JsClient;
+/**
+ * A wrapper around an OpenLayers map, adding specific features, such as SLD
+ * styling.
+ */
public class OpenLayersMapPart extends AbstractGeoJsObject {
- private String mapPartName;
+ private final String mapPartName;
public OpenLayersMapPart(JsClient jsClient, String mapPartName) {
super(mapPartName);
executeMethod(getMethodName(), layerName, styledLayerName);
}
- public void applyBboxStrategy(String layerName) {
- executeMethod(getMethodName(), layerName);
- }
-
public Layer getLayer(String name) {
// TODO deal with not found
- String reference = "getLayerByName('" + name + "')";
+ String reference = getReference() + ".getLayerByName('" + name + "')";
if (getJsClient().isInstanceOf(reference, AbstractOlObject.getJsClassName(VectorLayer.class))) {
return new VectorLayer(getJsClient(), reference);
} else if (getJsClient().isInstanceOf(reference, AbstractOlObject.getJsClassName(TileLayer.class))) {
return new Layer(getJsClient(), reference);
}
}
+
+ public String getMapPartName() {
+ return mapPartName;
+ }
+
}
package org.argeo.app.ol;
-import org.argeo.app.ux.js.JsReference;
-
public class VectorSource extends Source {
public VectorSource(Object... args) {
}
public VectorSource(String url, FeatureFormat format) {
- this(url, format, false);
- }
-
- public VectorSource(String url, FeatureFormat format, boolean bboxStrategy) {
+ setUrl(url);
setFormat(format);
- if (bboxStrategy) {
- setUrl(url);
- getNewOptions().put("strategy", new JsReference(getJsPackage() + ".bbox"));
- } else {
- setUrl(url);
- }
}
public void setUrl(String url) {