Atlaslog
Atlaslog / OpenLayers / API reference / RasterSource
OpenLayers · API reference

RasterSource

Quick answer

RasterSource is ol.source.Raster, a source that resamples several image sources onto one grid and runs a per-pixel or whole-image operation over them. Supply sources plus an operation(inputs, data) function, choose operationType pixel or image, and set threads, lib and projection. Display the result as an image layer for band math, indices or classification.

Last verified 2026-11-03 · OpenLayers 10.3.1 · Cite this page
new ol.source.Raster( options )
Key points
Example
var red = new ol.source.XYZ({ url: '/tiles/red/{z}/{x}/{y}.png' });
var nir = new ol.source.XYZ({ url: '/tiles/nir/{z}/{x}/{y}.png' });

var ndvi = new ol.source.Raster({
  sources: [red, nir],
  operationType: 'pixel',
  threads: 2,
  operation: function (inputs, data) {
    var r = inputs[0];
    var n = inputs[1];
    var out = new Uint8ClampedArray(r.length);

    for (var i = 0; i < r.length; i += 4) {
      var redValue = r[i];
      var nirValue = n[i];
      var index = (nirValue - redValue) / (nirValue + redValue + 1e-6);
      var v = Math.round(((index + 1) / 2) * 255);
      out[i] = v;
      out[i + 1] = 255 - v;
      out[i + 2] = 90;
      out[i + 3] = r[i + 3];
    }

    data.max = 1;
    return [out];
  }
});

var layer = new ol.layer.Image({ source: ndvi });
Notes
Runnable examplesChinese originalAll API references
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). RasterSource. https://www.jingweizhi.com/en/openlayers/api/raster-source.html (accessed 2026-11-03).