draggable pushpin windows phone 7 bing maps control

…衆ロ難τιáo~ 提交于 2019-12-05 06:44:24

I've not seen this done on a WP7 app yet - but here is a description for Silverlight 3 - http://pietschsoft.com/post/2010/05/30/Draggable-Pushpins-using-Bing-Maps-Silverlight-Control.aspx

When implementing this I'd guess that you'd want to be careful about where you actually drop the icon in relation to your finger - e.g. if you look at how the text caret is moved in a text block when you click/hold/drag, then you'll see that the caret position is offset above the finger so that you can always see it.

Yes you can. Here is a nice writeup how to implement this behavior.

Draggable PushPins

I was able to drag a Pushpin by adding an event handler for MouseMove and updating the Pushpin to the location of the mouse.

<my:Pushpin x:Name="pushpin" MouseLeftButtonDown="pushpin_MouseLeftButtonDown" MouseLeftButtonUp="pushpin_MouseLeftButtonUp" MouseMove="pushpin_MouseMove"/>

But the problem is the Map Control will also pan at the same time you are dragging the Pushpin. To solve that I had to add an event handler for mouse up and mouse down to the Pushpin and one for MapPan for the Map Control.

        private void mapControl_MapPan( object sender, MapDragEventArgs e )
        {
          if( isDragging )
          {
            e.Handled = true;
          }
        }

        private void pushpin_MouseLeftButtonDown( object sender, MouseButtonEventArgs e )
        {
          pushpin.CaptureMouse( );
          isDragging = true;
        }

        private void pushpin_MouseLeftButtonUp( object sender, MouseButtonEventArgs e )
        {
          pushpin.ReleaseMouseCapture( );
          isDragging = false;
        }

        private void pushpin_MouseMove( object sender, MouseEventArgs e )
        {
          pushpin.Location = mapControl.ViewportPointToLocation( e.GetPosition( mapControl) );
        }

That will prevent the map from panning while the Pushpin is being dragged.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!