Hi,
I'm using the latest RC of the Desktop and I'm trying to implement some functionality where a user can pick from a tool bar of images and drag them onto the map. Then I capture the Map_DragDrop Event and add these to an inMemoryLayer and display them on the map.
I sort of have it working but I ran into a problem, it seems that the screen coordinates passed into the Map_DragDrop event are the screen coordinates relative to the entire screen instead of the map control. When I use the ExtenHelpler.ToWorldCoordinate method it doesn't work unless I put the upper left point of the map in the upper left corner of the screen.
Is this a bug? I would expect the screen coordinates passed into the Map_DragDrop event would be relative to the Map Control.
Some Prerequisites:
1. I set the AllowDrop property on the Map to True.
2. My Map Unit is set to DecimalDegrees.
Below is my code:
// This is the button on the tool bar that the user will drag onto the Map.
private void button3_MouseDown(object sender, MouseEventArgs e)
{
this.button3.DoDragDrop(this.button3, DragDropEffects.Move);
}
// Implement the Map_DragEnter event so the cursor shows correctly once the user enters the map area with the draggable item.
private void Map_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
// Here is where I implement the Map_DragDrop event to capture where the user dropped the item. I get the screen coordinates from the DragEventArgs, then convert them to world coordinates and add it to my existing InMemoryFeatureLayer.
private void Map_DragDrop(object sender, DragEventArgs e)
{
LayerOverlay housesOverlay = (LayerOverlay)Map.Overlays["houseOverlay"];
housesOverlay.Lock.EnterWriteLock();
InMemoryFeatureLayer houses = (InMemoryFeatureLayer)housesOverlay.Layers["houses"];
PointShape ps = ExtentHelper.ToWorldCoordinate(Map.CurrentExtent, new ScreenPointF(e.X, e.Y), Map.Width, Map.Height);
Feature draggedFeature = new Feature(ps);
houses.InternalFeatures.Add(draggedFeature);
housesOverlay.Lock.ExitWriteLock();
Map.Refresh();
}
Thanks!