Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"
  />
  <title>ArcGIS JS API Tutorials: Access traffic using OAuth2</title>
  <link
      rel="stylesheet"
      href="https://js.arcgis.com/4.14/esri/themes/light/main.css"
    />
    <script src="https://js.arcgis.com/4.14/"></script>
  <style>
    html,
    body, #viewDiv{
      font-family: Avenir Next W00;
      font-size: 14px;
      width: 100%;
      height: 100%;
      margin: 0px;
      padding: 0px;
    }

    .action {
      color: blue;
      cursor: pointer;
      text-decoration: underline;
    }
  </style>

  <script>
    require([
      "esri/portal/Portal",
      "esri/identity/OAuthInfo",
      "esri/identity/IdentityManager",
      "esri/Map",
      "esri/views/MapView",
      "esri/layers/MapImageLayer",
      "dojo/dom-style",
      "dojo/dom-attr",
      "dojo/on",
      "dojo/dom"
    ], function(
        Portal, OAuthInfo, identityManager, Map, MapView, MapImageLayer,
        domStyle, domAttr, on, dom) {

      // ArcGIS Online or your portal address
      var portalUrl = "https://www.arcgis.com/sharing";

      function displayMap() {
        var portal = new Portal();

        // Once the portal has loaded, the user is signed in
        portal.load().then(function() {
          dom.byId('viewDiv').style.display = 'flex';

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

          var view = new MapView({
            container: "viewDiv",
            map: map,
            zoom: 14,
            center: [-118.24,34.05]
          });

          var traffic = new MapImageLayer({
            url: 'https://traffic.arcgis.com/arcgis/rest/services/World/Traffic/MapServer'
          })
          map.add(traffic);
        });
      }

      // subsitute your own client ID to identify who spawned the login and check for a matching redirect URI
      var info = new OAuthInfo({
        appId: "your client id", //*** Your Client ID value goes here ***//
        popup: false // inline redirects don't require any additional app configuration
      });

      identityManager.registerOAuthInfos([info]);

      // send users to arcgis.com to login
      on(dom.byId("sign-in"), "click", function() {
        identityManager.getCredential(portalUrl);
      });

      // log out and reload
      on(dom.byId("sign-out"), "click", function() {
        identityManager.destroyCredentials();
        window.location.reload();
      });

      identityManager.checkSignInStatus(portalUrl).then(function() {
       dom.byId('anonymousPanel').style.display = 'none';
       dom.byId('personalizedPanel').style.display = 'block';
       displayMap();
     });

    });
  </script>


</head>
<body>
  <div id="anonymousPanel" style="display: block; padding: 5px; text-align: center;">
    <span id="sign-in" class="action">Sign In</span> to see live traffic.
  </div>

  <div id="personalizedPanel" style="display: none; padding: 5px; text-align: center;">
    Welcome <span id="userId" style="font-weight: bold;"></span> &nbsp;-&nbsp;
    <span id="sign-out" class="action">Sign Out</span>
  </div>
  <!-- for the map -->
  <div id="viewDiv" style="display: none;"></div>
</body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console