const textMarker = new esmap.ESTextMarker({
x: map.center.x,
y: map.center.y,
scale: 1.5, // 设置整体缩放比例
text: "图片+文字",
image: "image/card.png",
imageStyle: {
align: 'center',
scale: 1, // 单独设置图片缩放比例
},
textStyle: {
fontSize: 14,
fillStyle: '#FFFFFF', // 填充色
strokeWidth: 2, // 边框厚度
strokeStyle: '#000000', // 边框色
shadowBlur: 3, // 阴影
shadowColor: '#000000', // 阴影颜色
},
height: 3,
showLevel: 20,
// callback: function (marker) { // 标注创建完成回调
// marker.setColor("#FF0000");
// }
});
/* 获取"一楼"的楼层对象,并且创建"一楼"的图文标注层,其他楼层以此类推 */
floor = map.getBuildingById(0).getFloor(1);
textLayer = floor.getOrCreateLayerByName('textLayer',esmap.ESLayerType.TEXT_MARKER);
textLayer.addMarker(textMarker); // 将图文标注添加进"对应楼层"的标注层,创建完成
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 是否必填 |
|---|---|---|---|---|---|
| x | x轴位置,如果不添加x和y,则默认坐标在场景中心。 | Number | —— | map.center.x | 否 |
| y | y轴位置,如果不添加x和y,则默认坐标在场景中心。 | Number | —— | map.center.y | 否 |
| height | 距离地面高度 | Number | —— | 6 | 否 |
| scale | 标注整体缩放比例 | Number | —— | 1 | 否 |
| text | 文字内容 | String | —— | —— | 否 |
| image | 图片路径 | String | —— | —— | 否 |
| imageStyle | 图片样式 | Object | —— | —— | 否 |
| imageStyle.align | 图片对齐方式 | String |
center(背景居中),left(左),right(右), top(上),bottom(下) |
center | 否 |
| imageStyle.space | 图片与文字间距 | Number | —— | 5 | 否 |
| imageStyle.size | 图片比例 | String|Number|Object | "auto":(图片比例自适应) 64: 将图片比例设置为64*64 {w:64,h:256}将图片尺寸设置为64*256 |
"auto" | 否 |
| imageStyle.scale | 图片缩放大小 | Number | 当有文字,但需要单独控制图片大小可以使用此参数 | 1 | 否 |
| textStyle | 文字样式 | Object | —— | —— | 否 |
| textStyle.fontSize | 文字大小 | Number | —— | 12 | 否 |
| textStyle.fillStyle | 文字填充色 | String | —— | #FFFFFF | 否 |
| textStyle.strokeStyle | 文字边框色 | String | —— | #000000 | 否 |
| textStyle.strokeWidth | 文字边框厚度 | Number | —— | 2 | 否 |
| textStyle.shadowBlur | 文字阴影 | Number | —— | 4 | 否 |
| textStyle.shadowColor | 文字阴影颜色 | String | —— | "rgba(0, 0, 0,1.0)" | 否 |
| textStyle.shadowOffsetX | 文字阴影X偏移 | Number | —— | 0 | 否 |
| textStyle.shadowOffsetY | 文字阴影Y偏移 | Number | —— | 0 | 否 |
| textStyle.offsetX | 文字X轴偏移 | Number | —— | 0 | 否 |
| textStyle.offsetY | 文字Y轴偏移 | Number | —— | 0 | 否 |
| center | 标注的中心点位偏移 | Object | —— | {x:0.5,y:0} | 否 |
| center.x | 中心点x轴偏移百分比 | Number | 0-1 | 0.5 | 否 |
| center.y | 中心点y轴偏移百分比 | Number | 0-1 | 0 | 否 |
| name | 标注名称 | String | —— | —— | 否 |
| id | 标注id,可自定义 | Number | —— | —— | 否 |
| fixedSize | 是否固定大小 | Boolean | true/false | true | 否 |
| showLevel | 到达场景缩放等级隐藏或者显示标注 | Number|Array|null | Number: 0 - 23, 如配置 15,
则超过15级显示 Array:[10, 20]: 在10~20级显示 null: 一直显示 |
16 | 否 |
| pickable | 控制是否可被点击 | Boolean | true/false | true | 否 |
| seeThrough | 是否穿透显示 | Boolean | true/false | false | 否 |
| callback | 标注完成创建的回调函数,参数会返回marker对象本身 | Function | —— | —— | 否 |
| renderOrder | 更改渲染等级,值越大显示等级越优先 | Number | —— | 77 | 否 |
map.on('loadComplete',()=>{
const textMarker = new esmap.ESTextMarker({
image: 'image/user.png',
scale: 2,
showLevel: 20,
height: 3,
id: 1,
name: '纯图片',
x: map.center.x,
y: map.center.y,
});
/* 获取"一楼"的楼层对象,并且创建"一楼"的图文标注层,其他楼层以此类推 */
floor = map.getBuildingById(0).getFloor(1);
textLayer = floor.getOrCreateLayerByName('textLayer',esmap.ESLayerType.TEXT_MARKER);
textLayer.addMarker(textMarker); // 将图文标注添加进"对应楼层"的标注层,创建完成
})
map.on('loadComplete',()=>{
const textMarker = new esmap.ESTextMarker({
height: 3,
text: "测试标签2",
showLevel: 20,
textStyle: {
fontSize: 14,
fillStyle: '#FFFFFF', //填充色
strokeWidth: 4, //边框厚度
strokeStyle: '#000000', //边框色
shadowBlur: 3, //阴影
shadowColor: '#000000', //阴影颜色
}
id: 2,
name: '纯文字',
x: map.center.x,
y: map.center.y,
});
/* 获取"一楼"的楼层对象,并且创建"一楼"的图文标注层,其他楼层以此类推 */
floor = map.getBuildingById(0).getFloor(1);
textLayer = floor.getOrCreateLayerByName('textLayer',esmap.ESLayerType.TEXT_MARKER);
textLayer.addMarker(textMarker); // 将图文标注添加进"对应楼层"的标注层,创建完成
})
// 首先获取"对应楼层"的楼层对象
floor = map.getBuildingById(0).getFloor(1); // 这里获取到"一楼"楼层对象
// 方法1:销毁某个楼层所有的图文标注层
floor.removeLayersByTypes(esmap.ESLayerType.TEXT_MARKER);
// 方法2:根据标注层名字销毁某个楼层的图文标注层
floor.removeLayersByNames('textLayer');
// 方法3: 销毁该标注层里的某一个图文标注
textLayer.remove(marker);
// 方法4: 销毁该标注层的所有标注
textLayer.removeAll();
标注支持手动控制显隐:
marker.visible = false // 隐藏标注
marker.visible = true // 显示标注
// 当多个图文标注的位置发生重叠碰撞时,会动态隐藏部分标注
textLayer.enableCollide()
marker.jump({
times: 100, // 跳跃执行100次
duration: 1, // 持续1秒
delay: 0.5, // 每次跳跃的间隔,默认为0
height: 10 // 跳跃的三维场景高度
});
// 停止跳跃
marker.stopJump();
marker.flash({
times: 20, // 执行次数
scale: 1.5, // 缩放倍数
delay: 5, // 每次跳跃的间隔,默认为0
});
// 停止闪烁
marker.stopFlash();
// 标注发光
marker.glow({
color: '#00FF00', // 设置光圈颜色
scale: 2, // 设置光圈效果大小
opacity: 0.2, // 设置光圈效果透明度
height:2, // 设置光圈高度
});
//停止光圈效果
marker.stopGlow();
marker.url = '新图片url'; // 动态更改图片资源
await marker.updateImage('新图片url'); // 针对需要确保更换图片资源后进行异步操作使用
marker.text = 'new content'; // 动态更改标注内容
// 如果是移动到另外楼层,需要自行删除此marker,然后新建立一个标注添加到对应楼层的标注层上面
marker.moveTo({
x: marker.mapCoord.x + 10, // 目标点x轴
y: marker.mapCoord.y + 10, // 目标点y轴
time: 0 // 位移动画时间,单位(秒/s)
})
let points =[ // 线段数据
{ "x":map.center.x, "y":map.center.y, "fnum":1, "offset":2 },
{ "x":map.center.x + 20, "y":map.center.y + 20, "fnum":1, "offset":2 },
{ "x":map.center.x - 20, "y":map.center.y - 20, "fnum":1, "offset":2 },
];
marker.movePath({
path: points,
offsetHeight: 3,
speed: 3, // speed为完成速度,time为完成时间,两个参数选其一
//time: 5,
loop: true,
onMoving: (e) => {
// 返回移动中信息的回调函数
// 不建议在该回调里做marker.url资源更改,建议使用气泡标注或者使用防抖函数控制
},
})
marker.updateTextStyle({
fontSize: 15,
fillStyle: "#FF0000",
strokeStyle: "#00FF00",
strokeWidth: 6,
})
marker.setHeight(20); // 设置高度
marker.setSize({ // 设置大小
width: 200,
height: 200,
})
marker.setScale(2); // 设置比例
marker.setColor("#FF0000"); //设置颜色
marker.setColor(false); // 恢复颜色
marker.setAlpha(0.2); // 设置透明度
