Select to view content in your preferred language

Labeling Info

2939
6
Jump to solution
04-24-2013 10:25 AM
JasonLevine
Deactivated User
I can see through the rest endpoint of my map service layer that its labeling information is being exposed under Drawing Info:
[ATTACH=CONFIG]23743[/ATTACH]

However, when trying to retrieve it through the latest ESRI flex API (version 3.2) using getAllDetails->LayerDetails, I can only see the renderer and transparency information.  How can I get at the labeling info that's being exposed via rest?

Also, I have a map service that has a layer with labels turned on by default.  I want to create a label button in my TOC that will ONLY toggle the layer's labels on/off without changing the default label symbology.  I've tried the following, but when the label button is clicked, the entire layer disappears from the map:
private var mapLayer:ArcGISDynamicMapServiceLayer;  for(var i:int = 0; i<map.layers.length; i++) {       if(map.layers is com.esri.ags.layers.ArcGISDynamicMapServiceLayer)       {             mapLayer = map.layers;             mapLayer.layerDrawingOptions = [];       } }  private function onLabelButtonClick(layerID:Number, show:Boolean):void {       var myDrawOptions:LayerDrawingOptions = new LayerDrawingOptions();       myDrawOptions.showLabels = show;       myDrawOptions.layerId = layerId;       mapLayer.layerDrawingOptions.push(myDrawOptions);       mapLayer.refresh(); }


I know at some point I'll have to check to see if myDrawOptions already exists in the layerDrawingOptions array to avoid duplicates, but I'm just trying to get something to work.  The main difference between what I'm trying to do and what the label samples in the flex gallery do is that I'm dealing with a layer that already has labels defined in the map service and I'm just trying to toggle them, not re-symbolize them.

Thanks for your help.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DasaPaddock
Esri Regular Contributor
You can get all layers at once using /layers.

See:
http://resources.arcgis.com/en/help/rest/apiref/layers.html

I'd use f=json instead of f=pjson to be more efficient.

There isn't a generic function for checking scale ranges in the API.

View solution in original post

0 Kudos
6 Replies
DasaPaddock
Esri Regular Contributor
How can I get at the labeling info that's being exposed via rest?

This isn't available in LayerDetails, but you can use the JSONTask to get it as a raw Object. What is your use case for it?
http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/tasks/JSONTask.html

I'll try to reproduce the issue with toggling the labels on and off. Are you using a public service?
0 Kudos
DasaPaddock
Esri Regular Contributor
Can you use this simple app to test your service and layer?

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:esri="http://www.esri.com/2008/ags">

    <esri:Map>
        <esri:ArcGISDynamicMapServiceLayer url="http://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/MapServer">
            <esri:layerDrawingOptions>
                <esri:LayerDrawingOptions layerId="1" showLabels="false"/>
            </esri:layerDrawingOptions>
        </esri:ArcGISDynamicMapServiceLayer>
    </esri:Map>

</s:Application>


This app works fine for me, but it's not a valid test since the layers don't have labels in this service.
0 Kudos
JasonLevine
Deactivated User
Hi Dasa,
My problem was with a typo somewhere else in my code; I managed to get the labels to toggle on/off. 

I need the Labeling Information so that I know what scales the labels for each layer are constrained to by default.
[ATTACH=CONFIG]23747[/ATTACH]

I tried using the JSONTask to retrieve it, but the response was just the basic layerInfo data:
[ATTACH=CONFIG]23748[/ATTACH]

var JaSONTask:JSONTask = new JSONTask(usaMapServiceLayer.url);
    var urlVariables:URLVariables = new URLVariables("f=pjson");
    JaSONTask.execute(urlVariables, new AsyncResponder(result,fail));
    function result(event:Object, token:Object = null):void
    {
     var result:Object = event;
    }
    function fail(event:FaultEvent):void
    {
     Alert.show(event.message.toString());
    }


Am I doing something wrong here?

Thanks,
Jason
0 Kudos
JasonLevine
Deactivated User
Hi Dasa,
I realized that I have to set my url to the individual layer that I need the labeling info for;  I thought I could get everything from one JSONTask call using the map service url, but it looks like I have to do it for each layer.

By chance, do you know if there's a property out there for labels that does the same thing that isInScaleRange does for a layer?  I can write my own function that can do this, but if there's a property out there somewhere that does it, I'd rather use it.

Thanks,
Jason
0 Kudos
DasaPaddock
Esri Regular Contributor
You can get all layers at once using /layers.

See:
http://resources.arcgis.com/en/help/rest/apiref/layers.html

I'd use f=json instead of f=pjson to be more efficient.

There isn't a generic function for checking scale ranges in the API.
0 Kudos
JasonLevine
Deactivated User
Thanks Dasa, that did the trick.  I can see all of my label properties now.  However, I've noticed what might be a bug with advanced label expressions.  All of my layers where I've used advanced python label expressions for labeling show hasLabels=true, but come up with null for event.drawingInfo.labelingInfo.  Is this a known issue?

Thanks,
Jason
0 Kudos