Section 8.3. Map Interaction


8.3. Map Interaction

Once you have rendered your initial map, your users may want to interact with it by zooming in, zooming out, or panning around the map. In order to provide this functionality, you need to implement panning and zooming on your map using the same RenderServiceSoap.GetMap method with more specific map options.

8.3.1. Programming Map Zoom

MapOptions object offers the Zoom property, of type double, with which you can set the zoom level of any given map. The MapPoints.Zoom property identifies the factor by which the map image is magnified; when a map is rendered, the Zoom value is initially set to one. To zoom in by 50%, set the Zoom value to 0.5; to zoom in again another 50%, set the Zoom value to 0.25; each time you divide the zoom value by 2, you zoom in 50% more than the previous level. The same logic works for zoom out. To zoom out the map by 50%, simply multiply the Zoom value by 2. After setting the new Zoom value to the MapSpecification object, call the GetMap method again with the same specification to zoom in or out; you can also get the initial map with the view zoomed in or out by setting the appropriate value. The following code shows how to set the zoom value to get the initial map with the view zoomed in by 50%:

     //Create render service     RenderServiceSoap renderService = new RenderServiceSoap( );     //Set credentials     . . .     //Create Map Specification     //Or assign to an existing map specification        //Zoom in by 50%     mapSpec.Options.Zoom = mapSpec.Options.Zoom/2;     //Get Map     MapImage[] maps = renderService.GetMap(mapSpec);

The Zoom value is set to the MapOptions.Zoom value and passed to the GetMap method; one thing to keep in mind regarding the Zoom value is that it must be a positive value, and it can't be zero.

8.3.2. Programming Map Pan

Similar to zoom, MapOptions object offers two properties, PanVertical and PanHorizontal, both of type double, which you can use to pan rendered maps. The MapPoints.PanVertical and MapPoints.PanHorizontal properties identify the factor by which the map image is panned. When a map is originally rendered, both the vertical and horizontal pan factors are set to zero. To pan the map north by 50% (half of the view), set the PanVertical value to 0.5, and to pan north by another 50%, increment the PanVertical value by 0.5 again; each time you increment the pan value by 0.5, you pan the map by another 50%. The same logic works for pan horizontal. However, there are a couple of things you need to keep in mind:

  • Positive pan values indicate pans east or north

  • Negative pan values indicate pans west or south

  • To pan northeast, southwest, southeast, or northwest, you need to set both pan vertical and pan horizontal values.

The following code shows how to set the pan the initial map by 20% north:

     //Create render service     RenderServiceSoap renderService = new RenderServiceSoap( );     //Set credentials     . . .     //Create Map Specification     //Or assign to an existing map specification     . . .        //Pan map North by 20%     mapSpec.Options.PanVertical =                    mapSpec.Options.PanVertical + 0.20     //Get Map     MapImage[] maps = renderService.GetMap(mapSpec);

Similarly, to pan the same map south instead of north, use the following pan factor:

        //Pan map South by 20%     mapSpec.Options.PanVertical =                    mapSpec.Options.PanVertical - 0.20     //Get Map     MapImage[] maps = renderService.GetMap(mapSpec);

Along the same lines, to pan the map northwest, set both PanVertical and PanHorizontal as follows:

 // +ve value for North mapSpec.Options.PanVertical           = mapSpec.Options.PanVertical + 0.20; //-ve value for West mapSpec.Options.PanHorizontal           = mapSpec.Options.PanHorizontal - 0.20; //Get Map MapImage[] maps = renderService.GetMap(mapSpec);

While these pan settings work well at higher zoom levels, you will soon realize that the 20% pan factor pans the map more than you would like it to pan at lower zoom levels; to compensate, you just need to multiply the pan factor by the zoom factor:

     //Compensate map pan with zoom factor        mapSpec.Options.PanVertical              = mapSpec.Options.PanVertical + 0.20 * mapSpec.Options.Zoom;     //Compensate map pan with zoom factor        mapSpec.Options.PanHorizontal             = mapSpec.Options.PanHorizontal - 0.20 * mapSpec.Options.Zoom;     //Get Map     . . .

Compensating the map pan with zoom value makes sure the panning is nonlinear at different zoom levels.




Programming MapPoint in  .NET
Programming MapPoint in .NET
ISBN: 0596009062
EAN: 2147483647
Year: 2005
Pages: 136
Authors: Chandu Thota

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net