Created
July 3, 2012 10:07
-
-
Save mourner/3038879 to your computer and use it in GitHub Desktop.
Leaflet API simplification proposal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
+1
+1 simplified
The current API is more readable in my opinion. Perhaps add support for method chaining on top of the current API?
I prefer the simplified API.
+1
Love the chaining. +1 for the simplified API
Simplified API is very sex; more jQuery like and less Google Maps.
+1 simplified
Implemented in the master branch with backwards compatibility — you can use both approaches in your code now!
I think the new version is more readable.
For example, on this line:
var map = L.map('map').setView([51.505, -0.09], 13);
Does that mean setView() returns the map object?
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
Definitely the simplified-api.