Hi,
Is it possible to pan the map while dragging a marker if the marker is moved to the side of the map?
Thanks,
Trevor
Pan the map while dragging a marker
Hi Trevor,
I think you can try to implement that like this: Find a event like mousemove, calculate current mouse position, if it’s near four sides, call wpfMap1.Pan to move map.
Regards,
Don
MouseMove doesn’t fire while a marker is dragging but the PositionChanged event on a marker works to detect the changing position of a marker. In this event I do:
if
(e.NewPosition.X > MapControl.CurrentExtent.UpperRightPoint.X)
{
MapControl.Pan(PanDirection.Right, 10);
}
which correctly moves the map but in doing so, the marker resets to its original location. The mouse cursor is still where it’s supposed to be and the marker is still being dragged (provided you haven’t let go of the mouse button) but the marker is now in the center of the screen instead of underneath the mouse cursor. Any way around this?
Hi Trevor,
As below is the workaround, I tested it works.
SimpleMarkerOverlay markerOverlay = new SimpleMarkerOverlay();
markerOverlay.DragMode = MarkerDragMode.Drag;
markerOverlay.Drawing += markerOverlay_Drawing;
markerOverlay.MarkerDragging += markerOverlay_MarkerDragging;
markerOverlay.MarkerDragged += markerOverlay_MarkerDragged;
bool dragging = false;
void markerOverlay_Drawing(object sender, DrawingOverlayEventArgs e)
{
if (dragging)
{
e.Cancel = true;
}
}
void marker_PositionChanged(object sender, PositionChangedMarkerEventArgs e)
{
if (e.NewPosition.X > wpfMap1.CurrentExtent.UpperRightPoint.X - 5)
{
wpfMap1.Pan(PanDirection.Right, 10);
}
}
void markerOverlay_MarkerDragging(object sender, MarkerDraggingSimpleMarkerOverlayEventArgs e)
{
dragging = true;
}
void markerOverlay_MarkerDragged(object sender, MarkerDraggedSimpleMarkerOverlayEventArgs e)
{
dragging = false;
wpfMap1.Refresh();
}
Please let me know whether it works for you.
Regards,
Don
works perfectly, thanks!
Hi Trevor,
I am glad to hear that works.
Any question please let us know.
Regards,
Don