Setting the Allowable Zoom Range and Extent of the Map

When you "SetURL()" for a layer, the last parameter determines if you want the scene to zoom to the bounds of the layer (True) or not (False). If you specify False for all the layers, you can then zoom to a specified area on the map using the commands below.

Note that you can only zoom to an area after the StartMap() function call as the function will set the final width and height of the Canvas HTML object.

Limiting the area the user can view

You can change the maximum bounds of the map which will limit how far the user can pan the map. You'll almost always want to limit the "Zoom" levels with this as well.

You can easily find the bounds by loading your data into a GIS application and moving the cursor over the corners of the data. Then, enter the x and y coordinate values as shown below.

var TheBounds = 
{
  	XMin: -500000, // left side (usually wester most edge)
	XMax: 2000000, // right side (usually eastern most edge)
	YMin: 3300000, // bottom side (usually southern most edge)
	YMax: 5000000 // top side (usually northern most edge)
}
TheCanvasMap.TheView.SetMaxBounds(TheBounds);
TheCanvasMap.TheView.SetZoomRange(-11,10);

The zoom range is computed by the equation:

PixelsPerMapUnit=2 ^ ZoomLevel

In other words, when there is 1 pixel per map unit (e.g. 1 pixel per degree or 1 pixel per meter), the zoom level is 0. As you "zoom out" there are more map units per pixel so the zoom level goes down (e.g. -1, -2, -3...). As you "zoom in" the number of pixels per map unit increase and the zoom level goes up (e.g. 1, 2, 3...). Play around with this a bit or set the coordinate units to CanvasMap.COORDINATE_UNITS_ZOOM and see how the zoom levels change.