How can I control the placement of a Symbol's captions?
Currently with a 'bubble' symbol the caption is appearing over the symbol I want it to display above by default.
Further for some of my applications I want to one piece a caption above the symbol and a value below the symbol, is this possible?
Hi dmurraylaing,By default, if MapElement's SymbolOrigin hasn't been set, the ValueTemplate will be centered according to the element's WorldRect.
However, to apply explicit positioning, you could use the following approach:private void MapLayer_Imported(object sender, Infragistics.Controls.Maps.MapLayerImportEventArgs e) { if (e.Action == MapLayerImportAction.End) { xamMap1.Layers["MapLayer"].ValueTemplate = LayoutRoot.Resources["placeSymb"] as DataTemplate;
MapElement mapEl = xamMap1.Layers[0].Elements["Russia"].First(); Point p = new Point(104.4140625, 62.59334083012024); mapEl.SymbolOrigin = xamMap1.MapProjection.ProjectToMap(p); } }where placeSymb is the ValueTemplate, defined few forum posts above.
Best regards,Milana Zhileva
I have almost got a workable solution, except for the alignment.
It looks like the value template is positioned with the top left hand corner at the symbol origin. I need to show the data template centered on the origin, setting HorizontalAlignment & VerticalAlignment appears to have no effect. Is there a way to adjust the alighnment?
Hi Milana,
Yep, that was my problem. I wasn't applying the value template correctly in the code behind. Once I added that, it worked as expected. Thanks for your help!
JP
Hi JP,You can also define the DataTemplate, you want to use, as a resource and then refer to it from Code Behind. A sample approach is the following:
<Grid x:Name="LayoutRoot"> <Grid.Resources> <DataTemplate x:Key="placeSymb"> <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <Image Source="Images/pizza.jpg" Height="50" Width="50" Grid.Row="0"/> <TextBlock Text="{Binding Name}" Grid.Row="1"/> </Grid> </DataTemplate> </Grid.Resources> <igMap:XamMap x:Name="xamMap1"> <igMap:XamMap.Layers> <igMap:MapLayer x:Name="MapLayer" IsAutoWorldRect="True" Imported="MapLayer_Imported"> <igMap:MapLayer.Reader> <igMap:ShapeFileReader Uri="/../../Shapefiles/world/world" DataMapping="Name=CNTRY_NAME; Value=POP_CNTRY"/> </igMap:MapLayer.Reader> </igMap:MapLayer> </igMap:XamMap.Layers> </igMap:XamMap> </Grid> private void MapLayer_Imported(object sender, Infragistics.Controls.Maps.MapLayerImportEventArgs e) { if (e.Action == MapLayerImportAction.End) { xamMap1.Layers["MapLayer"].ValueTemplate = LayoutRoot.Resources["placeSymb"] as DataTemplate; } } Hope that helps, Milana Zhileva
Hi,
Actually, I was attempting to do the same thing in moving the caption placement to underneath the symbol. I'm getting stuck because my symbols are being dynamically created in the layer and so the captions are set in code behind. Is there a way to manipulate its placement at that point or can it only be done in the xaml as used in the examples? TIA