AnsweredAssumed Answered

Using Feature Layer from ArcGIS Online in ArcGIS Javascript

Question asked by BrokenLegMike on Feb 13, 2019
Latest reply on Feb 15, 2019 by odoe

I'm playing around with the Javascript API for ArcGIS and wanted to use a feature layer from my Enterprise ArcGIS Online account. The script is quite simple, basically, create a map and add the feature layer. When I launch the webpage, the base map is populated and then I get a prompt to log into ArcGIS (see image below). I enter my enterprise credentials and it it tells me they are incorrect. My assumption is, that it's looking for credentials for a regular ArcGIS Online account (www.arcgis.com) as opposed to my enterprise account. So, my question is, how would I configure my Javascript to prompt me to log into my enterprise account. For reference, here is my code:

 

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>Intro to FeatureLayer - 4.10</title>

  <link rel="stylesheet" href="https://js.arcgis.com/4.10/esri/css/main.css">
  <script src="https://js.arcgis.com/4.10/"></script>

  <style>
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  </style>

  <script>
    require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer"
      ],
      function(
        Map, MapView,
        FeatureLayer
      ) {

        var map = new Map({
          basemap: "hybrid"
        });

        var view = new MapView({
          container: "viewDiv",
          map: map,

          extent: { // autocasts as new Extent()
            xmin: -9177811,
            ymin: 4247000,
            xmax: -9176791,
            ymax: 4247784,
            spatialReference: 102100
          }
        });

        /********************
         * Add feature layer
         ********************/


        // Sample Feature Layers
        var featureLayer = new FeatureLayer({
          url: "https://services6.arcgis.com/ubm4tcTYICKBpist/arcgis/rest/services/MineralPlacerCoalTitlesService3/FeatureServer"
        });

        map.add(featureLayer);

      });
  </script>
</head>

<body>
  <div id="viewDiv"></div>
</body>

</html>

 

 

Outcomes