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

              
                <html>
  <head>
    <meta 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 layers-imagerytilelayer sample, read the original sample description at developers.arcgis.com.
  https://developers.arcgis.com/javascript/latest/sample-code/layers-imagerytilelayer/index.html
  -->
<title>
      Change RasterStretchRenderer's ColorRamp
    </title>

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

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

      #rendererDiv {
        padding: 10px;
        width: 240px;
      }

      .slider {
        height: 40px;
        width: 100%;
        background-color: transparent;
      }
    </style>
    <script>
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/ImageryTileLayer",
        "esri/renderers/RasterStretchRenderer",
        "esri/widgets/Slider",
        "esri/tasks/support/AlgorithmicColorRamp"
      ], function (
        Map,
        MapView,
        ImageryTileLayer,
        RasterStretchRenderer,
        Slider,
        AlgorithmicColorRamp
      ) {
        // initial stretch type for the rasterStretchRenderer
        let stretchType = "standard-deviation";

        // color ramp assigned to rasterStretchRenderer
        let colorRamp = new AlgorithmicColorRamp({
          algorithm: "lab-lch",
          toColor: "red",
          fromColor: "yellow"
        });
       
       let colorRamp2 = new AlgorithmicColorRamp({
          algorithm: "lab-lch",
          toColor: "green",
          fromColor: "yellow"
        });

        // create a ImageryTileLayer from tiled elevation service
        var layer = new ImageryTileLayer({
          url:
            "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Elevation/MtBaldy_Elevation/ImageServer",
          opacity: 0.9
        });

        var map = new Map({
          basemap: "topo-vector",
          layers: [layer]
        });

        var view = new MapView({
          container: "viewDiv",
          map: map,
          zoom: 10,
          center: [-117.463, 34.306]
        });

        view.whenLayerView(layer).then(function () {
          updateRenderer("red");
        });

        view.ui.add("rendererDiv", "top-right");

        // This function is called when the layer view is loaded
        // or when user changes the renderer settings from the UI
        function updateRenderer(colorType) {
          // clone the layer renderer
          // layer's renderer needs to be cloned if it changes at runtime
          var renderer = layer.renderer.clone();
          
         
          switch (colorType) {
            case "red":
              renderer.colorRamp = colorRamp;
              break;
            case "green":
              renderer.colorRamp = colorRamp2;
              break;
          }
          // apply the cloned renderer back to the layer's renderer
          // changes will be immediate
          layer.renderer = renderer;
        }

        const colorSelect = document.getElementById("colorSelect");

        // listen to change event on stretchType dropdown
        colorSelect.addEventListener("change", function () {
          color = colorSelect.value;
          updateRenderer(color);
        });   
      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
    <div id="rendererDiv" class="esri-widget">
      <h3 class="esri-widget__heading">Switch Color</h3>

      <label class="esri-feature-form__label">Select stretch type</label>
      <select id="colorSelect" class="esri-input esri-select">
        <option value="red" selected>red</option>
        <option value="green">green</option>
      </select> 
    </div>
  </body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console