Select to view content in your preferred language

TimeSlider binding issues

4255
4
04-06-2011 07:23 AM
TerryGiles
Occasional Contributor III
I've created a user control which contains a combobox populated w/ the names of the layers in my map and a time slider.  When the user selects a layer in the combobox, it checks to see if the selected layer is a dynamic layer with a valid timeextent.  If so, I try to set the timeslider's min, max and value properties using that layer via bindings.  This seems to work (in debug timeControl has valid properties at the end of cbxLayers_SelectionChanged) but when the user changes the date range in the slider, the data on the map do not change to reflect that time period. 

One thing to note is that the layers in the map are all added when the maps loads, controlled by a parameter passed in.  This means I cannot set the binding in the XAML as the map may not contain any layers which support or have a TimeExtent.

Anyone see what I'm missing?  Thanks, TG

XAML
                                <esri:TimeSlider x:Name="timeControl" Grid.Row="1"  TimeMode="TimeExtent"
                                        PlaySpeed="0:0:1.5" Height="20" Width="200"/>



CS
private void cbxLayers_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ArcGISDynamicMapServiceLayer dlyr = null;

            ComboBoxItem cbi = ((sender as ComboBox).SelectedValue as ComboBoxItem);

            foreach (Layer l in _Map.Layers)
            {
                if (l.ID.ToLower() == cbi.Content.ToString().ToLower())
                {
                    if (l is ArcGISDynamicMapServiceLayer)  // need to add other time enabled layers later..
                    {
                        dlyr = l as ArcGISDynamicMapServiceLayer;
                    }
                    break;
                }
            }

            // time slider is in a tab control, on a tab called tabTime - hide if layer does not support Time Extent
            TabItem tab = tabQueryType.FindName("tabTime") as TabItem;
           

            if (dlyr == null)
            {
                tab.Visibility = Visibility.Collapsed;
               
            }
            else if (dlyr.TimeExtent == null)
            {
                tab.Visibility = Visibility.Collapsed;
            }
            else
            {
                tab.Visibility = Visibility.Visible;

                Binding b = new Binding("Layers[" + dlyr.ID + "].TimeExtent.Start");
                b.Source = _Map;
                b.Mode = BindingMode.OneWay;
                timeControl.SetBinding(TimeSlider.MinimumValueProperty, b);

                b = new Binding("Layers[" + dlyr.ID + "].TimeExtent.End");
                b.Source = _Map;
                b.Mode = BindingMode.OneWay;
                timeControl.SetBinding(TimeSlider.MaximumValueProperty, b);

                b = new Binding("Layers[" + dlyr.ID + "].TimeExtent");
                b.Source = _Map;
                b.Mode = BindingMode.OneWay;
                timeControl.SetBinding(TimeSlider.ValueProperty, b);

                List<DateTime> times = new List<DateTime>();
                DateTime dt = dlyr.TimeExtent.Start;
                while (dt < dlyr.TimeExtent.End)
                {
                    times.Add(dt);
                    dt = dt.AddDays(7);
                }
                timeControl.Intervals = times;


            }

            tabQueryType.SelectedIndex = 0;


        }

0 Kudos
4 Replies
ChristopherHill
Occasional Contributor
Did you set the binding of the Map.TimeExtent to the TimeSlider.Value?

<esri:Map x:Name="MyMap" TimeExtent="{Binding ElementName=MyTimeSlider, Path=Value}" >

Here is a basic example
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#TimeMapService
0 Kudos
TerryGiles
Occasional Contributor III
Did you set the binding of the Map.TimeExtent to the TimeSlider.Value?


Nope, completely forgot about that part.:o

I created another binding in the code behind like this & it works great.
                Binding b = new Binding("Value");
                b.Source = timeControl;
                _Map.SetBinding(Map.TimeExtentProperty, b);




Thanks Chris!

TG
0 Kudos
Rizky_DavitNugroho
New Contributor

Hi Terry,

I need to create TimeSlider in my project, I follow your step in your question but my timeslider doesn't work, can you please send me full code for your xaml & xaml.cs of your timeslider? Please, I need your help. my email rizky.davit@gmail.com

Thanks.

0 Kudos
DominiqueBroux
Esri Frequent Contributor

There are a few time slider samples in the interactive SDK. For example the Map Service - TimeSlider sample.

0 Kudos