Add controls to OpenLayers map
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 17 Oct 2023 06:41:44 +0000 (08:41 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 17 Oct 2023 06:41:44 +0000 (08:41 +0200)
js/src/geo/OpenLayersMapPart.js
js/src/geo/index.html
org.argeo.app.geo/src/org/argeo/app/ol/Layer.java

index 0e32e8832c410226de3e2c56fd9e6df105f671d1..160930d6b7447563b309de34030dcf808d24b00a 100644 (file)
@@ -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({
index bafe7fed417f385241b4061f7c216f9b2c59fa3e..bfc2233d70ad556227344b7bc5ae99b3359be8dc 100644 (file)
                        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;
                }
index 6cc73f3fa0d891223a8f87aaf9949cc06cb17175..f6ccd1bab4abb13fc319376ddd0fabc35edfaafb 100644 (file)
@@ -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