一、加载图层layer,随地图缩放

const img = new Image();
img.src = {imgUrl};
const map = new ol.Map({...});
const source = new ol.source.ImageCanvas({
	canvasFunction: function(extent, resolution, pixelRatio, size, /*, projection*/ ){
		const canvas = document.createElement('canvas');
		canvas.width = size[0];
		canvas.height = size[1];
		const ctx = canvas.getContext('2d');
		ctx.drawImage(img, 0, 0, size[0], size[1]);
		return canvas;
	}
});
const layer = new ol.layer.Image({source: source});
map.addLayer(layer);

二、加载静态浮层,不随地图缩放

const img = new Image();
img.src = {imgUrl};
const map = new ol.Map({...});
const canvas = map.getViewport().querySelector('canvas');
const ctx = canvas.getContext('2d');
map.on('postcompose', function(){
	// 可以实现动画效果
	ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
	this.render();
}, map);

效果图:
openlayers加载自定义图层
参考:https://viglino.github.io/ol-ext/examples/misc/map.control.cloud.html

相关文章:

  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-28
  • 2022-12-23
  • 2021-12-24
  • 2022-12-23
  • 2021-11-15
  • 2022-12-23
相关资源
相似解决方案