Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在openlayers 6中从地图的postcompose事件获取画布_Javascript_Dictionary_Canvas_Openlayers_Openlayers 6 - Fatal编程技术网

Javascript 如何在openlayers 6中从地图的postcompose事件获取画布

Javascript 如何在openlayers 6中从地图的postcompose事件获取画布,javascript,dictionary,canvas,openlayers,openlayers-6,Javascript,Dictionary,Canvas,Openlayers,Openlayers 6,我们正在使用openlayers,在5.3版中,我们使用了以下结构: map.once('postcompose', async(event) => { let canvas = event.context.canvas; // doing something with canvas } 但是在openLayers 6.0中,事件的参数上下文未定义(这当然破坏了我们的应用程序) 我读到: 层不再由单个画布元素组成。相反,它们将作为单个元素添加到地图视口中 那么如何获得单层画布呢

我们正在使用openlayers,在5.3版中,我们使用了以下结构:

map.once('postcompose', async(event) => {
  let canvas = event.context.canvas;
  // doing something with canvas
}
但是在openLayers 6.0中,事件的参数上下文未定义(这当然破坏了我们的应用程序)

我读到:

层不再由单个画布元素组成。相反,它们将作为单个元素添加到地图视口中

那么如何获得单层画布呢

我还读到:

画布上下文。由映射发送事件时不可用。仅在使用画布渲染器时可用,否则为null


是否可以通过某种方式将画布渲染器设置为所有层,以便“postcompose”事件的画布渲染Context2D不会未定义?

使用ol6在层上使用
postrender
事件,新的
getVectorContext
函数提供对即时向量渲染API的访问。

要在单个层上获取渲染上下文,请执行以下操作:

import {getVectorContext} from 'ol/render';

// construct your map and layers as usual

layer.on('postrender', function(event) {
  const vectorContext = getVectorContext(event);
  // use any of the drawing methods on the vector context
});

每个层都有自己的画布,可以在('postrender',…)上的
层中使用