Select to view content in your preferred language

What is equivalent of Bing maps MapsItemControl

2252
2
09-30-2014 10:26 AM
IvanDemkovitch
Deactivated User

I'm switching out of Bing Maps into ESRI but have hard time finding sample which will do the same thing..

I have layer on top of base map showing position of assets. Data bound via MVVM.

This is code from Bing Maps:

<m:MapItemsControl ItemsSource="{Binding Source={StaticResource WorkLayerData}}">

<m:MapItemsControl.ItemTemplate>

<DataTemplate>

<Canvas>

.... STUFF drawn here.....

</Canvas>                                              

</DataTemplate>

</m:MapItemsControl.ItemTemplate>

</m:MapItemsControl>

I figured that most close is ElementLayer in ESRI Silverlight control, but can't figure out how to bind it to my datasource and achieve similar result.

Any pointers?

2 Replies
dotMorten_esri
Esri Notable Contributor

Take a look at GraphicsLayer in the samples http://esriurl.com/slsdk. This will give you the better performance than ElementLayer. Your datasource would have to be IEnumerable<Graphic> though.

0 Kudos
IvanDemkovitch
Deactivated User

Finally got it working. I kept my data source as ObservableArray<MyObjectType>

There was issue with bindings on my custom template, so I had to come up with custom converter to get my object from Esri Binding. After than - everything works the same. In case someone has same problem here is code for converter:

public class ObjectToTrackedAssetConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return string.Empty;
            var datBinding = value as ESRI.ArcGIS.Client.DataBinding;
            if (datBinding == null) return null;

            return datBinding.Attributes.First().Value as TrackEsriViewModel.TrackedAsset;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }

Obviously, my TrackedAsset object implement INotifyData..

In XAML when I need to bind to my object's properties here is what need to be done:

<esri:GraphicsLayer>

                <esri:GraphicsLayer.GraphicsSource>

                    <esri:PointDataSource

                            ItemsSource="{Binding Source={StaticResource MappedData}}"

                            XCoordinateBinding="{Binding Longitude}"

                            YCoordinateBinding="{Binding Latitude}">

                    </esri:PointDataSource>

                </esri:GraphicsLayer.GraphicsSource>

                <esri:GraphicsLayer.Renderer>

                    <esri:SimpleRenderer>

                        <esri:MarkerSymbol>

                            <esri:MarkerSymbol.ControlTemplate>

                                <ControlTemplate>

                                    <Canvas

                                        DataContext="{Binding Converter={StaticResource ObjectToTrackedAssetConverter}}">

                                        <Button                               

                                            Style="{StaticResource LooklessButtonStyle}"

                                            Width="{Binding PushpinWidth}" Height="{Binding PushpinWidth}"

                                            Margin="{Binding PushpinMargin}"

                                            Command="{Binding DataContext.SelectedPushpinChangedCommand, ElementName=LayoutRoot}"

                                            CommandParameter="{Binding}"

                                            Cursor="Hand">

                                            <Ellipse

                                                Width="{Binding PushpinWidth}" Height="{Binding PushpinWidth}" Stroke="Black" Fill="{Binding IsGPSDataRecent, Converter={StaticResource BoolToGreenRedBrushConverter}}" StrokeThickness="1">

                                            </Ellipse>

                                        </Button>

                                    </Canvas>

                                </ControlTemplate>

                            </esri:MarkerSymbol.ControlTemplate>

                        </esri:MarkerSymbol>

                    </esri:SimpleRenderer>

                </esri:GraphicsLayer.Renderer>

            </esri:GraphicsLayer>

So, main thing is to set Canvas DataContext to MY object. Then, I get proper command and property routing and everything works just like it was before with Bing maps control. Performance is pretty good too.