This is a migrated thread and some comments may be shown as answers.

[Solved] RadMap - selected shape collection?

3 Answers 177 Views
Map for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Robert
Top achievements
Rank 1
Robert asked on 14 Dec 2013, 07:07 PM

Having some great experience with RadMap so far--great job on it!

I'd like to be able to get some access to the collection of shapes in order to inspect them as well as possibly select/unselect them programmatically.  However I can't really find any way to do that....

I can detect when a shape is tapped on using my ShapeSelectionChanged command...so I have *some* access to what's going on.  However I'd like to do things like:

-- clear all shape selections programatically

-- only allow a user to select two shapes (clearing the oldest)--for example choose two US States and see a side-by-side comparison

Any hints how to do things like these would be greatly appreciated!

3 Answers, 1 is accepted

Sort by
0
Accepted
Giuseppe
Telerik team
answered on 16 Dec 2013, 10:40 AM
Hello Robert,

Onto your questions:
  • You can get the selected shapes through the MapShapeSelectionBehavior.SelectedShapes property.
  • You can use the MapShapeSelectionBehavior.ClearSelection() method to clear the selected shapes, however, only single selection is supported programmatically through the MapShapeSelectionBehavior.SelectedShape property.
  • If the default MapShapeSelectionBehavior.SelectionMode options do not suit your scenario, you can create custom MapShapeSelectionBehavior. You can check the Map First Look example in our demo application that implements custom selection behavior (single shape selection per map layer) to get you started:

/// <summary>
/// Implements custom single selection mode per layer.
/// </summary>
public class MapSingleSelectionPerLayerBehavior : MapShapeSelectionBehavior
{
    private Dictionary<MapLayer, IMapShape> selectedShapesPerLayer;
    private IList<object> shapesToRemove;
 
    /// <summary>
    /// Initializes a new instance of the <see cref="MapSingleSelectionPerLayerBehavior"/> class.
    /// </summary>
    public MapSingleSelectionPerLayerBehavior()
    {
        this.SelectionMode = MapShapeSelectionMode.MultiExtended;
 
        this.selectedShapesPerLayer = new Dictionary<MapLayer, IMapShape>();
        this.shapesToRemove = new List<object>();
    }
 
    /// <summary>
    /// Initiates a hit test on the specified <see cref="T:Windows.Foundation.Point" /> location.
    /// </summary>
    /// <param name="location">The location.</param>
    /// <returns></returns>
    /// <remarks>
    /// The default <see cref="T:Telerik.UI.Xaml.Controls.Map.MapBehavior" /> logic returns only the top-most <see cref="T:Telerik.UI.Drawing.D2DShape" /> from the <see cref="T:Telerik.UI.Xaml.Controls.Map.MapShapeLayer" /> that matches the specific behavior requirements;
    /// you can override the default logic and return multiple <see cref="T:Telerik.UI.Drawing.D2DShape" /> instances (e.g. from layers that overlay one another) and the specific <see cref="T:Telerik.UI.Xaml.Controls.Map.MapBehavior" /> will
    /// manipulate all of them.
    /// </remarks>
    protected override IEnumerable<IMapShape> HitTest(Point location)
    {
        int layerCount = this.Map.Layers.Count;
        for (int i = layerCount - 1; i >= 0; i--)
        {
            var layer = this.Map.Layers[i] as MapShapeLayer;
            if (layer == null || !layer.IsSelectionEnabled)
            {
                continue;
            }
 
            var newShape = this.Map.HitTest(location, layer);
 
            if (this.selectedShapesPerLayer.ContainsKey(layer))
            {
                var oldShape = this.selectedShapesPerLayer[layer];
 
                // Disallow toggle selection.
                if (newShape == null || newShape == oldShape)
                {
                    continue;
                }
 
                if (oldShape != null)
                {
                    this.shapesToRemove.Add(oldShape);
                }
            }
 
            this.selectedShapesPerLayer[layer] = newShape;
 
            yield return newShape;
        }
    }
 
    /// <summary>
    /// Raises the <see cref="F:Telerik.UI.Xaml.Controls.Map.CommandId.ShapeSelectionChanged" /> command and the <see cref="E:Telerik.UI.Xaml.Controls.Map.MapShapeSelectionBehavior.SelectionChanged" /> event.
    /// </summary>
    /// <param name="removedItems">The removed items.</param>
    /// <param name="addedItems">The added items.</param>
    protected override void OnSelectionChanged(IList<object> removedItems, IList<object> addedItems)
    {
        base.OnSelectionChanged(this.shapesToRemove, addedItems);
 
        this.shapesToRemove.Clear();
    }
}


Hope this helps.



Regards,
Giuseppe
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Robert
Top achievements
Rank 1
answered on 17 Dec 2013, 03:10 PM
Thanks for the quick reply, Guiseppe.  Very helpful indeed.  Multi-select on the map would be helpful especially in use cases like dashboards where it's common to aggregate multi-select, e.g. "What are sales in New York and New Jersey?"
0
Giuseppe
Telerik team
answered on 18 Dec 2013, 11:33 AM
Hello Robert,

Thank you for elaborating on this.

You can log your feature request on supporting multiple shape selection programmatically in our Windows 8 feedback portal here so the community members can vote for it (and raise its priority).


Regards,
Giuseppe
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Map for XAML
Asked by
Robert
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Robert
Top achievements
Rank 1
Share this question
or