Hi.
Does anyone know of any sample apps or example code that demonstrates how to display labels on a Feature Layer?
Cheers,
-Paul
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:
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.
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
id: featureLayer_DM
featureTable: gdbFT
Button {
anchors {
left: parent.left
top: parent.top
text: " enable labels"
onClicked: {
console.log("labels enabled?", featureLayer_DM.enableLabels);
featureLayer_DM.enableLabels = true;
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?
Thanks Mahtab, the QML api doesn't seem to have a LabelLayer class, I'm hoping it's something they will implement.
Label Layer | ArcGIS API for JavaScript
Labeling features client-side | Guide | ArcGIS API for JavaScript
This is for JS API not sure if this will help.
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.
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.