Skip to content
Snippets Groups Projects
Commit 41a83225 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Allow for more than one WMS server

parent ccc8705a
No related branches found
No related tags found
No related merge requests found
......@@ -143,8 +143,9 @@ SITE_OWNER_URL = "http://www.example.com/"
# Grid models settings
WMS_SERVER_URL = "https://gridweb.vips.nibio.no/cgi-bin/"
AVAILABLE_GRID_MODELS = [
{"model_id":"SEPTREFHUM", "model_name": {"nb":"Septoria referansefuktmodell", "en":"Septoria reference humidity model"}},
{"model_id":"PSILARTEMP", "model_name": {"nb":"Gulrotflue svermetidspunktmodell", "en":"Carrot rust fly (Psila rosae) temperature model"}}
{"model_id":"SEPTREFHUM", "model_name": {"nb":"Septoria referansefuktmodell", "en":"Septoria reference humidity model"}, "url": "%sSEPTREFHUM" % WMS_SERVER_URL},
{"model_id":"PSILARTEMP", "model_name": {"nb":"Gulrotflue svermetidspunktmodell", "en":"Carrot rust fly (Psila rosae) temperature model"}, "url": "%sPSILARTEMP" % WMS_SERVER_URL},
{"model_id":"NAERSTADMO", "model_name": {"nb":"Nærstads modell", "en":"Nærstad's potato blight model"}, "url": "%sNAERSTADMO" % WMS_SERVER_URL}
]
# OpenLayers Map (map on front page) initial configuration
......
......@@ -27,7 +27,7 @@ proj4.defs(
let layers = [];
let mapserverURL=settings.WMS_SERVER_URL
//let mapserverURL=settings.WMS_SERVER_URL
let modelId = undefined;
let today = getSystemTime().format("YYYY-MM-DD");
let todayLayerIndex = undefined;
......@@ -165,7 +165,7 @@ function getLayersForCurrentTimestamp()
* @param {*} inputModelId model Id, e.g. PSILARTEMP
* @param {*} mapAttribution background map source information (displayed in the map)
*/
async function initGridMap(inputModelId, mapAttribution) {
async function initGridMap(inputModelId, wmsURL, mapAttribution) {
modelId = inputModelId;
var backgroundLayer = new ol.layer.Tile({
source: new ol.source.OSM({
......@@ -180,7 +180,7 @@ async function initGridMap(inputModelId, mapAttribution) {
// Get layers from WMS service
let parser = new ol.format.WMSCapabilities();
//console.info(mapserverURL + modelId + "?service=WMS&version=1.3.0&request=GetCapabilities");
let response = await fetch(mapserverURL + modelId + "?service=WMS&version=1.3.0&request=GetCapabilities&language=" + settings.currentLanguage);
let response = await fetch(wmsURL + "?service=WMS&version=1.3.0&request=GetCapabilities&language=" + settings.currentLanguage);
//console.info(response.status); // Response is 200 even if a model doesn't exist on the mapserver
let txt = await response.text();
......@@ -256,7 +256,7 @@ async function initGridMap(inputModelId, mapAttribution) {
layers.push(
new ol.layer.Image({
source: new ol.source.ImageWMS({
url: mapserverURL + modelId,
url: wmsURL,
params: { "LAYERS": modelId + "." + currentLayerParam + "." + dateStr, "TRANSPARENT": "TRUE" },
serverType: "mapserver",
ratio: 1,
......
......@@ -25,7 +25,7 @@
var longitude = {{settings.MAP_CENTER_LONGITUDE|unlocalize}};
var latitude = {{settings.MAP_CENTER_LATITUDE|unlocalize}};
var zoomLevel = {{settings.MAP_ZOOMLEVEL}};
initGridMap("{{model_id}}","{{settings.MAP_ATTRIBUTION|safe}}");
initGridMap("{{model_id}}","{{url}}", "{{settings.MAP_ATTRIBUTION|safe}}");
});
</script>
{% endblock %}
......
......@@ -35,7 +35,7 @@ def gridmap(request, model_id=None):
try:
for model in settings.AVAILABLE_GRID_MODELS:
if model_id == model["model_id"]:
context = {"model_id": model_id}
context = {"model_id": model_id, "url": model["url"]}
return render(request, 'spatial/gridmap.html', context)
except AttributeError:
pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment