CanvasMap
Getting Started Tutorials 3D Reference

Limiting the area the user can view

Setting the Allowable Zoom Range and Extent of the Map

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 TheView=TheMainContainer.GetView();
TheView.SetSetting("View2D","MinZoom",2.5);
TheView.SetSetting("View2D","MaxZoom",2.5);
TheView.SetSetting("View2D","MaxBounds",{
	Xs:[-31,67], // min,max
	Ys:[-46,60] // Min,max
});

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 CMMainContainer.COORDINATE_UNITS_ZOOM and see how the zoom levels change.

Web Mercator

A common approach for adding a background to maps is to use some of the tiled datasets that are available on the Web. These datasets are typically in the Web Mercator projection. This projection is based on the Google Mercator projection but has the scaling converted to set 1 meter as the unit of distance at the equator. This does not match with the original dimensions of the Google Mercator projection so, to keep the Web Mercator tiles at full size in the map, we need to set the zoom factor to a value that has the value 74 after the decimal, -.26 for negative zooms. Below is an example of setting the min and max zoom.

TheView.SetSetting("View2D","MinZoom",-5.26); 
TheView.SetSetting("View2D","MaxZoom",1.74); 

Disabling Panning

By default, clicking outside features will allow the user to pan the map. You can also display panning by setting the current tool to CMToolHandler.TOOL_INFO or CMToolHandler.TOOL_NONE. Setting the tool to CMToolHandler.TOOL_HAND will only allow panning while CMToolHandler.TOOL_SELECT will allow panning if no features are selected and will display info when features are selected.

var TheView=TheMainContainer.GetView();
TheView.SetTool(CMToolHandler.TOOL_NONE);