Skip to content

UIComponent

UIComponent is the abstract base class for DOM-based UI components. It extends Class and Eventable. UIMarker, InfoWindow, Menu, ToolTip and so on all extend it. It attaches a set of DOM elements to a map or a geometry object and provides common capabilities such as show/hide, positioning and collision. The static isSupport method tells whether an object supports hosting a UI component.

js
import { UIComponent } from "maptalks";
// UIComponent is an abstract base class, usually a subclass is used
const marker = new UIMarker(coordinate, { content: "<div>Hello</div>" }).addTo(map);

Constructor

js
new UIComponent(options)

Parameters:

  • options — UI component options.

options

NameTypeDescriptionDefault
animationStringThe animation effect on show/hide, one of fade, scale or fade,scale'scale'
animationDurationNumberDuration of the animation, in milliseconds500
singleBooleanWhether a single instance per object is kepttrue
eventsPropagationBooleanWhether UI events are propagatedfalse
eventsToStopArrayEvents whose bubbling is blocked (effective when eventsPropagation is true)null
autoPanBooleanWhether to auto-pan the map to fit the component when shownfalse
dxNumberHorizontal offset0
dyNumberVertical offset0
collisionBooleanWhether the component participates in collision detectionfalse
zIndexNumberThe z-index of the component0
visibleBooleanWhether the component is visibletrue

Member Methods

  • addTo(owner): UIComponent — Attaches the component to owner (a map or a geometry object).
  • getMap(): Map — Gets the map the component is attached to.
  • show(coordinate): UIComponent — Shows the component at the given coordinate.
  • hide(): UIComponent — Hides the component.
  • isVisible(): boolean — Whether the component is visible.
  • remove(): UIComponent — Removes the component from its host.
  • getSize(): Size — Gets the component's size.
  • getDOM(): HTMLElement — Gets the component's DOM element.
  • setZIndex(z): UIComponent — Sets the component's z-index.
  • getPosition(): Point — Gets the component's current position.
  • getOwner(): Object — Gets the component's host object.

Static Methods

  • isSupport(owner): boolean — Whether owner supports hosting a UI component.

Events

  • add — Fired when the component is attached.
  • showstart — Fired when the component starts to show.
  • showend — Fired when the component finishes showing.
  • hide — Fired when the component is hidden.
  • remove — Fired when the component is removed.
  • mouseover — Fired when the mouse enters the component.
  • mouseout — Fired when the mouse leaves the component.