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

ColorMeasureScale_PrepareCompleted fires before PreviewReadShapesCompleted and doesn't recognize changes to ExtendedData values

1 Answer 68 Views
Map
This is a migrated thread and some comments may be shown as answers.
Rajinder
Top achievements
Rank 1
Rajinder asked on 11 Apr 2015, 11:42 PM

A simple problem .. I need to insert an ExtendedData  property dynamically during runtime based on a user selection.  (Or, I could hack it and change the value of an existing extended property - I don't really care at this point).    I tried added the new property in the PreviewReadShapesCompleted event, but the colorizer doesn't recognize it.  Even if I change an existing ExtendedData property's value, the colorizer does not reset it's range. 

Is there some way to refresh the colorizer?  I've tried setting a MinValue and MaxValue and binding the colorizer's Min and Max values to them but that doesn't work either.

For example, using the sample from WPF SDK for InformationLayerColorizerModeCount (world.shp/world.dbf) , I change the value of the "SQKM" property in the InformationLayerColorizerModeCount event by dividing it by 10.  When the map shows,  all countries are pretty much the same color.  If I divide it by 5, there is more variation in color, but not as much.  If I multiply it by 10, than all countries are dark with little or no variation. 

 Debugging shows me that ColorMeasureScale_PrepareCompleted fires before the PreviewReadShapesCompleted event and apparently sets it range of values from the original DBF values.

I tried to read the shape files in manually ( http://docs.telerik.com/devtools/wpf/controls/radmap/features/information-layer/shapefiles-support)  )  , modify the stream, and pass that into the  ShapeReader, but the "shapes" do not contain an ExtendedPropertySet so I can't manipulate the values. 

 

StreamResourceInfo shapeResourceInfo = Application.GetResourceStream(new Uri("/InformationLayerColorizerModeCount;component/Resources/world.shp", UriKind.RelativeOrAbsolute));
StreamResourceInfo dbfResourceInfo = Application.GetResourceStream(new Uri("/InformationLayerColorizerModeCount;component/Resources/world.dbf", UriKind.RelativeOrAbsolute));
Telerik.Windows.Controls.Map.ExtendedPropertySet extData = new ExtendedPropertySet();
List<FrameworkElement> shapes = new List<FrameworkElement>();
var x = ShapeFileReader.Read(shapeResourceInfo.Stream, dbfResourceInfo.Stream);
foreach (var shape in shapes)
{
    this.informationLayer.Items.Add(shape);
}

 In the foreach loop, I want to grab a value from my  model for the specific country, and then either change the value of an existing ExtendedData or create a new one, but the "shape" instance does not have any property that allows me to do this despite the fact that I included the DBF file in the Read method. 

Maybe I should use a different technique altogether ?   It seems that this requirement would be quite common, i.e. user picks a variable, program colorizes the map according to that variable.  What am I missing ? 

Thanks

1 Answer, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 15 Apr 2015, 03:18 PM
Hello,

As far as I understand your requirement you need to update the Colorizer of the InformationLayer at runtime based on a change of the underlying dbf file. If so, you need to keep in mind that the ColorMeasureScale object is not designed to be updated at runtime based on a change in the underlying data file.

In order to update the colorizer you need to reset the Source and DataSource properties of the reader. Please take a look at the attached project. It demonstrates this approach.

You need to keep in mind that if you have large number of shapes this can decrease the overall performance of your application because of the reloading.

If this approach is not convenient you can try another one. It does not involve adding or removing UI elements from the visual tree (which takes time and resources). You can try to manually read the shapes from your file and fill the Items collection of the layer. Furthermore you can work directly with the properties of the UIElements in the Items collection of the layer instead of utilizing the colorizer object.
The idea is to create any type of mapping between the shapes in your files and the Items of the layer (e.g. Dictionary). When you detect that any of the properties of the shapes inside the files based on the custom mapping you will be able to find the UIElement that you need to change. This will allow you to modify the already existing UIElements instead of recreating new ones.

I hope this information is helpful.

Regards,
Pavel R. Pavlov
Telerik
 

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

 
Tags
Map
Asked by
Rajinder
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Share this question
or