I'm using Leaflet API. I'm using the Leaflet Draw plugin to select areas on the map. I need to set up a bounding box using leaflet draw to send to GeoServer.

The problem is when I use the following code:

var coords = the_layer.getLatLngs()[0];

I get the coordinates back like this:

LatLng(43.13306, -112.71973),LatLng(45.02695, -112.71973),LatLng(45.02695, -106.3916),LatLng(43.13306, -106.3916)

I need them back in this format (minx,miny,maxx,maxy):


So I need all of the non-numeric characters (excluding the commas) removed. I also need all spaces removed.

Is this possible?

1 Answer 1


Leaflet layers have methods to calculate a bounding box, and convert it to a string for sending to web services:

var coords = the_layer.getBounds().toBBoxString();

  • That's whacky. I swear i tried that and it said "toBBoxString() is not a funciton". That works now...Thanks!
    – MH7086
    Jul 3, 2017 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.