[Silverlight] Bing Maps Learning Series (V): Polygon graphics

Source: Internet
Author: User

Bing Maps Silverlight Control allows you to customize Polygon images, including triangles, rectangles (rectangles, diamond), and other Polygon images.

A polygon is a regular Graph composed of multiple edges. For example, a triangle is composed of three edges, to draw a triangle on a map, we need to know the coordinate values (precision and latitude) of the three vertices. The following code block:

private void btnPolygon_Click(object sender, RoutedEventArgs e){    MapPolygon polygon = new MapPolygon();    polygon.Fill = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);    polygon.StrokeThickness = 5;    polygon.Opacity = 0.7;    polygon.Locations = new LocationCollection() {                         new Location(34.9294740237661,107.506492025863),                         new Location(37.7814222409819, 105.979148275863),                         new Location(40.2865067209496, 109.219382650863) };    this.myMap.Children.Add(polygon);}
MapPolygon is a polygon class provided by Bing Maps. The above code block creates a triangle on a map. It uses coordinates of three points to locate and draw layers through Locations. The effect is as follows:
        
  
The Code is as follows:
Code
  Private void btnQuad_Click (object sender, RoutedEventArgs e)
{
MapPolygon polygon = new MapPolygon ();
// Fill color
Polygon. Fill = new System. Windows. Media. SolidColorBrush (System. Windows. Media. Colors. Red );
Polygon. Stroke = new System. Windows. Media. SolidColorBrush (System. Windows. Media. Colors. Yellow );
Polygon. StrokeThickness = 5;
Polygon. Opacity = 0.7;
Polygon. Locations = new LocationCollection (){
New Location (34.9294740237661, 107.506492025863 ),
New Location (37.7814222409819, 105.979148275863 ),
New Location (40.2865067209496, 109.219382650863 ),
New Location (29.8104584489867, 115.943992025863 )};
This. myMap. Children. Add (polygon );
}

  

In addition to the code above, you can also use the Map control to dynamically draw a polygon, as shown in the following example:

Code

<M: Map CredentialsProvider = "rule" x: Name = "myMap"
Center = "34.9294740237661, 107.506492025863" ZoomLevel = "4" NavigationVisibility = "Collapsed">
<M: MapPolygon Locations = "30,108 39,102 34.88, 90.021" Fill = "Red" StrokeThickness = "5" Opacity = "0.8"> </m: MapPolygon>
</M: Map>

      

 

 

For example, the red triangle is configured through initialization. In normal times, there are many dynamic creation methods in secondary development. As mentioned above, the quadrilateral is divided into diamond and Rectangle. Bing Maps also provides a class for drawing a Rectangle and a diamond. For example, a Rectangle is a Rectangle class. Secondary Development usually involves drawing some images on the map, or dynamically selecting and drawing on the map. It is very easy to understand the basic principles of drawing images, it is actually to add a child element to the Map control, which can also be understood as the UIElement of Silverlight.

 

We hope that you can use this article to discuss and exchange ideas and learn and make progress together.

 

Description

This document is a learning note and is intended to be shared with people with lofty ideals. You are welcome to repost this article, but mark the original article connection in a prominent position.

Author: Beniao

Article Source: http://beniao.cnblogs.com/or http://www.cnblogs.com/

 

 

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.