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" />
  <title>GeoJSONLayer | Sample | ArcGIS API for JavaScript 4.18</title>

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

  </style>

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

  <script>
    require(["esri/Map", "esri/layers/GeoJSONLayer", "esri/views/MapView", "esri/geometry/Extent", "esri/geometry/Polygon", "esri/Graphic"], function (
      Map,
      GeoJSONLayer,
      MapView,
      Extent, Polygon, Graphic
    ) {
      // If GeoJSON files are not on the same domain as your website, a CORS enabled server
      // or a proxy is required.
      const url = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.geojson";


      const template = {
        title: "Earthquake Info",
        content: "Magnitude {mag} {type} hit {place} on {time}",
        fieldInfos: [
          {
            fieldName: 'time',
            format: {
              dateFormat: 'short-date-short-time'
            }
          }
        ]
      };

      const renderer = {
        type: "simple",
        field: "mag",
        symbol: {
          type: "simple-marker",
          color: "orange",
          outline: {
            color: "white"
          }
        },
        visualVariables: [{
          type: "size",
          field: "mag",
          stops: [{
            value: 2.5,
            size: "4px"
          },
            {
              value: 8,
              size: "40px"
            }
          ]
        }]
      };

      const geojsonLayer = new GeoJSONLayer({
        url: url,
        copyright: "USGS Earthquakes",
        popupTemplate: template,
        renderer: renderer //optional
      });

      const map = new Map({
        basemap: "gray-vector",
        layers: [geojsonLayer]
      });

      const view = new MapView({
        container: "viewDiv",
        center: [-168, 46],
        zoom: 2,
        map: map
      });

      view.popup.autoOpenEnabled = false;
      view.on('click', (event) => {
        view.hitTest(event).then((response) => {
          if (response.results.length > 0) {
            response.results.forEach(result => {
              const layer = result.graphic.layer;
              if (layer === geojsonLayer) {
                const queryParams = geojsonLayer.createQuery();
                const gap = 10;
                const [minX, minY, maxX, maxY] = [event.x - gap, event.y - gap, event.x + gap, event.y + gap];
                const mapPoint1 = view.toMap({x: minX, y: minY});
                const mapPoint2 = view.toMap({x: maxX, y: maxY});
                const spatialReference = {
                  wkid: 102100,
                  latestWkid: 3857
                };
                const extent = new Extent({
                  xmin: mapPoint1.x,
                  ymin: mapPoint1.y,
                  xmax: mapPoint2.x,
                  ymax: mapPoint2.y,
                  spatialReference: spatialReference
                });
                
                var poly = Polygon.fromExtent(extent);
                
                var graphic = new Graphic({
                  geometry: poly,
                  symbol: {
                    type: 'simple-fill',
                    color: null
                  }
                });
                view.graphics.removeAll();
                view.graphics.add(graphic)
                queryParams.geometry = poly;
                //queryParams.num = 100;
                queryParams.returnGeometry = true;
                queryParams.outFields = ['*'];

geojsonLayer.queryFeatures(queryParams).then(result => {
                  const features = result.features;
                  console.log(features);
                  if (features.length === 0) {
                    // alert("not found");
                    console.log(features.length)
                  }
                });
              }
            });
          }
        });
      });
    });

  </script>
</head>

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

</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console