PointIconLayer
继承FeatureLayer类,支持点图标的渲染。
构造函数
| 构造函数 | 描述 |
|---|---|
| BMapGL.PointIconLayer(options: object) | 继承FeatureLayer类,支持点图标的渲染 |
配置选项
options属性除FeatureLayer参数外,增加以下参数:
| 属性 | 类型 | 描述 |
|---|---|---|
| isFlat | boolean | 是否是贴地图标,默认true |
| isFixed | boolean | 是否保持图标跟随地图层级改变而尺寸不变,默认true |
| style | object | 线图层显示样式配置对象,详见样式配置 |
样式配置
| 属性 | 类型 | 描述 |
|---|---|---|
| icon | string | StyleExpress | 图标地址,url |
| iconObj | (style,properties)=> {id:number,canvas:HTMLCanvasElement} | 通过函数形式返回图标,id代表图标标识,canvas代码图标来源 |
| sizes | [number,number] | 点的大小 |
| width | number | StyleExpress | 点的宽度大小 |
| height | number | StyleExpress | 点的高度大小 |
| userSizes | boolean | 是否使用sizes的宽高,还是使用width和height。默认true |
| anchors | [number,number] | 坐标点对应的锚点,中间点为[0,0],取值范围[-1,1] |
| offset | [number,number] | 偏移量 |
| scale | number | StyleExpress | 缩放比例 |
| rotation | number | StyleExpress | 旋转角度 |
| opacity | number | StyleExpress | 透明度 |
示例
ts
// 创建点图标图层
const layer = new BMapGL.PointIconLayer({
idKey: 'id',
crs: 'BD09LL',
isFlat: true,
isFixed: true,
style: {
icon: 'marker.png',
sizes: [32, 32],
anchors: [0, 0],
offset: [0, 0],
scale: 1,
rotation: 0,
opacity: 1
}
});
// 设置数据
layer.setData(geojsonData);
// 添加到地图
map.addLayer(layer);注意事项
图标设置:
- 支持URL和自定义Canvas两种方式
- 注意图标尺寸的合理性
- 考虑图标加载性能
样式控制:
- 合理设置锚点和偏移量
- 注意缩放和旋转效果
- 控制透明度范围
性能优化:
- 合理使用isFixed属性
- 注意图标缓存
- 控制图层数量
