Skip to main content

VectorItemsLayer.ItemsSource Property

Gets or sets the data source of vector items.

Namespace: DevExpress.UI.Xaml.Map

Assembly: DevExpress.UI.Xaml.Map.v21.2.dll

NuGet Package: DevExpress.Uwp.Controls

Declaration

public IEnumerable ItemsSource { get; set; }

Property Value

Type Description
IEnumerable

An object that is a data source of map vector items.

Example

To bind a vector item source to map control, do the following.

  • Create a VectorItemsLayer object and add it to the MapControl.Layers collection.
  • Assign the vector item source to the VectorItemsLayer.ItemsSource property of the object.
<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MapControl_Lesson3"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Map="using:DevExpress.UI.Xaml.Map"
    x:Class="MapControl_Lesson3.MainPage"
    mc:Ignorable="d">

    <Page.Resources>
        <DataTemplate x:Key="itemTemplate">
            <Image Width="40" Height="40" Source="Assets/Ship.png" 
                   RenderTransformOrigin="0.5,0.5">
                <Image.RenderTransform>
                    <CompositeTransform TranslateX="-20" TranslateY="-20"/>
                </Image.RenderTransform>
            </Image>
        </DataTemplate>
    </Page.Resources>

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Map:MapControl ZoomLevel="6">
            <Map:MapControl.CenterPoint>
                <Map:GeoPoint Latitude="-35" Longitude="145"/>
            </Map:MapControl.CenterPoint>
            <Map:ImageTilesLayer>
                <Map:ImageTilesLayer.DataProvider>
                    <Map:BingMapDataProvider BingKey="Your Bing Key"/>
                </Map:ImageTilesLayer.DataProvider>
            </Map:ImageTilesLayer>
            <Map:VectorItemsLayer ItemsSource="{Binding Shipwrecks}" 
                                  ToolTipPattern="{}{Name} ({Year})&#13;&#10;{Description}">
            </Map:VectorItemsLayer>
        </Map:MapControl>
    </Grid>
</Page>
using DevExpress.UI.Xaml.Map;
using System;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Xml.Linq;
using Windows.ApplicationModel;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace MapControl_Lesson3 {
    public sealed partial class MainPage : Page {
        const string filepath = "Assets\\ships.xml";

        ObservableCollection<MapItem> shipwrecks = new ObservableCollection<MapItem>();
        public ObservableCollection<MapItem> Shipwrecks { get { return shipwrecks; } }

        public MainPage() {
            this.InitializeComponent();
            LoadShipwrecks();
            this.DataContext = this;
        }

        void LoadShipwrecks() {
            string xmlFilepath = Path.Combine(Package.Current.InstalledLocation.Path, filepath);
            XDocument document = XDocument.Load(xmlFilepath);
            foreach (XElement element in document.Element("Ships").Elements()) {
                GeoPoint location = new GeoPoint() {
                    Latitude = Convert.ToDouble(element.Element("Latitude").Value, CultureInfo.InvariantCulture),
                    Longitude = Convert.ToDouble(element.Element("Longitude").Value, CultureInfo.InvariantCulture)
                };
                MapCustomElement e = new MapCustomElement() { 
                    Location = location, 
                    ContentTemplate = this.Resources["itemTemplate"] as DataTemplate };
                e.Attributes.Add(new MapItemAttribute() 
                {
                    Name = "Description", 
                    Value = element.Element("Description").Value
                });
                e.Attributes.Add(new MapItemAttribute() {
                    Name = "Name", 
                    Value = element.Element("Name").Value
                });
                e.Attributes.Add(new MapItemAttribute() 
                {
                    Name = "Year", 
                    Value = element.Element("Year").Value
                });

                shipwrecks.Add(e);
            }
        }
    }

}
See Also