import GeoJSON from 'ol/format/GeoJSON.js';
import GPX from 'ol/format/GPX.js';
import OSM from 'ol/source/OSM.js';
+import { isEmpty } from 'ol/extent';
import Select from 'ol/interaction/Select.js';
import Overlay from 'ol/Overlay.js';
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import { OverviewMap, ScaleLine, defaults as defaultControls } from 'ol/control.js';
+import { easeOut } from 'ol/easing';
import * as SLDReader from '@nieuwlandgeo/sldreader';
}
}
+ fitToLayer(layerName) {
+ // we cannot use 'this' in the function provided to OpenLayers
+ let mapPart = this;
+ const layer = this.getLayerByName(layerName);
+ const source = layer.getSource();
+ const extent = source.getExtent();
+ const options = {
+ duration: 1000,
+ padding: [20, 20, 20, 20],
+ easing: easeOut,
+ };
+ if (!isEmpty(extent))
+ this.#map.getView().fit(source.getExtent(), options);
+ source.on('featuresloadend', function(e) {
+ mapPart.getMap().getView().fit(source.getExtent(), options);
+ });
+ }
+
//
// STATIC FOR EXTENSION
//
}
/**
- * To be overridden with calls to {@link #loadExtension( Supplier<Boolean> toDo
- * = () -> { boolean success = browser.execute(); return success; }; String)}.
+ * To be overridden with calls to {@link #loadExtension(String)}.
*/
protected void loadExtensions() {
}
protected void loadExtension(String url) {
-// String js = """
-// var script = document.createElement("script");
-// script.src = '%s';
-// document.head.appendChild(script);
-// """;
-// browser.evaluate(String.format(Locale.ROOT, js, url));
browser.evaluate(String.format(Locale.ROOT, "import('%s')", url));
}