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

3 posts, 0 answers
  1. Kevin
    Kevin avatar
    4 posts
    Member since:
    Apr 2011

    Posted 29 Apr 2011 Link to this post

    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. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 04 May 2011 Link to this post

    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
  3. DevCraft banner
  4. Kevin
    Kevin avatar
    4 posts
    Member since:
    Apr 2011

    Posted 04 May 2011 Link to this post

    Thanks.  That worked.
Back to Top