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 charset="utf-8" />
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
  <title>Client Side Raster Functions Playground</title>

  <link rel="stylesheet" href="https://js.arcgis.com/next/esri/themes/light/main.css" />
  <script src="https://js.arcgis.com/next/"></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",
      "esri/config"
    ], function(Map, MapView, ImageryLayer, RasterFunction, esriConfig) {
      var imagePopupTemplate = {
        // autocasts as new PopupTemplate()
        title: "Data from {SensorName} satellite",
        content: "Rendered RGB values: <b>{Raster.ServicePixelValue} </b>" +
          "<br>Original values (Coastal Aerosal, Blue, Green, Red, NIR, SWIR 1, SWIR 2, Panchromatic, Cirrus, TIRS 1, TIRS2): <b>{Raster.ItemPixelValue} </b>"
      };
      var imageryLayerUrl = "https://landsat2.arcgis.com/arcgis/rest/services/Landsat8_Views/ImageServer";
      var layer = new ImageryLayer({
        url: imageryLayerUrl,
        renderingRule: returnRasterFunction('NDVI'),
        id: 'rasterLayer',
        popupTemplate: imagePopupTemplate
      });
      //////////////////////////
      /// RequestInterceptor ///
      //////////////////////////
      esriConfig.request.interceptors.push({
        // set the `urls` property to the URL of the ImageryLayer so that this
        // interceptor only applies to requests made to the ImageryLayer URL
        urls: imageryLayerUrl,
        error: function(err) {
          console.log("Christian Howard, this is the error: ", err);
          debugger;
        }
      });
      /**************************************************************
       * SELECT LOGIC TO CHANGE RASTER FUNCTION AND CREATE NEW IMAGE
       *************************************************************/
      function returnRasterFunction(rasterType) {
        const raster = new RasterFunction({
          functionName: 'BandArithmetic',
          functionArguments: {
            Raster: '$3294570', // OID of image from service
          },
          variableName: 'Raster',
        });
        switch (rasterType) {
          case 'NDVI':
            raster.functionArguments = {
              Method: 1,
              BandIndexes: '5 4',
              ...raster.functionArguments
            };
            break;
          case 'GNVDI': // WRONG NAME ON PURPOSE TO FORCE THE EXPORT IMAGE ERROR
            raster.functionArguments = {
              Method: 0,
              BandIndexes: '(B5 - B3) / (B5 + B3)',
              ...raster.functionArguments
            };
            break;
          default:
            console.log('No Raster Function for', rasterType);
        }
        return raster;
      }
      var select = document.getElementById("raster-select");
      select.addEventListener('change', function() {
        var layer = map.findLayerById('rasterLayer');
        map.remove(layer);
        var newLayer = new ImageryLayer({
          url: "https://landsat2.arcgis.com/arcgis/rest/services/Landsat8_Views/ImageServer",
          renderingRule: returnRasterFunction(this.value),
          id: 'rasterLayer',
          popupTemplate: imagePopupTemplate
        });
        // test code from geonet
        newLayer.on("layerview-create-error", function(event) {
          console.log('LAYERVIEW CREATE ERROR', event);
          //todo do something because of the error now
        });
        newLayer.on("layerview-create", function(event) {
          console.log('NO LAYERVIEW CREATE ERROR');
          // map.add(newLayer);
        });
        map.add(newLayer);
      });
      /*************************
       * Add image layer to map
       ************************/
      var map = new Map({
        basemap: "hybrid",
        layers: [layer]
      });
      var view = new MapView({
        container: "viewDiv",
        map: map,
        center: {
          // autocasts as esri/geometry/Point
          latitude: 48.7505,
          longitude: -71.0528,
          spatialReference: 3857
        },
        zoom: 8,
        popup: {
          actions: []
        }
      });
      window.view = view;
      view.ui.add('select', "top-right")
    });
  </script>
</head>

<body>
  <div id="viewDiv"></div>
  <div id='select'>
    <select id='raster-select'>
      <option value='NDVI'>NDVI</option>
      <option value='GNDVI'>GNDVI</option>
    </select>
  </div>
</body>

</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console