Reputation: 33
I have a tricky question concerning the possibility to put layers in grayscale with Open Layers 3.
I already achieve to put the whole map in grayscale using the possibilities of canvas element, like it can be seen in the examples proposed in the following discussion : OpenLayers 3 - tile canvas context
But my need is slightly different from these examples : I want to give users the possibility to put layers one by one in grayscale, without changing the colour of other layers. The idea is for instance to have one background layer in grayscale with other data over it in colour.
Does someone know how such a thing can be achieved ?
Thanks
Upvotes: 3
Views: 2399
Reputation: 6031
ol.source.Raster is what you are looking for. Here is an example.
var raster = new ol.source.Raster({
sources: [new ol.source.Stamen({
layer: 'watercolor'
})],
operation: function(pixels, data) {
// convert pixels to grayscale
return pixels;
}
});
This enables you to manipulate the pixel data of arbitrary sources on a per-layer base.
Upvotes: 3