]>
git.argeo.org Git - gpl/argeo-suite.git/blob - OpenLayersMapPart.js
6eff99f2ff58d8fe3635474bdc2a0e0628585fff
1 /** OpenLayers-based implementation.
2 * @module OpenLayersMapPart
5 import Map
from 'ol/Map.js';
6 import OSM
from 'ol/source/OSM.js';
7 import TileLayer
from 'ol/layer/Tile.js';
8 import { fromLonLat
} from 'ol/proj.js';
9 import VectorSource
from 'ol/source/Vector.js';
10 import Feature
from 'ol/Feature.js';
11 import { Point
} from 'ol/geom.js';
12 import VectorLayer
from 'ol/layer/Vector.js';
13 import GeoJSON
from 'ol/format/GeoJSON.js';
14 import GPX
from 'ol/format/GPX.js';
15 import Select
from 'ol/interaction/Select.js';
17 import MapPart
from './MapPart.js';
18 import { SentinelCloudless
} from './OpenLayerTileSources.js';
20 /** OpenLayers implementation of MapPart. */
21 export default class OpenLayersMapPart
extends MapPart
{
22 /** The OpenLayers Map. */
32 source
: new SentinelCloudless(),
44 /* GEOGRAPHICAL METHODS */
47 this.#map
.getView().setZoom(zoom
);
51 this.#map
.getView().setCenter(fromLonLat([lng
, lat
]));
54 addPoint(lng
, lat
, style
) {
55 let vectorSource
= new VectorSource({
56 features
: [new Feature({
57 geometry
: new Point(fromLonLat([lng
, lat
]))
60 this.#map
.addLayer(new VectorLayer({ source
: vectorSource
}));
63 addUrlLayer(url
, format
) {
65 if (format
=== 'GEOJSON') {
66 vectorSource
= new VectorSource({ url
: url
, format
: new GeoJSON() })
68 else if (format
=== 'GPX') {
69 vectorSource
= new VectorSource({ url
: url
, format
: new GPX() })
71 this.#map
.addLayer(new VectorLayer({
77 enableFeatureSingleClick() {
78 // we cannot use 'this' in the function provided to OpenLayers
80 this.#map
.on('singleclick', function(e
) {
83 e
.map
.forEachFeatureAtPixel(e
.pixel
, function(f
) {
87 mapPart
.callbacks
['onFeatureSingleClick'](feature
.get('path'));
91 enableFeatureSelected() {
92 // we cannot use 'this' in the function provided to OpenLayers
94 var select
= new Select();
95 this.#map
.addInteraction(select
);
96 select
.on('select', function(e
) {
97 if (e
.selected
.length
> 0) {
98 let feature
= e
.selected
[0];
99 mapPart
.callbacks
['onFeatureSelected'](feature
.get('path'));