TomTom Maps for JavaScript
    Preparing search index...

    Function bboxFromGeoJSON

    • Extracts or calculates a bounding box from GeoJSON objects.

      • An existing bbox property wins over the geometry, as for Point features from TomTom services, whose bbox may cover a broader area than the point itself.
      • Otherwise, it calculates one from the geometry coordinates, sampling large geometries.
      • It aggregates the boxes of collections.

      A calculated box crosses the antimeridian, with west > east, when that is the narrower way to enclose the input:

      • Points and multi-points take the narrower box, as bboxFromCoordsArray does.
      • A line or a ring follows its edges, which never wrap across the antimeridian (RFC 7946 §3.1.9): [[179, 0], [-179, 0]] spans 358°, and [[179, 0], [181, 0]] gives [179, 0, -179, 0].
      • The parts of a multi-geometry and the members of a collection merge as bboxFromBBoxes does, so a polygon cut at 180, as RFC 7946 asks, gets the box across the antimeridian.

      Parameters

      • hasBBox: HasBBox

        A GeoJSON object, such as a Feature, FeatureCollection or Geometry, or an array of them.

      Returns OptionalBBox

      The bounding box as [west, south, east, north], or undefined for invalid input.

      // From a Feature with existing bbox
      const place = await geocodeOne('Amsterdam');
      const bbox = bboxFromGeoJSON(place);
      // Returns the bbox that came with the place

      // From an array of GeoJSON objects
      const multiBbox = bboxFromGeoJSON([place1, place2, place3]);
      // Returns bbox encompassing all three places