OpenLayers6(3):Vue导出图片时报错“Uncaught DOMException: Failed to execute ‘toDataURL on ‘HTMLCanvasElement”

1.版本

  • OpenLayers:6.4.3


2.导出时候遇到报错


3.原因分析

原因:openlayers中加载的图层中存在不允许跨域的图层;

解决:找到相应的图层,添加 crossOrigin:'anonymous',处理跨域问题;

// 切片-图层
export function addlocalTileLayer(title, url, proj = 'EPSG:3857') {
    const tileLayer = new TileLayer({
        ...olextLayerOptions(title),
        source: new XYZSource({
            url: url,
            projection: proj,
            crossOrigin: 'anonymous'  // 添加允许跨域
        })
    });
    return tileLayer;
}

猜你喜欢

转载自blog.csdn.net/qq_34520411/article/details/124362360
今日推荐