
Setting the Map Extent
Take a look at the code below and you'll see a "SetURL()" call just above sectoin "2.3.5". This is the call that ses the data set for the layer. The last parameter of the call determines if you want the scene to zoom to the bounds of the layer (True) or not (False). We've set the value to "false" so we can set where we want the map to "zoom to". Scroll the code down a bit and you'll see how we call the "ZoomTo()" and "SetRefCenter()" function calls in the "View" object for the CanvasMap. Try changing these values a bit and see how it effects the map. If you lose the map, just referesh the page and start again.
TheCanvasMap.TheView.ZoomTo(1); TheCanvasMap.TheView.SetRefCenter(10,10);
|
Zooming to an area
To have the zooming work correctly you will need to:
- Pass "false" to the "SetURL()" function to keep CanvasMap from zooming to your data after it loads. We've changed this in the example above.
- Put the "ZoomTo()" and "SetRefCenter()" calls after the "StartMap()" function call so the HTML Canvas object is setup to match the dimensions of the div that contains it.
The zoom level value you'll specify for the "ZoomTo()" function is a scaling factor between the pixels on the screen and your reference or "map" units for your data. Since the data for the example is in geographic, a zoom level of 1 will give us one pixel per degree. A value of 2 will give us two pixels per degree, making the map "zoom in" to a higher resolution. A value of 0.5 will make the map zoom out or give us 0.5 pixels per degree (or 2 degrees per pixel). Try different values of the zoom to see the effect. Remember that when we start displaing projected data, the zoom levels will change quite a bit because the map units will be in meters or feet.
The values for the "SetRefCenter()" function are just the X (Longitude or Easting) and the Y (Latitude or Northing) for the center of the area to zoom to. Try zooming to different areas of the map and then zoom to one of the continents and write down the "ZoomTo()" and "SetRefCenter()" values for the next tutorial.