📄 wcsmapfunctionality.java
字号:
package com.esri.solutions.jitk.web.wcs.data;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import com.esri.adf.web.data.GISResource;
import com.esri.adf.web.data.MapFunctionality;
import com.esri.adf.web.data.TocNode;
import com.esri.adf.web.data.WebMap;
import com.esri.adf.web.data.export.ExportFunctionality;
import com.esri.adf.web.data.export.ExportProperties;
import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.data.geometry.WebPath;
import com.esri.adf.web.data.geometry.WebPoint;
import com.esri.adf.web.data.geometry.WebPolyline;
import com.esri.adf.web.util.MeasureUtil;
import com.esri.solutions.jitk.datasources.ogc.wcs.IWCSClient;
import com.esri.solutions.jitk.datasources.ogc.wcs.WCSClientFactory;
import com.esri.solutions.jitk.datasources.ogc.wcs.info.WCSCapabilities;
public class WCSMapFunctionality implements MapFunctionality, ExportFunctionality {
private static final Logger logger = LogManager.getLogger(WCSMapFunctionality.class);
private WCSMapResource resource = null;
private WebExtent extent = null;
private boolean disabled = false;
private double transparency = 1;
private boolean isVisible(String resourceName, Object[] webTocList) {
for(int i=0; i < webTocList.length; i++) {
if(((TocNode)webTocList[i]).getContent().getText().equalsIgnoreCase(resourceName)) {
if(!((TocNode)webTocList[i]).getContent().isChecked()) {
return false;
}
Object[] coverageList = ((TocNode)webTocList[i]).getChildren().toArray();
for(int j=0; j < coverageList.length; j++) {
if(!((TocNode)coverageList[j]).getContent().isChecked()) {
return false;
}
}
}
}
return true;
}
private String getBbox() {
StringBuffer sb = new StringBuffer();
sb.append(this.extent.getMinX() + ",");
sb.append(this.extent.getMinY() + ",");
sb.append(this.extent.getMaxX() + ",");
sb.append(this.extent.getMaxY());
if(this.resource.getDimension() == 3) {
sb.append(",0,0");
}
return sb.toString();
}
/**
* The initialization chores for the functionality must be performed in this method.
*/
public void initFunctionality(GISResource resource) {
this.resource = (WCSMapResource)resource;
this.extent = this.resource.getDefaultWebExtent();
}
/**
* Returns the GISResource associated with this functionality.
*/
public GISResource getResource() {
return resource;
}
/**
* The cleanup chores for the functionality must be performed in this method.
*/
public void destroyFunctionality() {}
/**
* Exports this map for the current extent.
*/
public InputStream exportImage() {
try {
if(isVisible(this.resource.getAlias(), this.resource.getWebContext().getWebToc().getRootNodes().toArray())) {
WebMap webMap = this.resource.getWebContext().getWebMap();
WCSCapabilities wcsCapabilities = this.resource.getWCSCapabilities();
IWCSClient wcsClient = WCSClientFactory.getInstance(wcsCapabilities.getVersion());
InputStream wcsIS = wcsClient.getCoverage( wcsCapabilities.getGetCoverageURL(), this.resource.getCoverage(),
this.resource.getEpsgId(), getBbox(),
webMap.getHeight(), webMap.getWidth(), this.resource.getFormat());
if(wcsIS != null) {
return ImageFormatConverter.toRGBStream(wcsIS, transparency, this.resource.getFormat());
} else {
return ImageFormatConverter.toRGBStream(this.resource.getNoMapImageStream(), transparency, this.resource.getFormat());
}
}
} catch(Exception e) {
logger.error("Unable to export image.", e);
}
return null;
}
/**
* Returns the current extent of this map.
*/
public WebExtent getCurrentExtent() {
return this.extent;
}
/**
* Returns the full extent of this map.
*/
public WebExtent getFullExtent() {
return this.resource.getDefaultWebExtent();
}
/**
* Returns the initial extent of this map.
*/
public WebExtent getInitialExtent() {
return this.resource.getDefaultWebExtent();
}
/**
* Returns the current scale of this map.
*/
public double getMapScale() {
// map scale calculation based on
// http://support.esri.com/index.cfm?fa=knowledgebase.techarticles.articleShow&d=23278
WebMap webMap = this.resource.getWebContext().getWebMap();
double dp = webMap.getDpi() * 39.3701;
List<WebPoint> webPoints = new ArrayList<WebPoint>();
WebExtent extent = getCurrentExtent();
webPoints.add(new WebPoint(extent.getMinX(), extent.getMinY()));
webPoints.add(new WebPoint(extent.getMaxX(), extent.getMinY()));
List<WebPath> webPaths = new ArrayList<WebPath>();
webPaths.add(new WebPath(webPoints));
WebPolyline webPolyline = new WebPolyline(webPaths);
double mapWidth = MeasureUtil.getDistance(webPolyline, this.resource.getWebContext().getSpatialReference());
double msf = mapWidth / webMap.getWidth();
return msf * dp;
}
/**
* Returns the transparency factor for this map functionality.
*/
public double getTransparency() {
return this.transparency;
}
/**
* Returns true if this map functionality is disabled.
*/
public boolean isDisabled() {
return this.disabled;
}
/**
* Set the current extent of this map.
*/
public void setCurrentExtent(WebExtent newMapExtent) {
this.extent = newMapExtent;
}
/**
* If true, this map functionality is disabled.
*/
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}
/**
* Sets the transparency factor for this map functionality.
*/
public void setTransparency(double transparency) {
this.transparency = transparency;
}
public InputStream export(ExportProperties props) {
try {
WCSCapabilities wcsCapabilities = this.resource.getWCSCapabilities();
IWCSClient wcsClient = WCSClientFactory.getInstance(wcsCapabilities.getVersion());
InputStream wcsIS = wcsClient.getCoverage( wcsCapabilities.getGetCoverageURL(), this.resource.getCoverage(),
this.resource.getEpsgId(), getBbox(),
props.getHeight(), props.getWidth(), this.resource.getFormat());
if(wcsIS != null) {
return ImageFormatConverter.toRGBStream(wcsIS, transparency, this.resource.getFormat());
} else {
return ImageFormatConverter.toRGBStream(this.resource.getNoMapImageStream(), transparency, this.resource.getFormat());
}
} catch(Exception e) {
logger.error("Unable to export image.", e);
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -