2019-11-21 13:06:13 +08:00
|
|
|
|
---
|
|
|
|
|
title: Marker
|
|
|
|
|
order: 3
|
|
|
|
|
---
|
|
|
|
|
|
2019-12-02 15:16:45 +08:00
|
|
|
|
Marker 地图标注 目前只支持 2D dom 标注
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
## 构造函数
|
|
|
|
|
|
2019-12-02 15:16:45 +08:00
|
|
|
|
Marker<br />`const Marker = new L7.Marker(option)`
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
#### option
|
|
|
|
|
|
2019-12-02 15:16:45 +08:00
|
|
|
|
- color `string` ![map-marker.png](https://cdn.nlark.com/yuque/0/2019/png/104251/1566814628445-4f3152c8-71d1-4908-a651-246c17e507b5.png#align=left&display=inline&height=32&name=map-marker.png&originHeight=32&originWidth=32&size=635&status=done&width=32) 设置默认 marker 的颜色
|
|
|
|
|
- element `Dom|string` 自定义 marker Dom 节点,可以是 dom 实例,也可以是 dom id
|
|
|
|
|
- anchor `string` 锚点位置 支持 center, top, top-left, top-right, bottom, bottom-left,bottom- right,left, right
|
|
|
|
|
- offset `Array` 偏移量 [ 0, 0 ] 分别表示 X, Y 的偏移量
|
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
|
|
|
|
|
|
|
|
|
#### 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
|
|
|
|
|
|
|
|
|
#### 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
|
|
|
|
|
|
|
|
|
## 示例代码
|
|
|
|
|
|
2019-12-02 15:16:45 +08:00
|
|
|
|
#### 默认 Marker
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
2019-12-02 15:16:45 +08:00
|
|
|
|
\*\*<br />`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');
|
2019-12-02 15:16:45 +08:00
|
|
|
|
el.className = 'lableclass';
|
|
|
|
|
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);
|
|
|
|
|
```
|