This is the documentation of version 1.0.0-rc.2. Go to the latest version, 1.0.0-rc.5.
TomTom Maps for JavaScript
    Preparing search index...

    Function bboxFromGeoJSON

    • Extracts or calculates a bounding box from GeoJSON objects.

      It handles various GeoJSON types, picking the best approach:

      • It uses an existing bbox property, which is fastest.
      • Otherwise, it calculates one from the geometry coordinates.
      • It aggregates the boxes of collections.
      • It samples large geometries for performance.

      An existing bbox wins over the geometry. This matters for Point features from TomTom services, whose bbox may cover a broader area than the point itself.

      Parameters

      • hasBBox: HasBBox

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

      Returns OptionalBBox

      The bounding box as [minLng, minLat, maxLng, maxLat], 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 a Polygon geometry (calculates bbox)
      const polygon = {
      type: 'Polygon',
      coordinates: [[
      [4.88, 52.36],
      [4.90, 52.36],
      [4.90, 52.38],
      [4.88, 52.38],
      [4.88, 52.36]
      ]]
      };
      const polyBbox = bboxFromGeoJSON(polygon);
      // Returns: [4.88, 52.36, 4.90, 52.38]

      // From a FeatureCollection (aggregates all features)
      const places = await discoverPlaces({ query: 'coffee' });
      const collectionBbox = bboxFromGeoJSON(places);
      // Returns bbox encompassing all search results

      // From a LineString (calculates from coordinates)
      const route = await calculateRoute({
      locations: [[4.9, 52.3], [4.5, 51.9]]
      });
      const routeBbox = bboxFromGeoJSON(route.features[0].geometry);
      // Returns bbox containing the entire route

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