You are viewing an older version of Mapbox.js. Check out v3.1.1 for the latest.

Path

An abstract class that contains options and constants shared between vector overlays (Polygon, Polyline, Circle). Do not use it directly.

Options

Option Type Default Description
stroke Boolean true Whether to draw stroke along the path. Set it to false to disable borders on polygons or circles.
color String '#03f' Stroke color.
weight Number 5 Stroke width in pixels.
opacity Number 0.5 Stroke opacity.
fill Boolean depends Whether to fill the path with color. Set it to false to disable filling on polygons or circles.
fillColor String same as color Fill color.
fillOpacity Number 0.2 Fill opacity.
dashArray String null A string that defines the stroke dash pattern. Doesn't work on canvas-powered layers (e.g. Android 2).
lineCap String null A string that defines shape to be used at the end of the stroke.
lineJoin String null A string that defines shape to be used at the corners of the stroke.
clickable Boolean true If false, the vector will not emit mouse events and will act as a part of the underlying map.
pointerEvents String null Sets the pointer-events attribute on the path if SVG backend is used.
className String '' Custom class name set on an element.

Events

You can subscribe to the following events using these methods.

Event Data Description
click MouseEvent Fired when the user clicks (or taps) the object.
dblclick MouseEvent Fired when the user double-clicks (or double-taps) the object.
mousedown MouseEvent Fired when the user pushes the mouse button on the object.
mouseover MouseEvent Fired when the mouse enters the object.
mouseout MouseEvent Fired when the mouse leaves the object.
contextmenu MouseEvent Fired when the user pushes the right mouse button on the object, prevents default browser context menu from showing if there are listeners on this event.
add Event Fired when the path is added to the map.
remove Event Fired when the path is removed from the map.
popupopen PopupEvent Fired when a popup bound to the path is open.
popupclose PopupEvent Fired when a popup bound to the path is closed.

Methods

Method Returns Description
addTo( <Map> map ) this Adds the layer to the map.
bindPopup( <String> html | <HTMLElement> el | <Popup> popup, <Popup options> options? ) this Binds a popup with a particular HTML content to a click on this path.
bindPopup( <Popup> popup, <Popup options> options? ) this Binds a given popup object to the path.
unbindPopup() this Unbinds the popup previously bound to the path with bindPopup.
openPopup( <LatLng> latlng? ) this Opens the popup previously bound by the bindPopup method in the given point, or in one of the path's points if not specified.
closePopup() this Closes the path's bound popup if it is opened.
setStyle( <Path options> object ) this Changes the appearance of a Path based on the options in the Path options object.
getBounds() LatLngBounds Returns the LatLngBounds of the path.
bringToFront() this Brings the layer to the top of all path layers.
bringToBack() this Brings the layer to the bottom of all path layers.
redraw() this Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.

Static properties

Constant Type Value Description
SVG Boolean depends True if SVG is used for vector rendering (true for most modern browsers).
VML Boolean depends True if VML is used for vector rendering (IE 6-8).
CANVAS Boolean depends True if Canvas is used for vector rendering (Android 2). You can also force this by setting global variable L_PREFER_CANVAS to true before the Leaflet include on your page — sometimes it can increase performance dramatically when rendering thousands of circle markers, but currently suffers from a bug that causes removing such layers to be extremely slow.
CLIP_PADDING Number 0.5 for SVG
0.02 for VML
How much to extend the clip area around the map view (relative to its size, e.g. 0.5 is half the screen in each direction). Smaller values mean that you will see clipped ends of paths while you're dragging the map, and bigger values decrease drawing performance.