2019-11-21 13:06:13 +08:00
|
|
|
|
---
|
|
|
|
|
title: Marker
|
|
|
|
|
order: 3
|
|
|
|
|
---
|
|
|
|
|
|
2020-01-30 23:43:27 +08:00
|
|
|
|
Marker 地图标注 目前只支持 2D Dom 标注
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
## 构造函数
|
|
|
|
|
|
2020-01-07 15:55:55 +08:00
|
|
|
|
Marker
|
|
|
|
|
|
|
|
|
|
`const Marker = new L7.Marker(option)`
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
#### option
|
|
|
|
|
|
2020-01-30 23:43:27 +08:00
|
|
|
|
- color `string`
|
|
|
|
|
![map-marker.png](https://gw.alipayobjects.com/mdn/antv_site/afts/img/A*BJ6cTpDcuLcAAAAAAAAAAABkARQnAQ) 设置默认 marker 的颜色
|
2019-12-02 15:16:45 +08:00
|
|
|
|
- element `Dom|string` 自定义 marker Dom 节点,可以是 dom 实例,也可以是 dom id
|
2020-01-20 18:06:02 +08:00
|
|
|
|
- anchor `string` 锚点位置 支持 center, top, top-left, top-right, bottom, bottom-left,bottom-right,left, right
|
2019-12-02 15:16:45 +08:00
|
|
|
|
- offset `Array` 偏移量 [ 0, 0 ] 分别表示 X, Y 的偏移量
|
2020-01-06 11:08:12 +08:00
|
|
|
|
- extData 用户自定义属性,支持任意数据类型,存储 marker 属性信息
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
## 方法
|
|
|
|
|
|
|
|
|
|
#### setLnglat
|
2019-12-02 15:16:45 +08:00
|
|
|
|
|
|
|
|
|
设置 marker 经纬度位置
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
#### addTo
|
2019-12-02 15:16:45 +08:00
|
|
|
|
|
|
|
|
|
将 marker 添加到地图 Scene
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
#### remove
|
2019-12-02 15:16:45 +08:00
|
|
|
|
|
|
|
|
|
移除 marker
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
#### getElement
|
2019-12-02 15:16:45 +08:00
|
|
|
|
|
|
|
|
|
获取 marker dom Element
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
2020-01-20 18:06:02 +08:00
|
|
|
|
### setElement
|
|
|
|
|
|
|
|
|
|
- element `dom`
|
|
|
|
|
|
|
|
|
|
设置 element 通过此方法更新 Marker 样式
|
|
|
|
|
|
2019-11-21 13:06:13 +08:00
|
|
|
|
#### getLngLat
|
2019-12-02 15:16:45 +08:00
|
|
|
|
|
|
|
|
|
获取 marker 经纬度坐标
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
#### togglePopup
|
2019-12-02 15:16:45 +08:00
|
|
|
|
|
|
|
|
|
开启或者关闭 marker 弹出框
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
2020-01-20 18:06:02 +08:00
|
|
|
|
#### openPopup
|
|
|
|
|
|
|
|
|
|
打开 Popup
|
|
|
|
|
|
|
|
|
|
### closePopup
|
|
|
|
|
|
|
|
|
|
关闭 popup
|
|
|
|
|
|
2019-11-21 13:06:13 +08:00
|
|
|
|
#### setPopup
|
2019-12-02 15:16:45 +08:00
|
|
|
|
|
|
|
|
|
为 marker 设置 popup
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
#### getPopup
|
|
|
|
|
|
2019-12-02 15:16:45 +08:00
|
|
|
|
获取 marker 弹出框
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
2020-01-06 11:08:12 +08:00
|
|
|
|
#### getExtData()
|
|
|
|
|
|
|
|
|
|
获取用户自定义数据
|
|
|
|
|
|
|
|
|
|
#### setExtData(data)
|
|
|
|
|
|
|
|
|
|
设置用户自定义数据
|
|
|
|
|
|
2019-11-21 13:06:13 +08:00
|
|
|
|
## 示例代码
|
|
|
|
|
|
2019-12-02 15:16:45 +08:00
|
|
|
|
#### 默认 Marker
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
2020-01-06 11:08:12 +08:00
|
|
|
|
`const marker = new L7.Marker({color:'blue'})`
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
2019-12-02 15:16:45 +08:00
|
|
|
|
#### 自定义 Marker
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
var el = document.createElement('label');
|
2020-01-17 00:40:37 +08:00
|
|
|
|
el.className = 'labelclass';
|
2019-12-02 15:16:45 +08:00
|
|
|
|
el.textContent = data[i].v;
|
|
|
|
|
el.style.background = getColor(data[i].v);
|
|
|
|
|
new L7.Marker({
|
|
|
|
|
element: el,
|
|
|
|
|
})
|
|
|
|
|
.setLnglat([data[i].x * 1, data[i].y])
|
|
|
|
|
.addTo(scene);
|
2019-11-21 13:06:13 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 设置 popup
|
|
|
|
|
|
|
|
|
|
```javascript
|
2019-12-02 15:16:45 +08:00
|
|
|
|
var popup = new L7.Popup({
|
|
|
|
|
anchor: 'left',
|
|
|
|
|
}).setText(item.name);
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
new L7.Marker({
|
2019-12-02 15:16:45 +08:00
|
|
|
|
element: el,
|
|
|
|
|
})
|
|
|
|
|
.setLnglat(item.coordinates)
|
2019-11-21 13:06:13 +08:00
|
|
|
|
.setPopup(popup)
|
|
|
|
|
.addTo(scene);
|
|
|
|
|
```
|
2020-01-06 11:08:12 +08:00
|
|
|
|
|
|
|
|
|
## 事件
|
|
|
|
|
|
|
|
|
|
### 鼠标事件
|
|
|
|
|
|
|
|
|
|
- mousemove
|
|
|
|
|
- click
|
|
|
|
|
- mousedown
|
|
|
|
|
- mouseup
|
|
|
|
|
- dblclick
|
|
|
|
|
- contextmenu
|
|
|
|
|
- mouseover
|
|
|
|
|
- mouseout
|
|
|
|
|
|
|
|
|
|
事件返回数据
|
|
|
|
|
|
|
|
|
|
- target 事件触发源
|
|
|
|
|
- data extData 用户自定义数据
|
|
|
|
|
- lnglat marker 经纬度
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
marker.on('click', (e) => {});
|
|
|
|
|
```
|
2020-01-19 20:45:21 +08:00
|
|
|
|
|
2020-01-19 20:22:30 +08:00
|
|
|
|
## demo 地址
|
2020-01-19 20:45:21 +08:00
|
|
|
|
|
2020-01-19 20:22:30 +08:00
|
|
|
|
[demo1](../../../examples/tutorial/marker)
|