In ArcGIS, data can be displayed on and interacted with using Layers. These Layers are collections of geographical data that share a common theme or a set of attributes. The combination of these Layers and their features is what makes up the fully-featured map and interface that is displayed to the user, providing powerful geographical analysis capabilities.
One such type of layer is the Feature Layer. The simplest way to create this Layer is to point to a Feature Service hosted on ArcGIS Server or ArcGIS Online, but it can also be constructed using a Feature Collection object. This Layer is most often used for visualizing certain sets of data on top of a base map, such as regions that make up an area or markers to show points of interest. We will be creating a simple Feature Collection, using Flickr’s API and a simple popup point structure below.
Creating a Simple Feature Layer
We will need to choose a data source for the Feature Layer we will be adding. We can use Flickr’s public feed to retrieve a set of pictures that contain geographical attributes. Every time the map is loaded, a few markers will show up, representing where that picture was posted from.
First, we will define the structure of the Feature Collection that will contain the data the layer will be using. Since each photo has only one location associated with it, we can use the esriGeometryPoint geometry type.
Next, we will define the layer itself, as well as the popup template for what will appear when the map marker is clicked. The icon for the Flickr popup is a simple map marker PNG stored in the img folder. Since the image is larger than needed, we can specify the width and height we need here.
The Feature Layer is most often used for visualizing certain sets of data on top of a base map, such as regions that make up an area or markers to show points of interest.
The ‘fields’ of the layer is the structure of the points that will be added; each one will have a unique ObjectID, as well as a description and title that we will set ourselves.
Next, it’s time to actually create the Feature Layer object, pull the data, and add it to the map.
The requestPhotos function is what will be doing most of the work: Pulling the pictures, adding the points to the map, and updating the Feature Layer itself.
This code will produce the following results: a full-screen map with markers representing the locational data of a set of pictures.
Clicking a marker will initiate the popup containing the details as defined in the template:
This small demonstration of a Feature Collection itself has many potential uses. Leveraging the hosted Feature Service to provide the data allows for even more functionality and possibilities while keeping the logic on the page itself just as neat and perhaps even simpler. With just a few lines of code, you can create similar interactive geospatial analytics UIs. Many creative examples are available on the ArcGIS samples page and range from carbon storage of trees in a neighborhood to a real-time stream of bus routes in Los Angeles.
Click here to view all of Tallan’s latest offerings, and find what’s right for your organization.