Skip to content

标记功能

BicMap 提供三种标记类型,满足不同场景的点位显示需求。

方向标记

可旋转的方向性标记,适用于机器人当前位置、定位点等场景。

js
const marker = bicMap.addDirectionalMarker(map, position, options)

参数

参数类型必需说明
mapMap地图实例
position[number, number]位置坐标 [经度, 纬度]
optionsObject配置选项(见下表)

options 参数

参数类型默认值说明
imagePathstring'/bicMap/assets/svg/pos.svg'图标路径,支持 SVG / PNG / JPG
initialRotationnumber0初始旋转角度(0–360°)
draggablebooleantrue是否可拖拽移动
rotationControlbooleantrue是否显示旋转控制手柄
initialEditModebooleanfalse是否初始进入编辑模式
highlightStyle.backgroundColorstring'rgba(76,175,80,0.15)'高亮背景色
highlightStyle.borderColorstring'#4CAF50'高亮边框色
highlightStyle.shadowColorstring'rgba(76,175,80,0.6)'高亮阴影色
onChangefunctionnull位置或旋转变化回调 (data) => {}

返回值:DirectionalMarker 对象

js
const marker = bicMap.addDirectionalMarker(map, [116.3912, 39.9073], {
  imagePath: '/assets/robot-pos.svg',
  initialRotation: 90,
  draggable: true,
  rotationControl: true,
  onChange: (data) => {
    console.log('位置:', data.lngLat)
    console.log('角度:', data.rotation)
  }
})

// 获取当前位置
const pos = marker.getPosition()

// 获取/设置旋转角度
const rot = marker.getRotation()
marker.setRotation(45)

// 编辑模式控制
marker.toggleEditMode()
marker.enableEditMode()
marker.disableEditMode()
const isEditing = marker.isInEditMode()

// 销毁标记
marker.remove()

批量 POI 标记

使用 WebGL 高效渲染大量 POI 点位,适合成百上千个点位的场景。

js
const markersController = bicMap.addBatchPOIMarkers(map, points, options)

points 数据结构

js
const points = [
  {
    id: 'poi-1',             // 唯一标识(必填)
    lngLat: [116.39, 39.90], // 位置坐标(必填)
    rotation: 0,             // 旋转角度
    name: '停靠点 A'         // 标签名称
  }
]

options 参数

参数类型默认值说明
imagePathstring'/bicMap/assets/img/pos.png'标记图标路径
sizenumber24标记大小(像素)
showLabelsbooleanfalse是否显示名称标签
labelIconPathstring'/bicMap/assets/img/poi-sig.png'标签图标路径
selectablebooleantrue是否可选中
selectedStyle.colorstring'#ffba40'选中扩散圆环边框色
selectedStyle.fillColorstring'#ffba40'选中扩散填充色
selectedStyle.animationDurationnumber2000扩散动画时长(ms)
onClickfunctionnull点击回调 (markerData) => {}
onSelectionChangefunctionnull选中状态变化回调

控制器方法

js
const ctrl = bicMap.addBatchPOIMarkers(map, points, options)

ctrl.updateMarkers(newPoints)        // 批量更新
ctrl.addMarker(markerData)           // 添加单个
ctrl.removeMarker(index)             // 按索引移除
ctrl.selectById('poi-1')             // 选中指定 ID
ctrl.clearSelection()                // 清除选中
ctrl.setSelectable(true)             // 设置可选中状态
ctrl.isSelectable()                  // 获取可选中状态
ctrl.toggleLabels()                  // 切换标签显示
ctrl.getMarkers()                    // 获取所有标记
ctrl.getSelectedMarker()             // 获取选中标记(单选)
ctrl.getSelectedMarkers()            // 获取所有选中标记
ctrl.getMarkerById('poi-1')          // 按 ID 获取
ctrl.clearMarkers()                  // 清除所有
ctrl.remove()                        // 销毁控制器

机器人标记

专门为机器人位置显示设计,支持朝向箭头、名称标签和实时更新。

js
const robotController = bicMap.addRobotMarkers(map, robots, options)

robots 数据结构

js
const robots = [
  {
    id: 'robot-001',           // 机器人 ID(必填)
    name: '配送机器人 A',      // 名称(必填)
    lngLat: [116.39, 39.90],   // 位置(必填)
    rotation: 90               // 朝向角度
  }
]

options 参数

参数类型必需默认值说明
svgPathstring机器人图标路径(推荐 SVG)
sizenumber30图标大小(像素)
showLabelsbooleantrue是否显示名称标签
onClickfunctionnull点击回调 (robotInfo) => {}
GPSToCartesianfunctionnullGPS→笛卡尔坐标转换函数

控制器方法

js
const ctrl = bicMap.addRobotMarkers(map, robots, options)

ctrl.addRobot(robotData)              // 添加机器人
ctrl.updateRobot(index, robotData)   // 更新指定索引机器人
ctrl.removeRobot(index)              // 移除指定索引机器人
ctrl.updateRobots(newRobots)         // 批量更新所有机器人
ctrl.toggleLabels()                  // 切换标签显示
ctrl.clearRobots()                   // 清除所有机器人
ctrl.remove()                        // 销毁控制器

实时位置更新示例

js
const robotController = bicMap.addRobotMarkers(map, [
  { id: 'r1', name: '巡检机器人', lngLat: [116.3912, 39.9073], rotation: 0 }
], {
  svgPath: '/assets/robot.svg',
  onClick: (info) => console.log('点击:', info.name)
})

// 模拟实时位置推送(WebSocket)
socket.on('robot:position', ({ index, lngLat, rotation }) => {
  robotController.updateRobot(index, { lngLat, rotation })
})