2019-11-21 13:06:13 +08:00
|
|
|
|
---
|
|
|
|
|
title: popup
|
|
|
|
|
order: 0
|
|
|
|
|
---
|
2019-12-02 15:16:45 +08:00
|
|
|
|
|
2019-11-21 13:06:13 +08:00
|
|
|
|
# popup
|
|
|
|
|
|
|
|
|
|
地图标注信息窗口,用于展示地图要素的属性信息
|
|
|
|
|
|
|
|
|
|
## 构造函数
|
2019-12-02 15:16:45 +08:00
|
|
|
|
|
2019-11-21 13:06:13 +08:00
|
|
|
|
Popup
|
|
|
|
|
|
|
|
|
|
```javascript
|
2019-12-02 15:16:45 +08:00
|
|
|
|
const popup = new L7.Popup(option);
|
2019-11-21 13:06:13 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### option
|
|
|
|
|
|
|
|
|
|
- closeButton
|
|
|
|
|
- closeOnClick
|
|
|
|
|
- maxWidth
|
|
|
|
|
- anchor
|
|
|
|
|
|
|
|
|
|
## 方法
|
|
|
|
|
|
|
|
|
|
#### setLnglat
|
2019-12-02 15:16:45 +08:00
|
|
|
|
|
2020-01-30 23:43:27 +08:00
|
|
|
|
设置 popup 的经纬度位置
|
|
|
|
|
|
|
|
|
|
**参数**:lnglat
|
|
|
|
|
|
|
|
|
|
支持数组
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
[112, 32];
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
经纬度对象
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
{
|
2020-02-01 21:29:32 +08:00
|
|
|
|
lng: 112.323,
|
|
|
|
|
lat: 30.456,
|
2020-01-30 23:43:27 +08:00
|
|
|
|
}
|
|
|
|
|
```
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
popup.setLnglat([112, 32]);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### addTo
|
|
|
|
|
|
2019-12-02 15:16:45 +08:00
|
|
|
|
**参数**:scene 地图 scene 实例
|
|
|
|
|
|
|
|
|
|
将 popup 添加到地图 scene 显示
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
popup.addTo(scene);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### setHtml
|
2019-12-02 15:16:45 +08:00
|
|
|
|
|
2019-11-21 13:06:13 +08:00
|
|
|
|
**参数**:html 字符串
|
|
|
|
|
|
2019-12-02 15:16:45 +08:00
|
|
|
|
设置 popup html 内容
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
```javascript
|
2020-01-30 23:43:27 +08:00
|
|
|
|
var html = `<p>省份
|
|
|
|
|
${feature.s} </p><p>地区
|
|
|
|
|
${feature.m}</p><p>数值
|
|
|
|
|
${feature.t}</p>`;
|
2019-11-21 13:06:13 +08:00
|
|
|
|
popup.setHtml(html);
|
|
|
|
|
```
|
|
|
|
|
|
2020-01-20 18:06:02 +08:00
|
|
|
|
#### setDOMContent
|
|
|
|
|
|
|
|
|
|
- 参数 htmlNode dom 对象
|
|
|
|
|
区别于 setHtml 对象只能传字符串
|
|
|
|
|
|
|
|
|
|
**tips**
|
2020-01-30 23:43:27 +08:00
|
|
|
|
|
2020-01-20 18:06:02 +08:00
|
|
|
|
如果需要将 react 组件渲染到 popup 可以用此方法。
|
|
|
|
|
|
2019-11-21 13:06:13 +08:00
|
|
|
|
#### setText
|
2019-12-02 15:16:45 +08:00
|
|
|
|
|
2019-11-21 13:06:13 +08:00
|
|
|
|
设置 popup 显示文本内容
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
popup.setText('hello world');
|
|
|
|
|
```
|
2020-01-21 12:40:46 +08:00
|
|
|
|
|
2020-01-21 11:56:04 +08:00
|
|
|
|
#### open
|
|
|
|
|
|
2020-01-21 12:40:46 +08:00
|
|
|
|
显示 popup
|
2020-01-21 11:56:04 +08:00
|
|
|
|
|
2020-01-21 12:40:46 +08:00
|
|
|
|
```javascript
|
2020-01-21 11:56:04 +08:00
|
|
|
|
popup.open();
|
|
|
|
|
```
|
2020-01-21 12:40:46 +08:00
|
|
|
|
|
2020-01-21 11:56:04 +08:00
|
|
|
|
#### close
|
2020-01-21 12:40:46 +08:00
|
|
|
|
|
|
|
|
|
显示 popup
|
2020-01-21 11:56:04 +08:00
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
popup.close();
|
|
|
|
|
```
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
2020-01-21 11:56:04 +08:00
|
|
|
|
#### open
|
|
|
|
|
|
|
|
|
|
显示 popup
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
popup.open();
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### close
|
|
|
|
|
|
|
|
|
|
显示 popup
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
popup.close();
|
|
|
|
|
```
|
|
|
|
|
|
2019-11-21 13:06:13 +08:00
|
|
|
|
#### remove
|
2019-12-02 15:16:45 +08:00
|
|
|
|
|
|
|
|
|
移除 popup
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
```javascript
|
2019-12-02 15:16:45 +08:00
|
|
|
|
popup.remove();
|
2019-11-21 13:06:13 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 事件
|
|
|
|
|
|
2020-01-21 11:56:04 +08:00
|
|
|
|
### open
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
popup.on('open', () => {});
|
|
|
|
|
```
|
|
|
|
|
|
2019-11-21 13:06:13 +08:00
|
|
|
|
#### close
|
|
|
|
|
|
|
|
|
|
```javascript
|
2019-12-02 15:16:45 +08:00
|
|
|
|
popup.on('close', () => {});
|
2019-11-21 13:06:13 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 示例代码
|
|
|
|
|
|
2019-12-02 15:16:45 +08:00
|
|
|
|
#### 添加 popup
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
var html = '<p>'+feature.m+'</p>';
|
|
|
|
|
const new L7.Popup().setLnglat([112, 32]).setHTML(html).addTo(scene);
|
|
|
|
|
```
|
|
|
|
|
|
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/point/column)
|
|
|
|
|
[demo2](../../../examples/line/path)
|