[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Member Tables
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Collapse]Map Control
   [Expand]Getting Started
    Layers
   [Expand]Coordinate Systems
   [Expand]Map Image Data
   [Expand]GIS Data
   [Expand]Vector Data
   [Expand]Visual Elements
   [Expand]Examples
   [Collapse]End-User Features
     Scrolling
     Zooming
     Select and Highlight Map Items
     Search Panel
     Map Editor
     Mini Map
     Printing and Exporting
   [Expand]Product Information
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Select and Highlight Map Items

The Map Control allows end users to select one or multiple Vector Items on a map surface, and provides API to interact with these items in code. Users can also highlight map items.

This article explains how to:

Expanded Allow Users to Highlight Items

Use the MapItemsLayerBase.EnableHighlighting property to specify whether users can highlight map items on the layer:

Expanded Configure Highlighted Items' Appearance

The following code customizes the appearance of vector items highlighted by the user:

The table below lists API members used by code listed above:

Member Description
MapItemsLayerBase.HighlightedItemStyle Specifies a style to apply to highlighted items on the layer.
MapItemStyle.Fill Defines a highlighted item's fill color.
MapItemStyle.Stroke Defines a highlighted item's stroke color.
MapItemStyle.StrokeWidth Specifies a highlighted item's stroke width in pixels.
MapItemTextStyle.TextColor Defines a highlighted item's text color.

Expanded Allow Users to Select Items

Use the MapItemsLayerBase.EnableSelection property to define whether users can select items on the layer:

The MapControl.SelectionMode property allows you to enable/disable selection for all map layers. The ElementSelectionMode enumeration lists available modes:

Mode

Example

Description

Single

A single map item can be selected on the map at the same time.

  • Tap a map item on a touchscreen device.
  • Hover over a map item with the mouse pointer and click it.

Multiple

Multiple map items can be selected at the same time.

You can use Rectangular Selection to select several items at once.

  • Hold the Shift key and the left mouse button;
  • Drag the mouse pointer to mark an area that includes map items to be selected;
  • Release the left mouse button. All map items within the area are selected.

Extended

Extended mode combines Single and Multiple selection mode behaviors.

  • Click an element to select it.
  • To select/deselect multiple elements, click them while the Ctrl key is pressed.

Extended mode also allows you to use Rectangular Selection

None

Users cannot select any map items.

The code below enables Multiple mode:

Expanded Customize Selected Items' Appearance

The following code customizes the appearance of items a user selects:

The table below lists the API members that code listed above uses:

Member Description
MapItemsLayerBase.SelectedItemStyle Specifies a style to apply to selected items in the layer.
MapItemStyle.Fill Defines a selected item's fill color.
MapItemStyle.Stroke Defines a selected item's stroke color.
MapItemStyle.StrokeWidth Specifies a selected item stroke's width in pixels.
MapItemTextStyle.TextColor Defines selected item text's color.

Expanded Specify Selection Rectangle Appearance

You can change the selection rectangle's fill color and outline appearance:

The code below configures the selection rectangle as in the image above:

The table below lists the API members that code listed above uses:

Member Description
MapControl.SelectedRegionStyle Specifies a style to apply to the Selection Rectangle's area.
BackgroundStyle.Fill Gets or sets the Selection Rectangle's fill color.
BorderedElementStyle.Stroke Gets or sets the Selection Rectangle's stroke color.

Expanded Interact with Selected Items in Code

The MapItemsLayerBase.SelectedItems collection stores the items a user selects. The MapItemsLayerBase.SelectedItem property keeps the SelectedItems collection's first item.

The Map control raises the MapControl.SelectionChanged event after the SelectedItems collection is changed.

The MapControl.SelectionChanging event occurs before any map item is selected. Set the MapSelectionChangingEventArgs.Cancel property to true to cancel the item's selection.

Demo: Map Elements (requires DevExpress Demo Center of version 16.2 or newer installed)

Note

Use MapItem.IsHitTestVisible to specify whether a user can highlight or select the item.

Is this topic helpful?​​​​​​​