⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aimsclient.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
字号:
package com.esri.solutions.jitk.web.tasks.resources;

import com.esri.aims.mtier.io.ConnectionProxy;
import com.esri.aims.mtier.model.map.Map;
import com.esri.aims.mtier.model.service.Services;

import java.net.URL;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

public class AIMSClient {
	private static Logger _logger = LogManager.getLogger(AIMSClient.class.getName());
	
	protected String _host;
	protected int _port;
	protected String _username;
	protected String _password;
	
	public AIMSClient(String host, int port, String username, String password) {
		_host = host;
		_port = port;
		_username = username;
		_password = password;		
    }
	
	public byte[] getMap(String service, int width, int height) {
		
        try {
            ConnectionProxy mConnection = new ConnectionProxy();

            if (_username != null) {
                mConnection.setUsername(_username);
            }

            if (_password != null) {
                mConnection.setPassword(_password);
            }

            if (_port > 0) {
                mConnection.setHost(_host);
                mConnection.setPort(_port);
                mConnection.setConnectionType(ConnectionProxy.TCP);
            } else {
                URL myurl = new URL(_host);
                mConnection.setUrl(myurl);
                mConnection.setConnectionType(ConnectionProxy.HTTP);
            }

            mConnection.setService(service);

            Map mMap = new Map();
            mMap.setWidth((long) width);
            mMap.setHeight((long) height);
            mMap.initMap(mConnection, 0, false, false, false, false);

            String response = mMap.sendArcXML(mMap.getArcXML(), 0);

            return response.getBytes();
        } catch (Exception e) {
        	_logger.warn("Could not get image from ArcIMS Service", e);
        }

        return null;
    }
	
    public String[] getServices() {
        String[] aimsServices;
        int svcCount = 0;

        try {
            ConnectionProxy connection = new ConnectionProxy();
            Services svc = new Services();

            if (chkStr(_username, null) != null) {
                connection.setUsername(_username);
            }

            if (chkStr(_password, null) != null) {
                connection.setPassword(_password);
            }

            if ((_host != null) && !_host.toLowerCase().startsWith("http")) {
                svc.getServices(_host, _port, _username, _password);
            
            } else if ((_host != null) && _host.toLowerCase().startsWith("http")) {
                URL url = new URL(_host);
                svc.getServices(url, _username, _password);
            
            } else {
                System.out.println("Invalid connection parameters.");
            }

            for (int i = 0; i < svc.getServicesCount(); i++) {
                if (svc.getService(i).getType().equalsIgnoreCase("imageServer") || svc.getService(i).getType().equalsIgnoreCase("ArcMapServer")) {
                	svcCount++;
                }
            }

            if (svcCount == 0) {
                System.out.println("No service available.");
            }

            aimsServices = new String[svcCount];

            int m = 0;

            for (int j = 0; j < svc.getServicesCount(); j++) {
                if (svc.getService(j).getType().equalsIgnoreCase("imageServer") || svc.getService(j).getType().equalsIgnoreCase("ArcMapServer")) {
                    aimsServices[m] = svc.getService(j).getName();
                    m++;
                }
            }

            return aimsServices;
            
        } catch (Exception e) {
        	_logger.warn("Unable to get aims service", e);

            return null;
        }
    }
    
	private String chkStr(String s, String defaultVal) {
		s = (s == null) ? "" : s.trim();
		return (s.length() == 0) ? defaultVal : s;
	}    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -