-
Notifications
You must be signed in to change notification settings - Fork 24
/
RasterService.js
58 lines (51 loc) · 1.37 KB
/
RasterService.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
/* global SITE_CONFIG */
/* global URLSearchParams */
import geoblaze from 'geoblaze';
import GeoRasterLayer from 'georaster-layer-for-leaflet';
const getResolution = () => {
const resolution = Number(new URLSearchParams(window.location.search).get('resolution'))
if (resolution) {
return resolution
}
if (SITE_CONFIG.resolution) {
return Number(SITE_CONFIG.resolution);
}
const width = document.documentElement.clientWidth;
const userAgent = window.navigator.userAgent;
const isAndroid = userAgent.includes("Android");
const isChromebook = userAgent.includes("CrOS");
if (width < 900 || isAndroid || isChromebook) {
return 32;
} else if (width < 1200) {
return 48;
} else {
return 64;
}
}
const RasterService = {
createRaster(input) {
return new Promise((resolve, reject) => {
geoblaze.load(input)
.then(georaster => {
let options = {
georaster: georaster,
opacity: 0.7,
resolution: getResolution()
};
const raster = new GeoRasterLayer(options);
resolve(raster);
}, error => {
reject(error);
});
});
},
createRasterFromGeoraster(georaster) {
const options = {
georaster,
opacity: 0.7,
resolution: getResolution()
}
return new GeoRasterLayer(options);
}
}
export default RasterService;