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';
export default class OpenLayersMapPart extends MapPart {
/** The OpenLayers Map. */
#map;
+ callbacks = {};
+
// Constructor
constructor() {
super();
});
}
+ /* GEOGRAPHICAL METHODS */
+
setZoom(zoom) {
this.#map.getView().setZoom(zoom);
}
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'));
+ }
+ });
+ }
}