draggable pushpin windows phone 7 bing maps control

情到浓时终转凉″ 提交于 2019-12-07 03:45:27

问题


Just wondering if there are any decent resources on how to program a draggable pushpin for a map in a windows phone 7 application. I've had a good look and can only find information about how to do it for a browser application.

Ideally I want the user to be able to click on a pushpin and drag it to a location on the map however, at the minute the only way I can think of doing this is for the user to drag the map and the pushpin remains at the centre of the map.


回答1:


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.




回答2:


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

Draggable PushPins




回答3:


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.



来源:https://stackoverflow.com/questions/5313890/draggable-pushpin-windows-phone-7-bing-maps-control

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