Image service layer

Download Sample Viewer

Description

This sample shows how to create and display an ArcGISImageServiceLayer. In the sample it is shown on top of an ArcGISTiledMapServiceLayer basemap.

Code snippet


    ArcGISImageServiceLayer imageServiceLayer = new ArcGISImageServiceLayer(
        "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Portland/CascadeLandsat/ImageServer");
    imageServiceLayer.setImageFormat(IMAGE_FORMAT.JPG_PNG);
    map.getLayers().add(imageServiceLayer);
  

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.dynamiclayers;

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

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.SwingUtilities;

import com.esri.core.geometry.Envelope;
import com.esri.core.map.ImageServiceParameters.IMAGE_FORMAT;
import com.esri.map.ArcGISImageServiceLayer;
import com.esri.map.ArcGISTiledMapServiceLayer;
import com.esri.map.JMap;
import com.esri.map.LayerList;

/**
 * This sample shows how to create and display an ArcGISImageServiceLayer. In the sample it 
 * is shown on top of an ArcGISTiledMapServiceLayer basemap.
 */
public class SimpleImageServiceApp {

  private JMap jMap;

  // Constructor
  public SimpleImageServiceApp() { }

  //------------------------------------------------------------------------
  // Core functionality
  //------------------------------------------------------------------------
  /**
   * Creates the JMap; creates and adds a tiled layer then an image service layer to the JMap.
   * @return a map
   */
  private JMap createMap() {

    final JMap map = new JMap();
    // set default extent to North America
    map.setExtent(new Envelope(-13486609,5713307,-13263258,5823117));

    LayerList layers = map.getLayers();

    // add layers
    ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer(
        "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");
    layers.add(tiledLayer);

    final ArcGISImageServiceLayer imageServiceLayer = new ArcGISImageServiceLayer(
        "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Portland/CascadeLandsat/ImageServer");
    imageServiceLayer.setImageFormat(IMAGE_FORMAT.JPG_PNG);
    layers.add(imageServiceLayer);

    return map;
  }

  //------------------------------------------------------------------------
  // 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
          SimpleImageServiceApp app = new SimpleImageServiceApp();

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

  // ------------------------------------------------------------------------
  // Public methods
  // ------------------------------------------------------------------------

  public JComponent createUI() {
    // application content
    JComponent contentPane = createContentPane();

    // map
    jMap = createMap();

    contentPane.add(jMap);

    return contentPane;
  }

  //------------------------------------------------------------------------
  // Private methods
  //------------------------------------------------------------------------
  /**
   * Creates a window.
   * @return a window.
   */
  private JFrame createWindow() {
    JFrame window = new JFrame("Image Service Layer Application");
    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);
        jMap.dispose();
      }
    });
    return window;
  }

  /**
   * Creates a content pane.
   * @return a content pane.
   */
  private static JLayeredPane createContentPane() {
    JLayeredPane contentPane = new JLayeredPane();
    contentPane.setBounds(100, 100, 1000, 700);
    contentPane.setLayout(new BorderLayout(0, 0));
    contentPane.setVisible(true);
    return contentPane;
  }
}
Feedback on this topic?