Snapshot mode

Download Sample Viewer

Description

This sample shows an ArcGISFeatureLayer in SNAPSHOT mode. In this mode, all the features from the associated feature service are retrieved and displayed as graphics on the client. Note that there is a maximum number of features allowed, so not all features from the service are actually displayed. Left-click on a feature to view the attributes of that feature.

Code snippet


    // create ArcGISFeatureLayer from service URL
    final ArcGISFeatureLayer featureLayer = new ArcGISFeatureLayer(URL_BLOCK_POINTS);
    // Snapshot mode will activate all features (up to maximum allowed) in the map
    featureLayer.setOperationMode(QueryMode.SNAPSHOT);
    // define a renderer to symbolize active features client-side
    featureLayer.setRenderer(new SimpleRenderer(SYM_CITY));
  

Sample Code

/* Copyright 2014 Esri

All rights reserved under the copyright laws of the United States
and applicable international laws, treaties, and conventions.

You may freely redistribute and use this sample code, with or
without modification, provided you include the original copyright
notice and use restrictions.

See the use restrictions.*/
package com.esri.client.samples.featurelayers;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.border.LineBorder;

import com.esri.toolkit.overlays.InfoPopupOverlay;
import com.esri.core.geometry.Envelope;
import com.esri.map.ArcGISFeatureLayer;
import com.esri.map.ArcGISTiledMapServiceLayer;
import com.esri.map.JMap;
import com.esri.map.LayerInitializeCompleteEvent;
import com.esri.map.LayerInitializeCompleteListener;
import com.esri.map.LayerList;
import com.esri.map.QueryMode;

/***
 * This sample shows an ArcGISFeatureLayer in SNAPSHOT mode. In this mode, all the 
 * features from the associated feature service are retrieved and displayed as graphics 
 * on the client. Note that there is a maximum number of features allowed, so not all 
 * features from the service are actually displayed. Left-click on a feature to view 
 * the attributes of that feature.
 */
public class SnapshotApp {

  private JMap map;

  // ------------------------------------------------------------------------
  // Constructor
  // ------------------------------------------------------------------------
  public SnapshotApp() {
  }

  // ------------------------------------------------------------------------
  // Core functionality
  // ------------------------------------------------------------------------
  /**
   * Creates an ArcGISFeatureLayer in Snapshot mode.
   */
  private ArcGISFeatureLayer createFeatureLayerInSnapshotMode() {

    final ArcGISFeatureLayer featureLayer = new ArcGISFeatureLayer(
        "http://sampleserver6.arcgisonline.com/arcgis/rest/services/SampleWorldCities/MapServer/0");

    // Snapshot mode will activate all features (up to maximum allowed) in the map
    featureLayer.setOperationMode(QueryMode.SNAPSHOT);

    return featureLayer;
  }

  /**
   * Creates the map for this application.
   * @return the JMap.
   */
  private JMap createMap() throws Exception {

    final JMap jMap = new JMap();
    // -----------------------------------------------------------------------------------------
    // Base Layer
    // -----------------------------------------------------------------------------------------
    final ArcGISTiledMapServiceLayer baseLayer = new ArcGISTiledMapServiceLayer(
        "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");
    // set to US extent
    jMap.setExtent(new Envelope(-17517313, -1387361, -2546029, 8598576));
    LayerList layers = jMap.getLayers();
    layers.add(baseLayer);

    // -----------------------------------------------------------------------------------------
    // Feature Layer - demographics by block points
    // -----------------------------------------------------------------------------------------
    final ArcGISFeatureLayer blockPointsLayer = createFeatureLayerInSnapshotMode();
    layers.add(blockPointsLayer);

    // -----------------------------------------------------------------------------------------
    // InfoPopupOverlay - a map overlay to display attributes of an active feature in a popup
    // -----------------------------------------------------------------------------------------
    final InfoPopupOverlay infoPopupOverlay =
        new InfoPopupOverlay();
    infoPopupOverlay.setItemTitle("City: {CITY_NAME}");
    jMap.addMapOverlay(infoPopupOverlay);

    // add the feature layer to the infopopup overlay once it is initialized
    blockPointsLayer.addLayerInitializeCompleteListener(new LayerInitializeCompleteListener() {
      @Override
      public void layerInitializeComplete(LayerInitializeCompleteEvent event) {
        infoPopupOverlay.addLayer(event.getLayer());
      }
    });

    return jMap;
  }

  // ------------------------------------------------------------------------
  // Static methods
  // ------------------------------------------------------------------------
  /**
   * Starting point of this application.
   * @param args arguments to this application.
   */
  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        try {
          // instance of this application
          SnapshotApp snapshotApp = new SnapshotApp();

          // create the UI, including the map, for the application.
          JFrame appWindow = snapshotApp.createWindow();
          appWindow.add(snapshotApp.createUI());
          appWindow.setVisible(true);
        } catch (Exception e) {
          // on any error, display the stack trace.
          e.printStackTrace();
        }
      }
    });
  }

  // ------------------------------------------------------------------------
  // Public methods
  // ------------------------------------------------------------------------
  /**
   * Creates and displays the UI, including the map, for this application.
   */
  public JComponent createUI() throws Exception {
    // application content
    JComponent contentPane = createContentPane();

    // description
    JPanel description = createDescription();
    contentPane.add(description);

    // map
    map = createMap();
    contentPane.add(map);

    return contentPane;
  }

  // ------------------------------------------------------------------------
  // Private methods
  // ------------------------------------------------------------------------
  /**
   * Creates a window.
   * @return a window.
   */
  private JFrame createWindow() {
    JFrame window = new JFrame("ArcGISFeatureLayer - Snapshot Mode");
    window.setBounds(100, 100, 1000, 700);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.getContentPane().setLayout(new BorderLayout(0, 0));
    window.addWindowListener(new WindowAdapter() {
      @Override
      public void windowClosing(WindowEvent windowEvent) {
        super.windowClosing(windowEvent);
        map.dispose();
      }
    });
    return window;
  }

  /**
   * Creates a content pane.
   * @return a content pane.
   */
  private static JLayeredPane createContentPane() {
    JLayeredPane contentPane = new JLayeredPane();
    contentPane.setLayout(new BorderLayout(0, 0));
    contentPane.setVisible(true);
    return contentPane;
  }

  /**
   * Creates a description for this application.
   * @return a JPanel that has the description text.
   */
  private JPanel createDescription() {
    JPanel descriptionContainer = new JPanel();
    descriptionContainer.setLayout(new BoxLayout(descriptionContainer, 0));
    descriptionContainer.setSize(280, 140);
    descriptionContainer.setLocation(10, 10);
    JTextArea description = new JTextArea(
        "The feature layer is in Snapshot mode, where all the features from the associated " +
            "layer resource are retrieved and displayed as graphics on the client. " +
            "Note that there is a maximum number of features allowed, so not all features from " +
            "the service are actually displayed. Left-click on a feature to view the attributes of " +
            "that feature."
        );
    description.setFont(new Font("Verdana", Font.PLAIN, 11));
    description.setForeground(Color.WHITE);
    description.setBackground(new Color(0, 0, 0, 180));
    description.setEditable(false);
    description.setLineWrap(true);
    description.setWrapStyleWord(true);
    description.setBorder(BorderFactory.createEmptyBorder(5,10,5,5));
    descriptionContainer.add(description);
    descriptionContainer.setBackground(new Color(0, 0, 0, 0));
    descriptionContainer.setBorder(new LineBorder(Color.BLACK, 3, false));
    return descriptionContainer;
  }
}
Feedback on this topic?