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-featurelayer-collection sample,
     read the original sample description at developers.arcgis.com.
     https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer-collection/index.html
     -->
    <title>Create a FeatureLayer with client-side graphics - 4.15</title>
    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>

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

    <!-- Library for for reading EXIF data from image files
    See https://github.com/exif-js/exif-js for more information -->

    <script src="https://cdn.jsdelivr.net/npm/exif-js"></script>

    <script>
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/core/promiseUtils",
        "esri/Graphic",
        "esri/geometry/Multipoint",
        "esri/tasks/Locator"
      ], function(
        Map,
        MapView,
        FeatureLayer,
        promiseUtils,
        Graphic,
        Multipoint,
        Locator
      ) {
        const view = new MapView({
          map: new Map({
            basemap: "gray-vector"
          }),
          container: "viewDiv",
          extent: {
            spatialReference: {
              wkid: 102100
            },
            xmin: -14488954,
            ymin: 3457304,
            xmax: -10656095,
            ymax: 5250211
          },
          popup: {
            dockEnabled: true,
            dockOptions: {
              position: "top-right",
              breakpoint: false
            }
          }
        });

        view
          .when()
          .then(fetchImages)
          .then(getFeaturesFromPromises)
          .then(createLayer)
          .then(addToView)
          .catch(function(e) {
            console.error("Creating FeatureLayer from photos failed", e);
          });

        /**
         * Fetches a list of images and returns a list of promises
         */
        function fetchImages() {
          const numPhotos = 18;
          const graphicPromises = [];
          const baseUrl =
            "https://arcgis.github.io/arcgis-samples-javascript/sample-data/featurelayer-collection/photo-";

          for (let i = 1; i <= numPhotos; i++) {
            const url = baseUrl + i.toString() + ".jpg";
            const graphicPromise = exifToGraphic(url, i);
            graphicPromises.push(graphicPromise);
          }

          return promiseUtils.eachAlways(graphicPromises);
        }

        // Filters only promises that resolve with valid values (a graphic
        // in this case) and resolves them as an array of graphics.
        // In other words, each attempt at fetching an image returns a promise.
        // Images that fail to fetch will be filtered out of the response array
        // so the images that successfully load can be added to the layer.
        function getFeaturesFromPromises(eachAlwaysResponses) {
          return eachAlwaysResponses
            .filter(function(graphicPromise) {
              return graphicPromise.value;
            })
            .map(function(graphicPromise) {
              return graphicPromise.value;
            });
        }

        const locatorTask = new Locator({
          url:
            "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"
        });

        //  Creates a client-side FeatureLayer from an array of graphics
        function createLayer(graphics) {
          return new FeatureLayer({
            source: graphics,
            objectIdField: "OBJECTID",
            fields: [
              {
                name: "OBJECTID",
                type: "oid"
              },
              {
                name: "url",
                type: "string"
              }
            ],
            popupTemplate: {
              title: function(event) {
                return locatorTask
                  .locationToAddress({
                    location: event.graphic.geometry
                  })
                  .then(function(response) {
                    return response.address;
                  })
                  .catch(function(error) {
                    return "The middle of nowhere";
                  });
              },
              content: "<img src='{url}'>"
            },
            renderer: {
              type: "simple",
              symbol: {
                type: "picture-marker",
                url:
                "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iMzQ4LjMzM3B4IiBoZWlnaHQ9IjM0OC4zMzNweCIgdmlld0JveD0iMCAwIDM0OC4zMzMgMzQ4LjMzNCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMzQ4LjMzMyAzNDguMzM0OyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PGc+PHBhdGggZmlsbD0iIzU2NTY1NiIgZD0iTTMzNi41NTksNjguNjExTDIzMS4wMTYsMTc0LjE2NWwxMDUuNTQzLDEwNS41NDljMTUuNjk5LDE1LjcwNSwxNS42OTksNDEuMTQ1LDAsNTYuODVjLTcuODQ0LDcuODQ0LTE4LjEyOCwxMS43NjktMjguNDA3LDExLjc2OWMtMTAuMjk2LDAtMjAuNTgxLTMuOTE5LTI4LjQxOS0xMS43NjlMMTc0LjE2NywyMzEuMDAzTDY4LjYwOSwzMzYuNTYzYy03Ljg0Myw3Ljg0NC0xOC4xMjgsMTEuNzY5LTI4LjQxNiwxMS43NjljLTEwLjI4NSwwLTIwLjU2My0zLjkxOS0yOC40MTMtMTEuNzY5Yy0xNS42OTktMTUuNjk4LTE1LjY5OS00MS4xMzksMC01Ni44NWwxMDUuNTQtMTA1LjU0OUwxMS43NzQsNjguNjExYy0xNS42OTktMTUuNjk5LTE1LjY5OS00MS4xNDUsMC01Ni44NDRjMTUuNjk2LTE1LjY4Nyw0MS4xMjctMTUuNjg3LDU2LjgyOSwwbDEwNS41NjMsMTA1LjU1NEwyNzkuNzIxLDExLjc2N2MxNS43MDUtMTUuNjg3LDQxLjEzOS0xNS42ODcsNTYuODMyLDBDMzUyLjI1OCwyNy40NjYsMzUyLjI1OCw1Mi45MTIsMzM2LjU1OSw2OC42MTF6Ii8+PC9nPjwvc3ZnPg==",
                width: `14px`,
                height: `14px`
              }
            }
          });
        }

        // Adds a given layer to the map in the view
        function addToView(layer) {
          view.map.add(layer);
        }

        /**
         * Fetches and loads an image from a url and gets the latitude/longitude
         * GPS data from the EXIF data of the image. Returns a promise that
         * resolves to a Graphic with a point geometry representing the location
         * where the photo was taken.
         */
        function exifToGraphic(url, id) {
          return promiseUtils.create(function(resolve, reject) {
            const image = document.createElement("img");
            image.src = url;
            image.onload = function() {
              image.load = image.onerror = null;
              EXIF.getData(image, function() {
                const latitude = EXIF.getTag(this, "GPSLatitude");
                const latitudeDirection = EXIF.getTag(this, "GPSLatitudeRef");
                const longitude = EXIF.getTag(this, "GPSLongitude");
                const longitudeDirection = EXIF.getTag(this, "GPSLongitudeRef");

                if (!latitude || !longitude) {
                  reject(
                    new Error(
                      "Photo doesn't contain GPS information: ",
                      this.src
                    )
                  );
                  return;
                }

                const location = new Multipoint({
                  points: [[
                    dmsDD(longitude, longitudeDirection),
                    dmsDD(latitude, latitudeDirection)
                  ]]
                });

                resolve(
                  new Graphic({
                    geometry: location,
                    attributes: {
                      url: url,
                      OBJECTID: id
                    }
                  })
                );
              });
            };

            image.onerror = function() {
              image.load = image.onerror = null;
              reject(new Error("Error while loading the image"));
            };
          });
        }

        // Converts a DMS coordinate to decimal degrees
        function dmsDD([degrees, minutes, seconds], direction) {
          let dd = degrees + minutes / 60 + seconds / 3600;
          if (direction === "S" || direction === "W") {
            dd *= -1;
          }
          return dd;
        }
      });
    </script>
  </head>

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

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console