Learn how to use
Pan and zoom the map to explore the layer styles.
A
In this tutorial, you will use three different renderers to style three hosted
Prerequisites
Steps
Create a new pen
- To get started, either complete the Display a map tutorial or
.
Get an access token
You need an
- Go to the Create an API key tutorial and create an
API key with the followingprivilege(s) :
- Privileges
- Location services > Basemaps
- Item access
- Note: If you are using your own custom data layer for this tutorial, you need to grant the
API key credentials access to the layer item. Learn more in Item access privileges.
- Note: If you are using your own custom data layer for this tutorial, you need to grant the
- Privileges
- In CodePen, set the
apiKeyproperty on the globalesriConfigvariable to your access token.var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};
To learn about other ways to get an access token, go to Types of authentication.
Display a map
Follow the steps in the Display a map tutorial to add a map with the arcgis/topographic basemap layer, centered on Point Dume State Beach, Malibu, California.
Add script and modules
In a new <script> at the bottom of the <body>, use $arcgis.import() to add the FeatureLayer module.
The $arcgis.import global function accepts a module path or array of module paths, and returns a promise that resolves with the requested modules. This function can only be used when working with the CDN; otherwise, use the standard import syntax. To learn more about the SDK’s different modules, visit the References page.
36 collapsed lines
<html>
<head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>ArcGIS Maps SDK for JavaScript Tutorials: Style a feature layer</title>
<script> var esriConfig = { apiKey: "YOUR_ACCESS_TOKEN", }; </script>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN --> <script type="module" src="https://js.arcgis.com/5.0/"></script>
<style> html, body { height: 100%; margin: 0; } </style>
</head>
<body>
<arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13">
<arcgis-zoom slot="top-left"></arcgis-zoom>
</arcgis-map>
<script type="module"> const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");
</script>4 collapsed lines
</body>
</html>Style trailheads (points)
Use the SimpleRenderer, PictureMarkerSymbol, and LabelClass classes to style the
-
Create a
trailheadsRendererand define it as asimplerenderer. Set thesymbolproperty to draw a hiker image accessed from itsurl.39 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Style a feature layer</title><script>var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");// Define a simple renderer and symbolconst trailheadsRenderer = {type: "simple",symbol: {type: "picture-marker",url: "http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png",width: "18px",height: "18px",},};5 collapsed lines</script></body></html> -
Create a
trailheadsLabelsand set thesymbolproperty to draw a label with theTRL_NAME.50 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Style a feature layer</title><script>var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");// Define a simple renderer and symbolconst trailheadsRenderer = {type: "simple",symbol: {type: "picture-marker",url: "http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png",width: "18px",height: "18px",},};// Define a label for the trailheadsconst trailheadsLabels = {symbol: {type: "text",color: "#FFFFFF",haloColor: "#5E8D74",haloSize: "2px",font: {size: "12px",family: "Noto Sans",style: "italic",weight: "normal",},},labelPlacement: "above-center",labelExpressionInfo: {expression: "$feature.TRL_NAME",},};6 collapsed lines</script></body></html> -
Create a
trailheadsFeatureLayer. Set theurlproperty to access its URL endpoint. Set therendererandlabelingInfobefore addingtrailheadsto themap. Thefeature layer will autocast therendererandlabelingInfoto create class instances of the objects.65 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Style a feature layer</title><script>var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");// Define a simple renderer and symbolconst trailheadsRenderer = {type: "simple",symbol: {type: "picture-marker",url: "http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png",width: "18px",height: "18px",},};// Define a label for the trailheadsconst trailheadsLabels = {symbol: {type: "text",color: "#FFFFFF",haloColor: "#5E8D74",haloSize: "2px",font: {size: "12px",family: "Noto Sans",style: "italic",weight: "normal",},},labelPlacement: "above-center",labelExpressionInfo: {expression: "$feature.TRL_NAME",},};// Create the layer and set the rendererconst trailheads = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0",renderer: trailheadsRenderer,labelingInfo: [trailheadsLabels],});5 collapsed lines</script></body></html> -
Use
document.querySelector()to get a reference to the Map component, then wait for it to be ready with the viewOnReady method. Then, addtrailheadslayer to the map after the renderer and label definitions.36 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Style a feature layer</title><script>var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();// Define a simple renderer and symbolconst trailheadsRenderer = {type: "simple",symbol: {type: "picture-marker",url: "http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png",width: "18px",height: "18px",},};// Define a label for the trailheadsconst trailheadsLabels = {symbol: {type: "text",color: "#FFFFFF",haloColor: "#5E8D74",haloSize: "2px",font: {size: "12px",family: "Noto Sans",style: "italic",weight: "normal",},},labelPlacement: "above-center",labelExpressionInfo: {expression: "$feature.TRL_NAME",},};// Create the layer and set the rendererconst trailheads = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0",renderer: trailheadsRenderer,labelingInfo: [trailheadsLabels],});viewElement.map.add(trailheads);</script>4 collapsed lines</body></html> -
View hiker symbols with trailhead names.
Style trails (lines)
Use the SimpleRenderer and VisualVariable classes to style trails in the Trails
-
Create a
trailsRendererand define it as asimplerenderer.83 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Style a feature layer</title><script>var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();// Define a simple renderer and symbolconst trailheadsRenderer = {type: "simple",symbol: {type: "picture-marker",url: "http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png",width: "18px",height: "18px",},};// Define a label for the trailheadsconst trailheadsLabels = {symbol: {type: "text",color: "#FFFFFF",haloColor: "#5E8D74",haloSize: "2px",font: {size: "12px",family: "Noto Sans",style: "italic",weight: "normal",},},labelPlacement: "above-center",labelExpressionInfo: {expression: "$feature.TRL_NAME",},};// Create the layer and set the rendererconst trailheads = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0",renderer: trailheadsRenderer,labelingInfo: [trailheadsLabels],});viewElement.map.add(trailheads);// Define a unique value renderer and symbolsconst trailsRenderer = {type: "simple",symbol: {color: "#BA55D3",type: "simple-line",style: "solid",},5 collapsed lines</script></body></html> -
In the
visualVariablesarray, set thefieldtoELEV_GAINto determine line width.92 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Style a feature layer</title><script>var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();// Define a simple renderer and symbolconst trailheadsRenderer = {type: "simple",symbol: {type: "picture-marker",url: "http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png",width: "18px",height: "18px",},};// Define a label for the trailheadsconst trailheadsLabels = {symbol: {type: "text",color: "#FFFFFF",haloColor: "#5E8D74",haloSize: "2px",font: {size: "12px",family: "Noto Sans",style: "italic",weight: "normal",},},labelPlacement: "above-center",labelExpressionInfo: {expression: "$feature.TRL_NAME",},};// Create the layer and set the rendererconst trailheads = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0",renderer: trailheadsRenderer,labelingInfo: [trailheadsLabels],});viewElement.map.add(trailheads);// Define a unique value renderer and symbolsconst trailsRenderer = {type: "simple",symbol: {color: "#BA55D3",type: "simple-line",style: "solid",},visualVariables: [{type: "size",field: "ELEV_GAIN",minDataValue: 0,maxDataValue: 2300,minSize: "3px",maxSize: "7px",},],};5 collapsed lines</script></body></html> -
Create a
trailsFeatureLayer. Set theurlto access its URL endpoint.104 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Style a feature layer</title><script>var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();// Define a simple renderer and symbolconst trailheadsRenderer = {type: "simple",symbol: {type: "picture-marker",url: "http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png",width: "18px",height: "18px",},};// Define a label for the trailheadsconst trailheadsLabels = {symbol: {type: "text",color: "#FFFFFF",haloColor: "#5E8D74",haloSize: "2px",font: {size: "12px",family: "Noto Sans",style: "italic",weight: "normal",},},labelPlacement: "above-center",labelExpressionInfo: {expression: "$feature.TRL_NAME",},};// Create the layer and set the rendererconst trailheads = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0",renderer: trailheadsRenderer,labelingInfo: [trailheadsLabels],});viewElement.map.add(trailheads);// Define a unique value renderer and symbolsconst trailsRenderer = {type: "simple",symbol: {color: "#BA55D3",type: "simple-line",style: "solid",},visualVariables: [{type: "size",field: "ELEV_GAIN",minDataValue: 0,maxDataValue: 2300,minSize: "3px",maxSize: "7px",},],};// Create the layer and set the rendererconst trails = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",renderer: trailsRenderer,opacity: 0.75,});5 collapsed lines</script></body></html> -
Add
trailslayer to the map. Set therendererandopacityproperties before addingtrailsto the map. Thefeature layer will autocast therenderera create class instances of the object.111 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Style a feature layer</title><script>var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();// Define a simple renderer and symbolconst trailheadsRenderer = {type: "simple",symbol: {type: "picture-marker",url: "http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png",width: "18px",height: "18px",},};// Define a label for the trailheadsconst trailheadsLabels = {symbol: {type: "text",color: "#FFFFFF",haloColor: "#5E8D74",haloSize: "2px",font: {size: "12px",family: "Noto Sans",style: "italic",weight: "normal",},},labelPlacement: "above-center",labelExpressionInfo: {expression: "$feature.TRL_NAME",},};// Create the layer and set the rendererconst trailheads = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0",renderer: trailheadsRenderer,labelingInfo: [trailheadsLabels],});viewElement.map.add(trailheads);// Define a unique value renderer and symbolsconst trailsRenderer = {type: "simple",symbol: {color: "#BA55D3",type: "simple-line",style: "solid",},visualVariables: [{type: "size",field: "ELEV_GAIN",minDataValue: 0,maxDataValue: 2300,minSize: "3px",maxSize: "7px",},],};// Create the layer and set the rendererconst trails = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",renderer: trailsRenderer,opacity: 0.75,});viewElement.map.add(trails, 0);5 collapsed lines</script></body></html> -
View trails of differing widths based on elevation gain.
Show bike-only trails (lines)
You can use a definitionExpression, SimpleRenderer and SimpleLineSymbol classes. The layer is added on top of the existing trails layer.
-
Create a
bikeTrailsRendererand define it as asimplerenderer. Set thesymbolto draw aline that is styled with dots in pink.113 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Style a feature layer</title><script>var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();// Define a simple renderer and symbolconst trailheadsRenderer = {type: "simple",symbol: {type: "picture-marker",url: "http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png",width: "18px",height: "18px",},};// Define a label for the trailheadsconst trailheadsLabels = {symbol: {type: "text",color: "#FFFFFF",haloColor: "#5E8D74",haloSize: "2px",font: {size: "12px",family: "Noto Sans",style: "italic",weight: "normal",},},labelPlacement: "above-center",labelExpressionInfo: {expression: "$feature.TRL_NAME",},};// Create the layer and set the rendererconst trailheads = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0",renderer: trailheadsRenderer,labelingInfo: [trailheadsLabels],});viewElement.map.add(trailheads);// Define a unique value renderer and symbolsconst trailsRenderer = {type: "simple",symbol: {color: "#BA55D3",type: "simple-line",style: "solid",},visualVariables: [{type: "size",field: "ELEV_GAIN",minDataValue: 0,maxDataValue: 2300,minSize: "3px",maxSize: "7px",},],};// Create the layer and set the rendererconst trails = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",renderer: trailsRenderer,opacity: 0.75,});viewElement.map.add(trails, 0);// Add bikes only trailsconst bikeTrailsRenderer = {type: "simple",symbol: {type: "simple-line",style: "short-dot",color: "#FF91FF",width: "1px",},};5 collapsed lines</script></body></html> -
Create a
bikeTrailsFeatureLayerand set theurlandrendererproperties. Set thedefinitionExpression(a SQL where clause) to access bike trails from the Trailsfeature layer before addingbikeTrailsto the map.124 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Style a feature layer</title><script>var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();// Define a simple renderer and symbolconst trailheadsRenderer = {type: "simple",symbol: {type: "picture-marker",url: "http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png",width: "18px",height: "18px",},};// Define a label for the trailheadsconst trailheadsLabels = {symbol: {type: "text",color: "#FFFFFF",haloColor: "#5E8D74",haloSize: "2px",font: {size: "12px",family: "Noto Sans",style: "italic",weight: "normal",},},labelPlacement: "above-center",labelExpressionInfo: {expression: "$feature.TRL_NAME",},};// Create the layer and set the rendererconst trailheads = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0",renderer: trailheadsRenderer,labelingInfo: [trailheadsLabels],});viewElement.map.add(trailheads);// Define a unique value renderer and symbolsconst trailsRenderer = {type: "simple",symbol: {color: "#BA55D3",type: "simple-line",style: "solid",},visualVariables: [{type: "size",field: "ELEV_GAIN",minDataValue: 0,maxDataValue: 2300,minSize: "3px",maxSize: "7px",},],};// Create the layer and set the rendererconst trails = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",renderer: trailsRenderer,opacity: 0.75,});viewElement.map.add(trails, 0);// Add bikes only trailsconst bikeTrailsRenderer = {type: "simple",symbol: {type: "simple-line",style: "short-dot",color: "#FF91FF",width: "1px",},};const bikeTrails = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",renderer: bikeTrailsRenderer,definitionExpression: "USE_BIKE = 'YES'",});5 collapsed lines</script></body></html> -
Add
bikeTrailslayer to the map. The feature layer will autocast therenderera create class instances of the object.130 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Style a feature layer</title><script>var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();// Define a simple renderer and symbolconst trailheadsRenderer = {type: "simple",symbol: {type: "picture-marker",url: "http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png",width: "18px",height: "18px",},};// Define a label for the trailheadsconst trailheadsLabels = {symbol: {type: "text",color: "#FFFFFF",haloColor: "#5E8D74",haloSize: "2px",font: {size: "12px",family: "Noto Sans",style: "italic",weight: "normal",},},labelPlacement: "above-center",labelExpressionInfo: {expression: "$feature.TRL_NAME",},};// Create the layer and set the rendererconst trailheads = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0",renderer: trailheadsRenderer,labelingInfo: [trailheadsLabels],});viewElement.map.add(trailheads);// Define a unique value renderer and symbolsconst trailsRenderer = {type: "simple",symbol: {color: "#BA55D3",type: "simple-line",style: "solid",},visualVariables: [{type: "size",field: "ELEV_GAIN",minDataValue: 0,maxDataValue: 2300,minSize: "3px",maxSize: "7px",},],};// Create the layer and set the rendererconst trails = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",renderer: trailsRenderer,opacity: 0.75,});viewElement.map.add(trails, 0);// Add bikes only trailsconst bikeTrailsRenderer = {type: "simple",symbol: {type: "simple-line",style: "short-dot",color: "#FF91FF",width: "1px",},};const bikeTrails = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",renderer: bikeTrailsRenderer,definitionExpression: "USE_BIKE = 'YES'",});viewElement.map.add(bikeTrails, 1);5 collapsed lines</script></body></html> -
View the location of bike trails in relation to other trails.
Style open spaces (polygons)
You can use renderers to style feature layer data by unique attribute values. Use the UniqueValueRenderer and SimpleFillSymbol classes to style
-
Create a
createFillSymbolfunction withvalueandcoloras parameters. The function will return asolid,simple-fillsymbol for each park type.132 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Style a feature layer</title><script>var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();// Define a simple renderer and symbolconst trailheadsRenderer = {type: "simple",symbol: {type: "picture-marker",url: "http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png",width: "18px",height: "18px",},};// Define a label for the trailheadsconst trailheadsLabels = {symbol: {type: "text",color: "#FFFFFF",haloColor: "#5E8D74",haloSize: "2px",font: {size: "12px",family: "Noto Sans",style: "italic",weight: "normal",},},labelPlacement: "above-center",labelExpressionInfo: {expression: "$feature.TRL_NAME",},};// Create the layer and set the rendererconst trailheads = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0",renderer: trailheadsRenderer,labelingInfo: [trailheadsLabels],});viewElement.map.add(trailheads);// Define a unique value renderer and symbolsconst trailsRenderer = {type: "simple",symbol: {color: "#BA55D3",type: "simple-line",style: "solid",},visualVariables: [{type: "size",field: "ELEV_GAIN",minDataValue: 0,maxDataValue: 2300,minSize: "3px",maxSize: "7px",},],};// Create the layer and set the rendererconst trails = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",renderer: trailsRenderer,opacity: 0.75,});viewElement.map.add(trails, 0);// Add bikes only trailsconst bikeTrailsRenderer = {type: "simple",symbol: {type: "simple-line",style: "short-dot",color: "#FF91FF",width: "1px",},};const bikeTrails = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",renderer: bikeTrailsRenderer,definitionExpression: "USE_BIKE = 'YES'",});viewElement.map.add(bikeTrails, 1);// Add parks with a class breaks renderer and unique symbolsfunction createFillSymbol(value, color) {return {value: value,symbol: {color: color,type: "simple-fill",style: "solid",outline: {style: "none",},},label: value,};}5 collapsed lines</script></body></html> -
Create an
openSpacesRendererand define it asunique-value. Set thefieldproperty toTYPE. In theuniqueValueInfosarray, set unique colors for each park type.148 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Style a feature layer</title><script>var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();// Define a simple renderer and symbolconst trailheadsRenderer = {type: "simple",symbol: {type: "picture-marker",url: "http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png",width: "18px",height: "18px",},};// Define a label for the trailheadsconst trailheadsLabels = {symbol: {type: "text",color: "#FFFFFF",haloColor: "#5E8D74",haloSize: "2px",font: {size: "12px",family: "Noto Sans",style: "italic",weight: "normal",},},labelPlacement: "above-center",labelExpressionInfo: {expression: "$feature.TRL_NAME",},};// Create the layer and set the rendererconst trailheads = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0",renderer: trailheadsRenderer,labelingInfo: [trailheadsLabels],});viewElement.map.add(trailheads);// Define a unique value renderer and symbolsconst trailsRenderer = {type: "simple",symbol: {color: "#BA55D3",type: "simple-line",style: "solid",},visualVariables: [{type: "size",field: "ELEV_GAIN",minDataValue: 0,maxDataValue: 2300,minSize: "3px",maxSize: "7px",},],};// Create the layer and set the rendererconst trails = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",renderer: trailsRenderer,opacity: 0.75,});viewElement.map.add(trails, 0);// Add bikes only trailsconst bikeTrailsRenderer = {type: "simple",symbol: {type: "simple-line",style: "short-dot",color: "#FF91FF",width: "1px",},};const bikeTrails = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",renderer: bikeTrailsRenderer,definitionExpression: "USE_BIKE = 'YES'",});viewElement.map.add(bikeTrails, 1);// Add parks with a class breaks renderer and unique symbolsfunction createFillSymbol(value, color) {return {value: value,symbol: {color: color,type: "simple-fill",style: "solid",outline: {style: "none",},},label: value,};}const openSpacesRenderer = {type: "unique-value",field: "TYPE",uniqueValueInfos: [createFillSymbol("Natural Areas", "#9E559C"),createFillSymbol("Regional Open Space", "#A7C636"),createFillSymbol("Local Park", "#149ECE"),createFillSymbol("Regional Recreation Park", "#ED5151"),],};5 collapsed lines</script></body></html> -
Create an
openspacesFeatureLayer. Set theurlto access its URL endpoint. Set therendererandopacityproperties before addingopenspacesto themap. The feature layer will autocast therendererto create class instances of the object.159 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Style a feature layer</title><script>var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();// Define a simple renderer and symbolconst trailheadsRenderer = {type: "simple",symbol: {type: "picture-marker",url: "http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png",width: "18px",height: "18px",},};// Define a label for the trailheadsconst trailheadsLabels = {symbol: {type: "text",color: "#FFFFFF",haloColor: "#5E8D74",haloSize: "2px",font: {size: "12px",family: "Noto Sans",style: "italic",weight: "normal",},},labelPlacement: "above-center",labelExpressionInfo: {expression: "$feature.TRL_NAME",},};// Create the layer and set the rendererconst trailheads = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0",renderer: trailheadsRenderer,labelingInfo: [trailheadsLabels],});viewElement.map.add(trailheads);// Define a unique value renderer and symbolsconst trailsRenderer = {type: "simple",symbol: {color: "#BA55D3",type: "simple-line",style: "solid",},visualVariables: [{type: "size",field: "ELEV_GAIN",minDataValue: 0,maxDataValue: 2300,minSize: "3px",maxSize: "7px",},],};// Create the layer and set the rendererconst trails = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",renderer: trailsRenderer,opacity: 0.75,});viewElement.map.add(trails, 0);// Add bikes only trailsconst bikeTrailsRenderer = {type: "simple",symbol: {type: "simple-line",style: "short-dot",color: "#FF91FF",width: "1px",},};const bikeTrails = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",renderer: bikeTrailsRenderer,definitionExpression: "USE_BIKE = 'YES'",});viewElement.map.add(bikeTrails, 1);// Add parks with a class breaks renderer and unique symbolsfunction createFillSymbol(value, color) {return {value: value,symbol: {color: color,type: "simple-fill",style: "solid",outline: {style: "none",},},label: value,};}const openSpacesRenderer = {type: "unique-value",field: "TYPE",uniqueValueInfos: [createFillSymbol("Natural Areas", "#9E559C"),createFillSymbol("Regional Open Space", "#A7C636"),createFillSymbol("Local Park", "#149ECE"),createFillSymbol("Regional Recreation Park", "#ED5151"),],};// Create the layer and set the rendererconst openspaces = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0",renderer: openSpacesRenderer,opacity: 0.2,});5 collapsed lines</script></body></html> -
Add
openspaceslayer to the map. The feature layer will autocast therendererto create class instances of the object.166 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Style a feature layer</title><script>var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();// Define a simple renderer and symbolconst trailheadsRenderer = {type: "simple",symbol: {type: "picture-marker",url: "http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png",width: "18px",height: "18px",},};// Define a label for the trailheadsconst trailheadsLabels = {symbol: {type: "text",color: "#FFFFFF",haloColor: "#5E8D74",haloSize: "2px",font: {size: "12px",family: "Noto Sans",style: "italic",weight: "normal",},},labelPlacement: "above-center",labelExpressionInfo: {expression: "$feature.TRL_NAME",},};// Create the layer and set the rendererconst trailheads = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0",renderer: trailheadsRenderer,labelingInfo: [trailheadsLabels],});viewElement.map.add(trailheads);// Define a unique value renderer and symbolsconst trailsRenderer = {type: "simple",symbol: {color: "#BA55D3",type: "simple-line",style: "solid",},visualVariables: [{type: "size",field: "ELEV_GAIN",minDataValue: 0,maxDataValue: 2300,minSize: "3px",maxSize: "7px",},],};// Create the layer and set the rendererconst trails = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",renderer: trailsRenderer,opacity: 0.75,});viewElement.map.add(trails, 0);// Add bikes only trailsconst bikeTrailsRenderer = {type: "simple",symbol: {type: "simple-line",style: "short-dot",color: "#FF91FF",width: "1px",},};const bikeTrails = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",renderer: bikeTrailsRenderer,definitionExpression: "USE_BIKE = 'YES'",});viewElement.map.add(bikeTrails, 1);// Add parks with a class breaks renderer and unique symbolsfunction createFillSymbol(value, color) {return {value: value,symbol: {color: color,type: "simple-fill",style: "solid",outline: {style: "none",},},label: value,};}const openSpacesRenderer = {type: "unique-value",field: "TYPE",uniqueValueInfos: [createFillSymbol("Natural Areas", "#9E559C"),createFillSymbol("Regional Open Space", "#A7C636"),createFillSymbol("Local Park", "#149ECE"),createFillSymbol("Regional Recreation Park", "#ED5151"),],};// Create the layer and set the rendererconst openspaces = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0",renderer: openSpacesRenderer,opacity: 0.2,});viewElement.map.add(openspaces, 0);6 collapsed lines</script></body></html>
Run the app
In CodePen, run your code to display the map.
The completed map should display all of the layers with a unique, data-driven style.
What’s next?
Learn how to use additional SDK features and ArcGIS services in these tutorials: