setCenter(lng, lat) {
throw new Error("Abstract method");
}
+
+ /** Add a single point. */
+ addPoint(lng, lat, style) {
+ throw new Error("Abstract method");
+ }
+
+ addUrlLayer(url, format) {
+ throw new Error("Abstract method");
+ }
}
--- /dev/null
+
+import WMTS from 'ol/source/WMTS.js';
+import WMTSTileGrid from 'ol/tilegrid/WMTS';
+import { getTopLeft } from 'ol/extent';
+import { getWidth } from 'ol/extent';
+import { get as getProjection } from 'ol/proj';
+
+export class SentinelCloudless extends WMTS {
+ static source_s2CL2019;
+ static EPSG4326 = getProjection('EPSG:4326');
+
+ static resolutions;
+ static matrixIds;
+
+ static {
+ let min_zoom = 6;
+ let max_zoom = 17;
+ let zoomOffset = 1;
+
+ // from https://s2maps.eu/
+ let size = getWidth(this.EPSG4326.getExtent()) / 512;
+ this.resolutions = new Array(max_zoom + zoomOffset);
+ this.matrixIds = new Array(max_zoom + zoomOffset);
+ for (let z = min_zoom; z <= max_zoom; ++z) {
+ // generate resolutions and matrixIds arrays for this WMTS
+ this.resolutions[z] = size / Math.pow(2, z);
+ this.matrixIds[z] = z;
+ }
+ }
+
+ constructor() {
+ super({
+ urls: [
+ "//a.s2maps-tiles.eu/wmts/",
+ "//b.s2maps-tiles.eu/wmts/",
+ "//c.s2maps-tiles.eu/wmts/",
+ "//d.s2maps-tiles.eu/wmts/",
+ "//e.s2maps-tiles.eu/wmts/"
+ ],
+ layer: 's2cloudless-2021',
+ matrixSet: 'WGS84',
+ format: 'image/jpeg',
+ projection: SentinelCloudless.EPSG4326,
+ tileGrid: new WMTSTileGrid({
+ origin: getTopLeft(SentinelCloudless.EPSG4326.getExtent()),
+ resolutions: SentinelCloudless.resolutions,
+ matrixIds: SentinelCloudless.matrixIds,
+ }),
+ style: 'default',
+ transition: 0,
+ wrapX: true
+ });
+ }
+}
\ No newline at end of file
import Map from 'ol/Map.js';
import OSM from 'ol/source/OSM.js';
import TileLayer from 'ol/layer/Tile.js';
-import View from 'ol/View.js';
-import { fromLonLat, toLonLat } from 'ol/proj.js';
+import { fromLonLat } from 'ol/proj.js';
+import VectorSource from 'ol/source/Vector.js';
+import Feature from 'ol/Feature.js';
+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 MapPart from './MapPart.js';
+import { SentinelCloudless } from './OpenLayerTileSources.js';
/** OpenLayers implementation of MapPart. */
export default class OpenLayersMapPart extends MapPart {
super();
this.#map = new Map({
layers: [
+ new TileLayer({
+ source: new SentinelCloudless(),
+ }),
new TileLayer({
source: new OSM(),
+ opacity: 0.4,
+ transition: 0,
}),
],
target: 'map',
setCenter(lng, lat) {
this.#map.getView().setCenter(fromLonLat([lng, lat]));
}
+
+ addPoint(lng, lat, style) {
+ let vectorSource = new VectorSource({
+ features: [new Feature({
+ geometry: new Point(fromLonLat([lng, lat]))
+ })]
+ });
+ this.#map.addLayer(new VectorLayer({ source: vectorSource }));
+ }
+
+ addUrlLayer(url, format) {
+ let vectorSource;
+ if (format === 'GEOJSON') {
+ vectorSource = new VectorSource({ url: url, format: new GeoJSON() })
+ }
+ else if (format === 'GPX') {
+ vectorSource = new VectorSource({ url: url, format: new GPX() })
+ }
+ this.#map.addLayer(new VectorLayer({
+ source: vectorSource,
+ }));
+ }
}
GEOJSON, GPX;
}
- void addPoint(Double lng, Double lat);
+ void addPoint(Double lng, Double lat, String style);
- void addUrlLayer(String layer, Format format);
+ void addUrlLayer(String url, Format format);
void setZoom(int zoom);
@Override
public Control createUiPart(Composite parent, Content context) {
SwtMapPart map = new SwtMapPart(parent, 0);
- // map.setCenter(13.404954, 52.520008); // Berlin
- map.setCenter(-74.00597, 40.71427); // NYC
+ map.setCenter(13.404954, 52.520008); // Berlin
+// map.setCenter(-74.00597, 40.71427); // NYC
+// map.addPoint(-74.00597, 40.71427, null);
map.setZoom(6);
+ // map.addUrlLayer("https://openlayers.org/en/v4.6.5/examples/data/geojson/countries.geojson",
+ // Format.GEOJSON);
return map;
}
}
@Override
- public void addPoint(Double lng, Double lat) {
- // TODO Auto-generated method stub
-
+ public void addPoint(Double lng, Double lat, String style) {
+ pageLoaded.thenAccept((b) -> {
+ browser.evaluate(
+ mapVar + ".addPoint(" + lng + ", " + lat + "," + (style == null ? "'default'" : style) + ")");
+ });
}
@Override
- public void addUrlLayer(String layer, Format format) {
- // TODO Auto-generated method stub
-
+ public void addUrlLayer(String url, Format format) {
+ pageLoaded.thenAccept((b) -> {
+ browser.evaluate(mapVar + ".addUrlLayer('" + url + "','" + format.name() + "')");
+ });
}
@Override