Custom zooming

You can use the center(x, y, scale, time) method to center and zoom on a specific 2D coordinate on the map.

This example demonstrates how to zoom in on points clustered around specific labels. The algorithm works as follows:

  1. Find the x, y coordinates of the label by searching the input array of points.
  2. Find the points clustered around the label using the cluster() method.
  3. Compute the bounding box of the points in cluster. Pass the coordinates of the center of the bounding box as the x and y parameters of center(). Compute zoom scale as the ratio of the dimensions of the bounding box of all points and the bounding box of the points in cluster.

Click the links below to zoom to a number of example labels. Press Esc to Reset zoom.

Zoom to: pertussis measles vaccine hepatitis B tuberculin malaria rotavirus AIDS vaccine rubella


All code for this custom zooming functionality is included directly in this HTML page. View the page source to examine the code.