Skip to content

MapQuest.js

L.mapquest.util

A set of utility functions for the MapQuest.js library.

L.mapquest.util.getCenterFromBoundingBox()

The getCenterFromBoundingBox function takes a MapQuest bounding box object and returns an L.LatLng object that is the center of the bounding box.

Syntax

js
var boundingBox = {
  'ul': {
    'lng': -77.089424,
    'lat': 38.893276
  },
  'lr': {
    'lng': -77.077087,
    'lat': 38.848926
  }
}

var center = L.mapquest.util.getCenterFromBoundingBox(boundingBox);

L.mapquest.util.getZoomFromBoundingBox()

The getZoomFromBoundingBox function takes a MapQuest bounding box object and returns an integer that is the zoom level of a map that contains the bounding box.

This function is helpful when creating a map from a directions response, where you have a bounding box but you do not have a zoom level.

Syntax

js
var boundingBox = {
  'ul': {
    'lng': -77.089424,
    'lat': 38.893276
  },
  'lr': {
    'lng': -77.077087,
    'lat': 38.848926
  }
}

var zoom = L.mapquest.util.getZoomFromBoundingBox(boundingBox);
js
var boundingBox = {
  'ul': {
    'lng': -77.089424,
    'lat': 38.893276
  },
  'lr': {
    'lng': -77.077087,
    'lat': 38.848926
  }
}

var calculatedCenter = L.mapquest.util.getCenterFromBoundingBox(boundingBox);
var calculatedZoom = L.mapquest.util.getZoomFromBoundingBox(boundingBox);

var map = L.mapquest.map('map', {
  center: calculatedCenter,
  layers: L.mapquest.tileLayer('map'),
  zoom: calculatedZoom
});