0

I've got a WMS Layer which contains many different images at different times. I'm able to display in Openlayers the images from a single time period if I specify a "time" parameter in params. I've seen it's possible to change the wms time automatically if you have a list of time values but was wondering if it was possible to take the time steps from the wms.

The time steps are all displayed in a WMS GetCapabilities request as well if that helps. Below is the javascript I have so far used in the OpenLayers call:

import Map from 'ol/Map.js';
import View from 'ol/View.js';
import TileLayer from 'ol/layer/Tile.js';
import ImageLayer from 'ol/layer/Image.js';
import OSM from 'ol/source/OSM.js';
import TileWMS from 'ol/source/TileWMS.js';
import ImageWMS from 'ol/source/ImageWMS.js';

var base_layer = new TileLayer({
  source: new OSM()
});

var dc_wms = new TileLayer({
  source: new TileWMS({
    url: 'http://localhost:5000/',
    params: {
      'LAYERS': '10DayIndices',
      'STYLE': 'ndvi',
      time: '2019-06-20'
    }
  })
});

var map = new Map({
  layers: [base_layer, dc_wms],
  target: 'map',
  view: new View({
  projection: 'EPSG:4326',
    center: [102.376126,48.031532],
    zoom: 6
  })
});

I can also provide more info on the GetCapabilities request (the time is in format ISO:8601) if that would help.

1 Answer 1

1

Found an answer to this when searching around further today (specifically when looking at this question), using the ol.format.WMSCapabilities() class, using the code below:

var url = "***my_wms_url**";

var GetCaps = new ol.format.WMSCapabilities();

fetch(url).then(function(response) {
      return response.text();
    }).then(function(text) {
      var result = GetCaps.read(text);
      var times = results.Capability.Layer.Layer[0].Dimension;
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.