X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=js%2Fsrc%2Fgeo%2FOpenLayersMapPart.js;h=4be5987b831f7d7617e9511b2f21449c0d1f805f;hb=720e78163faf96ccc966d155a516487af52ccec2;hp=6fedd7a2a382f9f6d8b77de9cbfae761a96b72cb;hpb=79f547b6827c6f2f8d2a0eb809d2a5ac9d1e1df3;p=gpl%2Fargeo-suite.git diff --git a/js/src/geo/OpenLayersMapPart.js b/js/src/geo/OpenLayersMapPart.js index 6fedd7a..4be5987 100644 --- a/js/src/geo/OpenLayersMapPart.js +++ b/js/src/geo/OpenLayersMapPart.js @@ -14,6 +14,7 @@ import VectorSource from 'ol/source/Vector.js'; 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'; @@ -22,6 +23,7 @@ import { Style, Icon } from 'ol/style.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'; @@ -260,6 +262,24 @@ export default class OpenLayersMapPart extends MapPart { } } + 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 //