src/ol/source/Raster.js
function getImageData(layer, frameState, layerState) {
  const renderer = layer.getRenderer();
  if (!renderer) {
    throw new Error('Unsupported layer type: ' + layer);
  }

  if (!renderer.prepareFrame(frameState, layerState)) {
    return null;
  }
  const width = frameState.size[0];
  const height = frameState.size[1];
  const element = renderer.renderFrame(frameState, layerState);
  if (!(element instanceof HTMLCanvasElement)) {
    throw new Error('Unsupported rendered element: ' + element);
  }
  if (element.width === width && element.height === height) {
    const context = element.getContext('2d');
    return context.getImageData(0, 0, width, height);
  }

  if (!sharedContext) {
    sharedContext = createCanvasContext2D(width, height);
  } else {
    const canvas = sharedContext.canvas;
    if (canvas.width !== width || canvas.height !== height) {
      sharedContext = createCanvasContext2D(width, height);
    } else {
      sharedContext.clearRect(0, 0, width, height);
    }
  }
  sharedContext.drawImage(element, 0, 0, width, height);
  return sharedContext.getImageData(0, 0, width, height);
}
function getImageData(layer, frameState, layerState) {
  const renderer = layer.getRenderer();
  if (!renderer) {
    throw new Error('Unsupported layer type: ' + layer);
  }

  if (!renderer.prepareFrame(frameState, layerState)) {
    return null;
  }
  const width = frameState.size[0];
  const height = frameState.size[1];
  const element = renderer.renderFrame(frameState, layerState);
  if (!(element instanceof HTMLCanvasElement)) {
    throw new Error('Unsupported rendered element: ' + element);
  }
  if (element.width === width && element.height === height) {
    const context = element.getContext('2d');
    return context.getImageData(0, 0, width, height);
  }

  if (!sharedContext) {
    sharedContext = createCanvasContext2D(width, height);
  } else {
    const canvas = sharedContext.canvas;
    if (canvas.width !== width || canvas.height !== height) {
      sharedContext = createCanvasContext2D(width, height);
    } else {
      sharedContext.clearRect(0, 0, width, height);
    }
  }
  sharedContext.drawImage(element, 0, 0, width, height);
  return sharedContext.getImageData(0, 0, width, height);
}
function getImageData ( layer , frameState , layerState ) { const renderer = layer . getRenderer ( ) ; if ( ! renderer ) { throw new Error ( 'Unsupported layer type: ' + layer ) ; } if ( ! renderer . prepareFrame ( frameState , layerState ) ) { return null ; } const width = frameState . size [ 0 ] ; const height = frameState . size [ 1 ] ; const element = renderer . renderFrame ( frameState , layerState ) ; if ( ! ( element instanceof HTMLCanvasElement ) ) { throw new Error ( 'Unsupported rendered element: ' + element ) ; } if ( element . width === width && element . height === height ) { const context = element . getContext ( '2d' ) ; return context . getImageData ( 0 , 0 , width , height ) ; } if ( ! sharedContext ) { sharedContext = createCanvasContext2D ( width , height ) ; } else { const canvas = sharedContext . canvas ; if ( canvas . width !== width || canvas . height !== height ) { sharedContext = createCanvasContext2D ( width , height ) ; } else { sharedContext . clearRect ( 0 , 0 , width , height ) ; } } sharedContext . drawImage ( element , 0 , 0 , width , height ) ; return sharedContext . getImageData ( 0 , 0 , width , height ) ; }
Get image data from a layer.
@param {import("../layer/Layer.js").default} layer Layer to render.
@param {import("../PluggableMap.js").FrameState} frameState The frame state.
@param {import("../layer/Layer.js").State} layerState The layer state.
@return {ImageData} The image data.
Get image data from a layer .