DynamicMapServiceLayer Labels - from Shapefile

4368
13
07-24-2014 05:52 AM
LeeColclough
New Contributor

I'm loading various shapefiles using ArcGIS for WPF and displaying them on a map (the mechanism for doing this is taken from the ArcGIS WPF runtime examples - see http://www.arcgis.com/home/item.html?id=953a530ada30477d95cc69e788268bc9).

I have a shapefile that contains Point information, and contained in it's attributes are the text labels that apply to those points. I cannot see how to access that information. I know the DBF file is being used as if I delete that file the shapefile will not render as it has no symbol information. Despite this, I cannot see when debugging the provided example how to access this information.

Obviously I could simply open the .dbf file manually but that seems awfully clunky. Does anyone have any help or pointers for me?

Many thanks in advance.

Lee.

0 Kudos
13 Replies
MichaelBranscomb
Esri Frequent Contributor

Hi,

You can run a QueryTask against the dynamically defined layer/service and as long as you set the Source property on the Query class instance you pass into the QueryTask then it will query your shapefile (rather than the original service source data).

Other aspects of the API support these dynamically defined layers too - again look for the Source property or in some cases a DynamicLayerInfos property.

Cheers

Mike

0 Kudos
LeeColclough
New Contributor

Thanks Mike - I'll look at that.  So there is no easy 'set a property to true' way to label a shapefile (in the same way that in ArcMap there is a 'Label ShapeFile' option on the layer) in ArcGIS for WPF SDK?

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi,

If labels have been configured in the dynamic service then these will be visible in the layer/map. If they are not visible you should be able to enable them via ESRI.ArcGIS.Client.LayerDrawingOptions.ShowLabels (ArcGIS Runtime SDK for Microsoft WPF - Library Reference‌). This again will require the use of the DynamicLayers capability, but you will have enabled this anyway if you are adding Shapefiles via this route. There is a labeling API on dynamic layers - for an example see ArcGIS API for Silverlight - Interactive Samples | ArcGIS for Developers‌.

Ultimately this will become much easier in the new .NET SDK where you will have support for direct read of Shapefiles and a much richer labeling API.

Cheers

Mike

0 Kudos
LeeColclough
New Contributor

In that case I think I'm clearly doing something daft!  I am using the AddShapeFileAndRasterData example project, and I have set the ShowLabels property of the LayerDrawingOptions class, to no avail.  I have also looked at the silverlight example and tried Creating LabelClass (and LabelOption) instances in the code and assigning to the LayerDrawingOptions, but nothing seems to make any difference.p

Essentially I've modified the LocalDynamicMapServiceLayer Initialized event handler like this:


LabelClassCollection labelCollection = new LabelClassCollection();
System.Windows.Media.FontFamily fontFam = new System.Windows.Media.FontFamily("Arial");
LabelClass labelClass = new LabelClass() 
{ 
     LabelPlacement = LabelPlacement.PointLabelPlacementAboveRight,
     LabelOptions = new LabelOptions() { Color = Colors.Blue, FontSize = 20, FontWeight = FontWeights.Bold, FontStyle = TextStyle.Normal, FontFamily = fontFam },
};
labelCollection.Add(labelClass);





// Create a new LayerDrawingOptions object to hold the renderer information.
var layerDrawOpt = new LayerDrawingOptions()
{
     // Match up the LayerID to the ID of the layer within the service.
     LayerID = counter,


     // Provide a renderer. In this example it is an empty SimpleMarkerSymbol.
     Renderer = new SimpleRenderer() { Symbol = new SimpleMarkerSymbol() { } },


     ShowLabels = true,
     ScaleSymbols = true,


     LabelClasses = labelCollection,
};





Everything else is as per the AddShapeFileAndRasterData example.  Based on your help so far and the silverlight example, I cannot see why this wouldn't work.  I'm going to pull the silverlight example into a debugger and mess around to see if I can get any clues, but any insight you have would be, as always, very welcome.

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi,

Unfortunately I am unable to look into this right now - but my advice would be to open Fiddler then run an example which does work as expected and run an example which does not work as expected, and compare the two requests. You should get an indication of what parts of the request are missing and the API typically matches the request parameters fairly closely.

Have you set the label field in the LabelClass?

Cheers

Mike

0 Kudos
LeeColclough
New Contributor

No Worries - I'm grateful for any assistance I can get.  I'll certainly try Fiddler.  As an aside, if I take the Silverlight example and transfer it directly into a WPF project, the labels do NOT draw.  Hmmm.

LabelClass doesn't have a Label field.  It has LabelExpression if that's what you meant?

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi,

Yes, sorry - LabelExpression. This is a string which represents the field name e.g. "[MyField]".

Cheers

Mike

0 Kudos
LeeColclough
New Contributor

Ok, I'm officially giving up, I can't seem to get this to work - I have code from the Silverlight example creating an ArcGISDynamicMapServiceLayer and it all works fine.  I have code creating a ArcGISLocalDynamicMapServiceLayer and it doesn't work.  The LabelClass used by both is the same (apart from the LabelExpression).  All the rest of the code (ie: creating the ArcGISLocalDynamicMapServiceLayer) is taken from the ESRI examples.

I've spoken to Esri UK support (on an unrelated issue) and they have suggested I submit a support request using my EDN subscriber support credits, which I will now do.  I'll update this post if I get any positive results.

In the meantime, thanks for your assistance up to this point.

Lee.

Edit:  apparently EDN doesn't come with any support as standard.  I cannot see my company paying out an extra $2000 just so I can get one of the SDK examples to work properly.  I guess I will need to look at alternatives.

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi,

I'll take a look at this as soon as I can - the fact you said the SL sample does not run correctly in WPF concerns me.

Cheers

Mike

0 Kudos