I'm trying to change raster layer with a selector.
I don't understand why the clear method don't work on tileWMS however it's on the API doc...
For a vector source, on an other app, it work :
var cqlFilter = 'date_debut BETWEEN 1000 AND 2000 OR date_fin BETWEEN 1000 AND 2000';
var urlTemplate = 'http://serveradress/geoserver/applications/wfs?service=WFS&' +
'version=1.0.0&request=GetFeature&' +
'typeNames=applications:patrimoine&' +
'CQL_FILTER=' + cqlFilter +
'&outputFormat=application/json&' +
'srsName=EPSG:4326';
console.log(urlTemplate);
var _vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function() {return urlTemplate;}
});
function changeDate(years) {
var dateMin = years[0];
var dateMax = years[1];
var cqlNewFilter = '(date_debut BETWEEN '+ dateMin + ' AND ' + dateMax + ' OR date_fin BETWEEN ' + dateMin + ' AND ' + dateMax + ')';
urlTemplate = 'http://serveradress/geoserver/applications/wfs?service=WFS&' +
'version=1.0.0&request=GetFeature&' +
'typeNames=applications:patrimoine&' +
'CQL_FILTER=' + cqlNewFilter +
'&outputFormat=application/json&' +
'srsName=EPSG:4326';
_vectorSource.clear(true);
_vectorSource.refresh();
};
var _cluster = new ol.source.Cluster({
distance: 50,
source: _vectorSource
});
var _layer = new ol.layer.Vector({
source: _cluster,
style: _patrimoineStyle
});
But whith a TileWMS layer it don't work, it tells me that _rasterSource.clear is not a function :
var anneeCouche = "2016_20cm";
var _rasterSource = new ol.source.TileWMS({
url: 'http://serveradress/geoserver/raster/wms?',
params: {LAYERS: 'raster:ortho'+anneeCouche}
});
function changeDate(annee) {
if (annee === '2013') {
var anneeCouche = "2013_20cm";
} else {
var anneeCouche = "2016_20cm";
};
_rasterSource.clear(true);
_rasterSource.refresh();
};
var _layer = new ol.layer.Tile({
title: 'Ortho',
source: _rasterSource
});
clear
method was introduced forol.source.TileWMS
in OL6 (and it is without parameter). – TomazicM Apr 9 '20 at 18:10