Bing map Learning Series (5) -- How to Use the graph nail layer and map layer

Source: Internet
Author: User
Document directory
  • 1. Add a pushpin Layer)
  • 2. Add a map layer)

We have also mentioned pushpin in the previous chapter. How can we implement it if we need to add a small graph nail tag to Bing Maps?

Thanks to original: http://www.cnblogs.com/beniao/archive/2009/12/01/1614191.html

1. Add a pushpin Layer)

The Bing Maps control has provided us with this function. maps. in the mapcontrol namespace, the pushpin class is provided to implement the graph nailing application. For example, we can use the following method to locate the position of a graph ordering layer on the map in mainpage. XAML. add the following code to the CS file:

Double longpolling = double. parse ("47.620574"); <br/> double latitude = double. parse ("-122.34942"); </P> <p> pushpin = new pushpin (); <br/> pushpin. location = new location (latitude, longpolling );

You can read a book to locate the location class. Then how can we add it to the map? In fact, the steps are very simple. The Bing Maps map control directly provides the graph nail layer, which can be added to the graph subscription layer through the embedded method. By default, the graphic tag provided by Bing Maps is used.

<M: Map credentialsprovider = "AmreePcQ50WyjCYvxNo0xUQDwiYVM8VFVTxmcW_1RmOb2x_7T1muW-fSTQQkOok1" X: Name = "map" center = "33.845881352, 105.165628188471" zoomlevel = "6.0"> <br/> <m: pushpin location = "33.845881352, 105.165628188471"> </M: pushpin> <br/> </M: Map>

As long as you follow the two steps above, you can directly locate the coordinates above 33.845881352 and 105.165628188471. As shown in the following figure, the location is China.

2. Add a map layer)

Through the above steps, we have successfully added a small map nail layer to the map. In addition to adding a map nail, we can also customize the map to add images, images, videos, etc, to add images, images, videos, and other data to a map, use the map layer provided by Bing Maps as follows:

<M: Map credentialsprovider = "AmreePcQ50WyjCYvxNo0xUQDwiYVM8VFVTxmcW_1RmOb2x_7T1muW-fSTQQkOok1" X: Name = "map" <br/> center = "33.845881352, 105.165628188471" zoomlevel = "6.0"> <br/> <m: pushpin location = "33.845881352, 105.165628188471" X: Name = "maypushpin"> </M: pushpin> <br/> <m: maplayer X: name = "mymaplayer"> </M: maplayer> <br/> </M: Map>

As shown above, a blank map layer is added to the map. Next, you can use the program to dynamically add what you want to add to the map layer. For example, we have located the China Map area above, can we add the Chinese flag to a map next? The answer is yes. How can this problem be solved?
Private void btnaddpushpin_click (Object sender, routedeventargs e) <br/>{< br/> double longpolling = double. parse (this. tblongitude2.text. trim (); <br/> double latitude = double. parse (this. tblatitude2.text. trim (); </P> <p> location = new location (latitude, longpolling); </P> <p> image = new image (); <br/> image. source = new bitmapimage (New uri ("http: // localhost: 2986/images/china.jpg", urikind. relativeorabsolute); <br/> image. stretch = stretch. none; <br/> image. imagefailed + = delegate (Object senders, exceptionroutedeventargs ex) <br/>{}; <br/> positionorigin position = new positionorigin (1.0, 1.0 ); </P> <p> This. mymaplayer. addchild (image, location, position); <br/>}

Similarly, you can use location to locate the accuracy and latitude of coordinates, and add the image sequence as an image object to the map layer as a display object. The effect is as follows:

So far, we have successfully inserted the Chinese flag on the map! The complete Silverlight code is as follows:

<Usercontrol X: class = "pushpinlayer. mainpage "<br/> xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "<br/> xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "<br/> xmlns: M =" CLR-namespace: Microsoft. maps. mapcontrol; Assembly = Microsoft. maps. mapcontrol "<br/> xmlns: D =" http://schemas.microsoft.com/expression/blend/2008 "xmlns: MC =" http://schemas.openxmlformats.org/markup-compatibility/2006 "<br/> MC: ignorable =" D "D: designwidth =" 500 "D: designheight = "500"> <br/> <grid X: Name = "layoutroot" width = "500" Height = "500"> <br/> <m: map credentialsprovider = "AmreePcQ50WyjCYvxNo0xUQDwiYVM8VFVTxmcW_1RmOb2x_7T1muW-fSTQQkOok1" X: Name = "map" <br/> center = "33.845881352, 105.165628188471" zoomlevel = "6.0"> <br/> <m: pushpin location = "33.845881352, 105.165628188471" X: Name = "maypushpin"> </M: pushpin> <br/> <m: maplayer X: name = "mymaplayer"> </M: maplayer> <br/> </m: map> <br/> <stackpanel horizontalalignment = "Left" verticalignment = "bottom" width = "180" Height = "200" background = "gray"> <br/> <textblock TEXT = "precision: "> </textblock> <br/> <textbox X: Name =" tblong.pdf "> </textbox> <br/> <textblock text =" latitude: "> </textblock> <br/> <textbox X: name = "tblatitude"> </textbox> <br/> <textblock text = ""> </textblock> <br/> <textblock text = "precision: "> </textblock> <br/> <textbox X: Name =" tblongitude2 "> </textbox> <br/> <textblock text =" latitude: "> </textblock> <br/> <textbox X: Name =" tblatitude2 "> </textbox> <br/> <button X: name = "btnaddpushpin" Click = "btnaddpushpin_click" content = "add a five-star red flag"> </button> <br/> </stackpanel> <br/> </GRID> <br/> </usercontrol>

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.