I followed
But my application fails to show the labels of the features.
I have no idea what I'm what I'm doing wrong.
My code is
FeatureLayer* iconLayer = new FeatureLayer(connectionsTable, _map);
QString labelDefJSON = "{";
labelDefJSON += "\"labelPlacement\" : \"esriServerPointLabelPlacementAboveRight\",";
labelDefJSON += "\"labelExpressionInfo\" :{";
labelDefJSON += "\"expression\" : \"$feature.Name\" },";
labelDefJSON += "\"symbol\" : {";
labelDefJSON += "\"type\": \"esriTS\",";
labelDefJSON += "\"font\" : { \"family\": \"Arial\", \"size\" : 11,\"weight\" : \"bold\"}";
labelDefJSON += "}";
labelDefJSON += "}";
LabelDefinition* labelDef = LabelDefinition::fromJson(labelDefJSON);
iconLayer->labelDefinitions()->append(labelDef);
iconLayer->setLabelsEnabled(true);
_map->operationalLayers()->append(iconLayer);
Before appending the layer to the operationalLayers(), I also set a renderer for the features themselves (icons). Could this interfere with showing the labels ?
The JSON string seems to be valid (according to VisualStudio's JSON Visualizer).
Searching the Internet, I've found some alternatives :
- start the JSON string with "labelingInfo"
- use "expression" : "return $feature.Name;"
- "value: "$feature.Name"
Nothing seems to help.
Should I maybe do something different with "setLabelsEnabled(true)" ?
Any help is welcome.
Regards,
Marc