Popup
Pop-up component.
new Popup(options: Object?)
parameter
| name | type | describe | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | Object | Requiredparameter
|
Case
var markerHeight = 50, markerRadius = 10, linearOffset = 25;
var popupOffsets = {
'top': [0, 0],
'top-left': [0,0],
'top-right': [0,0],
'bottom': [0, -markerHeight],
'bottom-left': [linearOffset, (markerHeight - markerRadius + linearOffset) * -1],
'bottom-right': [-linearOffset, (markerHeight - markerRadius + linearOffset) * -1],
'left': [markerRadius, (markerHeight - markerRadius) * -1],
'right': [-markerRadius, (markerHeight - markerRadius) * -1]
};
var popup = new mapmost.Popup({offset: popupOffsets, className: 'my-class'})
.setLngLat(e.lngLat)
.setHTML("<h1>Hello World!</h1>")
.setMaxWidth("300px")
.addTo(map);
Instance members
addTo
Add a popup to the map.
parameter
| name | type | describe |
|---|---|---|
| map | Map | Requiredto add Popup of Mapmost GL JS map. |
Case
var marker = new mapmost.Popup()
.setLngLat([30.5, 50.5])
.addTo(map); // Add a popup to the map
getElement
returnPopupof HTML element.
Case
// Revise `Popup` The font size of the element
const popup = new mapmost.Popup()
.setLngLat([-96, 37.8])
.setHTML("<p>Hello World!</p>")
.addTo(map);
const popupElem = popup.getElement();
popupElem.style.fontSize = "25px";
getLngLat
Returns the geographical location of the popup’s anchor.
The returned longitude will be passed previously setLngLat Set the longitude based on 360 changes in multiples of degrees, this is because Popup The longitude of the anchor should be completely surrounded by the surrounding area to ensure that the pop-up window can be displayed on the screen.
Case
const lngLat = popup.getLngLat();
getMaxWidth
Returns the maximum width of the popup window.
Case
const maxWidth = popup.getMaxWidth();
isOpen
If the pop-up window is in the pop-up state, it is true ,If it is closed, it is false。
Case
const isPopupOpen = popup.isOpen();
remove
Removed popup from adding map.
Case
var popup = new mapmost.Popup().addTo(map);
popup.remove();
setDOMContent
Set the pop-up window content to DOM Elements provided as nodes.
parameter
| name | type | describe |
|---|---|---|
| htmlNode | Node | RequiredUsed as pop-up window content DOM node. |
Case
// Generate an element with popup content
var div = window.document.createElement('div');
div.innerHTML = 'Hello, world!';
var popup = new mapmost.Popup()
.setLngLat(e.lngLat)
.setDOMContent(div)
.addTo(map);
setHTML
Set the popup content to be provided as a string HTML。
This method will not proceed HTML Filter or sanitize so it can only be used with trusted content.
parameter
| name | type | describe |
|---|---|---|
| html | String | RequiredUsed to represent pop-up window content HTML string. |
Case
const popup = new mapmost.Popup()
.setLngLat(e.lngLat)
.setHTML("<h1>Hello World!</h1>")
.addTo(map);
setLngLat
After setting the geographical location of the anchor of the pop-up window, move the pop-up window there. replaced trackPointer() effect.
parameter
| name | type | describe |
|---|---|---|
| lnglat | LngLatLike | RequiredSet the location of the pop-up window. |
Case
popup.setLngLat([-122.4194, 37.7749]);
setMaxWidth
Set the maximum width of the pop-up window. Essentially setting up CSS of max-width property.
parameter
| name | type | describe |
|---|---|---|
| maxWidth | String | RequiredA string representing the maximum width value. |
Case
popup.setMaxWidth('50');
setText
Set the content of the pop-up window to a string of text.
This feature will be available in DOM Create one within Text node, thus making the original HTML Cannot be inserted. When the pop-up content is provided by the user, this method can be used as a target XSS safety protection measures.
parameter
| name | type | describe |
|---|---|---|
| text | String | RequiredThe text content of the pop-up window. |
Case
var popup = new mapmost.Popup()
.setLngLat(e.lngLat)
.setText('Hello, world!')
.addTo(map);
trackPointer
Use the anchor of the popup to track the position of the cursor on the screen with the help of a pointing device (hidden in touch mode). replaced setLngLat effect. In most cases, here closeOnClick and closeButton should be set to false 。
Case
const popup = new mapmost.Popup({closeOnClick: false, closeButton: false})
.setHTML("<h1>Hello World!</h1>")
.trackPointer()
.addTo(map);
event
open
Triggered when the pop-up window is opened manually or programmatically.parameter
| name | type | describe |
|---|---|---|
| popup | Popup | RequiredThe opened object. |
close
Triggered when the pop-up window is closed manually or programmatically.parameter
| name | type | describe |
|---|---|---|
| popup | Popup | RequiredThe object is closed. |