labeling using javascript code?

390
1
03-18-2019 08:19 AM
JasonGillow1
New Contributor II

Hello

I am very new to javascript coding, I had a third party group build a webmap for us. We are in testing phase now and I am trying to learn basics. My layer data is stored in ArcGIS Online as feature service layers and we are using web token to connect to the data map and layers. I was wanting to set up labels for each feature and where to add the code in.

Here is a sample of the connected in the code

{
            type: 'feature',
            url: 'https://   /FeatureServer/1?token=' + tokenNumber,
            title: 'Parcels',
            options: {
                id: 'Parcels',
                opacity: 1.0,
                visible: true,
                outFields: ['*'],
                mode: 1
            },
            editorLayerInfos: {
                disableGeometryUpdate: false
            },
            legendLayerInfos: {
                exclude: false,
                layerInfo: {
                    title: 'Parcels'
                }
            },
            layerControlLayerInfos: {
                layerGroup: 'Parcels'
            }
        },

Any good references would help. Thank you

0 Kudos
1 Reply
BirajaNayak
Esri Contributor

Here is the sample code for Labels:

https://developers.arcgis.com/javascript/latest/sample-code/labels-basic/index.html

Here are details step provided on the link:

>>To add labels to the layer, first we create a LabelClass and assign values for various properties, such as color and font.

const labelClass = {   // autocasts as new LabelClass()  symbol: {     type: "text",  // autocasts as new TextSymbol()    color: "green",     haloColor: "black",     font: {  // autocast as new Font()      family: "playfair-display",       size: 12,       weight: "bold"    }   },   labelPlacement: "above-center",   labelExpressionInfo: {     expression: "$feature.MARKER_ACTIVITY"  } });

>> This sample loads a PortalItem from ArcGIS Online, then adds the label class to the labelingInfo property, and applies a renderer.

map.layers = [   new FeatureLayer({     portalItem: { // autocasts as new PortalItem      id: "6012738cd1c74582a5f98ea30ae9876f"    },     labelingInfo: [ labelClass ]   }) ];

Thanks,

Biraja