Class: InfoWindow

InfoWindow

用于在地图上弹出一个详细信息展示窗体

// 使用默认弹窗模板
const infoWindow = new InfoWindow({
    // element: ele,
    defaultTemplate: "popup",
    positioning: "bottom-center"
  });
this.$map.addOverlay(infoWindow);
this.$map.on("click", evt => {
  infoWindow.open(evt.coordinate, evt.coordinate);
});

new InfoWindow(options)

overlay/InfoWindow.js, line 25

构造详细信息展示窗体。

Name Type Description
options Object

通过options指定窗体样式

Name Type Default Description
element HTMLElement

自定义的覆盖元素,如果采用默认模板,则不需要设置

position Array

信息窗体显示基点位置

positioning String "bottom-center" optional

定义覆盖相对于其位置属性的实际位置。 可选值为:'bottom-left', 'bottom-center', 'bottom-right', 'center-left', 'center-center', 'center-right', 'top-left', 'top-center', and 'top-right'.

offset Array [0, 0] optional

信息窗体显示位置偏移量。

autoPan Boolean true optional

如果设置为true,则调用setPosition时将平移贴图, 以便覆盖在当前视口中完全可见。

defaultTemplate String

默认模板设置,若采用默认模板则自定义的element无效, "popup"--默认弹窗,"tooltip"--默认提示框

className String

弹窗容器(父元素)的类名

zIndex Number 0 optional

弹窗显示的顺序

content String | HTMLElement "" optional

采用默认模板时,才有效,指定模板内容

备注

更多的属性方法,请参考链接内容:https://openlayers.org/en/latest/apidoc/module-ol_Overlay-Overlay.html

Classes

InfoWindow

Methods

close()

overlay/InfoWindow.js, line 99

关闭信息窗体,只有当使用默认模板时,才生效

getOffset(){Array}

overlay/InfoWindow.js, line 179

获取放置弹窗时使用的像素偏移量

Returns:
Type Description
Array 放置弹窗时使用的像素偏移量。

getPosition(){Array}

overlay/InfoWindow.js, line 139

获取弹窗位置

Returns:
Type Description
Array 弹窗位置,经纬度数组

getPositioning(){String}

overlay/InfoWindow.js, line 160

获取弹窗相对于其position属性的实际放置方式

Returns:
Type Description
String 弹窗相对于其position属性的实际放置方式。

getZIndex(){Number}

overlay/InfoWindow.js, line 121

获取弹窗的显示顺序zIndex值

Returns:
Type Description
Number 弹窗显示顺序zIndex值

open(position, content)

overlay/InfoWindow.js, line 80

在地图的指定位置打开信息窗体,只有当使用默认模板时,才生效

Name Type Description
position Array

弹窗的经纬度位置

content String | HTMLElement

弹窗的内容,可以是HTML要素字符串或者HTMLElement对象

setOffset(offset)

overlay/InfoWindow.js, line 170

设置放置弹窗时使用的像素偏移量。数组中的第一个元素是水平偏移量。 正值将弹窗右移。数组中的第二个元素是垂直偏移量。正值会将弹窗向下移动。

Name Type Description
offset Array

放置弹窗时使用的像素偏移量。

setPosition(position)

overlay/InfoWindow.js, line 130

设置弹窗位置

Name Type Description
position Array

弹窗位置,经纬度数组

setPositioning(positioning)

overlay/InfoWindow.js, line 151

设置定义弹窗相对于其position属性的实际放置方式

Name Type Description
positioning String

定义弹窗相对于其position属性的实际放置方式。 当前默认使用的positioning值是'bottom-center'。可以通过此方法设置其他值,'bottom-left', 'bottom-center','bottom-right','center-left','center-center','center-right', 'top-left','top-center',和'top-right'。

setZIndex(zIndex)

overlay/InfoWindow.js, line 108

设置弹窗的显示顺序

Name Type Description
zIndex Number

弹窗渲染的z-index属性