📄 addsource.java
字号:
/* * Copyright 2006 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 use restrictions at /arcgis/java/samples/userestrictions. */package com.esri.arcgis.demo;import java.util.ArrayList;import javax.faces.application.FacesMessage;import javax.faces.context.FacesContext;import javax.faces.el.ValueBinding;import com.esri.adf.web.ags.data.AGSLocalMapResource;import com.esri.adf.web.ags.data.AGSUser;import com.esri.adf.web.ags.data.AGSGeocodeFunctionality;import com.esri.adf.web.ags.data.AGSMapResource;import com.esri.adf.web.aims.data.AIMSMapResource;import com.esri.adf.web.aws.data.AWSMapResource;import com.esri.adf.web.data.WebContext;import com.esri.adf.web.data.WebMap;import com.esri.adf.web.faces.component.ContextControl;import com.esri.adf.web.wms.data.WMSMapResource;import java.util.List;public class AddSource { ContextControl contextControl; AGSGeocodeFunctionality agswsGeocodeFunc; String agsHost = ""; String agsServerObject = ""; private String agsDomain=""; private String agsUsername=""; private String agsPassword=""; String aimsHost = ""; String aimsService = ""; String aimsResourceType = "ImageService"; Integer aimsPort = null; private String aimsUsername =""; private String aimsPassword=""; private String arcwebAuthenticationURL = ""; private String arcwebUserName = ""; private String arcwebPassword = ""; private String arcwebMapURL = ""; private String arcwebDataSource = ""; String agswsURL = ""; private String agswsCatalogURL=""; String wmsURL = ""; String addType = ""; ArrayList m_dataSources; public String addAgsSource() { FacesContext fc = FacesContext.getCurrentInstance(); if (agsServerObject == null || agsHost == null) { fc.addMessage(contextControl.getClientId(fc), new FacesMessage("Cannot add source with no value.")); return null; } WebContext mctx = (WebContext) contextControl.getWebContext(); AGSLocalMapResource ags = null; try { ValueBinding vb = fc.getApplication().createValueBinding("#{ags}"); ags = (AGSLocalMapResource) vb.getValue(fc); AGSUser user = new AGSUser(agsDomain, agsUsername,agsPassword, false); ags.setUser(user); ags.setServerObjectName(agsServerObject); List hosts = new ArrayList(); hosts.add(agsHost); ags.setHosts(hosts); ags.setAlias(agsServerObject); WebMap mmap = (WebMap) mctx.getWebMap(); mmap.setInitExtent(mmap.getCurrentExtent()); mctx.addResource("ags" + (mctx.getResources().size() + 1), ags, 0); agsServerObject=""; return "success"; } catch (Exception e) { fc.addMessage(contextControl.getClientId(fc), new FacesMessage("Unable to add source: " + agsServerObject + "@" + agsHost)); agsServerObject=""; e.printStackTrace(); if (ags != null) mctx.removeResource(ags); return "failure"; } } public String addAIMSSource() { FacesContext fc = FacesContext.getCurrentInstance(); WebContext mctx = (WebContext) contextControl.getWebContext(); AIMSMapResource aims = null; try { ValueBinding vb = fc.getApplication().createValueBinding("#{aims}"); aims = (AIMSMapResource) vb.getValue(fc); aims.setHostName(aimsHost); aims.setServiceName(aimsService); if (aimsPort != null) aims.setPort(aimsPort.intValue()); aims.setPassword(aimsPassword); aims.setUserName(aimsUsername); aims.setAlias(aimsService); WebMap mmap = (WebMap) mctx.getWebMap(); //WebExtent initExtent = mmap.getInitExtent(); mmap.setInitExtent(mmap.getCurrentExtent()); mctx.addResource("aims" + (mctx.getResources().size() + 1),aims, 0); aimsService=""; return "success"; } catch (Exception e) { fc.addMessage(contextControl.getClientId(fc), new FacesMessage("Unable to add AIMS source: " + aimsService + "@" + aimsHost)); aimsService=""; e.printStackTrace(); if (aims != null) mctx.removeResource(aims); return "failure"; } } public String addArcWebSource() { FacesContext fc = FacesContext.getCurrentInstance(); WebContext mctx = (WebContext) contextControl.getWebContext(); AWSMapResource arcWeb = null; if (getArcwebAuthenticationURL() == null || getArcwebUserName() == null || getArcwebPassword() == null) return null; try { ValueBinding vb = fc.getApplication().createValueBinding("#{arcweb}"); arcWeb = (AWSMapResource) vb.getValue(fc); arcWeb.setAuthenticationEndPointURL(getArcwebAuthenticationURL()); arcWeb.setUserName(getArcwebUserName()); arcWeb.setPassword(getArcwebPassword()); arcWeb.setAlias(getArcwebAuthenticationURL()); arcWeb.setMapImageEndPointURL(getArcwebMapURL()); arcWeb.setDataSource(getArcwebDataSource()); WebMap mmap = (WebMap) mctx.getWebMap(); mmap.setInitExtent(mmap.getCurrentExtent()); mctx.addResource("arcWeb" + (mctx.getResources().size() + 1),arcWeb, 0); return "success"; } catch (Exception e) { fc.addMessage(contextControl.getClientId(fc), new FacesMessage("Unable to add ArcWeb source: " + getArcwebAuthenticationURL())); e.printStackTrace(); if (arcWeb != null) mctx.removeResource(arcWeb); } return "failure"; } public String addAGSWSSource() { FacesContext fc = FacesContext.getCurrentInstance(); WebContext mctx = (WebContext) contextControl.getWebContext(); AGSMapResource agsWeb = null; if (agswsURL == null) return null; try { ValueBinding vb = fc.getApplication().createValueBinding("#{agsweb}"); agsWeb = (AGSMapResource)vb.getValue(fc); agsWeb.setEndPointURL(agswsURL); agsWeb.setAlias(agswsURL); WebMap mmap = (WebMap) mctx.getWebMap(); mmap.setInitExtent(mmap.getCurrentExtent()); mctx.addResource("agsWeb" + (mctx.getResources().size() + 1),agsWeb, 0); return "success"; } catch (Exception e) { fc.addMessage(contextControl.getClientId(fc), new FacesMessage("Unable to add AGSWeb source: " + agswsURL)); e.printStackTrace(); if (agsWeb != null) mctx.removeResource(agsWeb); } return "failure"; } public String addWMSSource() { FacesContext fc = FacesContext.getCurrentInstance(); WebContext mctx = (WebContext) contextControl.getWebContext(); WMSMapResource wms = null; try { ValueBinding vb = fc.getApplication().createValueBinding("#{wms}"); wms = (WMSMapResource) vb.getValue(fc); wms.setWmsURL(wmsURL); wms.setAlias(wmsURL); WebMap mmap = (WebMap) mctx.getWebMap(); mmap.setInitExtent(mmap.getCurrentExtent()); mctx.addResource("wms" + (mctx.getResources().size() + 1),wms, 0); wmsURL =""; return "success"; } catch (Exception e) { fc.addMessage(contextControl.getClientId(fc), new FacesMessage("Unable to add WMS source: " + wmsURL)); wmsURL=""; e.printStackTrace(); if (wms != null) mctx.removeResource(wms); } return "failure"; } public ContextControl getContextControl() { return contextControl; } public void setContextControl(ContextControl contextControl) { this.contextControl = contextControl; } public String getAgsHost() { return agsHost; } public void setAgsHost(String agsHost) { this.agsHost = agsHost; } public String getAgsServerObject() { return agsServerObject; } public void setAgsServerObject(String agsServerObject) { this.agsServerObject = agsServerObject; } public String getAimsHost() { return aimsHost; } public void setAimsHost(String aimsHost) { this.aimsHost = aimsHost; } public Integer getAimsPort() { return aimsPort; } public void setAimsPort(Integer aimsPort) { this.aimsPort = aimsPort; } public String getAimsResourceType() { return aimsResourceType; } public void setAimsResourceType(String aimsResourceType) { this.aimsResourceType = aimsResourceType; } public String getAimsService() { return aimsService; } public void setAimsService(String aimsService) { this.aimsService = aimsService; } public String getWmsURL() { return wmsURL; } public void setWmsURL(String wmsURL) { this.wmsURL = wmsURL; } public String getAddType() { return addType; } public void setAddType(String addType) { this.addType = addType; } public void setDataSources(ArrayList dataSources){ this.m_dataSources = dataSources; } public String getAimsUsername() { return aimsUsername; } public void setAimsUsername(String aimsUsername) { this.aimsUsername = aimsUsername; } public String getAimsPassword() { return aimsPassword; } public void setAimsPassword(String aimsPassword) { this.aimsPassword = aimsPassword; } public String getAgsDomain() { return agsDomain; } public void setAgsDomain(String agsDomain) { this.agsDomain = agsDomain; } public String getAgsUsername() { return agsUsername; } public void setAgsUsername(String agsUsername) { this.agsUsername = agsUsername; } public String getAgsPassword() { return agsPassword; } public void setAgsPassword(String agsPassword) { this.agsPassword = agsPassword; } public String getAgswsURL() { return agswsURL; } public void setAgswsURL(String agswsURL) { this.agswsURL = agswsURL; } public String getArcwebURL() { return getArcwebAuthenticationURL(); } public void setArcwebURL(String arcwebURL) { this.setArcwebAuthenticationURL(arcwebURL); } public String getArcwebAuthenticationURL() { return arcwebAuthenticationURL; } public void setArcwebAuthenticationURL(String arcwebAuthenticationURL) { this.arcwebAuthenticationURL = arcwebAuthenticationURL; } public String getArcwebUserName() { return arcwebUserName; } public void setArcwebUserName(String arcwebUserName) { this.arcwebUserName = arcwebUserName; } public String getArcwebPassword() { return arcwebPassword; } public void setArcwebPassword(String arcwebPassword) { this.arcwebPassword = arcwebPassword; } public String getArcwebMapURL() { return arcwebMapURL; } public void setArcwebMapURL(String arcwebMapURL) { this.arcwebMapURL = arcwebMapURL; } public String getArcwebDataSource() { return arcwebDataSource; } public void setArcwebDataSource(String arcwebDataSource) { this.arcwebDataSource = arcwebDataSource; } public String getAgswsCatalogURL() { return agswsCatalogURL; } public void setAgswsCatalogURL(String agswsCatalogURL) { this.agswsCatalogURL = agswsCatalogURL; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -