<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; }
Oh, that would awesome. But guess what would be even more, small complete sample with MVVM and Drag'n'drop :cool:.
I have this wired-up using a Command & ViewModel. I can post that part if anyone is interested, just let me know.
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 ); }
var mousePosition = Mouse.GetPosition(_map);
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.
if (_map.WrapAroundIsActive) mapPoint = Geometry.NormalizeCentralMeridian(mapPoint) as MapPoint;
How do I get to PART_Map?
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);
var mousePosition = Mouse.GetPosition(PART_Map); var mapPoint = PART_Map.ScreenToMap(mousePosition);
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.