public class PlotObjectSymbol : ESRI.ArcGIS.Client.Symbols.MarkerSymbol { public PlotObjectSymbol() { string template = @<ControlTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" > <Canvas> <Rectangle Fill=""{Binding Symbol.Symbol}"" Width=""{Binding Symbol.Size}"" Height=""{Binding Symbol.Size}"" /> <TextBlock Canvas.Top=""{Binding Symbol.Size}"" Text=""{Binding Symbol.LabelText}"" Style=""{Binding Symbol.LabelStyle}"" /> </Canvas> </ControlTemplate>"; System.IO.MemoryStream templateStream = new System.IO.MemoryStream(System.Text.UTF8Encoding.Default.GetBytes(template)); ControlTemplate = System.Windows.Markup.XamlReader.Load(templateStream) as ControlTemplate; } #region LabelText Property public string LabelText { get { return (string)base.GetValue(LabelTextProperty); } set { base.SetValue(LabelTextProperty, value); } } public static DependencyProperty LabelTextProperty = DependencyProperty.Register("LabelText", typeof(string), typeof(PlotObjectSymbol), new UIPropertyMetadata("")); #endregion ...
What I do is implement IRenderer along with the PlotObjectSymbol class: like this,
ControlTemplate in App.xaml:
<ControlTemplate x:Key="cntltemplate">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Symbol.ImageSource, Converter={StaticResource StringToImageSourceConverter}}"/>
<TextBlock Text="{Binding Symbol.LabelText}" />
</StackPanel>
</ControlTemplate>
StringToImageSourceConverter is an IValueConverter implementation that converts strings to an ImageSource.
public class PlotObjectSymbol : ESRI.ArcGIS.Client.Symbols.MarkerSymbol
{
public PlotObjectSymbol()
ControlTemplate = Application.Current.Resources["cntltemplate"] as ControlTemplate;
}
public string LabelText
get { return (string) base.GetValue(LabelTextProperty); }
set { base.SetValue(LabelTextProperty, value); }
public static DependencyProperty LabelTextProperty = DependencyProperty.Register("LabelText", typeof (string), typeof (PlotObjectSymbol), new UIPropertyMetadata(string.Empty));
public string ImageSource
get { return (string)base.GetValue(ImageSourceProperty); }
set { base.SetValue(ImageSourceProperty, value); }
public static DependencyProperty ImageSourceProperty = DependencyProperty.Register("ImageSource", typeof(string), typeof(PlotObjectSymbol), new UIPropertyMetadata(string.Empty));
public class LabelRenderer : IRenderer
public Symbol GetSymbol(Graphic graphic)
var pt = new PlotObjectSymbol();
pt.LabelText = (string)graphic.Attributes["Name"];
pt.ImageSource = "Images/marker.png";
graphic.Symbol = pt;
return graphic;
Also, keep the ControlTemplate xaml simple, as this turns to slow down the rendering refresh rate.
Another thing: <esri:Map UseAcceleratedDisplay="False" .../>
This is what I did... public class PlotObjectSymbol : ESRI.ArcGIS.Client.Symbols.MarkerSymbol { public PlotObjectSymbol() { string template = @<ControlTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" > <Canvas> <Rectangle Fill=""{Binding Symbol.Symbol}"" Width=""{Binding Symbol.Size}"" Height=""{Binding Symbol.Size}"" /> <TextBlock Canvas.Top=""{Binding Symbol.Size}"" Text=""{Binding Symbol.LabelText}"" Style=""{Binding Symbol.LabelStyle}"" /> </Canvas> </ControlTemplate>"; System.IO.MemoryStream templateStream = new System.IO.MemoryStream(System.Text.UTF8Encoding.Default.GetBytes(template)); ControlTemplate = System.Windows.Markup.XamlReader.Load(templateStream) as ControlTemplate; } #region LabelText Property public string LabelText { get { return (string)base.GetValue(LabelTextProperty); } set { base.SetValue(LabelTextProperty, value); } } public static DependencyProperty LabelTextProperty = DependencyProperty.Register("LabelText", typeof(string), typeof(PlotObjectSymbol), new UIPropertyMetadata("")); #endregion ... I just could not figure out how to center the text. I'm not a WPF guru.
You can use a GraphicsLayer on top of your FeatureLayer to hold the label.
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.