antv-l7/docs/api/component/marker.en.md

92 lines
1.6 KiB
Markdown
Raw Normal View History

2019-11-21 13:06:13 +08:00
---
title: Marker
order: 3
---
2020-11-17 10:59:32 +08:00
2020-11-16 15:19:41 +08:00
`markdown:docs/common/style.md`
2019-11-21 13:06:13 +08:00
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
`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` ![L7 Marker](https://gw.alipayobjects.com/zos/basement_prod/b10e0efd-8379-4b04-bcbb-5cfefaa0327f.svg)设置默认 marker 的颜色
- element    `Dom|string`    自定义 marker Dom 节点,可以是 dom 实例,也可以是 dom id
- anchor     `string`  锚点位置   支持 center, top, top-left, top-right, bottom, bottom-left,bottom-                        right,left, right
- offsets    `Array`  偏移量  [ 0, 0 ] 分别表示 X, Y 的偏移量
2019-11-21 13:06:13 +08:00
2019-12-02 15:16:45 +08:00
### 添加到 Scene
2019-11-21 13:06:13 +08:00
```javascript
scene.addMarker(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
#### 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
`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,
2020-03-09 01:04:27 +08:00
}).setLnglat([data[i].x * 1, data[i].y]);
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)
.setPopup(popup);
2019-11-21 13:06:13 +08:00
```
2022-01-17 20:40:10 +08:00
[demo1](../../../examples/tutorial/marker#amap)