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

Binding data to Rectangle in RadMap

3 Answers 125 Views
Map
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 01 Mar 2011, 10:19 PM

Hi everybody,

I'm working as on that example: http://www.telerik.com/help/silverlight/radmap-features-data-binding.html

But my data is not being binding. Someone can help me?

I have copied my code bellow:

MainPage.xaml
-------------------------

 

<UserControl x:Class="DemoSL.MainPage"
        mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
 <Grid x:Name="LayoutRoot">
  <telerik:RadMap x:Name="radMap" Width="600" Height="480">
    <telerik:InformationLayer x:Name="informationLayer" Visibility="Visible">
     <telerik:InformationLayer.ItemTemplate>
      <DataTemplate x:Name="dataTemplate">
       <Grid x:Name="gridContent" 
       telerik:MapLayer.BaseZoomLevel="{Binding BaseZoomLevel}"
       telerik:MapLayer.Location="{Binding Location}"
       telerik:MapLayer.ZoomRange="{Binding ZoomRange}"                       
        <telerik:MapLayer.HotSpot>
          <telerik:HotSpot X="0.5" Y="0.5"  XUnits="Fraction" YUnits="Fraction" 
                            ElementName="PART_Rectangle" />
        </telerik:MapLayer.HotSpot>
        <Rectangle x:Name="PART_Rectangle" Width="800" Height="800" Stroke="Red"
       StrokeThickness="3" Fill="Yellow" RadiusX="2" RadiusY="2">
          <ToolTipService.ToolTip>
           <ToolTip Content="{Binding Caption}" />
          </ToolTipService.ToolTip>
         </Rectangle>
        </Grid>
       </DataTemplate>
      </telerik:InformationLayer.ItemTemplate>
     </telerik:InformationLayer>
   </telerik:RadMap>
  </Grid>
</UserControl>

MainPage.xaml.cs
-------------------------
public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            BingMapProvider bingMap = new BingMapProvider(MapMode.Aerial, true, "MyBingMapKey");
            this.radMap.Provider = bingMap;
            this.radMap.InitializeCompleted += radMap_InitializeCompleted;
          
        void radMap_InitializeCompleted(object sender, EventArgs e)
        {
            ObservableCollection<MapItem> items = new ObservableCollection<MapItem>();
            items = GetMapData();
            this.informationLayer.ItemsSource = items;
        }
        private ObservableCollection<MapItem> GetMapData()
        {
            ObservableCollection<MapItem> data = new ObservableCollection<MapItem>();
            data.Add(new MapItem("Item1", new Location(42.6957539183824, 23.3327663758679), 5, new ZoomRange(5, 12)));
            data.Add(new MapItem("Item2", new Location(42.1429369264591, 24.7498095849434), 5, new ZoomRange(5, 12)));
            data.Add(new MapItem("Item3", new Location(42.5131732087098, 27.4611884843576), 5, new ZoomRange(5, 12)));
            data.Add(new MapItem("Item4", new Location(43.2073941930888, 27.9275176988258), 5, new ZoomRange(5, 12)));
            return data;
        }
    }

MapItem.cs
----------
public class MapItem
    {
        public MapItem(string caption, Location location, double baseZoomLevel, ZoomRange zoomRange)
        {
            this.Caption = caption;
            this.Location = location;
            this.BaseZoomLevel = baseZoomLevel;
            this.ZoomRange = zoomRange;
          
        public string Caption
        {
            get;
            set;
        }
        public Location Location
        {
            get;
            set;
        }
        public double BaseZoomLevel
        {
            get;
            set;
        }
        public ZoomRange ZoomRange
        {
            get;
            set;
        }
    }

Location.cs
-----------
public class Location
    {
        public Location(double xlocation, double ylocation)
        {
            this.Xlocation = xlocation;
            this.Ylocation = ylocation;
        }
        public double Xlocation
        {
            get;
            set;
         
        public double Ylocation
        {
            get;
            set;
        }
    }

ZoomRange.cs
------------
public class ZoomRange
    {
        public ZoomRange(double xzoom, double yzoom)
        {
            this.Xzoom = xzoom;
            this.Yzoom = yzoom;
        }
        public double Xzoom
        {
            get;
            set;
          
        public double Yzoom
        {
            get;
            set;
        }
    }

3 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 04 Mar 2011, 10:15 AM
Hello Kevin,

You've overridden Location and ZoomRange structures in your code. It will not work. You must use Location and ZoomRange structures from the Telerik.Windows.Controls.Map namespace.

Greetings,
Andrey Murzov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Kevin
Top achievements
Rank 1
answered on 04 Mar 2011, 03:51 PM
ohhh, Thank you so much, can you tell me if exists click event on MapRectangle?

Thank you so much again :)
0
Andrey
Telerik team
answered on 09 Mar 2011, 10:39 AM
Hello Kevin,

I think you can use the MouseLeftButtonDown event of the MapRectangle. The handler should set the Handled property of event arguments to "true" to prevent propagating the event to the map to avoid panning it to center according to standard behavior of mouse click.
        private void rect_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // ...

            
// prevent propagating event to the map
            e.Handled = true;
        }

All the best,
Andrey Murzov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Map
Asked by
Kevin
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Kevin
Top achievements
Rank 1
Share this question
or