From b4b19aebd564f6be5195f2e5ea1499ac8a3f40e7 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Tue, 17 Oct 2023 08:41:44 +0200 Subject: [PATCH] Add controls to OpenLayers map --- js/src/geo/OpenLayersMapPart.js | 34 ++++++++++++++++--- js/src/geo/index.html | 14 ++++++++ .../src/org/argeo/app/ol/Layer.java | 4 +-- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/js/src/geo/OpenLayersMapPart.js b/js/src/geo/OpenLayersMapPart.js index 0e32e88..160930d 100644 --- a/js/src/geo/OpenLayersMapPart.js +++ b/js/src/geo/OpenLayersMapPart.js @@ -2,19 +2,26 @@ * @module OpenLayersMapPart */ -import Map from 'ol/Map.js'; -import View from 'ol/View.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 { transformExtent } from 'ol/proj.js'; + import VectorLayer from 'ol/layer/Vector.js'; +import TileLayer from 'ol/layer/Tile.js'; + +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 Select from 'ol/interaction/Select.js'; import Overlay from 'ol/Overlay.js'; import { Style, Icon } from 'ol/style.js'; -import { transformExtent } from 'ol/proj.js'; + +import Map from 'ol/Map.js'; +import View from 'ol/View.js'; +import { OverviewMap, ScaleLine, defaults as defaultControls } from 'ol/control.js'; import * as SLDReader from '@nieuwlandgeo/sldreader'; @@ -25,6 +32,8 @@ export default class OpenLayersMapPart extends MapPart { /** The OpenLayers Map. */ #map; + #overviewMap; + /** Styled layer descriptor */ #sld; @@ -34,7 +43,24 @@ export default class OpenLayersMapPart extends MapPart { /** Constructor taking the mapName as an argument. */ constructor(mapName) { super(mapName); + this.#overviewMap = new OverviewMap({ + layers: [ + new TileLayer({ + source: new OSM(), + }), + ], + }); this.#map = new Map({ + controls: defaultControls({ + attribution: false, + rotate: false, + }).extend([this.#overviewMap, new ScaleLine({ + bar: false, + steps: 2, + text: false, + minWidth: 150, + maxWidth: 200, + })]), layers: [ ], // view: new View({ diff --git a/js/src/geo/index.html b/js/src/geo/index.html index bafe7fe..bfc2233 100644 --- a/js/src/geo/index.html +++ b/js/src/geo/index.html @@ -52,6 +52,20 @@ content: "✖"; } + .map .ol-scale-line { + bottom: 0px; + left: 50%; + margin-right: -50%; + transform: translate(-50%, -50%); + } + + .map .ol-scale-bar { + bottom: 0px; + left: 50%; + margin-right: -50%; + transform: translate(-50%, -50%); + } + #popup-content { font: 16px sans-serif; } diff --git a/org.argeo.app.geo/src/org/argeo/app/ol/Layer.java b/org.argeo.app.geo/src/org/argeo/app/ol/Layer.java index 6cc73f3..f6ccd1b 100644 --- a/org.argeo.app.geo/src/org/argeo/app/ol/Layer.java +++ b/org.argeo.app.geo/src/org/argeo/app/ol/Layer.java @@ -30,14 +30,14 @@ public class Layer extends AbstractOlObject { executeMethod(getMethodName(), source); } - public void setMinResolution(long minResolution) { + public void setMinResolution(double minResolution) { if (isNew()) getNewOptions().put("minResolution", minResolution); else executeMethod(getMethodName(), minResolution); } - public void setMaxResolution(long maxResolution) { + public void setMaxResolution(double maxResolution) { if (isNew()) getNewOptions().put("maxResolution", maxResolution); else -- 2.30.2