Skip to content

Instantly share code, notes, and snippets.

@ebrelsford
Created March 28, 2013 21:11
Show Gist options
  • Save ebrelsford/5266833 to your computer and use it in GitHub Desktop.
Save ebrelsford/5266833 to your computer and use it in GitHub Desktop.
A mixin for L.LatLngBounds that adds a toGeoJson method.
L.extend(L.LatLngBounds.prototype, {
toGeoJson: function() {
return {
'type': 'Polygon',
'coordinates': [[
[this.getSouthWest().lng, this.getSouthWest().lat],
[this.getNorthWest().lng, this.getNorthWest().lat],
[this.getNorthEast().lng, this.getNorthEast().lat],
[this.getSouthEast().lng, this.getSouthEast().lat],
[this.getSouthWest().lng, this.getSouthWest().lat],
]],
}
},
});
@chadwilcomb
Copy link

Nice! Thanks for making this!

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