I have a leaflet map that I need to fitBound on a given rectangle. The coordinate for the fit bound will be transfered in JSON via a REST call on a server. We are using GEOJson to encode our geometry

So my question is : what would be the correct way to encode this using geojson? The RC candidate seemed to include a BOX type that would be perfect, but this type is not present in the final specification.

So far I see :

  • There is a bbox attribute, but it seem to apply to a specific geometry. I couldn't use it on its own.
  • I could just send a dumb JSON array [-90, -180, 90, 180], but then I lose the advantages of using a standardised format.
  • I could use the BOX type but it appear to have been dropped.

What should I use to send this information?


I don't understand why you don't encode in a normal polygon and then when you need to use fitBounds you can use L.latLngBounds( latlngs ).

Something like this:

var bounds = L.latLngBounds([[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0],[100.0, 0.0]]); map.fitBounds(bounds);
  • Well, because I didn't think about that until now. No need to be condescending. I am new to the GIS world, hence why I asked this question in the first place! It may seem super obvious to you, but it is not to me. – Laurent Bourgault-Roy Feb 28 '14 at 18:28
  • Laurent, I think you are misreading this answer. The "I don't understand" locution looks to me like an effort to be both modest and tentative, offered in the spirit of "I think this might work but maybe there's more going on in your situation than I know about." Indeed, you should be very glad that a kind reader has taken the time and effort to offer a suggestion you did not think about before! – whuber Feb 28 '14 at 18:33
  • 1
    Fair point @whuber . I probably read it a little fast. Sorry about that. – Laurent Bourgault-Roy Feb 28 '14 at 18:38
  • I appreciate your understanding. It is hard to convey a tone of voice or attitude accurately in this written medium. Even those who are very good at projecting a sympathetic attitude sometimes are misread. In this GIS community it is rare for anybody to attack anyone else or even be condescending. We're glad you're here and participating--welcome to our site! (And welcome to you, too, ekaitht27--I see you are also a newcomer and I appreciate that you are answering as well as asking questions.) – whuber Feb 28 '14 at 18:43
  • @LaurentBourgault-Roy I didn't want to be impolite. Sorry about that but my mother thonge is not English ant it's difficult to me to express properly. As well may be I thought that I didn't understand the question, that is the reason that I used "don't understand" to try to be humble, this is my first answer in stackexchange. – ekaitht27 Mar 2 '14 at 10:13

As you have found out, the GeoJSON spec is completely silent on BOX type Geometries. So whatever you do will be non standard. That isn't something you should worry about.

But if you still want to make sure that it should be valid GeoJSON, I'll suggest that you send an empty FeatureCollection with a bbox attribute like this

{ "type": "FeatureCollection",
   "bbox": [68,8,102,45],
 "features": [] 

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.