In this lab you will apply custom styling to a feature layer.
-
Click create_starter_map/index.html and copy the contents to a new jsbin.com.
-
In
JSBin
>HTML
, update therequire
statement andfunction
definition.
require([
"esri/Map",
"esri/views/MapView",
/*** ADD ***/
"esri/layers/FeatureLayer",
"esri/symbols/SimpleLineSymbol",
"esri/renderers/UniqueValueRenderer",
"dojo/domReady!"
], function(Map, MapView, FeatureLayer, SimpleLineSymbol, UniqueValueRenderer) {
- Now set up a
UniqueValueRenderer
based off theTYPE
field.
...
var view = new MapView({
container: "viewDiv",
map: map,
center: [-122.68, 45.52],
zoom: 10
});
/*** ADD ***/
var renderer = new UniqueValueRenderer({
field: "TYPE",
defaultSymbol: new SimpleLineSymbol()
});
- Next we tell the renderer how to show each
TYPE
value (the values areMAX
,SC
,MAX/SC
andCR
). We want to highlightCR
, so we make the line wider and darker by setting the width to4
and thecolor
opacity to1
.
// Green for Type MAX
renderer.addUniqueValueInfo("MAX",
new SimpleLineSymbol({
color: [96, 219, 34, 0.8]
})
);
// Yellow for Type SC
renderer.addUniqueValueInfo("SC",
new SimpleLineSymbol({
color: [255, 255, 34, 0.8]
})
);
// Red for Type MAX/SC
renderer.addUniqueValueInfo("MAX/SC",
new SimpleLineSymbol({
color: [238, 71, 71, 0.8]
})
);
// Light blue for Type CR
renderer.addUniqueValueInfo("CR",
new SimpleLineSymbol({
color: [8, 197, 249, 1],
width: 4
})
);
- Lastly, we create the
FeatureLayer
, attach theUniqueValueRenderer
, and add it to the map.
/*** ADD ***/
var featureLayer = new FeatureLayer({
url: "https://services.arcgis.com/uCXeTVveQzP4IIcx/arcgis/rest/services/PDX_Rail_Lines/FeatureServer/0",
renderer: renderer
});
map.add(featureLayer);
Your app should look something like this:
- Add a Rail Stops feature layer to the map and then apply custom styles to it.