📄 resourceadder.java
字号:
public GISResource addWMSSource(String wmsInfo,
boolean transparent,
boolean projectMap,
boolean zoomMap) {
WMSMapResource resource = null;
FacesContext fc = null;
String[] wmsArray = null;
ValueBinding vb = null;
WebSpatialReference webSpatialRef = null;
if (!isWebContextInit()) {
throw new IllegalStateException("Before invoking this method, a web context must be set");
}
try {
wmsArray = wmsInfo.split("\\*");
fc = FacesContext.getCurrentInstance();
vb = fc.getApplication().createValueBinding("#{wms}");
resource = (WMSMapResource) vb.getValue(fc);
resource.setWmsURL(wmsArray[0]);
if (wmsArray.length > 1) {
resource.setAlias(wmsArray[1]);
} else {
IWMSClient wmsClient = new WMSClient(wmsArray[0]);
resource.setAlias(wmsClient.getTitle());
}
_webContext.addResource("wmsJITK" + java.util.UUID.randomUUID().toString(), resource, 0);
// ADF issue. Only can get the MapServerPort after adding the resource to webcontext
Iterator<com.esri.wms.client.SpatialReference> it = resource.getWmsMap().getSpatialReferences().iterator();
if (it.hasNext()) {
int id = it.next().toEPSG();
if (id > 0) {
webSpatialRef = WebSpatialReference.getWebSpatialReference(id);
if (_webContext.getSpatialReference() == null) {
projectMap = true;
}
if ((webSpatialRef != null) & projectMap) {
_webContext.setSpatialReference(webSpatialRef);
}
}
}
if (transparent) {
resource.getWmsMap().setTransparent(transparent);
}
return resource;
} catch (Exception ex) {
_logger.warn("Unable to add WMS source", ex);
if (resource != null) {
_webContext.removeResource(resource);
}
return null;
}
}
public GISResource addWFSSource(String url, String title, boolean projectMap, boolean zoomMap) {
if (!isWebContextInit()) {
throw new IllegalStateException("Before invoking this method, a web context must be set");
}
WFSMapResource resource = null;
try {
FacesContext fc = FacesContext.getCurrentInstance();
ValueBinding vb = fc.getApplication().createValueBinding("#{wfs}");
resource = (WFSMapResource) vb.getValue(fc);
resource.setAlias(title);
resource.setEndPointURL(url);
_webContext.addResource("wfsJITK" + UUID.randomUUID().toString(), resource, 0);
if (projectMap) {
//TODO: Get default WFS spatial reference and if different than
// the maps, reproject.
}
if (zoomMap) {
//TODO: Once a map functionality is implemented for WFS action can
// be taken here. For now, only query is supported. Do nothing.
}
}
catch (Exception ex) {
_logger.error("Unable to add WFS resource to map", ex);
if (resource != null) {
_webContext.removeResource(resource);
}
}
return resource;
}
public GISResource addWCSSource(String wcsParam,
boolean transparent,
boolean projectMap,
boolean zoomMap) {
WCSMapResource resource = null;
String coverageName = null;
String wcsURL = null;
String title = null;
String[] wcsArray = null;
String wcsInfo = null;
String[] params = null;
WCSCapabilities wcsCapabilities = null;
ValueBinding vb = null;
//WebMap mmap = null;
WebSpatialReference spatialReference = null;
if (!isWebContextInit()) {
throw new IllegalStateException("Before invoking this method, a web context must be set");
}
FacesContext fc = FacesContext.getCurrentInstance();
try {
wcsArray = wcsParam.split("\\*");
if (wcsArray.length > 1) {
wcsInfo = wcsArray[0];
params = wcsInfo.split("&");
wcsURL = params[0];
int pos = params[1].indexOf("=");
if (pos >= 0) {
coverageName = params[1].substring(pos + 1, params[1].length());
}
title = wcsArray[1];
} else {
wcsURL = wcsParam;
wcsCapabilities = new WCSHTTPClientBase().getCapabilities(wcsURL);
title = wcsCapabilities.getName();
Object[] coverages = wcsCapabilities.getCoverageInfos().keySet().toArray();
if(coverages != null && coverages.length == 1) {
coverageName = (String) coverages[0];
} else {
fc.getExternalContext().getSessionMap().put("toggleAddDataTaskWindow", "true");
}
}
if(chkStr(coverageName, null) == null) {
return null;
}
vb = fc.getApplication().createValueBinding("#{wcs}");
resource = (WCSMapResource) vb.getValue(fc);
resource.setCoverage(coverageName);
resource.setAlias(title);
resource.setEndPointURL(wcsURL);
_webContext.addResource("wcsJITK" + java.util.UUID.randomUUID().toString(), resource, 0);
spatialReference = resource.getDefaultSpatialReference();
if (_webContext.getSpatialReference() == null) {
projectMap = true;
}
if ((spatialReference != null) && projectMap) {
_webContext.setSpatialReference(spatialReference);
}
if(transparent) {
//wcs doesn't support background transparency
}
wcsURL = "";
return resource;
} catch (Exception ex) {
_logger.warn("Unable to add WCS source", ex);
if (resource != null) {
_webContext.removeResource(resource);
}
return null;
}
}
public GISResource addAIMSSource( String aimsHost,
String aimsPort,
String aimsUsername,
String aimsPassword,
String aimsService,
boolean transparent,
boolean projectMap,
boolean zoomMap) {
AIMSMapResource resource = null;
FacesContext fc = null;
ValueBinding vb = null;
WebMap mmap = null;
AIMSMapFunctionality mapFunc = null;
WebSpatialReference webSpatialRef = null;
if (!isWebContextInit()) {
throw new IllegalStateException("Before invoking this method, a web context must be set");
}
try {
fc = FacesContext.getCurrentInstance();
vb = fc.getApplication().createValueBinding("#{aims}");
resource = (AIMSMapResource) vb.getValue(fc);
if (resource == null) {
_logger.warn("No aims resource found - returning null");
return null;
}
resource.setHostName(aimsHost);
resource.setServiceName(aimsService);
if(chkStr(aimsPort, null) != null) {
resource.setPort(Integer.parseInt(aimsPort));
}
if(chkStr(aimsUsername, null) != null) {
resource.setUserName(aimsUsername);
}
if(chkStr(aimsPassword, null) != null) {
resource.setPassword(aimsPassword);
}
resource.setAlias(aimsService);
mmap = _webContext.getWebMap();
//WebExtent initExtent = mmap.getInitExtent();
mmap.setInitExtent(mmap.getCurrentExtent());
_webContext.addResource("aimsJITK" + java.util.UUID.randomUUID().toString(), resource, 0);
// ADF issue. Only can get the AIMSMapFunctionality after adding the resource to webcontext
mapFunc = (AIMSMapFunctionality) resource.getFunctionalities().get("map");
int id = 0;
if (mapFunc.getMap().getFeatureCoordSys() != null) {
id = (int) mapFunc.getMap().getFeatureCoordSys().getID();
}
if (id > 0) {
webSpatialRef = WebSpatialReference.getWebSpatialReference(id);
if (_webContext.getSpatialReference() == null) {
projectMap = true;
}
if ((webSpatialRef != null) && projectMap) {
_webContext.setSpatialReference(webSpatialRef);
}
}
if (transparent) {
mapFunc.getMap().setTransColor("255,255,254");
mapFunc.getMap().setBackground("255,255,254");
}
aimsService = "";
return resource;
} catch (Exception ex) {
_logger.warn("Unable to add AIMS source", ex);
if (resource != null) {
_webContext.removeResource(resource);
}
return null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -