2019-11-21 13:06:13 +08:00
|
|
|
|
---
|
2020-03-08 17:31:56 +08:00
|
|
|
|
title: Popup 信息框
|
2019-11-21 13:06:13 +08:00
|
|
|
|
order: 0
|
|
|
|
|
---
|
2020-11-17 10:59:32 +08:00
|
|
|
|
|
2020-11-16 15:19:41 +08:00
|
|
|
|
`markdown:docs/common/style.md`
|
2019-12-02 15:16:45 +08:00
|
|
|
|
|
2019-11-21 13:06:13 +08:00
|
|
|
|
地图标注信息窗口,用于展示地图要素的属性信息
|
|
|
|
|
|
|
|
|
|
## 构造函数
|
2019-12-02 15:16:45 +08:00
|
|
|
|
|
2019-11-21 13:06:13 +08:00
|
|
|
|
Popup
|
|
|
|
|
|
|
|
|
|
```javascript
|
2021-04-06 18:00:53 +08:00
|
|
|
|
const option = {};
|
2019-12-02 15:16:45 +08:00
|
|
|
|
const popup = new L7.Popup(option);
|
2019-11-21 13:06:13 +08:00
|
|
|
|
```
|
|
|
|
|
|
2021-04-06 18:00:53 +08:00
|
|
|
|
### option
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
2021-07-02 11:07:09 +08:00
|
|
|
|
- closeButton 是否显示关闭按钮,布尔值,默认为 true。
|
|
|
|
|
- closeButtonOffsets 显示关闭按钮时生效,[number, number],默认为 [0, 0],以右上角为起始点。
|
|
|
|
|
- closeOnClick 是否在点击地图的时候关闭弹框,布尔值,默认为 true
|
|
|
|
|
- maxWidth 弹框最宽值,默认为 240px
|
|
|
|
|
- anchor 弹框锚点,默认值为 bottom,可选值有 center、top、top-left、left、bottom-left、bottom、bottom-right、right、top-right
|
2019-11-21 13:06:13 +08:00
|
|
|
|
|
2020-03-08 17:31:56 +08:00
|
|
|
|
#### 添加到地图
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
scene.addPopup(popup);
|
|
|
|
|
```
|
|
|
|
|
|
2019-11-21 13:06:13 +08:00
|
|
|
|
## 方法
|
|
|
|
|
|
|
|
|
|
#### 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-03 17:26:19 +08:00
|
|
|
|
const lnglat = {
|
2020-02-03 20:34:30 +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]);
|
|
|
|
|
```
|
2020-03-08 18:04:13 +08:00
|
|
|
|
|
2020-02-21 22:55:11 +08:00
|
|
|
|
#### 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>`;
|
2020-02-21 22:55:11 +08:00
|
|
|
|
popup.setHTML(html);
|
2019-11-21 13:06:13 +08:00
|
|
|
|
```
|
|
|
|
|
|
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
|
|
|
|
|
2021-07-02 11:07:09 +08:00
|
|
|
|
#### setMaxWidth
|
|
|
|
|
|
|
|
|
|
设置 popup 最大宽度
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
popup.setMaxWidth('300px');
|
|
|
|
|
```
|
|
|
|
|
|
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
|
|
|
|
|
2020-03-14 12:31:09 +08:00
|
|
|
|
关闭 popup
|
2020-01-21 11:56:04 +08:00
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
popup.close();
|
|
|
|
|
```
|
2020-03-14 21:18:44 +08:00
|
|
|
|
|
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>';
|
2020-02-21 22:55:11 +08:00
|
|
|
|
const popup= new L7.Popup().setLnglat([112, 32]).setHTML(html);
|
|
|
|
|
scene.addPopup(popup);
|
2019-11-21 13:06:13 +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/point/column)
|
|
|
|
|
[demo2](../../../examples/line/path)
|