Solved! Go to Solution.
<i:Interaction.Triggers > <i:EventTrigger EventName="Loaded"> <cmd:EventToCommand Command="{Binding MapLoadedCommand, Source={StaticResource DragDropViewModel}}" PassEventArgsToCommand="True"/> </i:EventTrigger> </i:Interaction.Triggers>
private void MapLoaded(object parameter) { // See if the event sent the map in the event args var p1 = parameter as System.Windows.RoutedEventArgs; if (p1 == null) { throw new NullReferenceException("Cannot capture map reference."); return; } _map = p1.Source as Map; }
var mousePosition = Mouse.GetPosition(PART_Map); var mapPoint = PART_Map.ScreenToMap(mousePosition);
Have you tried getting the mouse position relative to the map, and then using ScreenToMap to get the map location, when in the drop event?var mousePosition = Mouse.GetPosition(PART_Map); var mapPoint = PART_Map.ScreenToMap(mousePosition);
How do I get to PART_Map?
if (_map.WrapAroundIsActive) mapPoint = Geometry.NormalizeCentralMeridian(mapPoint) as MapPoint;
One thing that could affect this (cant remember what versions of the SDK this was an issue) is that if your map is not full screen ie. you have another element on left/top of the map? If so, then the point could be that many pixels in wrong place.
var mousePosition = Mouse.GetPosition(_map);
private void Drop(object e) { var args = e as DragEventArgs; if (args == null) return; var mousePosition = args.GetPosition(_map); var mapPoint = _map.ScreenToMap(mousePosition); if (_map.WrapAroundIsActive) mapPoint = Geometry.NormalizeCentralMeridian(mapPoint) as MapPoint; var graphic = new Graphic(); graphic .Geometry = mapPoint; MyLayer.Graphics.Add(graphic ); }