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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

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"
    />
    <!--
     ArcGIS API for JavaScript, https://js.arcgis.com
     For more information about the popuptemplate-function sample,
     read the original sample description at developers.arcgis.com.
     https://developers.arcgis.com/javascript/latest/sample-code/popuptemplate-function/index.html
     -->
    <title>PopupTemplate - use functions to set content - 4.11</title>

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

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

    <script>
      var populationChange;
      require(["esri/Map", "esri/views/MapView", "esri/layers/Layer"], function(
        Map,
        MapView,
        Layer
      ) {
        var map = new Map({
          basemap: "dark-gray"
        });
        
        var field_names = [];

        // Create the MapView
        var view = new MapView({
          container: "viewDiv",
          map: map,
          zoom: 7,
          center: [-87, 34]
        });

        Layer.fromPortalItem({
          portalItem: {
            // autocasts as new PortalItem()
            id: "e8f85b4982a24210b9c8aa20ba4e1bf7"            
          }
        }).then(function(layer) {
          // add the layer to the map
          map.add(layer);
          // create a new popupTemplate for the layer
          // format the numeric field values using out of the box
          // NumberFormat function. Call populationChange() custom
          // function to calculate percent change for the county.
          var popupTemplate = {
            // autocasts as new PopupTemplate()
            //title: "Population in {layer.fields[1].alias}",
            title: function(data) {             
              createFieldNamesArray()
              return (
                "Population in <span>" +
                //data.graphic.attributes[layer.fields[1].alias] +
                data.graphic.attributes[field_names[1]] +
                "</span>"
              );
            },
            content:
              /*"As of 2010, the population in this area was <b>{POP2010:NumberFormat}</b> " +
              "and the density was <b>{POP10_SQMI:NumberFormat}</b> sq mi. " +
              "As of 2013, the population here was <b>{POP2013:NumberFormat}</b> " +
              "and the density was <b>{POP13_SQMI:NumberFormat}</b> sq mi. <br/> <br/>" +*/
              //"Percent change is {POP2013:populationChange}",
            function(data) {            
              createFieldNamesArray()
              
              var upArrow =
                '<svg width="16" height="16" ><polygon points="14.14 7.07 7.07 0 0 7.07 4.07 7.07 4.07 16 10.07 16 10.07 7.07 14.14 7.07" style="fill:green"/></svg>';
              var downArrow =
                '<svg width="16" height="16"><polygon points="0 8.93 7.07 16 14.14 8.93 10.07 8.93 10.07 0 4.07 0 4.07 8.93 0 8.93" style="fill:red"/></svg>';

              // calculate the population percent change from 2010 to 2013.
              //orig: var diff = data.POP2013 - data.POP2010;
              var diff = data.graphic.attributes[field_names[8]] - data.graphic.attributes[field_names[6]]; 
              var pctChange = (diff * 100) / data.graphic.attributes[field_names[6]];
              var arrow = diff > 0 ? upArrow : downArrow;

              // add green arrow if the percent change is positive.
              // red arrow for negative percent change.
              return (
                arrow +
                "<span style='color: " +
                (pctChange < 0 ? "red" : "green") +
                ";'>" +
                pctChange.toFixed(3) +
                "%</span>"
              );
            }
          };

          layer.popupTemplate = popupTemplate;
          
          function createFieldNamesArray() {
            if (!field_names.length) {
              field_names = layer.fields.map(function(item) {
                return item["alias"];
              });
            }
          }
        });
        
      });
      
      
    </script>
  </head>
  <body>
    <div id="viewDiv"></div>
  </body>
</html>

            
          
!

CSS

            
              
            
          
!

JS

            
              
            
          
!
999px

Console