###Add a feature layer to a map
In this lab you will add a feature layer to an ArcGIS API for JavaScript application.
-
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",
"dojo/domReady!"
], function(Map, MapView, FeatureLayer) {
- Now add the Styled Rail Lines to the map:
...
/*** ADD ***/
var featureLayer = new FeatureLayer({
url: "https://services.arcgis.com/uCXeTVveQzP4IIcx/arcgis/rest/services/PDX_Rail_Lines_Styled/FeatureServer/0"
});
map.add(featureLayer);
- Confirm that the JSBin
Output
panel shows a map with rail lines.
Your app should look something like this:
###Bonus
- Add a Rail Stops feature layer to the map, and then add a Neighborhoods feature layer.
- Ensure the layers are ordered with polygons on the bottom, lines and then points on top.
- If you added additional layers using the
add()
method, try theaddMany()
method instead. Read up on thelayers
collection and see how the API gives you a few ways to add layers to a map. - The 4.0 JS API works closely with ArcGIS Portals. Instead of the Feature Service URL, use the Portal Item ID to add layers. See the URLs of the Portal Items for Stops, Lines and Neighborhoods to get their IDs.