Skip to content

Instantly share code, notes, and snippets.

@mourner
Created July 3, 2012 10:07
Show Gist options
  • Save mourner/3038879 to your computer and use it in GitHub Desktop.
Save mourner/3038879 to your computer and use it in GitHub Desktop.
Leaflet API simplification proposal
var map = new L.Map('map');
map.setView(new L.LatLng(51.505, -0.09), 13);
var cloudmade = new L.TileLayer('http://{s}.tile.cloudmade.com/.../{z}/{x}/{y}.png', {
attribution: '[...]'
});
map.addLayer(cloudmade);
var marker = new L.Marker(new L.LatLng(51.5, -0.09));
marker.bindPopup("<b>Hello world!</b><br />I am a popup.").openPopup();
map.addLayer(marker);
var circle = new L.Circle(new L.LatLng(51.508, -0.11), 500, {color: '#f03', opacity: 0.7});
circle.bindPopup("I am a circle.");
map.addLayer(circle);
var polygon = new L.Polygon([
new L.LatLng(51.509, -0.08),
new L.LatLng(51.503, -0.06),
new L.LatLng(51.51, -0.047)
]);
polygon.bindPopup("I am a polygon.");
map.addLayer(polygon);
var map = L.map('map').setView([51.505, -0.09], 13);
var cloudmade = L.tileLayer('http://{s}.tile.cloudmade.com/.../{z}/{x}/{y}.png', {
attribution: '[...]'
}).addTo(map);
L.marker([51.5, -0.09])
.bindPopup("<b>Hello world!</b><br />I am a popup.")
.addTo(map)
.openPopup();
L.circle([51.508, -0.11], 500, {color: '#f03', opacity: 0.7})
.bindPopup("I am a circle.")
.addTo(map);
L.polygon([
[51.509, -0.08],
[51.503, -0.06],
[51.51, -0.047]])
.bindPopup("I am a polygon.")
.addTo(map);
@mourner
Copy link
Author

mourner commented Jul 5, 2012

Yep, all method that don't explicitly return some value (like getCenter) return the object itself for chaining.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment