<p>This reference reflects <strong>Leaflet 0.7.x</strong>. Check <ahref='reference-versions.html'>this list</a> if you are using a different version of Leaflet.</p>
<td>When this option is set, the map restricts the view to the given geographical bounds, bouncing the user back when they try to pan outside the view. To set the restriction dynamically, use <ahref="#map-setmaxbounds">setMaxBounds</a> method.</td>
</tr>
<tr>
<td><code><b>crs</b></code></td>
<td><code><ahref="#icrs">CRS</a></code></td>
<td><code>L.CRS.<br/>EPSG3857</code></td>
<td>Coordinate Reference System to use. Don't change this if you're not sure what it means.</td>
<td>Whether the map can be zoomed by using the mouse wheel. If passed <code><spanclass="hljs-string">'center'</span></code>, it will zoom to the center of the view regardless of where the mouse was.</td>
<td>Whether the map can be zoomed in by double clicking on it and zoomed out by double clicking while holding shift. If passed <code><spanclass="hljs-string">'center'</span></code>, double-click zoom will zoom to the center of the view regardless of where the mouse was.</td>
<td>Enables mobile hacks for supporting instant taps (fixing 200ms click delay on iOS/Android) and touch holds (fired as <code>contextmenu</code> events).</td>
<td>With this option enabled, the map tracks when you pan to another "copy" of the world and seamlessly jumps to the original one so that all overlays like markers and vector layers are still visible.</td>
<td>Set it to <code><spanclass="hljs-literal">false</span></code> if you don't want the map to zoom beyond min/max zoom and then bounce back when pinch-zooming.</td>
<td>If enabled, panning of the map will have an inertia effect where the map builds momentum while dragging and continues moving in the same direction for some time. Feels especially nice on touch devices.</td>
<td>Max speed of the inertial movement, in pixels/second.</td>
</tr>
<tr>
<td><code><b>inertiaThreshold</b></code></td>
<td><code>Number</code></td>
<td><code>depends</code></td>
<td>Number of milliseconds that should pass between stopping the movement and releasing the mouse or touch to prevent inertial movement. <code><spanclass="hljs-number">32</span></code> for touch devices and <code><spanclass="hljs-number">14</span></code> for the rest by default.</td>
<td>Won't animate zoom if the zoom difference exceeds this value.</td>
</tr>
<tr>
<td><code><b>markerZoomAnimation</b></code></td>
<td><code>Boolean</code></td>
<td>depends</td>
<td>Whether markers animate their zoom with the zoom animation, if disabled they will disappear for the length of the animation. By default it's enabled in all browsers that support CSS3 Transitions except Android.</td>
</tr>
</table>
<h3id="map-events">Events</h3>
<p>You can subscribe to the following events using <ahref="#events">these methods</a>.</p>
<td>Fired when the user pushes the right mouse button on the map, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).</td>
</tr>
<tr>
<td><code><b>focus</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired when the user focuses the map either by tabbing to it or clicking/panning.</td>
<td>Fired before mouse click on the map (sometimes useful when you want something to happen on click before any existing click handlers start running).</td>
</tr>
<tr>
<td><code><b>load</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired when the map is initialized (when its center and zoom are set for the first time).</td>
</tr>
<tr>
<td><code><b>unload</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired when the map is destroyed with <ahref="#map-remove">remove</a> method.</td>
</tr>
<trid="map-viewreset">
<td><code><b>viewreset</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired when the map needs to redraw its content (this usually happens on map zoom or load). Very useful for creating custom overlays.</td>
</tr>
<tr>
<td><code><b>movestart</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired when the view of the map starts changing (e.g. user starts dragging the map).</td>
</tr>
<tr>
<td><code><b>move</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired on any movement of the map view.</td>
</tr>
<trid="map-moveend">
<td><code><b>moveend</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired when the view of the map stops changing (e.g. user stopped dragging the map).</td>
</tr>
<tr>
<td><code><b>dragstart</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired when the user starts dragging the map.</td>
</tr>
<tr>
<td><code><b>drag</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired repeatedly while the user drags the map.</td>
<td>Pans the map to the closest view that would lie inside the given bounds (if it's not already), controlling the animation using the options specific, if any.</td>
<td>Checks if the map container size changed and updates the map if so — call it after you've changed the map size dynamically, also animating pan by default.</td>
<td>Checks if the map container size changed and updates the map if so — call it after you've changed the map size dynamically, also animating pan by default. If <code>options.pan</code> is <code><spanclass="hljs-literal">false</span></code>, panning will not occur. If <code>options.debounceMoveend</code> is <code><spanclass="hljs-literal">true</span></code>, it will delay <code>moveend</code> event so that it doesn't happen often even if the method is called many times in a row.</td>
<td>Restricts the map view to the given bounds (see <ahref="#map-maxbounds">map maxBounds</a> option)<!--, animating the map view if bounds are changed. The given animation options are passed through to `setView` or `panInsideBounds`, depending on map zoom level, and can be used to control how the map animates during this change-->.</td>
<td>Tries to locate the user using the <ahref="https://en.wikipedia.org/wiki/W3C_Geolocation_API">Geolocation API</a>, firing a <code>locationfound</code> event with location data on success or a <code>locationerror</code> event on failure, and optionally sets the map view to the user's location with respect to detection accuracy (or to the world view if geolocation failed). See <ahref="#map-locate-options">Locate options</a> for more details.</td>
<td>Stops watching location previously initiated by <code><b>map.locate</b>({watch: true})</code> and aborts resetting the map view if <code>map.locate</code> was called with <code>{setView: true}</code>.</td>
<td>Returns the maximum zoom level on which the given bounds fit to the map view in its entirety. If <code>inside</code> (optional) is set to <code><spanclass="hljs-literal">true</span></code>, the method instead returns the minimum zoom level on which the map view fits into the given bounds in its entirety.</td>
</tr>
<tr>
<td><code><b>getSize</b>()</code></td>
<td><code><ahref="#point">Point</a></code></td>
<td>Returns the current size of the map container.</td>
</tr>
<tr>
<td><code><b>getPixelBounds</b>()</code></td>
<td><code><ahref="#bounds">Bounds</a></code></td>
<td>Returns the bounds of the current map view in projected pixel coordinates (sometimes useful in layer and overlay implementations).</td>
</tr>
<tr>
<td><code><b>getPixelOrigin</b>()</code></td>
<td><code><ahref="#point">Point</a></code></td>
<td>Returns the projected pixel coordinates of the top left point of the map layer (useful in custom layer and overlay implementations).</td>
</tr>
</table>
<h3id="map-stuff-methods">Methods for Layers and Controls</h3>
<td>Runs the given callback when the map gets initialized with a place and zoom, or immediately if it happened already, optionally passing a function context.</td>
<td>If <code><spanclass="hljs-literal">true</span></code>, starts continuous watching of location changes (instead of detecting it once) using W3C <code>watchPosition</code> method. You can later stop watching using <code><b>map.stopLocate</b>()</code> method.</td>
<td>If <code><spanclass="hljs-literal">true</span></code>, automatically sets the map view to the user location with respect to detection accuracy, or to world view if geolocation failed.</td>
<td>Maximum age of detected location. If less than this amount of milliseconds passed since last geolocation response, <code>locate</code> will return a cached location.</td>
<td>An equivalent of passing <code>animate</code> to both zoom and pan options (see below).</td>
</tr>
</table>
<h3id="map-panoptions">Pan options</h3>
<tabledata-id='map'>
<tr>
<th>Option</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td><code><b>animate</b></code></td>
<td><code>Boolean</code></td>
<td><code>-</code></td>
<td>If <code><spanclass="hljs-literal">true</span></code>, panning will always be animated if possible. If <code><spanclass="hljs-literal">false</span></code>, it will not animate panning, either resetting the map view if panning more than a screen away, or just setting a new offset for the map pane (except for `panBy` which always does the latter).</td>
<td>The curvature factor of panning animation easing (third parameter of the <ahref="http://cubic-bezier.com/">Cubic Bezier curve</a>). <spanclass="hljs-number">1.0</span> means linear animation, the less the more bowed the curve.</td>
<td>If <code><spanclass="hljs-literal">true</span></code>, panning won't fire <code>movestart</code> event on start (used internally for panning inertia).</td>
</tr>
</table>
<h3id="map-zoomoptions">Zoom options</h3>
<tabledata-id='map'>
<tr>
<th>Option</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td><code><b>animate</b></code></td>
<td><code>Boolean</code></td>
<td><code>-</code></td>
<td>If not specified, zoom animation will happen if the zoom origin is inside the current view. If <code><spanclass="hljs-literal">true</span></code>, the map will attempt animating zoom disregarding where zoom origin is. Setting <code><spanclass="hljs-literal">false</span></code> will make it always reset the view completely without animation.</td>
<td>Sets the amount of padding in the top left corner of a map container that shouldn't be accounted for when setting the view to fit bounds. Useful if you have some control overlays on the map like a sidebar and you don't want them to obscure objects you're zooming to.</td>
<p>Map properties include interaction handlers that allow you to control interaction behavior in runtime, enabling or disabling certain features such as dragging or touch zoom (see <ahref="#ihandler">IHandler</a> methods). Example:</p>
<p>An object literal (returned by <ahref="#map-getpanes">map.getPanes</a></code>) that contains different map panes that you can use to put your custom overlays in. The difference is mostly in zIndex order that such overlays get.</p>
<tabledata-id='map'>
<tr>
<thclass="width100">Property</th>
<thclass="width100">Type</th>
<th>Description</th>
</tr>
<tr>
<td><code><b>mapPane</b></code></td>
<td><code>HTMLElement</code></td>
<td>Pane that contains all other map panes.</td>
</tr>
<tr>
<td><code><b>tilePane</b></code></td>
<td><code>HTMLElement</code></td>
<td>Pane for tile layers.</td>
</tr>
<tr>
<td><code><b>objectsPane</b></code></td>
<td><code>HTMLElement</code></td>
<td>Pane that contains all the panes except tile pane.</td>
</tr>
<tr>
<td><code><b>shadowPane</b></code></td>
<td><code>HTMLElement</code></td>
<td>Pane for overlay shadows (e.g. marker shadows).</td>
</tr>
<tr>
<td><code><b>overlayPane</b></code></td>
<td><code>HTMLElement</code></td>
<td>Pane for overlays like polylines and polygons.</td>
<td>Instantiates a Marker object given a geographical point and optionally an options object.</td>
</tr>
</table>
<h3id="marker-options">Options</h3>
<tabledata-id='marker'>
<tr>
<th>Option</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td><code><b>icon</b></code></td>
<td><code><ahref="#icon">L.Icon</a></code></td>
<td>*</td>
<td>Icon class to use for rendering the marker. See <ahref="#icon">Icon documentation</a> for details on how to customize the marker icon. Set to <code>new L.Icon.Default()</code> by default.</td>
<td>By default, zIndex for the marker image 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 <code>1000</code> (or high negative value, respectively).</td>
<td>Binds a popup with a particular HTML content to a click on this marker. You can also open the bound popup with the Marker <ahref="#marker-openpopup">openPopup</a> method.</td>
<p>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 <ahref="#ihandler">IHandler</a> methods). Example:</p>
<td>Marker dragging handler (by both mouse and touch).</td>
</tr>
</table>
<h2id="popup">Popup</h2>
<p>Used to open popups in certain places of the map. Use <ahref="#map-openpopup">Map#openPopup</a> to open popups while making sure that only one popup is open at one time (recommended for usability), or use <ahref="#map-addlayer">Map#addLayer</a> to open as many as you want.</p>
<h3>Usage example</h3>
<p>If you want to just bind a popup to marker click and then open it, it's really easy:</p>
<td>Instantiates a Popup object given an optional options object that describes its appearance and location and an optional source object that is used to tag the popup with a reference to the ILayer to which it refers.</td>
<td>Set it to <code><spanclass="hljs-literal">true</span></code> if you want to prevent users from panning the popup off of the screen while it is open.</td>
<td>Set it to <code><spanclass="hljs-literal">false</span></code> if you want to override the default behavior of the popup closing when user clicks the map (set globally by the <code>Map</code><code>closePopupOnClick</code> option).</td>
<p><code>{s}</code> means one of the available subdomains (used sequentially to help with browser parallel requests per domain limitation; subdomain values are specified in options; <code>a</code>, <code>b</code> or <code>c</code> by default, can be omitted), <code>{z}</code>— zoom level, <code>{x}</code> and <code>{y}</code>— tile coordinates.</p>
<p>You can use custom keys in the template, which will be <ahref="#util-template">evaluated</a> from TileLayer options, like this:</p>
<td>Maximum zoom number the tiles source has available. If it is specified, the tiles on all zoom levels higher than <code>maxNativeZoom</code> will be loaded from <code>maxNativeZoom</code> level and auto-scaled.</td>
<td>If set to <code><spanclass="hljs-literal">true</span></code>, the tile coordinates won't be wrapped by world width (-180 to 180 longitude) or clamped to lie within world height (-90 to 90). Use this if you use Leaflet for maps that don't reflect the real world (e.g. game, indoor or photo maps).</td>
<td>If set to <code><spanclass="hljs-literal">true</span></code>, the tiles just won't load outside the world width (-180 to 180 longitude) instead of repeating.</td>
<td>If set to <code><spanclass="hljs-literal">true</span></code>, the zoom number used in tile URLs will be reversed (<code>maxZoom - zoom</code> instead of <code>zoom</code>).</td>
<td>The explicit zIndex of the tile layer. Not set by default.</td>
</tr>
<tr>
<td><code><b>unloadInvisibleTiles</b></code></td>
<td><code>Boolean</code></td>
<td>depends</td>
<td>If <code><spanclass="hljs-literal">true</span></code>, all the tiles that are not visible after panning are removed (for better performance). <code><spanclass="hljs-literal">true</span></code> by default on mobile WebKit, otherwise <code><spanclass="hljs-literal">false</span></code>.</td>
</tr>
<tr>
<td><code><b>updateWhenIdle</b></code></td>
<td><code>Boolean</code></td>
<td>depends</td>
<td>If <code><spanclass="hljs-literal">false</span></code>, new tiles are loaded during panning, otherwise only after it (for better performance). <code><spanclass="hljs-literal">true</span></code> by default on mobile WebKit, otherwise <code><spanclass="hljs-literal">false</span></code>.</td>
<td>If <code><spanclass="hljs-literal">true</span></code> and user is on a retina display, it will request four tiles of half the specified size and a bigger zoom level in place of one to utilize the high resolution.</td>
<td>If <code><spanclass="hljs-literal">true</span></code>, all the tiles that are not visible after panning are placed in a reuse queue from which they will be fetched when new tiles become visible (as opposed to dynamically creating new ones). This will in theory keep memory usage low and eliminate the need for reserving new memory whenever a new tile is needed.</td>
<td>Merges an object with the new parameters and re-requests tiles on the current screen (unless <code>noRedraw</code> was set to <code><spanclass="hljs-literal">true</span></code>).</td>
</tr>
</table>
<h2id="tilelayer-canvas">TileLayer.Canvas</h2>
<p>Used to create Canvas-based tile layers where tiles get drawn on the browser side. Extends <ahref="#tilelayer">TileLayer</a>.</p>
<td>Indicates that tiles will be drawn asynchronously. <ahref="#tilelayer-canvas-tiledrawn">tileDrawn</a> method should be called for each tile after drawing completion.</td>
<td>You need to define this method after creating the instance to draw tiles; <code>canvas</code> is the actual canvas tile on which you can draw, <code>tilePoint</code> represents the tile numbers, and <code>zoom</code> is the current zoom.</td>
<td>If <code>async</code> option is defined, this function should be called for each tile after drawing completion. <code>canvas</code> is the same canvas element, that was passed to <ahref="#tilelayer-canvas-drawtile">drawTile</a>.</td>
</tr>
</table>
<h2id="imageoverlay">ImageOverlay</h2>
<p>Used to load and display a single image over specific bounds of the map, implements <ahref="#ilayer">ILayer</a> interface.</p>
<td>Whether to draw stroke along the path. Set it to <code><spanclass="hljs-literal">false</span></code> to disable borders on polygons or circles.</td>
<td>A string that defines the stroke <ahref="https://developer.mozilla.org/en/SVG/Attribute/stroke-dasharray">dash pattern</a>. Doesn't work on canvas-powered layers (e.g. Android 2).</td>
<td>A string that defines <ahref="https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-linecap">shape to be used at the end</a> of the stroke.</td>
<td>A string that defines <ahref="https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-linejoin">shape to be used at the corners</a> of the stroke.</td>
<td>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.</td>
</tr>
<tr>
<td><code><b>add</b></code></td>
<td><code><ahref="#event">Event</a></code>
<td>Fired when the path is added to the map.</td>
</tr>
<tr>
<td><code><b>remove</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired when the path is removed from the map.</td>
<td>Opens the popup previously bound by the <ahref="#path-bindpopup">bindPopup</a> method in the given point, or in one of the path's points if not specified.</td>
<td>Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.</td>
</tr>
</table>
<h3>Static properties</h3>
<tabledata-id='path'>
<tr>
<th>Constant</th>
<th>Type</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td><code>SVG</code></td>
<td><code>Boolean</code></td>
<td>depends</td>
<td>True if SVG is used for vector rendering (true for most modern browsers).</td>
</tr>
<tr>
<td><code>VML</code></td>
<td><code>Boolean</code></td>
<td>depends</td>
<td>True if VML is used for vector rendering (IE 6-8).</td>
</tr>
<tr>
<td><code>CANVAS</code></td>
<td><code>Boolean</code></td>
<td>depends</td>
<td>True if Canvas is used for vector rendering (Android 2). You can also force this by setting global variable <code>L_PREFER_CANVAS</code> to <code><spanclass="hljs-literal">true</span></code><em>before</em> 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.</td>
</tr>
<tr>
<td><code>CLIP_PADDING</code></td>
<td><code>Number</code></td>
<td><nobr><code><spanclass="hljs-number">0.5</span></code> for SVG</nobr><br/><nobr><code><spanclass="hljs-number">0.02</span></code> for VML</nobr></td>
<td>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.</td>
</tr>
</table>
<h2id="polyline">Polyline</h2>
<p>A class for drawing polyline overlays on a map. Extends <ahref="#path">Path</a>. Use <ahref="#map-addlayer">Map#addLayer</a> to add it to the map.</p>
<h3>Usage example</h3>
<pre><codeclass="javascript">// create a red polyline from an array of LatLng points
var polyline = L.polyline(latlngs, {color: 'red'}).addTo(map);
<td>How much to simplify the polyline on each zoom level. More means better performance and smoother look, and less means more accurate representation.</td>
<td>Allows adding, removing or replacing points in the polyline. Syntax is the same as in <ahref="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/splice">Array#splice</a>. Returns the array of removed points (if any).</td>
<td>Returns the LatLngBounds of the polyline.</td>
</tr>
<trid="polyline-togeojson">
<td><code><b>toGeoJSON</b>()</code></td>
<td><code>Object</code></td>
<td>Returns a <ahref="http://en.wikipedia.org/wiki/GeoJSON">GeoJSON</a> representation of the polyline (GeoJSON LineString Feature).</td>
</tr>
</table>
<h2id="multipolyline">MultiPolyline</h2>
<p>Extends <ahref="#featuregroup">FeatureGroup</a> to allow creating multi-polylines (single layer that consists of several polylines that share styling/popup).</p>
<td>Instantiates a multi-polyline object given an array of arrays of geographical points (one for each individual polyline) and optionally an options object.</td>
</tr>
</table>
<h3>Methods</h3>
<p>MultiPolylines accept all <ahref="#polyline">Polyline methods</a> but
have different behavior around their coordinate contents since they can contain
<td>Returns an array of arrays of geographical points in each line.</td>
</tr>
<tr>
<td><code><b>openPopup</b>()</td>
<td><code>this</code></td>
<td>Opens the popup previously bound by <ahref="#path-bindpopup">bindPopup</a>.</td>
</tr>
<trid="multipolyline-togeojson">
<td><code><b>toGeoJSON</b>()</code></td>
<td><code>Object</code></td>
<td>Returns a <ahref="http://en.wikipedia.org/wiki/GeoJSON">GeoJSON</a> representation of the multipolyline (GeoJSON MultiLineString Feature).</td>
</tr>
</table>
<h2id="polygon">Polygon</h2>
<p>A class for drawing polygon overlays on a map. Extends <ahref="#polyline">Polyline</a>. Use <ahref="#map-addlayer">Map#addLayer</a> to add it to the map.</p>
<p>Note that points you pass when creating a polygon shouldn't have an additional last point equal to the first one — it's better to filter out such points.</p>
<td>Instantiates a polygon object given an array of geographical points and optionally an options object (the same as for Polyline). You can also create a polygon with holes by passing an array of arrays of latlngs, with the first latlngs array representing the exterior ring while the remaining represent the holes inside.</td>
</tr>
</table>
<h3>Methods</h3>
<p>Polygon has the same options and methods as Polyline, with the following differences:</p>
<tabledata-id='polygon'>
<tr>
<thclass="width250">Method</th>
<th>Returns</th>
<th>Description</th>
</tr>
<trid="polygon-togeojson">
<td><code><b>toGeoJSON</b>()</code></td>
<td><code>Object</code></td>
<td>Returns a <ahref="http://en.wikipedia.org/wiki/GeoJSON">GeoJSON</a> representation of the polygon (GeoJSON Polygon Feature).</td>
</tr>
</table>
<h2id="multipolygon">MultiPolygon</h2>
<p>Extends <ahref="#featuregroup">FeatureGroup</a> to allow creating multi-polygons (single layer that consists of several polygons that share styling/popup).</p>
<td>Instantiates a multi-polygon object given an array of latlngs arrays (one for each individual polygon) and optionally an options object (the same as for MultiPolyline).</td>
</tr>
</table>
<h3>Methods</h3>
<p>MultiPolygons accept all <ahref="#polyline">Polyline methods</a> but
have different behavior around their coordinate contents since they can contain
<td>Returns an array of arrays of geographical points in each polygon.</td>
</tr>
<tr>
<td><code><b>openPopup</b>()</td>
<td><code>this</code></td>
<td>Opens the popup previously bound by <ahref="#path-bindpopup">bindPopup</a>.</td>
</tr>
<trid="multipolygon-togeojson">
<td><code><b>toGeoJSON</b>()</code></td>
<td><code>Object</code></td>
<td>Returns a <ahref="http://en.wikipedia.org/wiki/GeoJSON">GeoJSON</a> representation of the multipolygon (GeoJSON MultiPolygon Feature).</td>
</tr>
</table>
<h2id="rectangle">Rectangle</h2>
<p>A class for drawing rectangle overlays on a map. Extends <ahref="#polygon">Polygon</a>. Use <ahref="#map-addlayer">Map#addLayer</a> to add it to the map.</p>
<td>Redraws the rectangle with the passed bounds.</td>
</tr>
</table>
<h2id="circle">Circle</h2>
<p>A class for drawing circle overlays on a map. Extends <ahref="#path">Path</a>. Use <ahref="#map-addlayer">Map#addLayer</a> to add it to the map.</p>
<td>Sets the radius of a circle. Units are in meters.</td>
</tr>
<trid="circle-togeojson">
<td><code><b>toGeoJSON</b>()</code></td>
<td><code>Object</code></td>
<td>Returns a <ahref="http://en.wikipedia.org/wiki/GeoJSON">GeoJSON</a> representation of the circle (GeoJSON Point Feature).</td>
</tr>
</table>
<h2id="circlemarker">CircleMarker</h2>
<p>A circle of a fixed size with radius specified in pixels. Extends <ahref="#circle">Circle</a>. Use <ahref="#map-addlayer">Map#addLayer</a> to add it to the map.</p>
<td>Instantiates a circle marker given a geographical point and optionally an options object. The default radius is 10 and can be altered by passing a "radius" member in the path options object.</td>
<td>Sets the radius of a circle marker. Units are in pixels.</td>
</tr>
<trid="circlemarker-togeojson">
<td><code><b>toGeoJSON</b>()</code></td>
<td><code>Object</code></td>
<td>Returns a <ahref="http://en.wikipedia.org/wiki/GeoJSON">GeoJSON</a> representation of the circle marker (GeoJSON Point Feature).</td>
</tr>
</table>
<h2id="layergroup">LayerGroup</h2>
<p>Used to group several layers and handle them as one. If you add it to the map, any layers added or removed from the group will be added/removed on the map as well. Implements <ahref="#ilayer">ILayer</a> interface.</p>
<td>Iterates over the layers of the group, optionally specifying context of the iterator function.
<pre><code>group.eachLayer(function (layer) {
layer.bindPopup('Hello');
});</code></pre>
</td>
</tr>
<trid="layergroup-togeojson">
<td><code><b>toGeoJSON</b>()</code></td>
<td><code>Object</code></td>
<td>Returns a <ahref="http://en.wikipedia.org/wiki/GeoJSON">GeoJSON</a> representation of the layer group (GeoJSON FeatureCollection).</td>
</tr>
</table>
<h2id="featuregroup">FeatureGroup</h2>
<p>Extended <ahref="#layergroup">layerGroup</a> that also has mouse events (propagated from members of the group) and a shared bindPopup method. Implements <ahref="#ilayer">ILayer</a> interface.</p>
<td>Fired when a layer is removed from the map.</td>
</tr>
</table>
<h2id="geojson">GeoJson</h2>
<p>Represents a <ahref="http://geojson.org/geojson-spec.html">GeoJSON</a> object or an array of GeoJSON objects. Allows you to parse GeoJSON data and display it on the map. Extends <ahref="#featuregroup">FeatureGroup</a>.</p>
<pre><codeclass="javascript">L.geoJson(data, {
style: function (feature) {
return {color: feature.properties.color};
},
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.description);
}
}).addTo(map);</code></pre>
<p>Each feature layer created by it gets a <code>feature</code> property that links to the GeoJSON feature data the layer was created from (so that you can access its properties later).</p>
<td>Creates a GeoJSON layer. Optionally accepts an object in <ahref="http://geojson.org/geojson-spec.html">GeoJSON format</a> to display on the map (you can alternatively add it later with <code>addData</code> method) and an options object.</td>
<td>Function that will be used to decide whether to show a feature or not.</td>
</tr>
<trid="geojson-coordstolatlng">
<td><code><b>coordsToLatLng</b>(
<nobr><Array><i>coords</i></nobr> )</nobr>
</code></td>
<td>Function that will be used for converting GeoJSON coordinates to <ahref="#latlng">LatLng</a> points (if not specified, coords will be assumed to be WGS84 — standard <code>[longitude, latitude]</code> values in degrees).</td>
</tr>
</table>
<p>Additionally accepts all <ahref="#path-options">Path options</a> for polylines and polygons.</p>
<td>Creates a layer from a given GeoJSON feature.</td>
</tr>
<tr>
<td><code><b>coordsToLatLng</b>(
<nobr><Array><i>coords</i></nobr>,
<nobr><Boolean><i>reverse?</i> )</nobr>
</code></td>
<td><code><ahref="#latlng">LatLng</a></code></td>
<td>Creates a LatLng object from an array of 2 numbers (latitude, longitude) used in GeoJSON for points. If <code>reverse</code> is set to <code><spanclass="hljs-literal">true</span></code>, the numbers will be interpreted as (longitude, latitude).</td>
</tr>
<tr>
<td><code><b>coordsToLatLngs</b>(
<nobr><Array><i>coords</i></nobr>,
<nobr><Number><i>levelsDeep?</i></nobr>,
<nobr><Boolean><i>reverse?</i> )</nobr>
</code></td>
<td><code>Array</code></td>
<td>Creates a multidimensional array of LatLng objects from a GeoJSON coordinates array. <code>levelsDeep</code> specifies the nesting level (0 is for an array of points, 1 for an array of arrays of points, etc., 0 by default). If <code>reverse</code> is set to <code><spanclass="hljs-literal">true</span></code>, the numbers will be interpreted as (longitude, latitude).</td>
</tr>
</table>
<h2id="latlng">LatLng</h2>
<p>Represents a geographical point with a certain latitude and longitude.</p>
<p>All Leaflet methods that accept LatLng objects also accept them in a simple Array form and simple object form (unless noted otherwise), so these lines are equivalent:</p>
<pre><code>map.panTo([50, 30]);
map.panTo({lon: 30, lat: 50});
map.panTo({lat: 50, lng: 30});
map.panTo(L.latLng(50, 30));</code></pre>
<h3>Creation</h3>
<tabledata-id='latlng'>
<tr>
<thclass="width200">Factory</th>
<th>Description</th>
</tr>
<tr>
<td><code><b>L.latLng</b>(
<nobr><Number><i>latitude</i></nobr>,
<nobr><Number><i>longitude</i></nobr>,
<nobr><Number><i>altitude?</i> )</nobr>
</code></td>
<td>Creates an object representing a geographical point with the given latitude and longitude (and optionally altitude).</td>
<td>Returns the distance (in meters) to the given LatLng calculated using the Haversine formula. See <ahref="http://en.wikipedia.org/wiki/Haversine_formula">description on wikipedia</a>.</td>
<td>Returns <code><spanclass="hljs-literal">true</span></code> if the given LatLng point is at the same position (within a small margin of error).</td>
</tr>
<tr>
<td><code><b>toString</b>()</code></td>
<td><code>String</code></td>
<td>Returns a string representation of the point (for debugging purposes).</td>
</tr>
<tr>
<td><code><b>wrap</b>(
<nobr><Number><i>left</i></nobr>,
<nobr><Number><i>right</i> )</nobr>
</code></td>
<td><code><ahref="#latlng">LatLng</a></code></td>
<td>Returns a new <code>LatLng</code> object with the longitude wrapped around <code>left</code> and <code>right</code> boundaries (<code><spanclass="hljs-number">-180</span></code> to <code><spanclass="hljs-number">180</span></code> by default).</td>
<p>All Leaflet methods that accept LatLngBounds objects also accept them in a simple Array form (unless noted otherwise), so the bounds example above can be passed like this:</p>
<td>Creates a LatLngBounds object defined by the geographical points it contains. Very useful for zooming the map to fit a particular set of locations with <ahref="#map-fitbounds">fitBounds</a>.</td>
<td>Returns <code><spanclass="hljs-literal">true</span></code> if the rectangle is equivalent (within a small margin of error) to the given bounds.</td>
</tr>
<tr>
<td><code><b>toBBoxString</b>()</code></td>
<td><code>String</code></td>
<td>Returns a string with bounding box coordinates in a <code><spanclass="hljs-string">'southwest_lng,southwest_lat,northeast_lng,northeast_lat'</span></code> format. Useful for sending requests to web services that return geo data.</td>
<td>Returns bigger bounds created by extending the current bounds by a given percentage in each direction.</td>
</tr>
<tr>
<td><code><b>isValid</b>()</nobr>
</code></td>
<td><code>Boolean</code></td>
<td>Returns <code><spanclass="hljs-literal">true</span></code> if the bounds are properly initialized.</td>
</tr>
</table>
<h2id="point">Point</h2>
<p>Represents a point with x and y coordinates in pixels.</p>
<pre><code>var point = L.point(200, 300);</code></pre>
<p>All Leaflet methods and options that accept Point objects also accept them in a simple Array form (unless noted otherwise), so these lines are equivalent:</p>
<td>Creates a Point object with the given <code>x</code> and <code>y</code> coordinates. If optional <code>round</code> is set to <code><spanclass="hljs-literal">true</span></code>, rounds the <code>x</code> and <code>y</code> values.</td>
<td>Returns the result of subtraction of the given point from the current.</td>
</tr>
<tr>
<td><code><b>multiplyBy</b>(
<nobr><Number><i>number</i> )</nobr>
</code></td>
<td><code><ahref="#point">Point</a></code></td>
<td>Returns the result of multiplication of the current point by the given number.</td>
</tr>
<tr>
<td><code><b>divideBy</b>(
<nobr><Number><i>number</i></nobr>,
<nobr><Boolean><i>round?</i> )</nobr>
</code></td>
<td><code><ahref="#point">Point</a></code></td>
<td>Returns the result of division of the current point by the given number. If optional <code>round</code> is set to <code><spanclass="hljs-literal">true</span></code>, returns a rounded result.</td>
<td>Returns <code><spanclass="hljs-literal">true</span></code> if the both coordinates of the given point are less than the corresponding current point coordinates (in absolute values).</td>
</tr>
<tr>
<td><code><b>toString</b>()</code></td>
<td><code>String</code></td>
<td>Returns a string representation of the point for debugging purposes.</td>
</tr>
</table>
<h2id="bounds">Bounds</h2>
<p>Represents a rectangular area in pixel coordinates.</p>
<p>All Leaflet methods that accept Bounds objects also accept them in a simple Array form (unless noted otherwise), so the bounds example above can be passed like this:</p>
<td>Creates an icon instance with the given options.</td>
</tr>
</table>
<h3id="icon-options">Options</h3>
<tabledata-id='icon'>
<tr>
<th>Option</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><code><b>iconUrl</b></code></td>
<td><code>String</code>
<td>(required) The URL to the icon image (absolute or relative to your script path).</td>
</tr>
<tr>
<td><code><b>iconRetinaUrl</b></code></td>
<td><code>String</code>
<td>The URL to a retina sized version of the icon image (absolute or relative to your script path). Used for Retina screen devices.</td>
</tr>
<tr>
<td><code><b>iconSize</b></code></td>
<td><code><ahref="#point">Point</a></code></td>
<td>Size of the icon image in pixels.</td>
</tr>
<tr>
<td><code><b>iconAnchor</b></code></td>
<td><code><ahref="#point">Point</a></code></td>
<td>The 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.</td>
</tr>
<tr>
<td><code><b>shadowUrl</b></code></td>
<td><code>String</code>
<td>The URL to the icon shadow image. If not specified, no shadow image will be created.</td>
</tr>
<tr>
<td><code><b>shadowRetinaUrl</b></code></td>
<td><code>String</code>
<td>The URL to the retina sized version of the icon shadow image. If not specified, no shadow image will be created. Used for Retina screen devices.</td>
</tr>
<tr>
<td><code><b>shadowSize</b></code></td>
<td><code><ahref="#point">Point</a></code></td>
<td>Size of the shadow image in pixels.</td>
</tr>
<tr>
<td><code><b>shadowAnchor</b></code></td>
<td><code><ahref="#point">Point</a></code></td>
<td>The coordinates of the "tip" of the shadow (relative to its top left corner) (the same as <code>iconAnchor</code> if not specified).</td>
</tr>
<tr>
<td><code><b>popupAnchor</b></code></td>
<td><code><ahref="#point">Point</a></code></td>
<td>The coordinates of the point from which popups will "open", relative to the icon anchor.</td>
</tr>
<tr>
<td><code><b>className</b></code></td>
<td><code>String</code>
<td>A custom class name to assign to both icon and shadow images. Empty by default.</td>
</tr>
</table>
<h2id="divicon">DivIcon</h2>
<p>Represents a lightweight icon for markers that uses a simple <code>div</code> element instead of an image.</p>
<p>By default, it has a <code><spanclass="hljs-string">'leaflet-div-icon'</span></code> class and is styled as a little white square with a shadow.</p>
<td>Creates a div icon instance with the given options.</td>
</tr>
</table>
<h3id="divicon-options">Options</h3>
<tabledata-id='divicon'>
<tr>
<th>Option</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><code><b>iconSize</b></code></td>
<td><code><ahref="#point">Point</a></code></td>
<td>Size of the icon in pixels. Can be also set through CSS.</td>
</tr>
<tr>
<td><code><b>iconAnchor</b></code></td>
<td><code><ahref="#point">Point</a></code></td>
<td>The 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.</td>
</tr>
<tr>
<td><code><b>popupAnchor</b></code></td>
<td><code><ahref="#point">Point</a></code></td>
<td>The coordinates of the point from which popups will "open", relative to the icon anchor.</td>
</tr>
<tr>
<td><code><b>className</b></code></td>
<td><code>String</code>
<td>A custom class name to assign to the icon. <code><spanclass="hljs-string">'leaflet-div-icon'</span></code> by default.</td>
</tr>
<tr>
<td><code><b>html</b></code></td>
<td><code>String</code>
<td>A custom HTML code to put inside the div element, empty by default.</td>
</tr>
</table>
<h2id="control">Control</h2>
<p>The base class for all Leaflet controls. Implements <ahref="#icontrol">IControl</a> interface. You can add controls to the map like this:</p>
<td>Returns the HTML container of the control.</td>
</tr>
</table>
<h3id="control-positions">Control Positions</h3>
<p>Control positions (map corner to put a control to) are set using strings. Margins between controls and the map border are set with CSS, so that you can easily override them.</p>
<p>A basic zoom control with two buttons (zoom in and zoom out). It is put on the map by default unless you set its <code>zoomControl</code> option to <code><spanclass="hljs-literal">false</span></code>. Extends <ahref="#control">Control</a>.</p>
<p>The attribution control allows you to display attribution data in a small text box on a map. It is put on the map by default unless you set its <code>attributionControl</code> option to <code><spanclass="hljs-literal">false</span></code>, and it fetches attribution texts from layers with <code>getAttribution</code> method automatically. Extends <ahref="#control">Control</a>.</p>
<p>The layers control gives users the ability to switch between different base layers and switch overlays on/off (check out the <ahref="https://leafletjs.com/examples/layers-control.html">detailed example</a>). Extends <ahref="#control">Control</a>.</p>
<td>Creates an attribution control with the given layers. Base layers will be switched with radio buttons, while overlays will be switched with checkboxes. Note that all base layers should be passed in the base layers object, but only one should be added to the map during map instantiation.</td>
<td>If <code><spanclass="hljs-literal">true</span></code>, the control will assign zIndexes in increasing order to all of its layers so that the order is preserved when switching them on/off.</td>
</tr>
</table>
<h3id="control-layers-config">Layer Config</h3>
<p>An object literal with layer names as keys and layer objects as values:</p>
<pre><code>{
"<someName1>": layer1,
"<someName2>": layer2
}</code></pre>
<p>The layer names can contain HTML, which allows you to add additional styling to the items:</p>
<td>Fired when an overlay is deselected through the control.</td>
</tr>
</table>
<h2id="control-scale">Control.Scale</h2>
<p>A simple scale control that shows the scale of the current center of screen in metric (m/km) and imperial (mi/ft) systems. Extends <ahref="#control">Control</a>.</p>
<td>If <code><spanclass="hljs-literal">true</span></code>, the control is updated on <code>moveend</code>, otherwise it's always up-to-date (updated on <code>move</code>).</td>
</tr>
</table>
<h2id="events">Events methods</h2>
<p>A set of methods shared between event-powered classes (like Map). Generally, events allow you to execute some function when something happens with an object (e.g. the user clicks on the map, causing the map <code><spanclass="hljs-string">'click'</span></code> event).</p>
<td>Adds a listener function (<code>fn</code>) to a particular event type of the object. You can optionally specify the context of the listener (object the <code><spanclass="hljs-keyword">this</span></code> keyword will point to). You can also pass several space-separated types (e.g. <code><spanclass="hljs-string">'click dblclick'</span></code>).</td>
<td>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 <code>addEventListener</code>, you must pass the same context to <code>removeEventListener</code> in order to remove the listener.</td>
<td>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.</td>
<p>Event object is an object that you receive as an argument in a listener function when some event is fired, containing useful information about that event. For example:</p>
<td>The name of the layer that was added or removed.</td>
</tr>
</table>
<h3id="tile-event">TileEvent</h3>
<tabledata-id='tile-event'>
<tr>
<thclass="width100">property</th>
<thclass="width100">type</th>
<th>description</th>
</tr>
<tr>
<td><code><b>tile</b></code></td>
<td><code>HTMLElement</code></td>
<td>The tile element (image).</td>
</tr>
<tr>
<td><code><b>url</b></code></td>
<td><code>String</code></td>
<td>The source URL of the tile.</td>
</tr>
</table>
<h3id="tileerror-event">TileErrorEvent</h3>
<tabledata-id='tileerror-event'>
<tr>
<thclass="width100">property</th>
<thclass="width100">type</th>
<th>description</th>
</tr>
<tr>
<td><code><b>tile</b></code></td>
<td><code>HTMLElement</code></td>
<td>The tile element (image).</td>
</tr>
<tr>
<td><code><b>url</b></code></td>
<td><code>String</code></td>
<td>The <code>src</code> attribute of the tile element.</td>
</tr>
</table>
<h3id="resize-event">ResizeEvent</h3>
<tabledata-id='resize-event'>
<tr>
<thclass="width100">property</th>
<thclass="width100">type</th>
<th>description</th>
</tr>
<tr>
<td><code><b>oldSize</b></code></td>
<td><code><ahref="#point">Point</a></code></td>
<td>The old size before resize event.</td>
</tr>
<tr>
<td><code><b>newSize</b></code></td>
<td><code><ahref="#point">Point</a></code></td>
<td>The new size after the resize event.</td>
</tr>
</table>
<h3id="geojson-event">GeoJSON event</h3>
<tabledata-id='geojson-event'>
<tr>
<thclass="width100">property</th>
<thclass="width100">type</th>
<th>description</th>
</tr>
<tr>
<td><code><b>layer</b></code></td>
<td><code><ahref="#ilayer">ILayer</a></code></td>
<td>The layer for the GeoJSON feature that is being added to the map.</td>
</tr>
<tr>
<td><code><b>properties</b></code></td>
<td><code>Object</code></td>
<td>GeoJSON properties of the feature.</td>
</tr>
<tr>
<td><code><b>geometryType</b></code></td>
<td><code>String</code></td>
<td>GeoJSON geometry type of the feature.</td>
</tr>
<tr>
<td><code><b>id</b></code></td>
<td><code>String</code></td>
<td>GeoJSON ID of the feature (if present).</td>
</tr>
</table>
<h3id="popup-event">Popup event</h3>
<tabledata-id='popup-event'>
<tr>
<thclass="width100">property</th>
<thclass="width100">type</th>
<th>description</th>
</tr>
<tr>
<td><code><b>popup</b></code></td>
<td><code><ahref="#popup">Popup</a></code></td>
<td>The popup that was opened or closed.</td>
</tr>
</table>
<h3id="dragend-event">DragEndEvent</h3>
<tabledata-id='layer-event'>
<tr>
<thclass="width100">property</th>
<thclass="width100">type</th>
<th>description</th>
</tr>
<tr>
<td><code><b>distance</b></code></td>
<td><code>Number</code></td>
<td>The distance in pixels the draggable element was moved by.</td>
</tr>
</table>
<!-- <h3>TileEvent</h3> -->
<h2id="class">Class</h2>
<p><code>L.Class</code> powers the OOP facilities of Leaflet and is used to create almost all of the Leaflet classes documented here.</p>
<p>In addition to implementing a simple classical inheritance model, it introduces several special properties for convenient code organization —<code>options</code>, <code>includes</code> and <code>statics</code>.</p>
<pre><code>var MyClass = L.Class.extend({
initialize: function (greeter) {
this.greeter = greeter;
// class constructor
},
greet: function (name) {
alert(this.greeter + ', ' + name)
}
});
// create instance of MyClass, passing "Hello" to the constructor
var a = new MyClass("Hello");
// call greet method, alerting "Hello, World"
a.greet("World");
</code></pre>
<p>The <code>initialize</code> method is your class's constructor function, meaning that it gets called when you do <code>new MyClass(...)</code>.</p>
<h3>Class Factories</h3>
<p>You may have noticed that Leaflet objects are created without using the <code>new</code> keyword. This is achieved by complementing each class with a lowercase factory method:</p>
<pre><code>new L.Map('map'); // becomes:
L.map('map');</code></pre>
<p>The factories are implemented very easily, and you can do this for your own classes:</p>
<pre><code>L.map = function (id, options) {
return new L.Map(id, options);
};</code></pre>
<h3>Inheritance</h3>
<p>You use <code>L.Class.extend</code> to define new classes, but you can use the same method on any class to inherit from it:</p>
<pre><code>var MyChildClass = MyClass.extend({
// ... new properties and methods
});</code></pre>
<p>This will create a class that inherits all methods and properties of the parent class (through a proper prototype chain), adding or overriding the ones you pass to <code>extend</code>. It will also properly react to <code>instanceof</code>:</p>
<pre><code>var a = new MyChildClass();
a instanceof MyChildClass; // true
a instanceof MyClass; // true
</code></pre>
<p>You can call parent methods (including constructor) from corresponding child ones (as you do with <code>super</code> calls in other languages) by accessing parent class prototype and using JavaScript's <code>call</code> or <code>apply</code>:</p>
<pre><code>var MyChildClass = MyClass.extend({
initialize: function () {
MyClass.prototype.initialize.call(this, "Yo");
},
greet: function (name) {
MyClass.prototype.greet.call(this, 'bro ' + name + '!');
<p><code>options</code> is a special property that unlike other objects that you pass to <code>extend</code> will be merged with the parent one instead of overriding it completely, which makes managing configuration of objects and default values convenient:</p>
<pre><code>var MyClass = L.Class.extend({
options: {
myOption1: 'foo',
myOption2: 'bar'
}
});
var MyChildClass = MyClass.extend({
options: {
myOption1: 'baz',
myOption3: 5
}
});
var a = new MyChildClass();
a.options.myOption1; // 'baz'
a.options.myOption2; // 'bar'
a.options.myOption3; // 5</code></pre>
<p>There's also <code>L.Util.setOptions</code>, a method for conveniently merging options passed to constructor with the defaults defined in the class:</p>
<pre><code>var MyClass = L.Class.extend({
options: {
foo: 'bar',
bla: 5
},
initialize: function (options) {
L.Util.setOptions(this, options);
...
}
});
var a = new MyClass({bla: 10});
a.options; // {foo: 'bar', bla: 10}</code></pre>
<h3>Includes</h3>
<p><code>includes</code> is a special class property that merges all specified objects into the class (such objects are called mixins). A good example of this is <code>L.Mixin.Events</code> that <ahref="#events">event-related methods</a> like <code>on</code>, <code>off</code> and <code>fire</code> to the class.</p>
<pre><code> var MyMixin = {
foo: function () { ... },
bar: 5
};
var MyClass = L.Class.extend({
includes: MyMixin
});
var a = new MyClass();
a.foo();</code></pre>
<p>You can also do such includes in runtime with the <code>include</code> method:</p>
<p><code>statics</code> is just a convenience property that injects specified object properties as the static properties of the class, useful for defining constants:</p>
<pre><code>var MyClass = L.Class.extend({
statics: {
FOO: 'bar',
BLA: 5
}
});
MyClass.FOO; // 'bar'</code></pre>
<h3>Constructor Hooks</h3>
<p>If you're a plugin developer, you often need to add additional initialization code to existing classes (e.g. editing hooks for <code>L.Polyline</code>). Leaflet comes with a way to do it easily using the <code>addInitHook</code> method:</p>
<pre><code>MyClass.addInitHook(function () {
// ... do something in constructor additionally
// e.g. add event listeners, set custom properties etc.
});</code></pre>
<p>You can also use the following shortcut when you just need to make one additional method call:</p>
<p>A namespace with properties for browser/feature detection used by Leaflet internally.</p>
<pre><code>if (L.Browser.ie6) {
alert('Upgrade your browser, dude!');
}</code></pre>
<tabledata-id='browser'>
<tr>
<thclass="width100">property</th>
<thclass="width100">type</th>
<th>description</th>
</tr>
<tr>
<td><code><b>ie</b></code></td>
<td><code>Boolean</code></td>
<td><code><spanclass="hljs-literal">true</span></code> for all Internet Explorer versions.</td>
</tr>
<tr>
<td><code><b>ie6</b></code></td>
<td><code>Boolean</code></td>
<td><code><spanclass="hljs-literal">true</span></code> for Internet Explorer 6.</td>
</tr>
<tr>
<td><code><b>ie7</b></code></td>
<td><code>Boolean</code></td>
<td><code><spanclass="hljs-literal">true</span></code> for Internet Explorer 7.</td>
</tr>
<tr>
<td><code><b>ielt9</b></code></td>
<td><code>Boolean</code></td>
<td><code><spanclass="hljs-literal">true</span></code> for Internet Explorer versions less than 9.</td>
</tr>
<tr>
<td><code><b>webkit</b></code></td>
<td><code>Boolean</code></td>
<td><code><spanclass="hljs-literal">true</span></code> for webkit-based browsers like Chrome and Safari (including mobile versions).</td>
</tr>
<tr>
<td><code><b>webkit3d</b></code></td>
<td><code>Boolean</code></td>
<td><code><spanclass="hljs-literal">true</span></code> for webkit-based browsers that support CSS 3D transformations.</td>
</tr>
<!--<tr>
<td><code><b>gecko</b></code></td>
<td><code>Boolean</code></td>
<td><code><spanclass="hljs-literal">true</span></code> for Gecko-based browsers like Firefox and Mozilla.</td>
</tr>
<tr>
<td><code><b>opera</b></code></td>
<td><code>Boolean</code></td>
<td><code><spanclass="hljs-literal">true</span></code> for Opera.</td>
</tr>-->
<tr>
<td><code><b>android</b></code></td>
<td><code>Boolean</code></td>
<td><code><spanclass="hljs-literal">true</span></code> for Android mobile browser.</td>
</tr>
<tr>
<td><code><b>android23</b></code></td>
<td><code>Boolean</code></td>
<td><code><spanclass="hljs-literal">true</span></code> for old Android stock browsers (2 and 3).</td>
</tr>
<tr>
<td><code><b>mobile</b></code></td>
<td><code>Boolean</code></td>
<td><code><spanclass="hljs-literal">true</span></code> for modern mobile browsers (including iOS Safari and different Android browsers).</td>
</tr>
<tr>
<td><code><b>mobileWebkit</b></code></td>
<td><code>Boolean</code></td>
<td><code><spanclass="hljs-literal">true</span></code> for mobile webkit-based browsers.</td>
</tr>
<tr>
<td><code><b>mobileOpera</b></code></td>
<td><code>Boolean</code></td>
<td><code><spanclass="hljs-literal">true</span></code> for mobile Opera.</td>
</tr>
<tr>
<td><code><b>touch</b></code></td>
<td><code>Boolean</code></td>
<td><code><spanclass="hljs-literal">true</span></code> for all browsers on touch devices.</td>
</tr>
<tr>
<td><code><b>msTouch</b></code></td>
<td><code>Boolean</code></td>
<td><code><spanclass="hljs-literal">true</span></code> for browsers with Microsoft touch model (e.g. IE10).</td>
</tr>
<tr>
<td><code><b>retina</b></code></td>
<td><code>Boolean</code></td>
<td><code><spanclass="hljs-literal">true</span></code> for devices with Retina screens.</td>
</tr>
</table>
<h2id="util">Util</h2>
<p>Various utility functions, used by Leaflet internally.</p>
<h3>Methods</h3>
<tabledata-id='util'>
<tr>
<th>Method</th>
<th>Returns</th>
<th>Description</th>
</tr>
<tr>
<td><code><b>extend</b>(
<nobr><Object><i>dest</i></nobr>,
<nobr><Object><i>src?..</i> )</nobr>
</code></td>
<td><code>Object</code></td>
<td>Merges the properties of the <code>src</code> object (or multiple objects) into <code>dest</code> object and returns the latter. Has an <code>L.extend</code> shortcut.</td>
</tr>
<tr>
<td><code><b>bind</b>(
<nobr><Function><i>fn</i></nobr>,
<nobr><Object><i>obj</i> )</nobr>
</code></td>
<td><code>Function</code></td>
<td>Returns a function which executes function <code>fn</code> with the given scope <code>obj</code> (so that <code><spanclass="hljs-keyword">this</span></code> keyword refers to <code>obj</code> inside the function code). Has an <code>L.bind</code> shortcut. Not a polyfill for ES 5 <code>bind</code> (compare <code>L.bind</code> to the <ahref="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill">MDN-recommended polyfill</a> for <code>Function.prototype.bind</code>).</td>
<td>Applies a unique key to the object and returns that key. Has an <code>L.stamp</code> shortcut.</td>
</tr>
<tr>
<td><code><b>requestAnimFrame</b>(
<nobr><Function><i>fn</i></nobr>,
<nobr><Object><i>context?</i></nobr>,
<nobr><Boolean><i>immediate?</i></nobr>,
<nobr><HTMLElement><i>element?</i> )</nobr>
</code></td>
<td><code>Number</code></td>
<td>Schedules <code>fn</code> to be executed when the browser repaints. When <code>immediate</code> is set, <code>fn</code> is called immediately if the browser doesn't have native support for <code>requestAnimationFrame</code>, otherwise it's delayed. Returns an id that can be used to cancel the request.</td>
</tr>
<tr>
<td><code><b>cancelAnimFrame</b>(
<nobr><Number><i>id</i> )</nobr>
</code></td>
<td>-</td>
<td>Cancels a previous request to <code>requestAnimFrame</code>.</td>
</tr>
<tr>
<td><code><b>limitExecByInterval</b>(
<nobr><Function><i>fn</i></nobr>,
<nobr><Number><i>time</i></nobr>,
<nobr><Object><i>context?</i> )</nobr>
</code></td>
<td><code>Function</code></td>
<td>Returns a wrapper around the function <code>fn</code> that makes sure it's called not more often than a certain time interval <code>time</code>, but as fast as possible otherwise (for example, it is used for checking and requesting new tiles while dragging the map), optionally passing the scope (<code>context</code>) in which the function will be called.</td>
<td>Returns the number <code>num</code> rounded to <code>digits</code> decimals.</td>
</tr>
<tr>
<td><code><b>splitWords</b>(
<nobr><String><i>str</i> )</nobr>
</code></td>
<td><code>String[]</code></td>
<td>Trims and splits the string on whitespace and returns the array of parts.</code></td>
</tr>
<tr>
<td><code><b>setOptions</b>(
<nobr><Object><i>obj</i></nobr>,
<nobr><Object><i>options</i> )</nobr>
</code></td>
<td><code>Object</code></td>
<td>Merges the given properties to the <code>options</code> of the <code>obj</code> object, returning the resulting options. See <ahref="#class-options">Class options</a>. Has an <code>L.setOptions</code> shortcut.</td>
</tr>
<tr>
<td><code><b>getParamString</b>(
<nobr><Object><i>obj</i> )</nobr>
</code></td>
<td><code>String</code></td>
<td>Converts an object into a parameter URL string, e.g. <nobr><code>{a: "foo", b: "bar"}</code></nobr> translates to <code><spanclass="hljs-string">'?a=foo&b=bar'</span></code>.</td>
<td>Simple templating facility, accepts a template string of the form <code><spanclass="hljs-string">'Hello {a}, {b}'</span></code> and a data object like <code>{a: 'foo', b: 'bar'}</code>, returns evaluated string (<code><spanclass="hljs-string">'Hello foo, bar'</span></code>). You can also specify functions instead of strings for data values — they will be evaluated passing <code>data</code> as an argument.</td>
</tr>
<tr>
<td><code><b>isArray</b>(
<nobr><Object><i>obj</i> )</nobr>
</code></td>
<td><code>Boolean</code></td>
<td>Returns <code><spanclass="hljs-literal">true</span></code> if the given object is an array.</td>
</tr>
<tr>
<td><code><b>trim</b>(
<nobr><String><i>str</i> )</nobr>
</code></td>
<td><code>String</code></td>
<td>Trims the whitespace from both ends of the string and returns the result.</td>
</tr>
</table>
<h3>Properties</h3>
<tabledata-id='util'>
<tr>
<th>Property</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><code><b>emptyImageUrl</b></code></td>
<td><code>String</code></td>
<td>Data URI string containing a base64-encoded empty GIF image. Used as a hack to free memory from unused images on WebKit-powered mobile devices (by setting image <code>src</code> to this string).</td>
</tr>
</table>
<h2id="transformation">Transformation</h2>
<p>Represents an affine transformation: a set of coefficients <code>a</code>, <code>b</code>, <code>c</code>, <code>d</code> for transforming a point of a form <code>(x, y)</code> into <code>(a*x + b, c*y + d)</code> and doing the reverse. Used by Leaflet in its projections code.</p>
<pre><code>var transformation = new L.Transformation(2, 5, -1, 10),
<td>Returns the reverse transformation of the given point, optionally divided by the given scale. Only accepts real <code>L.Point</code> instances, not arrays.</td>
</tr>
</table>
<h2id="lineutil">LineUtil</h2>
<p>Various utility functions for polyline points processing, used by Leaflet internally to make polylines lightning-fast.</p>
<td>Dramatically reduces the number of points in a polyline while retaining its shape and returns a new array of simplified points. Used for a huge performance boost when processing/displaying Leaflet polylines for each zoom level and also reducing visual noise. <code>tolerance</code> affects the amount of simplification (lesser value means higher quality but slower and with more points). Also released as a separated micro-library <ahref="http://mourner.github.com/simplify-js/">Simplify.js</a>.</td>
<td>Clips the segment <code>a</code> to <code>b</code> by rectangular bounds. Returns either false or an array of clipped points. Used by Leaflet to only show polyline points that are on the screen or near, increasing performance.</td>
</tr>
</table>
<h2id="polyutil">PolyUtil</h2>
<p>Various utility functions for polygon geometries.</p>
<td>Clips the polygon geometry defined by the given points by rectangular bounds. Used by Leaflet to only show polygon points that are on the screen or near, increasing performance. Note that polygon points needs different algorithm for clipping than polyline, so there's a separate method for it.</td>
</tr>
</table>
<h2id="domevent">DomEvent</h2>
<p>Utility functions to work with the DOM events, used by Leaflet internally.</p>
<td>Adds a listener <code>fn</code> to the element's DOM event of the specified type. <code><spanclass="hljs-keyword">this</span></code> keyword inside the listener will point to <code>context</code>, or to the element if not specified.</td>
<td>Prevents the default action of the event from happening (such as following a link in the <code>href</code> of the <code>a</code> element, or doing a <code>POST</code> request with page reload when <code>form</code> is submitted). Use it inside listener functions.</pre>
<td>Adds <code>stopPropagation</code> to the element's <code><spanclass="hljs-string">'click'</span></code>, <code><spanclass="hljs-string">'doubleclick'</span></code>, <code><spanclass="hljs-string">'mousedown'</span></code> and <code><spanclass="hljs-string">'touchstart'</span></code> events.</td>
<td>Returns <code><spanclass="hljs-literal">true</span></code> if the element class attribute contains <code>name</code>.</td>
</tr>
<tr>
<td><code><b>addClass</b>(
<nobr><HTMLElement><i>el</i></nobr>,
<nobr><String><i>name</i> )</nobr>
</code></td>
<td>-</td>
<td>Adds <code>name</code> to the element's class attribute.</td>
</tr>
<tr>
<td><code><b>removeClass</b>(
<nobr><HTMLElement><i>el</i></nobr>,
<nobr><String><i>name</i> )</nobr>
</code></td>
<td>-</td>
<td>Removes <code>name</code> from the element's class attribute.</td>
</tr>
<tr>
<td><code><b>setOpacity</b>(
<nobr><HTMLElement><i>el</i></nobr>,
<nobr><Number><i>value</i> )</nobr>
</code></td>
<td>-</td>
<td>Set the opacity of an element (including old IE support). Value must be from <code>0</code> to <code>1</code>.</td>
</tr>
<tr>
<td><code><b>testProp</b>(
<nobr><String[]><i>props</i> )</nobr>
</code></td>
<td><code>String</code> or <code><spanclass="hljs-literal">false</span></code></td>
<td>Goes through the array of style names and returns the first name that is a valid style name for an element. If no such name is found, it returns <code><spanclass="hljs-literal">false</span></code>. Useful for vendor-prefixed styles like <code>transform</code>.</td>
<td>Returns a CSS transform string to move an element by the offset provided in the given point. Uses 3D translate on WebKit for hardware-accelerated transforms and 2D on other browsers.</td>
<td>Sets the position of an element to coordinates specified by <code>point</code>, using CSS translate or top/left positioning depending on the browser (used by Leaflet internally to position its layers). Forces top/left positioning if <code>disable3D</code> is <code><spanclass="hljs-literal">true</span></code>.</td>
</tr>
<tr>
<td><code><b>getPosition</b>(
<nobr><HTMLElement><i>el</i> )</nobr>
</code></td>
<td><ahref="#point">Point</a></td>
<td>Returns the coordinates of an element previously positioned with <code>setPosition</code>.</td>
</tr>
</table>
<h3>Properties</h3>
<tabledata-id='domutil'>
<tr>
<th>Property</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><code><b>TRANSITION</b></nobr>
</code></td>
<td><code>String</code></td>
<td>Vendor-prefixed transition style name (e.g. <code><spanclass="hljs-string">'webkitTransition'</span></code> for WebKit).</td>
</tr>
<tr>
<td><code><b>TRANSFORM</b></nobr>
</code></td>
<td><code>String</code></td>
<td>Vendor-prefixed transform style name.</td>
</tr>
</table>
<h2id="posanimation">PosAnimation</h2>
<p>Used internally for panning animations, utilizing CSS3 Transitions for modern browsers and a timer fallback for IE6-9.</p>
<pre><codeclass="javascript">var fx = new L.PosAnimation();
<td>Runs an animation of a given element to a new position, optionally setting duration in seconds (<code><spanclass="hljs-number">0.25</span></code> by default) and easing linearity factor (3rd argument of the <ahref="http://cubic-bezier.com/#0,0,.5,1">cubic bezier curve</a>, <code><spanclass="hljs-number">0.5</span></code> by default).</td>
</tr>
</table>
<h3>Events</h3>
<p>You can subscribe to the following events using <ahref="#events">these methods</a>.</p>
<tabledata-id='posanimation'>
<tr>
<thclass="width100">Event</th>
<thclass="width100">Data</th>
<th>Description</th>
</tr>
<tr>
<td><code><b>start</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired when the animation starts.</td>
</tr>
<tr>
<td><code><b>step</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired continuously during the animation.</td>
</tr>
<tr>
<td><code><b>end</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired when the animation ends.</td>
</tr>
</table>
<h2id="draggable">Draggable</h2>
<p>A class for making DOM elements draggable (including touch support). Used internally for map and marker dragging. Only works for elements that were positioned with <ahref="#domutil-setposition">DomUtil#setPosition</a>.</p>
<pre><codeclass="javascript">var draggable = new L.Draggable(elementToDrag);
<td>Creates a Draggable object for moving the given element when you start dragging the <code>dragHandle</code> element (equals the element itself by default).</td>
</tr>
</table>
<h3>Events</h3>
<p>You can subscribe to the following events using <ahref="#events">these methods</a>.</p>
<tabledata-id='draggable'>
<tr>
<thclass="width100">Event</th>
<thclass="width100">Data</th>
<th>Description</th>
</tr>
<tr>
<td><code><b>dragstart</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired when the dragging starts.</td>
</tr>
<tr>
<td><code><b>predrag</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired continuously during dragging <em>before</em> each corresponding update of the element position.</td>
</tr>
<tr>
<td><code><b>drag</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired continuously during dragging.</td>
</tr>
<tr>
<td><code><b>dragend</b></code></td>
<td><code><ahref="#event">Event</a></code></td>
<td>Fired when the dragging ends.</td>
</tr>
</table>
<h3>Methods</h3>
<tabledata-id='draggable'>
<tr>
<thclass="width100">Method</th>
<thclass="width100">Returns</th>
<th>Description</th>
</tr>
<tr>
<td><code><b>enable</b>()</code></td>
<td><code>-</code></td>
<td>Enables the dragging ability.</td>
</tr>
<tr>
<td><code><b>disable</b>()</code></td>
<td><code>-</code></td>
<td>Disables the dragging ability.</td>
</tr>
</table>
<!--<h3>Static Properties</h3>
<table>
<tr>
<th>Property</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><code><b>START</b></code></td>
<td><code>String</code></td>
<td>Name of the DOM event that initiates dragging. <code><spanclass="hljs-string">'mousedown'</span></code> for desktop browsers, <code><spanclass="hljs-string">'touchstart'</span></code> for mobile devices.</td>
</tr>
<tr>
<td><code><b>MOVE</b></code></td>
<td><code>String</code></td>
<td>Name of the DOM event for drag moving. <code><spanclass="hljs-string">'mousemove'</span></code> for desktop browsers, <code><spanclass="hljs-string">'touchmove'</span></code> for mobile devices.</td>
</tr>
<tr>
<td><code><b>END</b></code></td>
<td><code>String</code></td>
<td>Name of the DOM event that ends dragging. <code><spanclass="hljs-string">'mouseup'</span></code> for desktop browsers, <code><spanclass="hljs-string">'touchend'</span></code> for mobile devices.</td>
</tr>
</table>-->
<h2id="ihandler">IHandler</h2>
<p>An interface implemented by <ahref="#map-interaction-handlers">interaction handlers</a>.</p>
<tabledata-id='ihandler'>
<tr>
<thclass="width100">Method</th>
<thclass="width100">Returns</th>
<th>Description</th>
</tr>
<tr>
<td><code><b>enable</b>()</code></td>
<td>-</td>
<td>Enables the handler.</td>
</tr>
<tr>
<td><code><b>disable</b>()</code></td>
<td>-</td>
<td>Disables the handler.</td>
</tr>
<tr>
<td><code><b>enabled</b>()</code></td>
<td><code>Boolean</code></td>
<td>Returns <code><spanclass="hljs-literal">true</span></code> if the handler is enabled.</td>
</tr>
</table>
<h2id="ilayer">ILayer</h2>
<p>Represents an object attached to a particular location (or a set of locations) on a map. Implemented by <ahref="#tilelayer">tile layers</a>, <ahref="#marker">markers</a>, <ahref="#popup">popups</a>, <ahref="#imageoverlay">image overlays</a>, <ahref="#path">vector layers</a> and <ahref="#layergroup">layer groups</a>.</p>
<td>Should contain code that creates DOM elements for the overlay, adds them to <ahref="#map-panes">map panes</a> where they should belong and puts listeners on relevant map events. Called on <code>map.addLayer(layer)</code>.</td>
<td>Should contain all clean up code that removes the overlay's elements from the DOM and removes listeners previously added in <code>onAdd</code>. Called on <code>map.removeLayer(layer)</code>.</td>
</tr>
</table>
<h3>Implementing Custom Layers</h3>
<p>The most important things know about when implementing custom layers are Map <ahref="#map-viewreset">viewreset</a> event and <ahref="#map-latlngtolayerpoint">latLngToLayerPoint</a> method. <code>viewreset</code> is fired when the map needs to reposition its layers (e.g. on zoom), and <code>latLngToLayerPoint</code> is used to get coordinates for the layer's new position.</p>
<p>Another event often used in layer implementations is <ahref="#map-moveend">moveend</a> which fires after any movement of the map (panning, zooming, etc.).</p>
<p>Another thing to note is that you'll usually need to add <code>leaflet-zoom-hide</code> class to the DOM elements you create for the layer so that it hides during zoom animation. Implementing zoom animation for custom layers is a complex topic and will be documented separately in future, but meanwhile you can take a look at how it's done for Leaflet layers (e.g. <code>ImageOverlay</code>) in the source.</p>
<h3>Custom Layer Example</h3>
<p>Here's how a custom layer implementation usually looks:</p>
<pre><code>var MyCustomLayer = L.Class.extend({
initialize: function (latlng) {
// save position of the layer or any options from the constructor
this._latlng = latlng;
},
onAdd: function (map) {
this._map = map;
// create a DOM element and put it into one of the map panes
// add a viewreset event listener for updating layer's position, do the latter
map.on('viewreset', this._reset, this);
this._reset();
},
onRemove: function (map) {
// remove layer's DOM elements and listeners
map.getPanes().overlayPane.removeChild(this._el);
map.off('viewreset', this._reset, this);
},
_reset: function () {
// update layer's position
var pos = this._map.latLngToLayerPoint(this._latlng);
L.DomUtil.setPosition(this._el, pos);
}
});
map.addLayer(new MyCustomLayer(latlng));
</code></pre>
<h2id="icontrol">IControl</h2>
<p>Represents a UI element in one of the corners of the map. Implemented by <ahref="#control-zoom">zoom</a>, <ahref="#control-attribution">attribution</a>, <ahref="#control-scale">scale</a> and <ahref="#control-layers">layers</a> controls.</p>
<h3>Methods</h3>
<p>Every control in Leaflet should extend from <ahref="#control">Control</a> class and additionally have the following methods:</p>
<td>Should contain code that creates all the neccessary DOM elements for the control, adds listeners on relevant map events, and returns the element containing the control. Called on <code>map.addControl(control)</code> or <code>control.addTo(map)</code>.</td>
<td>Optional, should contain all clean up code (e.g. removes control's event listeners). Called on <code>map.removeControl(control)</code> or <code>control.removeFrom(map)</code>. The control's DOM container is removed automatically.</td>
</tr>
</table>
<h3>Custom Control Example</h3>
<pre><code>var MyControl = L.Control.extend({
options: {
position: 'topright'
},
onAdd: function (map) {
// create the control container with a particular class name
var container = L.DomUtil.create('div', 'my-custom-control');
// ... initialize other DOM elements, add listeners, etc.
return container;
}
});
map.addControl(new MyControl());
</code></pre>
<p>If specify your own constructor for the control, you'll also probably want to process options properly:</p>
<pre><code>var MyControl = L.Control.extend({
initialize: function (foo, options) {
// ...
L.Util.setOptions(this, options);
},
// ...
});</code></pre>
<p>This will allow you to pass options like <code>position</code> when creating the control instances:</p>
<p>An object with methods for projecting geographical coordinates of the world onto a flat surface (and back). See <ahref="http://en.wikipedia.org/wiki/Map_projection">Map projection</a>.</p>
<td>Spherical Mercator projection — the most common projection for online maps, used by almost all free and commercial tile providers. Assumes that Earth is a sphere. Used by the <code>EPSG:3857</code> CRS.</td>
<td>Elliptical Mercator projection — more complex than Spherical Mercator. Takes into account that Earth is a geoid, not a perfect sphere. Used by the <code>EPSG:3395</code> CRS.</td>
</tr>
<tr>
<td><code><b>L.Projection.LonLat</b></code></td>
<td>Equirectangular, or Plate Carree projection — the most simple projection, mostly used by GIS enthusiasts. Directly maps <code>x</code> as longitude, and <code>y</code> as latitude. Also suitable for flat worlds, e.g. game maps. Used by the <code>EPSG:3395</code> and <code>Simple</code> CRS.</td>
</tr>
</table>
<h2id="icrs">ICRS</h2>
<p>Defines coordinate reference systems for projecting geographical points into pixel (screen) coordinates and back (and to coordinates in other units for WMS services). See <ahref="http://en.wikipedia.org/wiki/Coordinate_reference_system">Spatial reference system</a>.</p>
<td>Projects geographical coordinates into coordinates in units accepted for this CRS (e.g. meters for <code>EPSG:3857</code>, for passing it to WMS services).</td>
</tr>
<tr>
<td><code><b>scale</b>(
<nobr><Number><i>zoom</i> )</nobr>
</code></td>
<td><code>Number</code></td>
<td>Returns the scale used when transforming projected coordinates into pixel coordinates for a particular zoom. For example, it returns <code>256 * 2^zoom</code> for Mercator-based CRS.</td>
</tr>
<tr>
<td><code><b>getSize</b>(
<nobr><Number><i>zoom</i> )</nobr>
</code></td>
<td><code><ahref="#point">Point</a></code></td>
<td>Returns the size of the world in pixels for a particular zoom.</td>
<td>Transformation that this CRS uses to turn projected coordinates into screen coordinates for a particular tile service.</td>
</tr>
<tr>
<td><code><b>code</b></code></td>
<td><code>String</code></td>
<td>Standard code name of the CRS passed into WMS services (e.g. <code><spanclass="hljs-string">'EPSG:3857'</span></code>).</td>
</tr>
</table>
<h3>Defined CRS</h3>
<p>Leaflet comes with a set of already defined CRS to use out of the box:</p>
<tabledata-id='defined-crs'>
<tr>
<th>Projection</th>
<th>Description</th>
</tr>
<tr>
<td><code><b>L.CRS.EPSG3857</b></code></td>
<td>The most common CRS for online maps, used by almost all free and commercial tile providers. Uses Spherical Mercator projection. Set in by default in Map's <code>crs</code> option.</td>
</tr>
<tr>
<td><code><b>L.CRS.EPSG4326</b></code></td>
<td>A common CRS among GIS enthusiasts. Uses simple Equirectangular projection.</td>
</tr>
<tr>
<td><code><b>L.CRS.EPSG3395</b></code></td>
<td>Rarely used by some commercial tile providers. Uses Elliptical Mercator projection.</td>
</tr>
<tr>
<td><code><b>L.CRS.Simple</b></code></td>
<td>A simple CRS that maps longitude and latitude into <code>x</code> and <code>y</code> directly. May be used for maps of flat surfaces (e.g. game maps). Note that the <code>y</code> axis should still be inverted (going from bottom to top).</td>
</tr>
</table>
<p>If you want to use some obscure CRS not listed here, take a look at the <ahref="https://github.com/kartena/Proj4Leaflet">Proj4Leaflet</a> plugin.</p>
<h2id="global">Global Switches</h2>
<p>Global switches are created for rare cases and generally make Leaflet to not detect a particular browser feature even if it's there. You need to set the switch as a global variable to <code><spanclass="hljs-literal">true</span></code><em>before</em> including Leaflet on the page, like this:</p>
<td>Forces Leaflet to use the Canvas back-end (if available) for vector layers instead of SVG. This can increase performance considerably in some cases (e.g. many thousands of circle markers on the map).</td>
</tr>
<tr>
<td><code><b>L_NO_TOUCH</b></code></td>
<td>Forces Leaflet to not use touch events even if it detects them.</td>
</tr>
<tr>
<td><code><b>L_DISABLE_3D</b></code></td>
<td>Forces Leaflet to not use hardware-accelerated CSS 3D transforms for positioning (which may cause glitches in some rare environments) even if they're supported.</td>
</tr>
</table>
<h2id="noconflict">noConflict</h2>
<p>This method restores the L global variable to the original value it had before Leaflet inclusion, and returns the real Leaflet namespace so you can put it elsewhere, like this:<p>
<pre><code>// L points to some other library
...
// you include Leaflet, it replaces the L variable to Leaflet namespace
var Leaflet = L.noConflict();
// now L points to that other library again, and you can use Leaflet.Map etc.</code></pre>
<h2id="version">version</h2>
<p>A constant that represents the Leaflet version in use.<p>
<pre><code>L.version // contains "0.5" (or whatever version is currently in use)</code></pre>
<script>
var tables = document.getElementsByTagName('table');
for (var i = 0, len = tables.length; i <len;i++){
var id = tables[i].getAttribute('data-id'),
tds = tables[i].getElementsByTagName('td');
for (var j = 0, tdLen = tds.length; j <tdLen;j++){
if (tds[j].cellIndex === 0) {
tds[j].parentNode.id = id + '-' + (tds[j].textContent || tds[j].innerText).split('(')[0].toLowerCase();