Arcgis for Java(一)在应用程序中添加地图

Arcgis Runtime SDK for Java包含一个JMap容器,使你可以显示不同源的地图信息,比如来自ArcGIS for Server services, Bing Maps, Open Street Map等等。
本例将使你的地图显示来自ArcGIS for Server map service的tiled layer,而且可以显示一个标记图形。

package application;

import java.awt.EventQueue;
import javax.swing.JFrame;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import com.esri.runtime.ArcGISRuntime;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.map.Graphic;
import com.esri.core.symbol.PictureMarkerSymbol;
import com.esri.map.ArcGISTiledMapServiceLayer;
import com.esri.map.GraphicsLayer;
import com.esri.map.JMap;
import com.esri.map.MapEvent;
import com.esri.map.MapEventListener;
import com.esri.map.MapOptions;
import com.esri.map.MapOptions.MapType;

public class newClass {

  private JFrame window;
  private JMap map;

  public newClass() {
    window = new JFrame();
    window.setSize(800, 600);
    window.setLocationRelativeTo(null); // center on screen
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.getContentPane().setLayout(new BorderLayout(0, 0));

    // dispose map just before application window is closed.
    window.addWindowListener(new WindowAdapter() {
      @Override
      public void windowClosing(WindowEvent windowEvent) {
        super.windowClosing(windowEvent);
        map.dispose();
      }
    });

    map = new JMap();
    ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
    map.getLayers().add(tiledLayer);
    map.setExtent(new Envelope(-371147, 7536055, -341260, 7557266));
    GraphicsLayer graphicsLayer = new GraphicsLayer();
    graphicsLayer.setName("Marker graphics");
    map.getLayers().add(graphicsLayer);

    map.addMapEventListener(new MapEventListener() {

          @Override
          public void mapReady(MapEvent event) {
            SpatialReference mapSR=event.getMap().getSpatialReference();
            System.out.println("the map spatial reference is wkid="+mapSR.getID());
            Point point=GeometryEngine.project(3.2008, 55.9486, mapSR);
            PictureMarkerSymbol symbol = new PictureMarkerSymbol("http://static.arcgis.com/images/Symbols/Basic/RedShinyPin.png");
            Graphic pointGraphic=new Graphic(point,symbol);
            graphicsLayer.addGraphic(pointGraphic);
          }

          @Override
          public void mapExtentChanged(MapEvent event) {
            // TODO Auto-generated method stub
          }

          @Override
          public void mapDispose(MapEvent event) {
            // TODO Auto-generated method stub
          }
        });

    window.getContentPane().add(map,BorderLayout.CENTER);

  }

  /**
   * Starting point of this application.
   * @param args
   */
  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {

      @Override
      public void run() {
        try {
          newClass application = new newClass();
          application.window.setVisible(true);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    });
  }
}

你可能感兴趣的:(ArcGis,API,for,Flex)