Select to view content in your preferred language

Is Labelling Graphics Possible in Quartz 100?

2294
10
Jump to solution
04-18-2017 01:37 PM
JamesRichards1
Regular Contributor

In 10.2.7 we had ability to label Graphics as explained here:

Label map features—ArcGIS Runtime SDK for .NET | ArcGIS for Developers 

Is this functionality missing in Quartz 100? Or am I just not finding it in the documentation? 

If this is not available, is it going to be in the next release? We are in the middle of upgrading to Quartz but will have to backslide to 10.2.7 if there is no viable way to label graphics. Labeling them 1 at a time with Text Symbol is not going to work as we need the nice conflict detection that was available in 10.2.7.

0 Kudos
10 Replies
ChuckKnaab
Emerging Contributor

Hi Micheal,  

Thanks for the help.  That was exactly what I needed!  I wasn't expecting to be able to eliminate the "Attributes" property name from the $feature object when accessing data stored in that dictionary.  I think that would be a worthy addition to the documentation for sure. 

Here is a full code sample for anyone else that might come across this in the future: 

using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI;
using System.Drawing;
using System.Windows;
using System.Threading.Tasks;
using Esri.ArcGISRuntime.Geometry;

namespace EsriGraphicsLabelExample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private const string LabelDefinitionJson =
            @"{
                    ""labelExpressionInfo"":{""expression"":""$feature.MyCustomKey""},
                    ""labelPlacement"":""esriServerPointLabelPlacementAboveLeft"",
                    ""symbol"":
                        { 
                            ""angle"":0,
                            ""backgroundColor"":[0,0,0,0],
                            ""borderLineColor"":[0,0,0,0],
                            ""borderLineSize"":0,
                            ""color"":[0,0,255,255],
                            ""font"":
                                {
                                    ""decoration"":""none"",
                                    ""size"":10,
                                    ""style"":""normal"",
                                    ""weight"":""normal""
                                },
                            ""haloColor"":[255,255,255,255],
                            ""haloSize"":2,
                            ""horizontalAlignment"":""center"",
                            ""kerning"":false,
                            ""type"":""esriTS"",
                            ""verticalAlignment"":""middle"",
                            ""xoffset"":0,
                            ""yoffset"":0
                        }
               }";

        public MainWindow()
        {
            InitializeComponent();
            Initialize();
        }

        private async Task Initialize()
        {
            // Create the map with streets basemap.
            MyMapView.Map = new Map(Basemap.CreateStreets());
  
            //Create a new graphic.
            var graphic1 = new Graphic(new MapPoint(0, 0, MyMapView.SpatialReference), new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, Color.Red, size:10));
            graphic1.Attributes["MyCustomKey"] = null;

            //Load the label definition from Json.
            var labelDefinition = LabelDefinition.FromJson(LabelDefinitionJson);

            var overlay = new GraphicsOverlay()
            {
                Id = "MyOverlay",
                LabelsEnabled = true,
                LabelDefinitions = { labelDefinition }
            };

            var graphic2 = new Graphic(new MapPoint(100, 100, MyMapView.SpatialReference), new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Triangle, Color.Blue, size: 10));
            //Set a property in the graphic's Attributes dictionary to symbolize off of: 
            graphic2.Attributes["MyCustomKey"] = 123;

            //Add the graphics to the overlay.
            overlay.Graphics.Add(graphic1);
            overlay.Graphics.Add(graphic2);

            // Add the graphics overlay to the map view
            MyMapView.GraphicsOverlays.Add(overlay);

            MyMapView.Map.InitialViewpoint = new Viewpoint(0, 0, 1000);
        }
    }
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

And simple window xaml for testing: 

<Window x:Class="EsriGraphicsLabelExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <esri:MapView x:Name="MyMapView" />
    </Grid>
</Window>

Thanks!

0 Kudos