Joshua Ault
Top achievements
Rank 1
Joshua Ault
asked on 14 Apr 2010, 06:54 PM
Hello:
I just have a quick question. I am following the MVVM model and I am running into a problem with displaying an information layer. I have an ObservableCollection of locations. For each location I am adding a pinpoint to an information layer. My question is, how do I get this InformationLayer to display on the map after I have added the pinpoints to it, following MVVM.
Thank You
Josh
4 Answers, 1 is accepted
0
Hello Joshua,
We are aware about this problem with information layer. It will be fixed in 2010.Q1 SP1.
As workaround you can call the informationLayer.InvalidateArrange() method.
Kind regards,
Andrey Murzov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
We are aware about this problem with information layer. It will be fixed in 2010.Q1 SP1.
As workaround you can call the informationLayer.InvalidateArrange() method.
Kind regards,
Andrey Murzov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sorin Mecu
Top achievements
Rank 1
answered on 19 May 2010, 10:05 PM
Because InformationLayer derives from MapLayer you can use attached properties like so:
...
<DataTemplate >
<Grid
layers:MapLayer.BaseZoomLevel="{Binding Path=BaseZoomLevel}"
layers:MapLayer.Location="{Binding Path=PinPointLocation}"
layers:MapLayer.ZoomRange="{Binding Path=ZoomRangeVisibility}" >
...
Where your pinPoint have 3 properties with the same name like the ones from InformationLayer ( you can change them )
...
<DataTemplate >
<Grid
layers:MapLayer.BaseZoomLevel="{Binding Path=BaseZoomLevel}"
layers:MapLayer.Location="{Binding Path=PinPointLocation}"
layers:MapLayer.ZoomRange="{Binding Path=ZoomRangeVisibility}" >
...
Where your pinPoint have 3 properties with the same name like the ones from InformationLayer ( you can change them )
0
Pete
Top achievements
Rank 1
answered on 12 May 2011, 03:59 PM
Has this problem been solved? I am unable to get binding to the information layer to work using MVVM.
If I add items in code behind (this.informationLayer.Items.Add(location)) it works.
If I bind to the ItemsSource and add items to the LocationCollection that it is bound to, then nothing shows.
If I add items in code behind (this.informationLayer.Items.Add(location)) it works.
If I bind to the ItemsSource and add items to the LocationCollection that it is bound to, then nothing shows.
<
telerik:InformationLayer
x:Name
=
"informationLayer"
ItemsSource
=
"{Binding Items}"
>
<
telerik:InformationLayer.DataMappings
>
<
telerik:DataMapping
FieldName
=
"Location"
ValueMember
=
"Location"
/>
</
telerik:InformationLayer.DataMappings
>
<
telerik:InformationLayer.ItemTemplate
>
<
DataTemplate
>
<
Grid
>
<Ellipse
telerik:MapLayer.Location="{Binding}"
ToolTipService.ToolTip="{Binding Description}"
....
private LocationCollection _items;
private LocationCollection Items
{
get
{
return _items;
}
set
{
_items = value;
OnPropertyChanged("Items");
}
}
0
Hi XamlmaX,
The problem has been fixed in the 2010 Q3. The data binding works fine with latest build of the RadMap control. You can see how it can be done here:
http://demos.telerik.com/silverlight/#Map/DataBinding
Unfortunately your code snippets do not provide enough information about how you have implemented it. But I see a couple of possible problems in your XAML:
1. Data mapping you are using will not work because the Location object does not have a property or field with name 'Location'. Actually you do not need data mapping at all in this scenario.
2. Since your data objects are Locations it is not necessary to specify binding for MapLayer.Location attachable property in the data template. But if you are using it the telerik:MapLayer.Location="{Binding}" must be defined in the TOP level element in the data template (Grid in your case).
Here it is code for simple implementation of the collection binding within MVVM (it adds new locations on mouse click):
Greetings,
Andrey Murzov
the Telerik team
The problem has been fixed in the 2010 Q3. The data binding works fine with latest build of the RadMap control. You can see how it can be done here:
http://demos.telerik.com/silverlight/#Map/DataBinding
Unfortunately your code snippets do not provide enough information about how you have implemented it. But I see a couple of possible problems in your XAML:
1. Data mapping you are using will not work because the Location object does not have a property or field with name 'Location'. Actually you do not need data mapping at all in this scenario.
2. Since your data objects are Locations it is not necessary to specify binding for MapLayer.Location attachable property in the data template. But if you are using it the telerik:MapLayer.Location="{Binding}" must be defined in the TOP level element in the data template (Grid in your case).
Here it is code for simple implementation of the collection binding within MVVM (it adds new locations on mouse click):
public
class
RadMapDataModel : INotifyPropertyChanged
{
private
LocationCollection items;
public
RadMapDataModel()
{
this
.Items =
new
LocationCollection();
}
public
LocationCollection Items
{
get
{
return
this
.items;
}
set
{
this
.items = value;
OnPropertyChanged(
"Items"
);
}
}
public
event
PropertyChangedEventHandler PropertyChanged;
private
void
OnPropertyChanged(
string
propertyName)
{
if
(
this
.PropertyChanged !=
null
)
{
this
.PropertyChanged(
this
,
new
PropertyChangedEventArgs(propertyName));
}
}
}
<
UserControl
x:Class
=
"ShowPinPointsCS.MainPage"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
d:DesignHeight
=
"300"
d:DesignWidth
=
"400"
>
<
UserControl.Resources
>
<
DataTemplate
x:Key
=
"Ellipse"
>
<
Grid
telerik:MapLayer.Location
=
"{Binding}"
telerik:MapLayer.HotSpot
=
"0.5,0.5"
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"14"
/>
<
ColumnDefinition
Width
=
"Auto"
/>
</
Grid.ColumnDefinitions
>
<
Ellipse
Width
=
"14"
Height
=
"14"
Fill
=
"Red"
/>
</
Grid
>
</
DataTemplate
>
</
UserControl.Resources
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
telerik:RadMap
x:Name
=
"radMap"
Center
=
"37.7,2.2"
ZoomLevel
=
"8"
MapMouseClick
=
"AddLocationToCollection"
>
<
telerik:RadMap.Provider
>
<
telerik:OpenStreetMapProvider
/>
</
telerik:RadMap.Provider
>
<
telerik:InformationLayer
x:Name
=
"informationLayer"
ItemsSource
=
"{Binding Items}"
ItemTemplate
=
"{StaticResource Ellipse}"
/>
</
telerik:RadMap
>
</
Grid
>
</
UserControl
>
private
void
AddLocationToCollection(
object
sender, MapMouseRoutedEventArgs eventArgs)
{
this
.dataModel.Items.Add(eventArgs.Location);
}
Greetings,
Andrey Murzov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items