Select to view content in your preferred language

Cannot get a layer to appear on map

799
1
Jump to solution
01-06-2023 02:38 PM
JACOBSTEINBERG
New Contributor

This is my first time using the ArcGIS API for JavaScript. I'm running into a fairly elementary error. I cannot get a layer I have hosted on ArcGIS Online to appear on the map. Here is my code:

require([
    "esri/config",
    "esri/Map",
    "esri/layers/FeatureLayer",
    "esri/views/MapView"
], function (esriConfig, Map, MapView, FeatureLayer) {

    //Setting the API key
    esriConfig.apiKey = api key hidden

    const map = new Map({
        basemap: "arcgis-topographic"
    });

    const view = new MapView({
        container: "viewDiv",
        map: map,
        extent: {
            xmin: -88.4407865369763,
            ymin: 44.2519512604157,
            xmax: -87.57033074655209,
            ymax: 44.58559644055305,
            spatialReference: 4326
        },
    });

    let one_year_high = new FeatureLayer({
        id: "1-year-high",
        apiKey: api key hidden
    });

    map.add(one_year_high);

});

 

This script produces the following error in my browser:

[esri.Map] #add() The item being added is not a Layer or a Promise that resolves to a Layer.

My layer can be found here: https://services.arcgis.com/HRPe58bUyBqyyiCt/ArcGIS/rest/services/1_year_high_lake_level/FeatureServ...

I can't figure out why it won't appear.

 

Thanks in advance.

 

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Esri Frequent Contributor

In your require and function, the MapView and FeatureLayer order are swapped. When using amd, the order matters.

View solution in original post

0 Kudos
1 Reply
ReneRubalcava
Esri Frequent Contributor

In your require and function, the MapView and FeatureLayer order are swapped. When using amd, the order matters.

0 Kudos