Leaflet (software)
{{Short description|JavaScript library for web mapping applications}}
{{Infobox software
| name = Leaflet
| logo = File:Leaflet_logo.svg
| author = Volodymyr Agafonkin
| released = {{start date|2011|05|13}}
| latest release version = {{wikidata|property|preferred|references|edit@end|Q13685322|P348|P548=Q2804309}}
| latest release date = {{
start date and age|{{wikidata|qualifier|preferred|single|Q13685322|P348|P548=Q2804309|P577}}}}
| programming language = JavaScript
| platform = See Browser support
| genre = JavaScript library
| license = BSD-2-Clause{{cite web |url=https://github.com/Leaflet/Leaflet/blob/master/LICENSE |title=License - Leaflet |access-date=2018-11-03 |publisher=Leaflet}}
| website = {{URL|leafletjs.com}}
}}
{{Portal|Free and open-source software}}
Leaflet is a JavaScript library used to build web mapping applications. It allows developers without a GIS background to display tiled web maps hosted on a public server, with optional tiled overlays. It can load feature data from GeoJSON files, style it and create interactive layers, such as markers with popups when clicked.
First released in 2011,{{cite web |url=http://robinlovelace.net/software/2014/03/05/webmap-test.html |title=Testing web map APIs - Google vs OpenLayers vs Leaflet |url-status=dead |archive-url=https://web.archive.org/web/20171103225922/http://robinlovelace.net/software/2014/03/05/webmap-test.html |archive-date=2017-11-03 |last=Lovelace |first=Robin |access-date=2018-11-03}} it supports most mobile and desktop platforms, supporting HTML5 and CSS3. Among its users are FourSquare, Pinterest, Flickr, and the USGS.
Leaflet is open source, and is developed by Volodymyr Agafonkin, who joined Mapbox in 2013.{{cite web |url=https://www.mapbox.com/blog/vladimir-agafonkin-joins-mapbox/ |title=Leaflet Creator Vladimir Agafonkin Joins MapBox |date=2014-08-06 |access-date=2018-11-03 |last=MacWright|first=Tom}}
Leaflet is an open-source, JavaScript-based library for creating interactive maps. It was created in 2011 by Volodymyr Agafonkin, a Ukrainian citizen.Agafonkin, V. (2024, July 28). An open-source JavaScript library for mobile-friendly interactive maps. https://leafletjs.com/index.html It covers a wide range of features a developer would need in creating interactive maps. It is supported by many browsers such as Chrome, Firefox, Safari 5+, Opera 12+, Internet Explorer 9 or later versions, and Edge.Agafonkin, V. (2024, July 28). An open-source JavaScript library for mobile-friendly interactive maps. https://leafletjs.com/index.html It supports many third-party plugins, thus enabling the developer to integrate different kinds of features, such as Tile and image layering, Overlay displays, and various interactions into the map; these plugins help the developer create excellent maps. Agafonkin, V. (2024, July 28). An open-source JavaScript library for mobile-friendly interactive maps. https://leafletjs.com/index.html
Being a lightweight (about 42 KB of JS) Agafonkin, V. (2024, July 28). An open-source JavaScript library for mobile-friendly interactive maps. https://leafletjs.com/index.html as intended, Leaflet enjoys a fantastic community of contributors helping to maintain it. It is built with simplicity; one good thing about Leaflet is its readable, easy-to-follow source code with rich API documentation. The Leaflet is still new; more effort could focused on providing detailed source code examples, such as step-by-step guidance for implementing third-party plugins. Most of its resources are docked in GitHub and can easily be downloaded and modified however you wish, and the source codes are entirely open source.Agafonkin, V. (2024, July 28). An open-source JavaScript library for mobile-friendly interactive maps. https://leafletjs.com/index.html
So far, three versions of Leaflet have been released, with its most stable version (Leaflet 1.9.4) released on May 18, 2023. The previous version (Leaflet 1.8.0) was released on April 18, 2022. A new version (Leaflet 2.0) is being developed, and its release date is yet to be set. {{cite web |url=https://www.mapbox.com/blog/vladimir-agafonkin-joins-mapbox/ |title=Leaflet Creator Vladimir Agafonkin Joins MapBox |date=2014-08-06 |access-date=2018-11-03 |last=MacWright|first=Tom}}
Use
A typical use of Leaflet involves binding a Leaflet "map" element to an HTML element such as a div. Layers and markers are then added to the map element.
#map {
height: 250px;
width: 400px;
border: 1px solid gray;
}
// Initialize the map
var map = L.map('map').setView([51.505, -0.09], 13);
// Add the tile layer (you can choose a different map style by changing the URL)
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
// Add a circle overlay with a specific radius and color
var circle = L.circle([51.508, -0.11], {
color: 'red',
radius: 500 // Radius in meters
}).addTo(map);
// Add a marker with a popup
var marker = L.marker([51.5, -0.09]).addTo(map)
.bindPopup('Hello World!
I am a popup.');
In this code sample, the Leaflet library itself is accessible through the variable L
.
Features
Leaflet supports Web Map Service (WMS) layers, GeoJSON layers, Vector layers and Tile layers natively. Many other types of layers are supported via plugins.
Like other web map libraries, the basic display model implemented by Leaflet is one basemap, plus zero or more translucent overlays, with zero or more vector objects displayed on top.
= Elements =
The major Leaflet object types are:{{cite web |url=https://leafletjs.com/reference.html |title=Leaflet API reference |access-date=2018-11-03}}
- Raster types (TileLayer and ImageOverlay)
- Vector types (Path, Polygon, and specific types such as Circle)
- Grouped types (LayerGroup, FeatureGroup and GeoJSON)
- Controls (Zoom, Layers, etc.)
There is also a variety of utility classes such as interfaces for managing projections, transformations and interacting with the DOM.
= Support for GIS formats =
Leaflet has core support for multiple GIS standard formats, with others supported in plugins.
= Browser support =
Leaflet 0.7 supports Chrome, Firefox, Safari 5+, Opera 12+ and IE 7–11.{{cite web |url=https://leafletjs.com/#features |title=Features |access-date=2018-11-03}}
= Examples of useful features =
{{POV|section|date=September 2024}}
Leaflet's {{Code|onEachFeature}} is quite handy when dealing with, for example, GeoJSON data. The function contains two parameters: "feature" and "layer". "feature" allows us to access each object inside the GeoJSON and "layer" allows us to add popups, tooltips etc.
An example in JavaScript is given below:
let geoJson = L.geoJSON(geoJsonData, {
weight: 2,
onEachFeature: getFeature,
style: getStyle
}).addTo(map);
const getFeature = (feature, layer) => {
if (!feature.properties.name) return
layer.bindTooltip(feature.properties.cityName);
layer.bindPopup(
`
- Name: ${feature.properties.cityName}
- Population: ${feature.properties.population}
)
};
It is also possible to add "async" keyword to {{Code|getFeature}} function in order to use promises such as {{Code|fetch()}}. We can utilise properties in each object of GeoJSON to create customised jsonqueries and get, for example, city-specific information and display them using {{Code|layer.bindTooltip}}, {{Code|layer.bindPopup}}, etc.
Comparison with other libraries
Leaflet is directly comparable with OpenLayers, as both are open source, client-side only JavaScript libraries. The library as a whole is much smaller, around 7,000 lines of code compared to OpenLayers' 230,000 (as of 2015).{{cite web |url=https://www.openhub.net/p/compare?project_0=OpenLayers&project_1=Leaflet |title=OpenHub.net comparison between OpenLayers and Leaflet |access-date=2018-11-03 |website=OpenHub.net |url-status=dead |archive-url=https://web.archive.org/web/20140808124119/https://www.openhub.net/p/compare?project_0=OpenLayers&project_1=Leaflet |archive-date=2014-08-08}} It has a smaller code footprint than OpenLayers (around 123 KB{{cite web |title=Leaflet frontpage |url=https://leafletjs.com/ |website=Leaflet - An Open-Source JavaScript Library for Mobile-Friendly Interactive Maps |access-date=2018-11-03}} vs 423 KB{{cite web |title=OpenLayers 3.4.0 compressed source code |url=http://openlayers.org/en/v3.4.0/build/ol.js |publisher=OpenLayers.org |access-date=2018-11-03 |archive-url=https://web.archive.org/web/20161129010528/http://openlayers.org/en/v3.4.0/build/ol.js |archive-date=2016-11-29 |url-status=dead }}) due partly to its modular structure. The code base is newer, and takes advantage of recent features of JavaScript, plus HTML5 and CSS3. However, Leaflet lacks features OpenLayers supports, such as Web Feature Service (WFS)Various plugins providing WFS-support are listed on https://leafletjs.com/plugins.html and native support for projections other than Google Web Mercator (EPSG 3857).{{cite web |url=https://leafletjs.com/reference.html#projection |title=Projection |access-date=2018-11-03}}
It is also comparable to the proprietary, closed source Google Maps API (debuting in 2005) and Bing Maps API, both of which incorporate a significant server-side component to provide services such as geocoding, routing, search and integration with features such as Google Earth.{{citation needed|date=April 2015}} Google Maps API provides speed and simplicity, but is not flexible, and can only be used to access Google Maps services. The new DataLayer part of Google's API does allow external data sources to be displayed, however.{{cite web |url=https://developers.google.com/maps/documentation/javascript/datalayer |title=Data Layer |publisher=Google Inc. |work=Google Maps Platform |access-date=2018-11-03}}
History
Leaflet began life in 2010 as "Web Maps API", a JavaScript library for the CloudMade mapping provider, where Agafonkin worked at the time. In May 2011, CloudMade announced the first release of Leaflet, built from scratch but using parts of the old API code.{{cite web |url=http://blog.cloudmade.com/2011/05/13/announcing-leaflet-a-modern-open-source-javascript-library-for-interactive-maps/ |title=Announcing Leaflet: a Modern Open Source JavaScript Library for Interactive Maps |date=2011-05-13 |access-date=2018-11-03 |website=CloudMade |url-status=dead |archive-url=https://archive.today/20140811222442/http://blog.cloudmade.com/2011/05/13/announcing-leaflet-a-modern-open-source-javascript-library-for-interactive-maps/ |archive-date=2014-08-11}}
- 0.1: May 17, 2011
- 0.2: June 18, 2011
- 0.3: Feb 14, 2012
- 0.4: Jul 30, 2012
- 0.5: Jan 17, 2013
- This release introduced Retina support and many usability and user experience improvements.{{cite web |url=https://leafletjs.com/2013/01/17/leaflet-0-5-released.html |title=Leaflet 0.5 Released |date=2013-01-17 |first=Vladimir |last=Agafonkin |access-date=2018-11-03}}
- 0.6: Jun 26, 2013
- This release expanded the API's range of methods and events, improved usability, and added GeoJSON saving. It was completed in a 2-day code sprint supported by Mapbox.{{cite web |url=https://leafletjs.com/2013/06/26/leaflet-0-6-released-dc-code-sprint-mapbox.html |title=Leaflet 0.6 Released, Code Sprint in DC with MapBox |date=2013-06-26 |first=Vladimir |last=Agafonkin |access-date=2018-11-03}}
- 0.7: Nov 22, 2013
- This release focused on bug fixing, announcing that refactoring and potential backward incompatibilities would come soon.{{cite web |url=https://leafletjs.com/2013/11/18/leaflet-0-7-released-plans-for-future.html |title=Leaflet 0.7 Release, MapBox and Plans for Future |date=2013-11-18 |first=Vladimir |last=Agafonkin |access-date=2018-11-03}}
- 1.0: Sep 27, 2016
- This release contained over 400 changes compared to v0.7.7:{{cite web |url=https://leafletjs.com/2016/09/27/leaflet-1.0-final.html |title=Meet Leaflet 1.0. |date=2016-09-27 |first=Vladimir |last=Agafonkin |access-date=2018-11-03}}
- Performance improvements in all aspects of the library and vector layers in particular.
- Flyover animations (zooming and panning in a curve).
- Fractional zoom level support.
- Better tile loading algorithm with less flickering.
- Custom pane management (including multiple vector layer panes and interleaving vectors and tile layers).
- Better support for non-standard projections.
- More accessibility features.
- Improved documentation.
- Stability improvements.
- 1.1: Jun 27, 2017
- This release adds video overlays and makes a transition to ECMAScript 6 modules.
- 1.2: Oct 25, 2017
- 1.3: Jan 15, 2018
- 1.3.2: Jul 17, 2018
- 1.3.3: Jul 18, 2018
- 1.3.4: Aug 21, 2018
- 1.4.0: Dec 30, 2018
- 1.5.0 and 1.5.1: May 8, 2019
- 1.6.0: Nov 17, 2019
- 1.7.1: September 4, 2020
- 1.8: April 18, 2022 Leaflet 1.8 released in the middle of war
- 1.9: September 22, 2022[https://github.com/Leaflet/Leaflet/releases/tag/v1.9.0 v1.9.0]
In March 2022, the developer urged action on the Russian invasion of Ukraine on the Leaflet website.{{Cite web |date=2022-03-21 |title=Leaflet - a JavaScript library for interactive maps |url=https://leafletjs.com/ |access-date=2022-03-22 |website= |archive-url=https://web.archive.org/web/20220321033923/https://leafletjs.com/ |archive-date=21 March 2022 |url-status=dead}}
References
{{Reflist|2}}
External links
- {{Official website}}
- [https://leafletjs.com/examples.html Leaflet Tutorials]
- [https://wiki.openstreetmap.org/wiki/Tile_servers Maps for Leaflet TileLayer]
- openstreetmap:leaflet
{{OpenStreetMap}}
- {{usurped|1=[https://web.archive.org/web/20220217213717/http://www.owlapps.net/modules/owlapps_apps/embedmap/ Free web app made with Leaflet: embedMap]}}
Category:Free software programmed in JavaScript
Category:Geographical technology
Category:Keyhole Markup Language