1

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):

-109.46777343750001,47.96050238891509,-108.58886718750001,48.16608541901253

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

Is this possible?

3

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();

|improve this answer|||||
  • That's whacky. I swear i tried that and it said "toBBoxString() is not a funciton". That works now...Thanks! – Marcus Holden Jul 3 '17 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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