Skip to content

Instantly share code, notes, and snippets.

@mourner
Created July 3, 2012 10:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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);
@pbanavara
Copy link

Definitely the simplified-api.

@ErrorProne
Copy link

+1

@caseycesari
Copy link

+1 simplified

@cmoad
Copy link

cmoad commented Jul 3, 2012

The current API is more readable in my opinion. Perhaps add support for method chaining on top of the current API?

@bsudekum
Copy link

bsudekum commented Jul 3, 2012

I prefer the simplified API.

@rlightner
Copy link

+1

@bartek
Copy link

bartek commented Jul 5, 2012

Love the chaining. +1 for the simplified API

@WolfieZero
Copy link

Simplified API is very sex; more jQuery like and less Google Maps.

+1 simplified

@mourner
Copy link
Author

mourner commented Jul 5, 2012

Implemented in the master branch with backwards compatibility — you can use both approaches in your code now!

@ZoltanVeres
Copy link

I think the new version is more readable.

@frewsxcv
Copy link

frewsxcv commented Jul 5, 2012

For example, on this line:

var map = L.map('map').setView([51.505, -0.09], 13);

Does that mean setView() returns the map object?

@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