JSAPI GL提供的GroundOverlay类支持在地图底面上叠加覆盖物,覆盖物可以是图片、自定义Canvas、视频。
GroundOverlay类继承Overlay类,基于Bounds确定在地面上的显示范围和大小,通过options来配置覆盖物的类型、源、透明度等。
构造函数:
参数说明:
options属性变量:
创建地面叠加层使用BMapGL.GroundOverlay类,其继承自Overlay,通过map.addoverlay()方法将创建的叠加层添加到地图上。
// 创建叠加物显示的范围Boundsvar pStart = new BMapGL.Point(117.19635, 36.24093);var pEnd = new BMapGL.Point(117.2035, 36.24764);var bounds = new BMapGL.Bounds(new BMapGL.Point(pStart.lng, pEnd.lat),new BMapGL.Point(pEnd.lng, pStart.lat),);// 创建地面叠加层实例var imgOverlay = new BMapGL.GroundOverlay(bounds, {type: 'image',url: '/jsdemo/img/shouhuimap.png',opacity: 1,});// 叠加层添加到地图map.addOverlay(imgOverlay);
当叠加层纹理是canvas类型时,使用方法与图片类似,在options中设置其纹理源。
// 自定义canvasfunction getTextureCanvas() {var textureCanvas = document.createElement('canvas');textureCanvas.width = textureCanvas.height = 200;var ctx = textureCanvas.getContext('2d');ctx.fillStyle = '#79a913';ctx.strokeStyle = 'white';ctx.lineWidth = 6;ctx.lineCap = 'square';ctx.fillRect(0, 0, 200, 200);ctx.moveTo(50, 50);ctx.lineTo(150, 50);ctx.lineTo(150, 150);ctx.lineTo(50, 150);ctx.lineTo(50, 50);ctx.stroke();return textureCanvas;}// 添加canvas叠加层var canvasSource = getTextureCanvas();var pStart = new BMapGL.Point(116.447717, 39.919173);var pEnd = new BMapGL.Point(116.453125, 39.923475);var bounds = new BMapGL.Bounds(new BMapGL.Point(pStart.lng, pEnd.lat),new BMapGL.Point(pEnd.lng, pStart.lat),);var canvasOverlay = new BMapGL.GroundOverlay(bounds, {type: 'canvas',url: canvasSource,opacity: 0.9,});map.addOverlay(canvasOverlay);
当叠加层纹理是video类型时,使用方法与图片和canvas类似,在options中设置其纹理源。
var pStart = new BMapGL.Point(94.582033, -7.989754);var pEnd = new BMapGL.Point(145.358572, 30.813867);var bounds = new BMapGL.Bounds(new BMapGL.Point(pStart.lng, pEnd.lat),new BMapGL.Point(pEnd.lng, pStart.lat),);var imgOverlay = new BMapGL.GroundOverlay(bounds, {type: 'video',url: '/jsdemo/img/cloud.mov',opacity: 0.5,});map.addOverlay(imgOverlay);
上一篇
下一篇
本篇文章对您是否有帮助?