更新时间:2026/07/27 10:37
您当前查看的是 JSAPI GL 历史版本文档。该版本仅用于维护现有项目,不建议用于新项目开发。新项目请使用 JSAPI 4.0,如需升级现有项目,请参考升级指南。
You are viewing the legacy JSAPI GL documentation. This version is maintained for existing projects only and is not recommended for new development. For new projects, use the JSAPI 4.0 documentation. If you are upgrading an existing project, please refer to the Migration Guide.
You are viewing the legacy JSAPI GL documentation. This version is maintained for existing projects only and is not recommended for new development. For new projects, use the JSAPI 4.0 documentation. If you are upgrading an existing project, please refer to the Migration Guide.
自定义覆盖物
简介
为了支持更丰富多彩的地图覆盖物类型,提供自定义覆盖物类 CustomOverlay,支持开发者自定义DOM覆盖物叠加到地图上,比如实现自定义的Canvas、SVG、DOM元素,常用于叠加自定义的表格、图片、文字、GIF动画、视频等
该自定义覆盖物一次只能创建一个覆盖物,如果想要批量创建同类型的覆盖物,可以移步自定义Html覆盖物图层类CustomHtmlLayer,支持根据GeoJSON格式数据进行批量自定义覆盖物叠加。
类参考
构造函数
参数说明:
方法
事件
通过addEventListener(event, callback)方法进行事件绑定,支持如下事件:
图层示例
JavaScript
// 创建自定义覆盖物DOMfunction createDOM(feature) { const img = document.createElement('img'); img.style.height = '240px'; img.style.width = '80px'; img.src = 'https://bj.bcebos.com/v1/mapopen-pub-jsapigl/assets/images/fire.gif'; img.draggable = false; return img;} // 创建自定义覆盖物const customOverlay = new BMapGL.CustomOverlay(createDOM, { point: new BMapGL.Point(116.40342230333138, 39.92498414216742), opacity: 0.5, map: map, offsetY: -10, properties: { title: 'this is a title', size: '100' }}); // 将自定义覆盖物添加到地图上map.addOverlay(customOverlay); // 绑定鼠标事件customOverlay.addEventListener('click', function (e) { console.log('eeee', e);});本篇文章对您是否有帮助?