Development and application of "Silverlight" Bing maps five: To achieve the drag-and-drop of Pushpin (pushpin)

Source: Internet
Author: User
Tags silverlight

Development and application of "Silverlight" Bing maps Five: Implement drag-and-drop (draggable) extension of Pushpin (Pushpin)

Currently, there is no drag-and-drop Pushpin (pushpin) control in Bing Maps, and its powerful, flexible architectural design provides developers with very powerful extended support to implement the drag-and-drop of Pushpin controls.

System.Object
    System.Windows.DependencyObject
      System.Windows.UIElement
        System.Windows.FrameworkElement
          System.Windows.Controls.Control
            System.Windows.Controls.ContentControl
             Microsoft.Maps.MapControl.Pushpin

Before extending Pushpin, understand the structure design of the Pushpin control in the Bing Maps Silverlight controls (such as the upper code structure), The Pushpin is developed by extending the ContentControl control in Silverlight and adding the positional coordinates (Location) attributes and other related properties and fields. In view of the position of the Pushpin is mainly used location attribute, so this article only proposed this attribute, the other field properties in detail in the subsequent related Bovenri introduction.

In the use of the Bing Maps Silverlight control Development, there are two main ways to use the built-in Pushpin (without the ability to drag and drop operations), which is to add to the Maplayer as a child object after the dynamic creation of the background code, Another way is to directly configure it directly in XAML code. The following code block:

<m:Map x:Name="myMap" Margin="0,0,0,0" CredentialsProvider="{StaticResource MyCredentials}">
   <m:MapLayer x:Name="MapLayer">
     <m:Pushpin Location="29.5076372217973, 106.489384971208" Content="D"></m:Pushpin>
  </m:MapLayer>
</m:Map>

By the structure of the code snippet, it is clear that the parent of the Pushpin Control (pushpin) is a Maplayer object, and in Maplayer there is a property parentmap can get the current Maplayer object belonging to that map control object. It is then possible to get to the map control directly belonging to the Pushpin object, which means that the map control can be dynamically controlled in the Pushpin control.

Next, by customizing a drag-and-drop Pushpin class to extend the Pushpin controls built into the Bing Maps Silverlight control, you can implement a basic drag-and-drop Pushpin structure with the following code.

public class DraggablePushpin : Microsoft.Maps.MapControl.Pushpin
{
     /// <summary>
     /// 是否正在拖放
     /// </summary>
     private bool IsDragging = false;
     /// <summary>
     /// 鼠标拖放
     /// </summary>
     private EventHandler<MapMouseDragEventArgs> MapMouseDragHandler;
     /// <summary>
     /// 鼠标左键弹起
     /// </summary>
     private MouseButtonEventHandler MapMouseLeftButtonUpHandler;
     /// <summary>
     /// 鼠标移动
     /// </summary>
     private MouseEventHandler MapMouseMoveHandler;
}

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.