Use existing shapes file and populate ExtendedData dynamically

2 posts, 0 answers
  1. Rajinder
    Rajinder avatar
    6 posts
    Member since:
    Dec 2012

    Posted 09 Apr 2015 Link to this post

     I've been using samples from the SDK along with this post   http://www.telerik.com/forums/accessing-the-dbf-file  but have failed to do what I'm hoping should be simple ;-)

     I need to show a map of the U.S. with the states as shapes, color coded to a value that I set dynamically.   E.g. population, average income, total number of hospital beds, etc.  The values (1 for each state) are provided by my underlying model based on user selections on the screen.    E.g.  User sees a combo box listing the various variables to map, picks one, and the map colors the states based on 1 value per state.  

     Looking at the examples, it seems I need 2 files .. 

    • A "shp" file that contains the actual shape definition.  I downloaded U.S. state shape file from http://www.arcgis.com/home/item.html?id=f7f805eb65eb4ab787a0a3e1116ca7e5
    • A "dbf" file that contains some data that is magically keyed to the items in the shp file. The corresponding dbf file from the above site has only basic data such as Name, FIPS code, etc. 

    Since the values that will drive the color of the shapes can only be determines at run-time, I'd like to just have a call-back, or some method, to provide a value to each of the 50 state shapes.   

    I thought the Telerik Forum's post (above)  above link would solve my problem, but I get a compile error on a couple lines, and I'm wondering if this is a Silverlight vs WPF issue, or a version issue or a simple case of user error.  on the following 2 statements.  this.informationLayer.Reader does not have a "Source" or a "DataSource" property.   (also please see attached screenshot) 

    this.informationLayer.Reader.Source = new Uri(string.Format(ShapeRelativeUriFormat, "world.shp"), UriKind.Relative);
    this.informationLayer.Reader.DataSource = new Uri(string.Format(ShapeRelativeUriFormat, "world.dbf"), UriKind.Relative);

    My Xaml is pasted below.   I've tried to  attached the project files in a zip file, but it is over 2Meg.  It is actually the sample from the SDK browser with a few lines of code as suggested by the forum link above.... 

    Thanks for your advice. 

     

    <Window x:Class="InformationLayerColorizerModeCount.MainWindow"
            Title="MainWindow" Height="800" Width="1200">
        <Grid>
            <telerik:RadMap x:Name="radMap" InitializeCompleted="radMap_InitializeCompleted">
                <telerik:RadMap.Provider>
                    <telerik:EmptyProvider />
                </telerik:RadMap.Provider>
                <telerik:InformationLayer x:Name="informationLayer">
                    <telerik:InformationLayer.Reader>
                        <telerik:MapShapeReader DataSource="/InformationLayerColorizerModeCount;component/Resources/world.dbf"
                                                Source="/InformationLayerColorizerModeCount;component/Resources/world.shp" />
                    </telerik:InformationLayer.Reader>
                    <telerik:InformationLayer.Colorizer>
                        <telerik:ColorMeasureScale ExtendedPropertyName="SQKM" Mode="Count" TickMarkCount="7">
                            <telerik:ColorMeasureScale.ShapeFillCollection>
                                <telerik:MapShapeFill Fill="#FFFAB935" Stroke="White" StrokeThickness="2" />
                                <telerik:MapShapeFill Fill="#FFC9441C" Stroke="White" StrokeThickness="2" />
                            </telerik:ColorMeasureScale.ShapeFillCollection>
                        </telerik:ColorMeasureScale>
                    </telerik:InformationLayer.Colorizer>
                </telerik:InformationLayer>
            </telerik:RadMap>
        </Grid>
    </Window>

     

  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 14 Apr 2015 Link to this post

    Hello Rajinder,

    Reader property of the InformationLayer is of type MapShapeReaderBase but this class does not provide Source and DataSource properties. In XAML you set the Reader to be MapShapeReader. MapShapeReader class inherits from MapShapeReaderBase and it provides Source and DataSource properties.
    This means you need a cast:
    MapShapeReader reader = this.informationLayer.Reader as MapShapeReader;
    if (reader != null)
    {
             reader.Source = new Uri(....)
    }


    Regards,
    Petar Mladenov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top