Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
925
Updating a MapLayer's DataSource
posted

Hi,

I am sure there is a simple way to do this, but having tried a few ways with no success I thought I better post the question.

I have a map with multiple layers (world, state, county etc.). Each layer is bound to the same data source currently and displaying data as a heat map. Depending on the the query run by the user the source could hold data associated with either countries, states, counties. This data is being pulled dynamically from a SSAS data source and to change the query the user is selecting levels of a geographic heierarchy.

The issue I have is that when the data source changes, the heat map of a particular layer is not being cleared down and remains the colour it was before even though there is no data associated with the elements. I have tried binding to the DataSource property of the map layer and using property changed events to update the UI. I have tried setting the DataSource property manually and calling DataBind(). I have also tried calling RenderWindow() after updating the source, each having no effect.

Any help would be appreciated.

Regards,

Chris

  • 2505
    Offline posted

    Hi Chris,

    Please, take a look at the following post: http://forums.infragistics.com/forums/p/53321/276279.aspx#276279.

    Hope that helps,
    Milana Zhileva

  • 925
    posted

    Have been able to get the desired behaviour, but I am sure there must be a better way than this:

    protected override void ResetElements()
            {
                map.Layers[CountriesLayer].Elements.ToList().ForEach(ResetElement);
                map.Layers[StatesLayer].Elements.ToList().ForEach(ResetElement);
                map.Layers[UsCountiesLayer].Elements.ToList().ForEach(ResetElement);
                map.Layers[UkCountiesLayer].Elements.ToList().ForEach(ResetElement);
            }
            private static void ResetElement(MapElement element)
            {
                if (!string.IsNullOrEmpty(element.Caption))
                    element.Caption = element.Name;
                element.Value = double.NaN;
            }


            protected override void InitializeData(List<SimpleDataCollection> data)
            {
                ResetElements();

                MapData = data.Count == 1 ? data[0] : null;

                UpdateElements();
            }

            private void UpdateElements()
            {
                map.Layers[CountriesLayer].Elements.ToList().ForEach(el => UpdateElement(el, true));
                map.Layers[StatesLayer].Elements.ToList().ForEach(el => UpdateElement(el, false));
                map.Layers[UsCountiesLayer].Elements.ToList().ForEach(el => UpdateElement(el, false));
                map.Layers[UkCountiesLayer].Elements.ToList().ForEach(el => UpdateElement(el, false));
            }

            private static void UpdateElement(MapElement element, bool isCountry)
            {
                if (isCountry)
                {
                    // Just show country names where we have values
                    element.Caption = double.IsNaN(element.Value) ? string.Empty : string.Format("{0} ({1})", element.Name, element.Value);
                }
                else
                {
                    // Show name regardless for states/counties
                    element.Caption = double.IsNaN(element.Value) ? element.Name : string.Format("{0} ({1})", element.Name, element.Value);
                }
            }