What's the best way to go about adding labels (counties within a state, specifically in my case) to one of the state SHP/DBF examples from the drill down demo? Is it done in the SHP file or can I do it from the DBF data?
Thanks in advance!
Thanks in advance!
3 Answers, 1 is accepted
0
Accepted
Hi James,
You can add labels as TextBlock objects from code in the CountyLayerReaderReadCompleted method of the example which is called after the shape file with counties is read. In this case each read shape contains the name of the county in its extended data from DBF. Unfortunately the example data files do not contain coordinates for best label positions, but for the most part it will be correct to use the center of county.
The sample code is the following:
The example uses additional "LabelLayer" layer for labels rendering. You should also add it to the RadMap.
Regards,
Andrey Murzov
the Telerik team
You can add labels as TextBlock objects from code in the CountyLayerReaderReadCompleted method of the example which is called after the shape file with counties is read. In this case each read shape contains the name of the county in its extended data from DBF. Unfortunately the example data files do not contain coordinates for best label positions, but for the most part it will be correct to use the center of county.
The sample code is the following:
private
void
CountyLayerReaderReadCompleted(
object
sender, ReadShapesCompletedEventArgs eventArgs)
{
if
(eventArgs.Error !=
null
)
return
;
this
.LabelLayer.Items.Clear();
HotSpot hotSpot =
new
HotSpot();
hotSpot.X = 0.5;
hotSpot.Y = 0.5;
foreach
(MapShape shape
in
this
.CountyLayer.Items)
{
shape.MouseLeftButtonUp +=
this
.CountyShapeMouseLeftButtonUp;
string
name = (
string
)shape.ExtendedData.GetValue(CountyExtendedPropertyName);
TextBlock label =
new
TextBlock();
point.Text = name;
MapLayer.SetLocation(label, shape.GeographicalBounds.Center);
MapLayer.SetHotSpot(label, hotSpot);
this
.LabelLayer.Items.Add(label);
}
this
.BringIntoView(
this
.stateShape);
}
The example uses additional "LabelLayer" layer for labels rendering. You should also add it to the RadMap.
<
telerik:RadMap
x:Name
=
"RadMap1"
Background
=
"#D9E1FF"
BorderBrush
=
"Black"
BorderThickness
=
"1"
UseDefaultLayout
=
"False"
MouseClickMode
=
"None"
MouseDoubleClickMode
=
"None"
ZoomLevel
=
"4"
Center
=
"36.8174363084084, -97.3212482126264"
>
<
telerik:RadMap.Provider
>
<
telerik:EmptyProvider
MinZoomLevel
=
"4"
MaxZoomLevel
=
"8"
/>
</
telerik:RadMap.Provider
>
<
telerik:InformationLayer
x:Name
=
"StateLayer"
>
<
telerik:InformationLayer.ShapeFill
>
<
telerik:MapShapeFill
Fill
=
"#FFF0D9"
Stroke
=
"#B1946D"
StrokeThickness
=
"1"
/>
</
telerik:InformationLayer.ShapeFill
>
<
telerik:InformationLayer.HighlightFill
>
<
telerik:MapShapeFill
Fill
=
"#FFEEA6"
Stroke
=
"#B1946D"
StrokeThickness
=
"1"
/>
</
telerik:InformationLayer.HighlightFill
>
</
telerik:InformationLayer
>
<
telerik:InformationLayer
x:Name
=
"CountyLayer"
>
<
telerik:InformationLayer.ShapeFill
>
<
telerik:MapShapeFill
Fill
=
"#FFDBA3"
Stroke
=
"#B1946D"
StrokeThickness
=
"1"
/>
</
telerik:InformationLayer.ShapeFill
>
<
telerik:InformationLayer.HighlightFill
>
<
telerik:MapShapeFill
Fill
=
"#FFEEA6"
Stroke
=
"#B1946D"
StrokeThickness
=
"1"
/>
</
telerik:InformationLayer.HighlightFill
>
</
telerik:InformationLayer
>
<
telerik:InformationLayer
x:Name
=
"LabelLayer"
/>
</
telerik:RadMap
>
Regards,
Andrey Murzov
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0

James
Top achievements
Rank 1
answered on 22 Nov 2010, 06:21 PM
Thanks very much. You are right that it does not end up looking ideal. I saw that coming. Still, nice to know how to hook into the loading of each shape in the layer. Very nice.
0
Hi James,
The map control does not contain an event which occurs after the item is added to the information layer. If you provide us with more details about things you try to implement, then we can help you to choose another way to do it.
Kind regards,
Andrey Murzov
the Telerik team
The map control does not contain an event which occurs after the item is added to the information layer. If you provide us with more details about things you try to implement, then we can help you to choose another way to do it.
Kind regards,
Andrey Murzov
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF