Commit 57d0f703 authored by Matija Obreza's avatar Matija Obreza
Browse files

Updated to [abcd].static.genesys-pgr.org

parent f45a1cf9
......@@ -25,7 +25,7 @@ export const AVAILABLE_LAYERS = layerNames.map((layerName) => ({
name: layerName,
title: `accessions.climate.${ layerName }`,
description: `accessions.climateDescription.${ layerName }`,
url: `https://{s}.tile.genesys-pgr.org/worldclim1.4/${ layerName }/{z}/{x}/{y}.png`,
url: `https://{s}.static.genesys-pgr.org/worldclim1.4/${ layerName }/{z}/{x}/{y}.png`,
}));
export default MapLayer;
import * as UrlTemplate from 'url-template';
import { axiosBackend } from 'utilities/requestUtils';
import axios from 'axios';
import TileClimate from 'model/genesys/TileClimate';
const URL_GET_CURRENT_CLIMATE = UrlTemplate.parse(`/api/v1/climate/current/{latitude},{longitude}`);
const URL_GET_FUTURE_CLIMATE = UrlTemplate.parse(`/api/v1/climate/future/{latitude},{longitude}`);
const URL_GET_PAST_CLIMATE = UrlTemplate.parse(`/api/v1/climate/past/{latitude},{longitude}`);
const URL_GET_CURRENT_CLIMATE = UrlTemplate.parse(`https://a.static.genesys-pgr.org/worldclim1.4/json/current/{col}/{row}.json`);
function lon2Col(longitude: number) {
if (longitude == null) {
return null;
}
const columns = 8640;
const ncol = Math.round((columns) * (longitude % 360 + 180) / 360) % columns;
return ncol;
}
function lat2Row(latitude: number) {
if (latitude == null) {
return null;
}
const rows = 4320;
const nrow = Math.round((rows) * (latitude % 180 + 90) / 180) % rows;
return rows - nrow;
}
/*
* Defined in Swagger as 'climate'
......@@ -19,57 +35,27 @@ class ClimateService {
* @param longitude longitude
*/
public static getCurrentClimate(latitude: number, longitude: number): Promise<TileClimate> {
const apiUrl = URL_GET_CURRENT_CLIMATE.expand({ latitude, longitude });
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
url: apiUrl,
method: 'GET',
...content,
}).then(({ data }) => data as TileClimate);
}
/**
* getFutureClimate at /api/v1/climate/future/{latitude},{longitude}
*
* @param latitude latitude
* @param longitude longitude
*/
public static getFutureClimate(latitude: number, longitude: number): Promise<TileClimate> {
const apiUrl = URL_GET_FUTURE_CLIMATE.expand({ latitude, longitude });
const col = lon2Col(longitude);
const row = lat2Row(latitude);
if (col == null || row == null) {
return Promise.resolve(null);
}
console.log(`(${latitude},${longitude}) = ${col}/${row}.json`);
const apiUrl = URL_GET_CURRENT_CLIMATE.expand({ col, row });
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
return axios.request({
url: apiUrl,
headers: {
authorization: null,
},
method: 'GET',
...content,
}).then(({ data }) => data as TileClimate);
}
/**
* getPastClimate at /api/v1/climate/past/{latitude},{longitude}
*
* @param latitude latitude
* @param longitude longitude
*/
public static getPastClimate(latitude: number, longitude: number): Promise<TileClimate> {
const apiUrl = URL_GET_PAST_CLIMATE.expand({ latitude, longitude });
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
url: apiUrl,
method: 'GET',
...content,
}).then(({ data }) => data as TileClimate);
}
}
export default ClimateService;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment