b = map_name.zoomTo(latitude, longitudeʃ, zoom_levelʅ);
b = map_name.zoomTo(min_latitude, min_longitude, max_latitude, max_longitudeʃ, paddingʅ);
The
Map.zoomTo function pans and zooms a
Map to center the map on a given point, or to fit a rectangular region of the map to the screen. The
Map.zoomTo function may be used before the map is displayed to set the initial view, or it may be used in a callback function to change the view while the map is showing.
The first format example (point) moves the map so that the point with coordinates (latitude, longitude) is at the center of the screen. If the optional zoom_level is specified, the map is also zoomed to the specified zoom level. zoom_level is a number representing the level of detail to show. Zoom level one fits the entire world on the screen. Each consecutive zoom level is twice as detailed as the preceding level. Zoom level 15 shows streets, and zoom level 20 shows individual buildings. The minimum and maximum zoom levels supported will depend on the base map being used. If no zoom level is specified, the current zoom level is maintained.
The second format example (rectangle) pans and zooms the map to fit the rectangular region of the map with corners at (min_latitude, min_longitude) and (max_latitude, max_longitude). If the optional padding is specified, the map will be zoomed less so that the rectangular region will fit onto the screen with extra padding on each side. This can be used so that the edges of the rectangle do not line up exactly with the edge of the screen. The padding is specified as a percentage of the width of the screen. A padding of 5 would add padding equal to 5% of the device screen width.
If
Map.zoomTo is not called before the map is shown, then the initial view is determined in the order listed:
- If there are any markers, the view is set to fit all of the markers onto the screen.
- Next, if an offline map file that specifies an extent is used as a base map, the view is set to the extent of the offline map file.
- Last, the initial view is the entire world.
The function returns a logical value of 1 (true) if the map is zoomed/panned and 0 (false) if there is an error (for example, if the rectangle is invalid).
// Declare a map
Map mymap;
// Set initial view to center on the point 38.84839, -76.931098 at street level
mymap.zoomTo(38.84839, -76.931098, 15);
// Display the map
mymap.show();
// Declare a map
Map mymap;
// Set initial view to fit a rectangular region with 15% padding
mymap.zoomTo(38.841546, -76.937428, 38.853679, -76.911550, 15);
// Display the map
mymap.show();