Skip to content

InfoWindow

InfoWindow 是地图气泡窗口,继承自 UIComponent。它在地图上以浮层气泡的形式展示内容,常用于点击要素后显示详情,包含标题与内容区,并可组合自定义 HTML。

js
import { InfoWindow } from "maptalks";

const infoWindow = new InfoWindow({
  title: "Hello",
  content: "<div>World</div>"
});

infoWindow.addTo(map).show(coordinate);

构造函数

js
new InfoWindow(options)

参数:

  • options — 气泡窗口配置项,其部分属性同 InfoWindow.options 配置项。

options 配置项

配置名类型描述默认值
titleString / HTMLElement气泡标题null
contentString / HTMLElement气泡内容null
widthString气泡宽度'auto'
minHeightNumber气泡最小高度120
autoPanBoolean显示时是否自动平移地图true
autoCloseOnString触发自动关闭的事件null
autoOpenOnString触发自动打开的事件'click'
customBoolean是否使用自定义内容false
enableTemplateBoolean是否使用默认模板false

成员方法

  • setTitle(title): InfoWindow — 设置气泡标题。
  • getTitle(): String — 获取气泡标题。
  • setContent(content): InfoWindow — 设置气泡内容。
  • getContent(): String — 获取气泡内容。
  • addTo(owner): InfoWindow — 将气泡挂载到 owner 上。
  • show(coordinate): InfoWindow — 在指定坐标处显示气泡。
  • getOffset(): Point — 获取气泡偏移。
  • getTransformOrigin(): String — 获取气泡的变换原点。

事件

  • contentchange — 气泡内容改变时触发。