"Bing Map Learning Series" (3)--How to control the map via the Bing Maps Silverlight controls

Source: Internet
Author: User
Tags silverlight

The last article raises the question of how users can programmatically control a map.

Using the Bing Maps Silverlight control will be very easy to do, this paper mainly describes how to map some of the common controls, including map loading mode, according to the accuracy and latitude positioning, zoom degree.

This article thanks to the original author: http://www.cnblogs.com/beniao/archive/2009/11/28/1612418.html
dynamic setting of map loading mode

In the "Bing Map Learning Series" (2)-How to display the map loading mode through the Bing Maps Silverlight control Show Map, you can set up a pattern map loading mode for map controls and load maps according to the established patterns when presenting the data. In fact, we can also change the loading rendering mode of the map through the program dynamically, which is the same as the mode loading mode, which is controlled by the Mode property of the map control (Bing Maps Silverlight control).

For example, in the program to achieve the previous article described in the three patterns map display, in the MainPage.xaml.cs file can be written as follows to write code implementation:

private void Road_click (object sender, RoutedEventArgs e) {this.map.Mode = new Roadmode ();} private void Aerial_click (ob Ject sender, RoutedEventArgs e) {this.map.Mode = new Aerialmode (false);} private void Aeriallabel_click (object sender, R Outedeventargs e) {this.map.Mode = new Aerialmode (true);}

Through the layout of three buttons to achieve three modes of switching, the corresponding front-end Silverlight code (that is, mainpage.xaml part of the code) is as follows:

<grid x:name= "LayoutRoot" width= "height=" > <m:map "credentialsprovider=" Amreepcq50wyjcyvxno0xuqdwiyvm8vfvtxmcw_1rmob2x_7t1muw-fstqqkook1 "x:name=" map "navigationvisibility=" Collapsed " > </m:Map> <stackpanel horizontalalignment= "left" verticalalignment= "top" orientation= "Horizontal" background= "Gray" > <button margin= "5" width= "" height= "" click= "Road_click" > <TextBlock> path Mode < /textblock> </Button> <button margin= "5" width= "height=" "click=" > Aerial_click > Satellite mode (no signposts) </TextBlock> </Button> <button margin= "5" width= "height=" click= "Aeriallabel_" Click "> <TextBlock> satellite Mode (with signposts) </TextBlock> </Button> </StackPanel> </Grid>

After running, the effect is shown in the following illustration:

second, dynamic positioning

It can be said that all map systems (such as the common Google maps,bing maps,arcgis,mapinfo, etc.) are positioned by precision (longitude) and latitude (Latitude). In the Bing Maps development, we can also achieve dynamic positioning, Bing Maps Silverlight control provides dynamic positioning of the relevant APIs we can call directly.

The precision and latitude of the map are represented by a double value (which is also possible with the Int,float type value set in the test Bing Maps), and it is necessary to be aware when setting the latitude of precision that the wrong degree value throws a Silverlight exception.

The code is as follows:

private void Dynamic_click (object sender, RoutedEventArgs e) {double latitude = 0; double longitude = 0; double. TryParse (Tblatitude.text, out latitude); Double. TryParse (Tblongitude.text, out longitude); This.map.SetView (New Location (latitude, longitude), 5); }

The Setview method provides multiple overloaded versions, one of which is to map coordinates by location object using precision and latitude to construct map coordinates and map zoom degree parameters. The coordinates of the precision and latitude of the map positioning are the center of the current map display area, and the "center" attribute of the map control is available, which is worth the central coordinates (precision, latitude) of the current display map.

The code looks like this:

Public MainPage () {InitializeComponent (); This.map.ViewChangeOnFrame + = Delegate (object sender, Microsoft.Maps.MapControl.MapEventArgs e) {double longitude = this.map.Center.Longitude; Double latitude = This.map.Center.Latitude; }; Third, dynamic setting zoom degree

Map Zoom can also be said to zoom and reduce the extent of the lens, you can set the map control Zoomlevel properties for dynamic control. The zoom value is limited to a value of only 1---16, the following for the map to set the default load zoom level.

The code for the front-end Silverlight is as follows:

<m:map credentialsprovider= "Amreepcq50wyjcyvxno0xuqdwiyvm8vfvtxmcw_1rmob2x_7t1muw-fstqqkook1" x:Name= "Map" Navigationvisibility= "Collapsed" zoomlevel= "5" > </m:Map>

At the same time also support the dynamic setting zoom degree, through the program dynamic change zoomlevel value on the OK, the following sample code:

private void Zoomlevel_click (object sender, RoutedEventArgs e) {double zoomlevel = 1d; double. TryParse (This.tbZoomLevel.Text.Trim (), out zoomlevel); This.map.ZoomLevel = Zoomlevel; }

The post-run effect diagram looks like this:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.