Skip to content

onClick(callback)

船舶点击事件 [去看示例]

html
<script>
  const callBack = (e) => {
    console.log(e, '返回值')
  }
  shipControl.onClick(callBack)
  //返回值示例

  返回值如下: [
    {
      id: 413245090,
      properties: {
        mmsi: '413245090',
        hdg: 263,
        cog: 248,
        rot: 0,
        updateTime: '1763971752000',
        sog: 8.7,
        location: '29.937700,122.113930',
        enname: 'ZHOUGANGTUO38',
        cnname: '舟港拖38',
        typeId: 52,
        length: 40,
        width: 11,
        statusId: 0,
        status: '在航(主机推动)',
        draft: 4.1,
        imo: '0',
        callsign: 'BOKC2',
        toBow: 15,
        toStern: 25,
        toStarboard: 4,
        toPort: 7,
        builtDate: '2020-12-02',
        cstatus: 0,
        ctype2: 0,
        nationalityCode: 'CN',
        source: 0,
        bdts: '1745387849000',
        shipSource: 2,
        id: '413245090',
        name: '舟港拖38',
        lon: '122.113930',
        lat: '29.937700',
        color: 'rgba(255,255,255,0.5)',
        imageName: 'offline_straight',
        course: 263,
      },
      distance: 238.7,
      geometry: {
        type: 'Point',
        coordinates: [122.113938331604, 29.937698900516423],
      },
    },
  ]
</script>
参数说明
id船舶唯一ID
propertiesaddShip方法中传入的该船舶数据
distance该船舶距离点击位置的距离(M)
geometry所在位置与数据类型

onMouseenter(callback)

船舶鼠标移入事件 [去看示例]

html
<script>
  const callBack = (e) => {
    // console.log(e, '返回值')
    map.getCanvas().style.cursor = 'pointer' //将鼠标样式改为手势
  }
  shipControl.onMouseenter(callBack)
  //返回值如onClick
</script>

onMouseleave(callback)

船舶鼠标移出事件

html
<script>
  const callBack = () => {
    map.getCanvas().style.cursor = '' //将鼠标样式恢复
  }
  shipControl.onMouseleave(callBack)
</script>

offClick()

移除船舶点击事件

html
<script>
  shipControl.offClick()
</script>

offMouseenter()

移除船舶鼠标移入事件

html
<script>
  shipControl.offMouseenter()
</script>

offMouseleave()

移除船舶鼠标移出事件

html
<script>
  shipControl.offMouseleave()
</script>