How to display labels on a feature layer

7600
7
Jump to solution
09-06-2015 06:16 PM
PaulHaakma
Regular Contributor

Hi.

Does anyone know of any sample apps or example code that demonstrates how to display labels on a Feature Layer?

Cheers,

-Paul

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
PaulHaakma
Regular Contributor

Thanks Marika - I had noticed that property early on but couldn't get it to work - I just spent some time playing with it now and figured out how to get it working...

To start with, the feature service needs to have been published with labels set up in the MXD. If this isn't the case, I still don't know how to manually define this within the app (e.g. in the same way as you could manually define a renderer).

What I was doing wrong before was this:

FeatureLayer{ 

   enableLabels: true;

}

For some reason, setting this property like that didn't work - when I queried the enableLabels property from within the app when running it returned false.

But this did work:

FeatureLayer{

onStatusChanged: {

                if(status === Enums.LayerStatusInitialized) {

                   enableLabels = true;

}  }  }

So, the key is to set the enableLabels property AFTER the layer has initialized.

If anyone finds out how to manually override the labels, let me know. For example, I might have a default labelling setup in the service, but want my user to be able to click a button and change the label field.

Cheers,

-Paul

View solution in original post

7 Replies
PaulHaakma
Regular Contributor

No answer yet on how or whether you can actually display labels on a feature layer. My workaround for now was to loop through every feature in the layer and add a graphic to a graphics layer with a TextSymbol, setting the text from an attribute each time.

Not entirely ideal but functional for now.

0 Kudos
MahtabAlam1
Occasional Contributor
0 Kudos
PaulHaakma
Regular Contributor

Thanks Mahtab, the QML api doesn't seem to have a LabelLayer class, I'm hoping it's something they will implement.

0 Kudos
MarikaVertzonis
Esri Regular Contributor

I don't have example code, but have been pointed to this property

ArcGIS Runtime SDK for Qt QML API: FeatureLayer Class Reference

Have you tried this? What happened when you tried?

0 Kudos
PaulHaakma
Regular Contributor

Thanks Marika - I had noticed that property early on but couldn't get it to work - I just spent some time playing with it now and figured out how to get it working...

To start with, the feature service needs to have been published with labels set up in the MXD. If this isn't the case, I still don't know how to manually define this within the app (e.g. in the same way as you could manually define a renderer).

What I was doing wrong before was this:

FeatureLayer{ 

   enableLabels: true;

}

For some reason, setting this property like that didn't work - when I queried the enableLabels property from within the app when running it returned false.

But this did work:

FeatureLayer{

onStatusChanged: {

                if(status === Enums.LayerStatusInitialized) {

                   enableLabels = true;

}  }  }

So, the key is to set the enableLabels property AFTER the layer has initialized.

If anyone finds out how to manually override the labels, let me know. For example, I might have a default labelling setup in the service, but want my user to be able to click a button and change the label field.

Cheers,

-Paul

MarikaVertzonis
Esri Regular Contributor

I did some more poking around and found that this (declaratively enabling labels) was something that was addressed in the last release of the Qt SDK (which both beta 3 and beta 4 of AppStudio does use). The following sample does work for me - but unfortunately (or fortunately - depends which way you look at it!) it resembles first case that you describe. ie:

   FeatureLayer {

            enableLabels: true
        }

The last part of the sample is indeed a button to change state of the labels (to see the change in this example change the initial state of the labels to false. I wonder if the problem your seeing is to do with the order of the components?

import QtQuick 2.3

import QtQuick.Controls 1.2
import ArcGIS.AppFramework 1.0
import ArcGIS.AppFramework.Runtime 1.0
App {
    id: app
    width: 400
    height: 640
    Geodatabase  {
        id: gdb
        path: "C:\\Users\\Marika\\Desktop\\QtTest\\QtTest\\azlandbase.geodatabase"
    }
    Map {
        id: mainMap
        anchors.fill: parent
        GeodatabaseFeatureTable {
            id: gdbFT
            geodatabase: gdb.valid ? gdb : null
            featureServiceLayerId: 0
        }
        FeatureLayer {
            id: featureLayer_DM
            featureTable: gdbFT
            enableLabels: true
        }
    }
    Button {
        anchors {
            left: parent.left
            top: parent.top
        }
        text: " enable labels"
        onClicked: {
            console.log("labels enabled?", featureLayer_DM.enableLabels);
            featureLayer_DM.enableLabels = true;
            console.log("labels enabled?", featureLayer_DM.enableLabels);
        }
    }
}

					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
0 Kudos
MarikaVertzonis
Esri Regular Contributor

And the second part of my answer is with respect specifically to whether the labels can be added even if they were not defined in the mxd. For that - more work is required in the ArcGIS Runtime API. Currently this feature is only complete in .NET, and is on its way in all the other API's.