Skip to main content

markers

DG.Marker

DG.Marker is used to display clickable/draggable icons on the map.

DG.marker([54.98, 82.89]).addTo(map);

Creation

FactoryDescription
DG.Marker( <LatLng> latlng, <Marker options> options? ) Instantiates a Marker object given a geographical point and optionally an options object.

Options

OptionTypeDefaultDescription
iconIcon*Icon class to use for rendering the marker. See Icon documentation for details on how to customize the marker icon. Set to new DG.Icon.Default() by default.
interactiveBoolean trueIf false, the marker will not emit mouse events and will act as a part of the underlying map.
draggableBoolean falseWhether the marker is draggable with mouse/touch or not.
keyboardBoolean trueWhether the marker can be tabbed to with a keyboard and clicked by pressing enter.
titleString ''Text for the browser tooltip that appear on marker hover (no tooltip by default).
altString ''Text for the alt attribute of the icon image (useful for accessibility).
zIndexOffsetNumber 0By default, marker images zIndex is set automatically based on its latitude. Use this option if you want to put the marker on top of all others (or below), specifying a high value like 1000 (or high negative value, respectively).
opacityNumber 1.0The opacity of the marker.
riseOnHoverBoolean falseIf true, the marker will get on top of others when you hover the mouse over it.
riseOffsetNumber 250The z-index offset used for the riseOnHover feature.
paneString 'markerPane'Map pane where the markers icon will be added.

Events

EventDataDescription
clickMouseEventFired when the user clicks (or taps) the marker.
dblclickMouseEventFired when the user double-clicks (or double-taps) the marker.
mousedownMouseEventFired when the user pushes the mouse button on the marker.
mouseoverMouseEventFired when the mouse enters the marker.
mouseoutMouseEventFired when the mouse leaves the marker.
contextmenuMouseEventFired when the user right-clicks on the marker.
moveEventFired when the marker is moved via setLatLng or by dragging. Old and new coordinates are included in event arguments as oldLatLng, latlng.
Dragging events
EventDataDescription
dragstartEventFired when the user starts dragging the marker.
movestartEventFired when the marker starts moving (because of dragging).
dragEventFired repeatedly while the user drags the marker.
dragendDragEndEventFired when the user stops dragging the marker.
moveendEventFired when the marker stops moving (because of dragging).

Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

Methods

MethodReturnsDescription
getLatLng()LatLngReturns the current geographical position of the marker.
setLatLng( <LatLng> latlng) thisChanges the marker position to the given point.
setZIndexOffset( <Number> offset) thisChanges the zIndex offset of the marker.
setIcon( <Icon> icon) thisChanges the marker icon.
setOpacity( <Number> opacity) thisChanges the opacity of the marker.
bindLabel(<String> content, <Label options> options?)this{/* TODO: translate */}
unbindLabel()this{/* TODO: translate */}
showLabel()this{/* TODO: translate */}
hideLabel()this{/* TODO: translate */}

Popup methods inherited from Layer

Methods inherited from Layer

Methods inherited from Evented

Interaction handlers

Interaction handlers are properties of a marker instance that allow you to control interaction behavior in runtime, enabling or disabling certain features such as dragging (see Handler methods). Example:

marker.dragging.disable();
PropertyTypeDescription
draggingHandlerMarker dragging handler (by both mouse and touch).

DG.Icon

Represents an icon to provide when creating a marker.

var myIcon = DG.icon({
iconUrl: 'my-icon.png',
iconRetinaUrl: 'my-icon@2x.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
shadowUrl: 'my-icon-shadow.png',
shadowRetinaUrl: 'my-icon-shadow@2x.png',
shadowSize: [68, 95],
shadowAnchor: [22, 94],
});

DG.marker([50.505, 30.57], { icon: myIcon }).addTo(map);

Creation

FactoryDescription
DG.icon( <Icon options> options) Creates an icon instance with the given options.

Options

OptionTypeDefaultDescription
iconUrlString null(required) The URL to the icon image (absolute or relative to your script path).
iconRetinaUrlString nullThe URL to a retina sized version of the icon image (absolute or relative to your script path). Used for Retina screen devices.
iconSizePoint nullSize of the icon image in pixels.
iconAnchorPoint nullThe coordinates of the "tip" of the icon (relative to its top left corner). The icon will be aligned so that this point is at the marker's geographical location. Centered by default if size is specified, also can be set in CSS with negative margins.
popupAnchorPoint nullThe coordinates of the point from which popups will "open", relative to the icon anchor.
shadowUrlString nullThe URL to the icon shadow image. If not specified, no shadow image will be created.
shadowRetinaUrlString null
shadowSizePoint nullSize of the shadow image in pixels.
shadowAnchorPoint nullThe coordinates of the "tip" of the shadow (relative to its top left corner) (the same as iconAnchor if not specified).
classNameString ''A custom class name to assign to both icon and shadow images. Empty by default.

Options inherited from Layer

Events

Events inherited from Layer

Popup events inherited from Layer

Methods

MethodReturnsDescription
createIcon(<HTMLElement> oldIcon?)HTMLElementCalled internally when the icon has to be shown, returns a <img> HTML element styled according to the options.
createShadow(<HTMLElement> oldIcon?)HTMLElementAs createIcon, but for the shadow beneath it.

Popup methods inherited from Layer

Methods inherited from Layer

Methods inherited from Evented

DG.DivIcon

Represents a lightweight icon for markers that uses a simple <div> element instead of an image. Inherits from Icon but ignores the iconUrl and shadow options.

// you can set .my-div-icon styles in CSS
var myIcon = DG.divIcon({ className: 'my-div-icon' });

DG.marker([50.505, 30.57], { icon: myIcon }).addTo(map);

Creation

FactoryDescription
DG.DivIcon( <DivIcon options> options ) Creates a DivIcon instance with the given options.

Options

OptionTypeDefaultDescription
htmlString ''Custom HTML code to put inside the div element, empty by default.
bgPosPoint [0, 0]Optional relative position of the background, in pixels

Options inherited from Icon

Options inherited from Layer

Events

Events inherited from Layer

Popup events inherited from Layer

Methods

Methods inherited from Icon

Popup methods inherited from Layer

Methods inherited from Layer

Methods inherited from Evented