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

How do I generate a heat map for the world based on my data

2 Answers 58 Views
Map
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 29 Apr 2011, 04:49 PM
The example code uses a generated dbf file, but I need to get data at runtime based, for example "hugs per captia".

I get NaN in the legend when I tried the following code:

public partial class Example : UserControl
    {
        private bool initialized;
        private const string NonDbfDataField = "HugsPerCapita";
  
        public Example()
        {
            InitializeComponent();
            this.RadMap1.InitializeCompleted += new EventHandler(RadMap1_InitializeCompleted);
        }
  
        void RadMap1_InitializeCompleted(object sender, EventArgs e)
        {
            if (!this.initialized)
            {
                this.initialized = true;
                this.InformationLayer.Reader.PreviewReadCompleted += new PreviewReadShapesCompletedEventHandler(Reader_PreviewReadCompleted);
            }
        }
  
        private void Reader_PreviewReadCompleted(object sender, PreviewReadShapesCompletedEventArgs eventArgs)
        {
            if (eventArgs.Error == null)
            {
                foreach (MapShape shape in eventArgs.Items)
                {
                    this.SetAdditionalData(shape);
                }
            }
        }
  
        private void SetAdditionalData(MapShape shape)
        {
            ExtendedData extendedData = shape.ExtendedData;
            if (extendedData != null)
            {
                // add new property to ExtendedData  
                if (!extendedData.PropertySet.ContainsKey(NonDbfDataField))
                {
                    extendedData.PropertySet.RegisterProperty(NonDbfDataField, "", typeof(int), 0);
                }
  
                string country = (string)shape.ExtendedData.GetValue("ISO_2DIGIT");
                int additionalFieldValue = this.GetHugsByCountry(country);
  
                // assign value to new property  
                shape.ExtendedData.SetValue(NonDbfDataField, additionalFieldValue);
                  
            }
        }
  
        private int GetHugsByCountry(string stateName)
        {
            return 43 ; 
        }  
  
          
  
    }

2 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 04 May 2011, 08:14 AM
Hello Kevin,

You didn't provide your XAML, but as I can suppose looking into your code you specify source to the reader in XAML. If it is so, then the reader will start (and actually finish) reading of the shape file BEFORE you assign event handler to the PreviewReadCompleted event. It occurs when WPF process XAML and set Source property to reader. As result your application never come into it. You should assign event handler in XAML or initialize reader in the code completely.

Solution for XAML:


<telerik:InformationLayer.Reader
    <telerik:MapShapeReader Source="/ExtendedData;component/world.shp" 
        PreviewReadCompleted="MapPreviewReadCompleted"/> 
</telerik:InformationLayer.Reader>

Solution for code behind:

public MainWindow() 
    InitializeComponent(); 
    MapShapeReader reader = new MapShapeReader(); 
    reader.PreviewReadCompleted += new PreviewReadShapesCompletedEventHandler(this.MapPreviewReadCompleted); 
    this.informationLayer.Reader = reader; 
    this.radMap.InitializeCompleted += new EventHandler(radMap_InitializeCompleted); 
  
private void radMap_InitializeCompleted(objectsender, EventArgs e) 
    this.informationLayer.Reader.Source = new Uri("/ExtendedData;component/world.shp", UriKind.RelativeOrAbsolute); 


All the best,
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
Kevin
Top achievements
Rank 1
answered on 04 May 2011, 03:35 PM
Thanks.  That worked.
Tags
Map
Asked by
Kevin
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Kevin
Top achievements
Rank 1
Share this question
or