ym.modules.provider.Popup
Overview
Used to open pop-ups at specific locations on the map. Use Map.openPopup
to open popups, ensuring only one popup is open at a time (recommended for ease of use), or use Map.addLayer
to open as many as you want.
Example calls
Open a popup and bind it to a marker click in the following way:
Path overlays like polylines have a bindPopup
method. Here is another way to open a popup on a map:
var popup = ym.popup()
.setLatLng(latlng)
.setContent('<p>Hello world!<br />This is a nice popup.</p>')
.openOn(map);
Initialization
Factory: ym.popup(options, source)
Instantiates a popup object with an optional Options object that describes its appearance and position and an optional Source object that is used to provide the popup with a reference to the ILayer to which it refers.
Parameter | Description | Data type | Default value |
---|---|---|---|
options | [optional] | PopupOptions | |
source | [optional] | ILayer |
Parameter: options
You can use Path-options and additionally the following options:
Name | Description | Data type | Default value |
---|---|---|---|
maxWidth | Maximum width of the popup. | int | 300 |
minWidth | Minimum width of the popup. | int | 50 |
maxHeight | If set, a scrollable container of the specified height is created within a popup if its content exceeds this height. | int | null |
autoPan | Set it to false if you do not want the map to perform a move animation to adjust the open popup. | bool | true |
keepInView | Set it to true if you want to prevent users from dragging the popup from the visible area while it is open. | bool | false |
closeButton | Controls the presence of a close button in the popup. | bool | true |
offset | The offset of the popup position. Useful to control the anchor of the popup when opening on some overlays. | Point | Point(0, 6) |
autoPanPaddingTopLeft | The border between the popup and the upper left corner of the map view after automatic moving. | Point | null |
autoPanPaddingBottomRight | The border between the popup and the bottom right corner of the map view after automatic moving. | Point | null |
autoPanPadding | Sets the distance for automatic shifting top left and bottom right to the same value. | Point | Point(5, 5) |
zoomAnimation | Specifies whether the popup should be animated when zooming. Disable it if you have problems with Flash content in popups. | bool | true |
closeOnClick | Set it to false if you want to override the default behavior of the popup when clicking on the map (globally through the Map closePopupOnClick option). | bool | null |
className | A custom class name that is assigned to the popup. | string | '' |
Methods
addTo(map)
Adds the popup to the map.
Parameter | Description | Data type | Default value |
---|---|---|---|
map | Map |
- Return: this
openOn()
Adds the popup to the map and closes the previous one. The same as map.openPopup(popup)
.
Parameter | Description | Data type | Default value |
---|---|---|---|
map | Map |
- Return: this
setLatLng(latlng)
Defines the geographical point where the popup opens.
Parameter | Description | Data type | Default value |
---|---|---|---|
latlng | LatLng |
- Return: this
getLatLng()
Returns the geographic point of the popup.
- Return: LatLng
setContent(htmlContent)
Sets the HTML content of the popup.
Parameter | Description | Data type | Default value |
---|---|---|---|
htmlContent | String or HTMLElement |
- Return: this
getContent()
Returns the content of the popup.
- Return: string or HTMLElement
update()
Updates the popup content, layout, and position. Useful to update the popup when something inside has changed, for example, an image has been loaded.
- Return: this