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 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>
      Point clustering - basic configuration | Sample | ArcGIS API for
      JavaScript 4.16
    </title>
    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
        background: rgba(50, 50, 50);
      }

      #infoDiv {
        padding: 10px;
      }
    </style>
    <link
      rel="stylesheet"
      href="https://js.arcgis.com/4.15/esri/themes/dark-red/main.css"
    />
    <script src="https://js.arcgis.com/4.16/"></script>
    <script>
      require([
        "esri/Map",
        "esri/layers/GeoJSONLayer",
        "esri/views/MapView",
        "esri/widgets/Legend",
        "esri/widgets/Expand",
        "esri/widgets/Home",
        "esri/symbols/PictureMarkerSymbol"
      ], function (
        Map,
        GeoJSONLayer,
        MapView,
        Legend,
        Expand,
        Home,
        PictureMarkerSymbol
      ) {
        const geojson = {
          type: "FeatureCollection",
          features: [
            {
              type: "Feature",
              properties: {
                home_value: 20,
                school_value: 0,
                store_value: 0
              },
              geometry: {
                type: "Point",
                coordinates: [-154.248046875, 62.34960927573042]
              }
            },
            {
              type: "Feature",
              properties: {
                home_value: 0,
                school_value: 110,
                store_value: 0
              },
              geometry: {
                type: "Point",
                coordinates: [-156.09375, 61.05828537037916]
              }
            },
            {
              type: "Feature",
              properties: {
                home_value: 30,
                school_value: 0,
                store_value: 0
              },
              geometry: {
                type: "Point",
                coordinates: [-144.404296875, 62.79493487887006]
              }
            },
            {
              type: "Feature",
              properties: {
                home_value: 22,
                school_value: 0,
                store_value: 0
              },
              geometry: {
                type: "Point",
                coordinates: [-144.580078125, 61.81466389468391]
              }
            },
            {
              type: "Feature",
              properties: {
                home_value: 0,
                school_value: 0,
                store_value: 70
              },
              geometry: {
                type: "Point",
                coordinates: [-145.17333984375, 62.45648663758143]
              }
            }
          ]
        };
        const blob = new Blob([JSON.stringify(geojson)], {
          type: "application/json"
        });
        const neourl = URL.createObjectURL(blob);
        console.log(neourl);
        const clusterConfig = {
          type: "cluster",
          clusterRadius: "200px",
          clusterMinSize: "24px",
          clusterMaxSize: "50px",
          popupTemplate: {
            content: "This cluster represents {cluster_count} hangouts.",
            fieldInfos: [
              {
                fieldName: "cluster_avg_home_value",
                label: "Average wind speed (km/h)",
                format: {
                  places: 0
                }
              },
              {
                fieldName: "cluster_avg_school_value",
                label: "Average wind direction (degrees)",
                format: {
                  places: 0
                }
              },
              {
                fieldName: "cluster_avg_store_value",
                label: "Average temperature (°F)",
                format: {
                  places: 0
                }
              }
            ]
          },
          labelingInfo: [
            {
              deconflictionStrategy: "none",
              labelExpressionInfo: {
                expression: "Text($feature.cluster_count, '#,###')"
              },
              symbol: {
                type: "text",
                color: "#000000",
                yoffset: 5,
                font: {
                  weight: "bold",
                  family: "Noto Sans",
                  size: "12px"
                }
              },
              labelPlacement: "center-center"
            },
            {
              deconflictionStrategy: "none",
              labelExpressionInfo: {
                expression:
                  "IIf($feature.cluster_avg_home_value < 1, '-', $feature.cluster_avg_home_value * $feature.cluster_count)"
              },
              symbol: {
                type: "text",
                color: "#000000",
                yoffset: -10,
                xoffset: -16,
                font: {
                  weight: "bold",
                  family: "Noto Sans",
                  size: "12px"
                }
              },
              labelPlacement: "center-center"
            },
            {
              deconflictionStrategy: "none",
              labelExpressionInfo: {
                expression:
                  "IIf($feature.cluster_avg_school_value < 1, '-', $feature.cluster_avg_school_value * $feature.cluster_count)"
              },
              symbol: {
                type: "text",
                color: "#000000",
                yoffset: -10,
                xoffset: -1,
                font: {
                  weight: "bold",
                  family: "Noto Sans",
                  size: "12px"
                }
              },
              labelPlacement: "center-center"
            },
            {
              deconflictionStrategy: "none",
              labelExpressionInfo: {
                expression:
                  "IIf($feature.cluster_avg_store_value < 1, '-', $feature.cluster_avg_store_value * $feature.cluster_count)"
              },
              symbol: {
                type: "text",
                color: "#000000",
                yoffset: -10,
                xoffset: 15,
                font: {
                  weight: "bold",
                  family: "Noto Sans",
                  size: "12px"
                }
              },
              labelPlacement: "center-center"
            }
          ]
        };
        let url1 = "http://json-serve.surge.sh/geojsonserve.json";
        var pinUrl =
          "https://static.arcgis.com/images/Symbols/Shapes/BluePin1LargeB.png";
        var picBaseUrl = "http://json-serve.surge.sh/hangout.svg";
        var svgIcon = {
          type: "picture-marker",
          url: picBaseUrl,
          width: "94px",
          height: "64px"
        };
        var pin = {
          type: "picture-marker",
          url: pinUrl,
          width: "94px",
          height: "64px"
        };
        var classBreakRenderer = {
          type: "class-breaks",
          field: "cluster_count",
          visualVariables: [
            {
              type: "size",
              field: "home_value",
              minDataValue: 0,
              maxDataValue: 60,
              minSize: 40,
              maxSize: 40
            },
            {
              type: "size",
              field: "school_value",
              minDataValue: 0,
              maxDataValue: 60,
              minSize: 40,
              maxSize: 40
            },
            {
              type: "size",
              field: "store_value",
              minDataValue: 0,
              maxDataValue: 60,
              minSize: 40,
              maxSize: 40
            }
          ],
          classBreakInfos: [
            {
              minValue: 0,
              maxValue: 1,
              symbol: pin
            },
            {
              minValue: 2,
              maxValue: Number.POSITIVE_INFINITY,
              symbol: svgIcon
            }
          ]
        };
        const layer = new GeoJSONLayer({
          title: "ClusterLayer",
          url: neourl,
          featureReduction: clusterConfig,
          renderer: classBreakRenderer
        });
        const map = new Map({
          layers: [layer]
        });
        const view = new MapView({
          container: "viewDiv",
          extent: {
            spatialReference: {
              wkid: 5936
            },
            xmin: 1270382,
            ymin: -1729511,
            xmax: 2461436,
            ymax: -953893
          },
          spatialReference: {
            wkid: 5936
          },
          map: map
        });
        view.ui.add(
          new Home({
            view: view
          }),
          "top-left"
        );
        const legend = new Legend({
          view: view,
          container: "legendDiv"
        });
        const infoDiv = document.getElementById("infoDiv");
        view.ui.add(
          new Expand({
            view: view,
            content: infoDiv,
            expandIconClass: "esri-icon-layer-list",
            expanded: false
          }),
          "top-left"
        );

        function findLayer(title) {
          return map.allLayers.find(function (layer) {
            return layer.title === title;
          });
        }
        let copiedLayers = findLayer("ClusterLayer");
        view.watch("scale", function (newValue) {
          console.log(newValue);
          if (newValue <= 2475898) {
            map.removeAll();
            console.log(map.allLayers);
          } else if (newValue > 2475898) {
            map.addMany([copiedLayers]);
          }
        });
        const toggleButton = document.getElementById("cluster");
        toggleButton.addEventListener("click", function () {
          let fr = layer.featureReduction;
          layer.featureReduction =
            fr && fr.type === "cluster" ? null : clusterConfig;
          toggleButton.innerText =
            toggleButton.innerText === "Enable Clustering"
              ? "Disable Clustering"
              : "Enable Clustering";
        });
        console.log(map.allLayers.items);
      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
    <div id="infoDiv" class="esri-widget">
      <button id="cluster" class="esri-button">Disable Clustering</button>
      <div id="legendDiv"></div>
    </div>
  </body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console