How to show labels for dynamic layer info in ArcGIS Dynamic Map Service Layer

681
7
03-18-2021 11:52 PM
shilpakaramar
New Contributor II

I have used below code for show dynamic layers which is working fine and now I have to display labels for that dynamic layers.

How to do that with below code?

 

var dataSource = new esri.layers.TableDataSource();
    var layerSource = new esri.layers.LayerDataSource();
    var dynamicLayerInfo = new esri.layers.DynamicLayerInfo();
    var drawingOptions = new esri.layers.LayerDrawingOptions();
    var layerinfoTemplate = new www.InfoTemplate();
    var options = [];
    dataSource.workspaceId = "..."
    dataSource.dataSourceName = "..."; //shapefile name
    layerSource.dataSource = dataSource;
    dynamicLayerInfo.id = i;
    dynamicLayerInfo.name = "...";
    dynamicLayerInfo.source = layerSource;

    dynamicLayerInfos.push(dynamicLayerInfo);
    var labelClass = new w.LabelClass({
        useCodedValues: false,
        labelExpression: "Name: {CITY_NAME} Area: {CITY_AREA}",
        labelPlacement: 'esriServerLinePlacementAboveAfter',
        symbol: new w.TextSymbol({
                      color: new w.Color("#000000")
                })
        });
        drawingOptions.renderer = new SimpleRenderer(new SimpleLineSymbol(new 
 SimpleLineSymbol.STYLE_SOLID, new Color([0, 0, 0]), 2));
        drawingOptions.showLabels = true;
        options[0] = drawingOptions;
        EsriDynamicLayer.setDynamicLayerInfos(dynamicLayerInfos, true);
        EsriDynamicLayer.setLayerDrawingOptions(options);
0 Kudos
7 Replies
nita14
by
Regular Contributor

Hi,

please enable dynamic layers support on your service first.

https://enterprise.arcgis.com/en/server/latest/publish-services/windows/enabling-dynamic-layers-on-a...

Hope this helps,

Adam

0 Kudos
shilpakaramar
New Contributor II

Hi @nita14 

the dynamic layer is already enabled and dyaminc layers are already visible in the map.

Now I want to show labels of the layers that are visible in map,

Can you help me on that

0 Kudos
nita14
by
Regular Contributor
0 Kudos
shilpakaramar
New Contributor II

@nita14 

yes i have assign it like below

 

var labelClass = new w.LabelClass({
                        useCodedValues: false,
                        labelExpression: "Name: {CITY_NAME} Area: {CITY_AREA}",
                        labelPlacement: 'esriServerLinePlacementAboveAfter',
                        symbol: new w.TextSymbol({
                            color: new w.Color("#000000")
                          })
                      });
                      drawingOptions.labelingInfo = [labelClass];
0 Kudos
nita14
by
Regular Contributor
labelPlacement: 'esriServerLinePlacementAboveAfter',

is wrong. Check valid values first.

https://developers.arcgis.com/javascript/3/jsapi/labelclass-amd.html#labelplacement

Basically, leave only labelExpression and check it that works. Zoom in the map to check if labels are there.

Adam

0 Kudos
shilpakaramar
New Contributor II

@nita14 

Tried this but not showing labels

var labelClass = new w.LabelClass({
                        labelExpression: "Name: {CITY_NAME} Area: {CITY_AREA}",
                      });
                    drawingOptions.labelingInfo = [labelClass];
0 Kudos
shilpakaramar
New Contributor II

can you help me in this.. I am literally stuck in this.

0 Kudos