forked from earthdaily/Examples-and-showcases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaps.js
81 lines (69 loc) · 3 KB
/
maps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* This opbject contains 2 methods:
* - createOpenlayersMap to create an Openlayers map from the result of the MapProduct API.
* - createLeafletMap to create a Leaflet map from the result of the MapProduct API.
*/
const maps = {
/**
* @function createOpenlayersMap
* @description Creates an Openlayers map
* An OSM layer is added as a background layer.
* The image extent must be in projection 3857.
* @param params Result from mapProduct.getProduct().
* @param params.imageExtent Image extent in EPSG:3957 [Xmin, Ymin, Xmax, Ymax].
* @param params.url URL of the Blob Image.
*/
createOpenlayersMap: function (params) {
const imageExtent = params.imageExtent;
const url = params.url;
// Computes the center of the image extent to use it as the center of the map view. [X,Y]
const center = [(imageExtent[0] + imageExtent[2]) / 2, (imageExtent[1] + imageExtent[3]) / 2];
const map = new ol.Map({
layers: [
// Adds a background layer.
new ol.layer.Tile({
source: new ol.source.OSM(),
}),
// Adds the image product to the map.
new ol.layer.Image({
source: new ol.source.ImageStatic(
{
imageExtent,
url
}
),
})],
// HTMLElement ID used to display the map.
target: 'map_ol',
view: new ol.View({
center,
zoom: 14,
})
});
},
/**
* @function createLeafletMap
* @description Creates a Leaflet map
* An OSM layer is added as a background layer.
* The image extent must be in system 4326.
* @param params Result from mapProduct.getProduct().
* @param params.imageExtent Image extent in EPSG:3957 [Xmin, Ymin, Xmax, Ymax].
* @param params.url URL of the Blob Image.
*/
createLeafletMap: function (params) {
let imageExtent = params.imageExtent;
const url = params.url;
// Computes the center of the image extent to use it as the center of the map view. [Lat,Lon].
const center = [(imageExtent[1] + imageExtent[3]) / 2, (imageExtent[0] + imageExtent[2]) / 2];
// Rewrites the image extent to be used by Leaflet. [[Latmin, Lonmin], [Latmax, Lonmax]].
imageExtent = [[imageExtent[1], imageExtent[0]], [imageExtent[3], imageExtent[2]]];
// Creates the map in the HTMLElement which ID is 'map_leaflet'.
const map = L.map('map_leaflet').setView(center, 14);
// Adds OSM layer as a background layer.
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
tileSize: 256,
}).addTo(map);
// Adds the image product layer.
L.imageOverlay(url, imageExtent).addTo(map);
}
}