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();
        }
      }
    });
  }
}
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值