Uncaught DOMException: Failed to execute ‘toDataURL‘ on ‘HTMLCanvasElement‘

【background】

Openlayers is used in Vue to export the map as a picture. Originally, the map was loaded using the official method provided by openlayers, but the map was loaded too slowly. After changing to a sky map, the picture could not be exported and an error was reported.

Insert picture description here
【problem causes】

After using Tiandi, the cross-domain problem was not solved, so the image export failed

[Solution]

Add crossOrigin:'anonymous'to deal with cross-domain issues

let tiandiditu = new Tile({
    
    
	source: new XYZ({
    
    
			crossOrigin:'anonymous',
			url: '',
	}),
});

Guess you like

Origin blog.csdn.net/weixin_42547014/article/details/113116612