2

I'm using the ArcGIS API for JavaScript to create an interactive map in a web page. When I try to add a layer with an specific id, doesn't recognize the layer and I receive this error:

enter image description here

The code to add the layer is:

require([
          "esri/Map",
          "esri/views/MapView", // SceneView
          "esri/layers/Layer",
          "dojo/domReady!"
        ], function(Map, MapView, Layer) {
          var map = new Map({
            basemap: "gray" // streets, topo, satellite, gray
          });

          var view = new MapView({
            container: "viewDiv",  // Reference to the DOM node that will contain the view
            map: map,               // References the map object created in step 3
            zoom: 4,  // Sets the zoom level based on level of detail (LOD)
            center: [-58, -15]  // Sets the center point of view in lon/lat
          });

          // Add a layer in the map
          Layer.fromPortalItem({ 
            portalItem: { // autocast as esri/portal/PortalItem
                id: "405b97de934143aebe4784e833258a0f"
            }
          }).then(addLayer).otherwise(rejection);

          // Adds the layer to the map once it loads
          function addLayer(lyr) {
            map.add(lyr);
            alert("Layer added");
          }

          function rejection(err) {
            alert("Layer failed to load: " + err);
          }
});

The layer is in the arcgis portal (layer) with the extension .lyr.

2
  • We can't see the layer since it is in Portal. Maybe you need to be signed in for the web map to work? Commented Jul 14, 2016 at 16:11
  • How can I put the layer in the Portal? Commented Jul 18, 2016 at 11:17

1 Answer 1

1

It seems you are using the class Layer and not an object of the class. Take a look at the line:

function(Map, MapView, Layer) {
...

This is telling that you will use 3 classes: Map, MapView and Layer.

You already created 2 objects for Map and MapView:

var map = new Map({
...

var view = new MapView({
...

But you haven't created any object for Layer. Something like:

var lyr = new Layer({
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.