X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.app.geo.js%2Fsrc%2Forg.argeo.app.geo.js%2FOpenLayersMapPart.js;h=6eff99f2ff58d8fe3635474bdc2a0e0628585fff;hb=69adaa7b31078cb30043b073dada14dee1a9e75d;hp=7c157eb19226a1716545aa4e11f09232060292fb;hpb=20c77f2bd654c45b88175ddb62d5dc6e8a1e52f9;p=gpl%2Fargeo-suite.git diff --git a/org.argeo.app.geo.js/src/org.argeo.app.geo.js/OpenLayersMapPart.js b/org.argeo.app.geo.js/src/org.argeo.app.geo.js/OpenLayersMapPart.js index 7c157eb..6eff99f 100644 --- a/org.argeo.app.geo.js/src/org.argeo.app.geo.js/OpenLayersMapPart.js +++ b/org.argeo.app.geo.js/src/org.argeo.app.geo.js/OpenLayersMapPart.js @@ -12,6 +12,7 @@ import { Point } from 'ol/geom.js'; import VectorLayer from 'ol/layer/Vector.js'; import GeoJSON from 'ol/format/GeoJSON.js'; import GPX from 'ol/format/GPX.js'; +import Select from 'ol/interaction/Select.js'; import MapPart from './MapPart.js'; import { SentinelCloudless } from './OpenLayerTileSources.js'; @@ -20,6 +21,8 @@ import { SentinelCloudless } from './OpenLayerTileSources.js'; export default class OpenLayersMapPart extends MapPart { /** The OpenLayers Map. */ #map; + callbacks = {}; + // Constructor constructor() { super(); @@ -38,6 +41,8 @@ export default class OpenLayersMapPart extends MapPart { }); } + /* GEOGRAPHICAL METHODS */ + setZoom(zoom) { this.#map.getView().setZoom(zoom); } @@ -67,4 +72,32 @@ export default class OpenLayersMapPart extends MapPart { source: vectorSource, })); } + + /* CALLBACKS */ + enableFeatureSingleClick() { + // we cannot use 'this' in the function provided to OpenLayers + let mapPart = this; + this.#map.on('singleclick', function(e) { + let feature = null; + // we chose only one + e.map.forEachFeatureAtPixel(e.pixel, function(f) { + feature = f; + }); + if (feature !== null) + mapPart.callbacks['onFeatureSingleClick'](feature.get('path')); + }); + } + + enableFeatureSelected() { + // we cannot use 'this' in the function provided to OpenLayers + let mapPart = this; + var select = new Select(); + this.#map.addInteraction(select); + select.on('select', function(e) { + if (e.selected.length > 0) { + let feature = e.selected[0]; + mapPart.callbacks['onFeatureSelected'](feature.get('path')); + } + }); + } }