I have developed a workaround. The FeatureLayer in my case is created from a MapImageLayer and a MapImageLayer does handle dynamic repositioning. I have used the MapImageLayer to effectively create a layer that only contains labels and loaded it to my map as well as the FeatureLayer which handles all the other attributes on the map.
This creates a MapImageLayer with only the sublayer I want and hides everything but the labels.
//Label only mapImageLayer
const mapImage = new MapImageLayer({
url: 'url',
listMode: hide,
sublayers: [
{
id: 8,
legendEnabled: false,
listMode: 'hide',
opacity: 0
}
]
I gave my FeatureLayer a LabelClass with a labelExpressionInfo of an empty string to trick it into thinking it's doing the labeling.
labelClass: [
{
labelExpressionInfo: {
expression: ' '
},
symbol: {
type: 'text',
color: 'black',
font: {
family: 'Noto Sans',
size: 7,
weight: 'normal'
}
},
labelPlacement: 'always-horizontal'
}
]
And I used reactiveUtils to turn on/off the MapImageLayer when the layer it is tied to or its labels are turned on/off.
sublayer8 = mapImage.findSublayerById(8)
feature8 = jimuMapView.view.map.findLayerById('featureLayer8')
reactiveUtils.watch(() => [feature8?.visible, feature8?.labelsVisible], ([visible, labels]) => {
if (visible && labels) {
sublayer8.visible = true
} else {
sublayer8.visible = false
}
})
GIS Developer
City of Arlington, Texas