Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <title>Intro to ImageryLayer | Sample | ArcGIS API for JavaScript 4.23</title>

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

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

    <script>
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/ImageryLayer",
        "esri/layers/support/RasterFunction"
      ], (Map, MapView, ImageryLayer, RasterFunction) => {
        const slope = new RasterFunction({
          functionName: 'Slope Degrees',
        })

        const rasterClip = new RasterFunction({
          functionName: 'Clip',
          functionArguments: {
            ClippingGeometry: {"spatialReference":{"latestWkid":3857,"wkid":102100},"rings":[[[-12347054.018395461,3747660.64982666],[-12332536.357499849,3747642.884189226],[-12332249.867934851,3734580.5126524474],[-12347121.050086282,3734725.6235733326],[-12347054.018395461,3747660.64982666]]]},
            ClippingType: 1,
            Raster: slope
          }
        })
        
        const water = new RasterFunction({
          functionName: 'Remap',
          functionArguments: {
            InputRanges: [0, 100],
            OutputValues: [50],
            GeometryType: 'esriGeometryEnvelope',
            Geometries: [
              {
                spatialReference: { latestWkid: 3857, wkid: 102100 },
                "rings": [ [ [ -12341994.5440037, 3742276.467355759 ], [ -12338522.929441707, 3742369.6249839813 ], [ -12338398.719270743, 3740046.954503397 ], [ -12341963.939334173, 3740131.453249509 ], [ -12341994.5440037, 3742276.467355759 ] ] ]
              }
            ],
            Raster: slope
          }
        })
        
        
        
        const layer = new ImageryLayer({
          url: "https://elevation.nationalmap.gov/arcgis/rest/services/3DEPElevation/ImageServer",
          renderingRule: water,
          pixelFilter: colorize
        });

        /**************************
         * Add image layer to map
         *************************/

        const map = new Map({
          basemap: "satellite",
          layers: [layer]
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          center: [-110.88527305333872, 31.838175304063586],
          zoom: 12
        });
        
        function colorize(pixelData) {
          if (
            pixelData === null ||
            pixelData.pixelBlock === null ||
            pixelData.pixelBlock.pixels === null
          ) {
            return
          }

          const pixelBlock = pixelData.pixelBlock

          // The pixels visible in the view
          const pixels = pixelBlock.pixels
          let mask = pixelBlock.mask

          // The number of pixels in the pixelBlock
          const numPixels = pixelBlock.width * pixelBlock.height

          // Get the pixels containing temperature values in the only band of the data
          const p1 = pixels[0]

          const rBand = new Uint8Array(p1.length)
          const gBand = new Uint8Array(p1.length)
          const bBand = new Uint8Array(p1.length)

          // Loop through all the pixels in the view
          for (let i = 0; i < numPixels; i++) {
            // skip noData pixels
            if (mask[i] === 0) {
              continue
            }

            if (p1[i] === 50) {
              rBand[i] = 0
              gBand[i] = 255
              bBand[i] = 0
            } else {
              rBand[i] = 255
              gBand[i] = 0
              bBand[i] = 0
            }
          }

          // Set the new pixel values on the pixelBlock
          pixelData.pixelBlock.pixels = [rBand, gBand, bBand] // assign rgb values to each pixel
          pixelData.pixelBlock.statistics = null
          pixelData.pixelBlock.pixelType = 'u8'
        }
      });
    </script>
  </head>

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

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console