InfoWindow
AMap.InfoWindow
Info window, the map can only display one info window at a time. It is recommended to set the size of the info window through style display. Construct an info window object and set the properties of the info window object through InfoOptions
new AMap.InfoWindow(opts: InfoOptions)Parameter
options (InfoOptions): Info window parameters
Demo
var infoWindow = new AMap.InfoWindow({
content: "Information window",
anchor: "bottom-center",
});
// Open the information window on the map
infoWindow.open(map, map.getCenter());Method
open(map, position, height)
Open the information window
Parameter:
map (Map) Map object to be displayed in the info window
position (Vector2) Base position of the info window display, optional. If omitted, the base position is displayed according to the position attribute. If set, it will override the position set by the position attribute
height (number) Height of the info window, optional
Demo:
infoWindow.open(map, [100.491422, 13.749313]);close()
Close info window
Demo:
infoWindow.close();getIsOpen()
Get whether the info window is open
return value: (boolean) Boolean value, whether it is in the open state
Demo:
infoWindow.getIsOpen();setSize(size)
Set information window size (effective when isCustom is false)
Parameter: size (Size | Vector2) Information window size
Demo:
infoWindow.setSize([10, 10]);getSize()
Get information window size
return value: (Vector2) Info window size
Demo:
infoWindow.getSize();setContent(content)
Set the display content of the info window
Parameter: content (HTMLElement | string) Display content, the value is a user-defined DOM node or HTML fragment of a DOM node
Demo:
var content = [
"<div class='info'>This is a custom window",
"So you can customize both the content and the style",
"<img src='https://webapi.amap.com/images/sharp.png'></div>",
];
infoWindow.setContent(content);Set the style
.info {
background-color: #fff;
text-align: center;
padding: 10px;
position: relative;
border: 1px solid #b9b9b9;
}
.info img {
width: 30px;
height: 23px;
position: absolute;
left: calc(50% - 15px);
bottom: -23px;
}getContent()
Get the display content of the info window
return value: (HTMLElement | string) Display content of the info window
Demo:
infoWindow.getContent();setAnchor(anchor)
Set the anchor point of the info window. Default: 'bottom-center'. Options: 'top-left'|'top-center'|'top-right'|'middle-left'|'center'|'middle-right'|'bottom-left'|'bottom-center'|'bottom-right'
Parameter: anchor (string) Anchor position, e.g., 'top-left'
Demo:
infoWindow.setAnchor('top-left');getAnchor()
Get information window anchor orientation
return value: (string) Window anchor orientation
Demo:
infoWindow.getAnchor();getExtData()
Get user-defined attributes
return value: (any | undefined) The value set by the extData attribute, returns null if not set
Demo:
infoWindow.getExtData();setExtData(extData)
Set user-defined attributes
Parameter: extData (any) User-defined data, supporting any data type of JavaScript API
Demo:
infoWindow.setExtData({id:1});Event
For event object property descriptions, go to:MapsEvent