wrld.js

Layer

A set of methods from the Layer base class that all Leaflet layers use. Inherits all methods, options and events from L.Evented.

Usage example

var layer = L.Marker(latlng).addTo(map);
layer.addTo(map);
layer.remove();

Options

Option Type Default Description
pane String 'overlayPane' By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default.

Events

Event Data Description
add Event Fired after the layer is added to a map
remove Event Fired after the layer is removed from a map

Popup events

Event Data Description
popupopen PopupEvent Fired when a popup bound to this layer is opened
popupclose PopupEvent Fired when a popup bound to this layer is closed

Tooltip events

Event Data Description
tooltipopen TooltipEvent Fired when a tooltip bound to this layer is opened.
tooltipclose TooltipEvent Fired when a tooltip bound to this layer is closed.

Methods

Classes extending L.Layer will inherit the following methods:
Method Returns Description
addTo(<Map> map) this

Adds the layer to the given map

remove() this

Removes the layer from the map it is currently active on.

removeFrom(<Map> map) this

Removes the layer from the given map

getPane(<String> name?) HTMLElement

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

Popup methods

All layers share a set of methods convenient for binding popups to it.
var layer = L.Polygon(latlngs).bindPopup('Hi There!').addTo(map);
layer.openPopup();
layer.closePopup();

Popups will also be automatically opened when the layer is clicked on and closed when the layer is removed from the map or another popup is opened.

Method Returns Description
bindPopup(<String|HTMLElement|Function|Popup> content, <Popup options> options?) this

Binds a popup to the layer with the passed content and sets up the neccessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

unbindPopup() this

Removes the popup previously bound with bindPopup.

openPopup(<LatLng> latlng?) this

Opens the bound popup at the specificed latlng or at the default popup anchor if no latlng is passed.

closePopup() this

Closes the popup bound to this layer if it is open.

togglePopup() this

Opens or closes the popup bound to this layer depending on its current state.

isPopupOpen() boolean

Returns true if the popup bound to this layer is currently open.

setPopupContent(<String|HTMLElement|Popup> content) this

Sets the content of the popup bound to this layer.

getPopup() Popup

Returns the popup bound to this layer.

Tooltip methods

All layers share a set of methods convenient for binding tooltips to it.
var layer = L.Polygon(latlngs).bindTooltip('Hi There!').addTo(map);
layer.openTooltip();
layer.closeTooltip();
Method Returns Description
bindTooltip(<String|HTMLElement|Function|Tooltip> content, <Tooltip options> options?) this

Binds a tooltip to the layer with the passed content and sets up the neccessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

unbindTooltip() this

Removes the tooltip previously bound with bindTooltip.

openTooltip(<LatLng> latlng?) this

Opens the bound tooltip at the specificed latlng or at the default tooltip anchor if no latlng is passed.

closeTooltip() this

Closes the tooltip bound to this layer if it is open.

toggleTooltip() this

Opens or closes the tooltip bound to this layer depending on its current state.

isTooltipOpen() boolean

Returns true if the tooltip bound to this layer is currently open.

setTooltipContent(<String|HTMLElement|Tooltip> content) this

Sets the content of the tooltip bound to this layer.

getTooltip() Tooltip

Returns the tooltip bound to this layer.

Extension methods

Every layer should extend from L.Layer and (re-)implement the following methods.
Method Returns Description
onAdd(<Map> map) this

Should contain code that creates DOM elements for the layer, adds them to map panes where they should belong and puts listeners on relevant map events. Called on map.addLayer(layer).

onRemove(<Map> map) this

Should contain all clean up code that removes the layer's elements from the DOM and removes listeners previously added in onAdd. Called on map.removeLayer(layer).

getEvents() Object

This optional method should return an object like { viewreset: this._reset } for addEventListener. The event handlers in this object will be automatically added and removed from the map with your layer.

getAttribution() String

This optional method should return a string containing HTML to be shown on the Attribution control whenever the layer is visible.

beforeAdd(<Map> map) this

Optional method. Called on map.addLayer(layer), before the layer is added to the map, before events are initialized, without waiting until the map is in a usable state. Use for early initialization only.

Method Returns Description
on(<String> type, <Function> fn, <Object> context?) this

Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').

on(<Object> eventMap) this

Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}

off(<String> type, <Function> fn?, <Object> context?) this

Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.

off(<Object> eventMap) this

Removes a set of type/listener pairs.

off() this

Removes all listeners to all events on the object.

fire(<String> type, <Object> data?, <Boolean> propagate?) this

Fires an event of the specified type. You can optionally provide an data object — the first argument of the listener function will contain its properties. The event might can optionally be propagated to event parents.

listens(<String> type) Boolean

Returns true if a particular event type has any listeners attached to it.

once() this

Behaves as on(…), except the listener will only get fired once and then removed.

addEventParent(<Evented> obj) this

Adds an event parent - an Evented that will receive propagated events

removeEventParent(<Evented> obj) this

Removes an event parent, so it will stop receiving propagated events

addEventListener() this

Alias to on(…)

removeEventListener() this

Alias to off(…)

clearAllEventListeners() this

Alias to off()

addOneTimeEventListener() this

Alias to once(…)

fireEvent() this

Alias to fire(…)

hasEventListeners() Boolean

Alias to listens(…)

v0.1.1452