Intellij IDEA构建Arcgis objects for java项目

本文介绍如何在IntelliJ IDEA中使用32位JDK 1.8和Maven构建一个包含ArcGIS Engine依赖的Spring Boot项目,并展示了如何通过Java代码初始化ArcGIS Engine并创建基本的地图界面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

网上大多数arcgis objects for java的项目都是用Eclipse开发,这次我用Intellij IDEA构建了一个Spring boot 项目,引入了Arcgis Engine依赖,具体如下:

一、项目环境

1、32位jdk:1.8 ,目前Arcgis Engine只支持32位JDK
2、maven:3.6.3
3、Arcgis 10.2
4、Arcgis Engine 10.2
5、Intellij IDEA 2019.3

二、项目结构

项目结构很平常的Spring boot项目结构

三、Maven依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.3.5.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.jiayu</groupId>
	<artifactId>arcEngine</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>arcEngine</name>
	<description>Demo project for Spring Boot</description>

	<properties>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<!--ae-->
		<dependency>
			<groupId>com.esri</groupId>
			<artifactId>arcobjects</artifactId>
			<scope>system</scope>
			<version>10.2</version>
			<systemPath>${pom.basedir}\src\lib\arcobjects.jar</systemPath>
		</dependency>

	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
		<resources>
			<resource>
				<directory>${pom.basedir}/src/lib</directory>
				<targetPath>BOOT-INF/lib/</targetPath>
				<includes>
					<include>**/*.jar</include>
				</includes>
			</resource>
		</resources>
	</build>

</project>

四、项目配置

1、找到arcgisobject.jar包,位置在Arcgis安装目录下的“C:\Program Files (x86)\ArcGIS\Desktop10.2\java\lib\arcobjects.jar”,在项目的Src/lib下添加
该jar包。
在这里插入图片描述

2、设置项目的SDK,一定要是32位版本的
在这里插入图片描述
3、Maven导入依赖

五、项目启动
1、新建一个类,添加以下代码
public class AoInitUtil {
    /**
     * 初始化ae
     * 初始化ae或许可失败,会报错或者返回null
     * @param aoInit
     * @return
     */
    public AoInitialize initializeEngine(AoInitialize aoInit) throws IOException {
        //初始化ae
        EngineInitializer.initializeVisualBeans();

        // 设置使用的arcgis产品和版本,使ao能运行在不同的arcgis环境下
        VersionManager versionManager = new VersionManager();

        // 第一个参数是arcgis产品编号:1=desktop,2=engine,5=server
        // 此参数可以通过枚举查看esriProductCode
        boolean s = versionManager.loadVersion(1, "10.2");


        aoInit = new AoInitialize();

        //判断并使用哪个级别的许可,PS:目前应该只能用desktop相关的许可,也就是Advanced,Standard,Basic等
        if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeAdvanced) == esriLicenseStatus.esriLicenseAvailable) {
            aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced);
        } else if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeStandard) == esriLicenseStatus.esriLicenseAvailable) {
            aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeStandard);
        } else if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeBasic) == esriLicenseStatus.esriLicenseAvailable) {
            aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeBasic);
        } else if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB) == esriLicenseStatus.esriLicenseAvailable) {
            aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
        } else if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeArcServer) == esriLicenseStatus.esriLicenseAvailable) {
            aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer);
        } else {
            aoInit = null;
        }

        return aoInit;
    }
}

2、添加可视化页面

这里用的都是arcgis object里自带的组件

public class EngineVisualBeans {

    public static void initialVisual() throws IOException {
        //ae许可初始化
        AoInitialize aoInit = null;

        AoInitUtil aoInitUtil = new AoInitUtil();
        //初始化ae
        //初始化ae或许可失败,会报错或者返回null
        aoInit = aoInitUtil.initializeEngine(aoInit);

        if (aoInit == null) {
            JOptionPane.showMessageDialog(null, "ae初始化失败");
            return;
        }

        //Create a map visual component and load a .mxd map document.
        MapBean map = new MapBean(); //地图容器

        //Create a toolbar visual component and add standard ESRI tools and commands.
        ToolbarBean toolbar = new ToolbarBean(); //工具栏
        toolbar.addItem(ControlsMapZoomInTool.getClsid(), 0, 0, false, 0,
                esriCommandStyles.esriCommandStyleIconOnly); //缩小
        toolbar.addItem(ControlsMapZoomOutTool.getClsid(), 0, 0, false, 0,
                esriCommandStyles.esriCommandStyleIconOnly); //放大
        toolbar.addItem(new ControlsMapFullExtentCommand(), 0,  - 1, false, 0,
                esriCommandStyles.esriCommandStyleIconOnly); //全图
        toolbar.addItem(ControlsMapPanTool.getClsid(), 0, 0, false, 0,
                esriCommandStyles.esriCommandStyleIconOnly); //移动

        //Create a table of contents (TOCBean) visual component for the map.
        TOCBean toc = new TOCBean(); //内容列表

        //Buddy up the map component with the toolbar and TOC components.
        toolbar.setBuddyControl(map);
        toc.setBuddyControl(map);

        //Build the frame.
        JFrame frame = new JFrame("Arcgis Engine");
        frame.add(map, BorderLayout.CENTER);
        frame.add(toolbar, BorderLayout.NORTH);
        frame.add(toc, BorderLayout.WEST);
        frame.setSize(600,600);
        frame.setLocation(600,250);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }


}

2、Spring boot启动类中代码如下:

@SpringBootApplication
public static void main(String[] args) throws IOException {
		//初始化AE,初始化界面
		EngineVisualBeans.initialVisual();
		//Spring 初始化
		SpringApplication.run(ArcEngineApplication.class, args);
	}
        

启动项目即可看到AE界面:
在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值