MindFusion WinForms Programmer's Guide
Drag and Drop

Drag and drop from or to the map can be implemented using the standard Windows Forms drag and drop API. You will only need to convert between map and screen coordinates where appropriate, and probably use hit-testing methods to find what map element is under the mouse pointer. Use the MapToClient and ClientToMap methods to convert location latitude/longitude coordinates to or from pixel coordinates. Use the HitTest method of the Map class to find out what map element lies at the mouse position.

The following excerpt from the Palette sample project demonstrates how to add DecorationImage objects for images dragged from a ListView to the MapView:

C#  Copy Code

private void mapView_DragOver(object sender, DragEventArgs e)
{
    var clientPoint = mapView.PointToClient(new Point(e.X, e.Y));
    var geoLocation = mapView.ClientToMap(clientPoint);
    var state = mapView.BaseMap.HitTest(geoLocation);

    e.Effect = state != null ? DragDropEffects.Copy : DragDropEffects.None;
}

private void mapView_DragDrop(object sender, DragEventArgs e)
{
    var clientPoint = mapView.PointToClient(new Point(e.X, e.Y));
    var geoLocation = mapView.ClientToMap(clientPoint);
    var state = mapView.BaseMap.HitTest(geoLocation);

    e.Effect = state != null ? DragDropEffects.Copy : DragDropEffects.None;

    if (state != null)
    {
        int index = (int)e.Data.GetData(typeof(Int32));
        var decoration = new DecorationImage(
            images[index], geoLocation.Y, geoLocation.X);
        decoration.Label = lvImages.Items[index].Text +
            " in " + state.DatabaseRow["NAME_1"];
        decorationLayer.Decorations.Add(decoration);
        mapView.Invalidate();
    }
}