Popup
在地图指定位置上弹出窗口。
示例
//在一个marker上弹出气泡
marker.bindPopup(popupContent).openPopup();
//弹出气泡可以和各种图层对象绑定使用,也可以单独使用
var popup = W.popup()
.setLatLng(latlng)
.setContent('<p>Hello world!<br />This is a nice popup.</p>')
.openOn(map);
构造函数
| 方法 | 描述 |
|---|---|
| W.popup( < Popup options > options?,< Layer > source?) | options可设置外观、位置。 可选的souce 用来指定相关的图层 |
构造选项
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| maxWidth | Number | 300 | 弹出气泡最大宽度, 单位是像素 |
| minWidth | Number | 50 | 弹出气泡最小宽度, 单位是像素 |
| maxHeight | Number | null | 如果指定的该值,当内容过多时,会出现滚动条 |
| autoPan | Boolean | true | 如果不想在弹出气泡时出现移动动画,将该值设置为false |
| autoPanPaddingTopLeft | Point | null | 自动平移地图后,气泡离左上角的距离 |
| autoPanPaddingBottomRight | Point | null | 自动平移地图后,气泡到右下角的距离 |
| autoPanPadding | Point | Point(5, 5) | 同时设置自动平移后,气泡到左上角及右下角的距离 |
| keepInView | Boolean | false | 设置为true之后,可以防止通过移动地图导致气泡在屏幕之外 |
| closeButton | Boolean | true | 在气泡中显示关闭按钮 |
| closeOnClick | Boolean | * | 在点击地图时,气泡是否自动关闭。默认值取Map的closePopupOnClick选项。 |
| autoClose | Boolean | true | 默认情况下其他气泡打开时,该气泡会自动关闭,如果不想要这种默认行为,将该值设置为false |
| className | String | '' | 给气泡设置自定义css类 |
方法
| 方法 | 返回值 | 描述 |
|---|---|---|
| getLatLng() | LatLng | 获取气泡坐标位置 |
| setLatLng(<LatLng> latlng) | this | 设置气泡弹出坐标位置 |
| getContent() | String/HTMLElement | 获取气泡内容元素 |
| setContent(< String / HTMLElement / Function > htmlContent) | this | 设置气泡内容,如果传入的是一个函数,设置该函数时会传入source layer,执行该函数后必须返回一个String或者HTMLElement |
| getElement() | String / HTMLElement | 同 getContent() |
| update() | null | 更新气泡的内容、位置,当气泡内置的某些属性发生变化(如图片已加载)时 |
| isOpen() | Boolean | 判断该气泡是否在地图上打开显示 |
| bringToFront() | this | 将该气泡放置到其他气泡前面 (相同的地图面板) |
| bringToBack() | this | 将该气泡放置到其他气泡后面 (相同的地图面板) |
| openOn(<Map> map) | this | 将气泡打开,同map.openPopup(popup) |