📄 agswsclient.java
字号:
package com.esri.solutions.jitk.web.tasks.resources;
import java.io.InputStream;
import java.net.URL;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import com.esri.arcgisws.EsriImageFormat;
import com.esri.arcgisws.EsriImageReturnType;
import com.esri.arcgisws.ImageDescription;
import com.esri.arcgisws.ImageDisplay;
import com.esri.arcgisws.ImageType;
import com.esri.arcgisws.MapDescription;
import com.esri.arcgisws.MapImage;
import com.esri.arcgisws.MapServerBindingStub;
import com.esri.arcgisws.MapServerInfo;
import com.esri.arcgisws.ServiceCatalogBindingStub;
import com.esri.arcgisws.ServiceDescription;
import com.esri.solutions.jitk.datasources.ogc.wms.InputStreamConverter;
public class AGSWSClient {
private static Logger _logger = LogManager.getLogger(AGSWSClient.class.getName());
public AGSWSClient() {
}
public byte[] getAGSWSMap(String urlinfo, int width, int height) {
try {
String[] urlArray = urlinfo.split("\\*");
String url = urlArray[1];
MapServerBindingStub mapSvr = new MapServerBindingStub(new java.net.URL(url), null);
ImageType imageType = new ImageType(EsriImageFormat.esriImagePNG, EsriImageReturnType.esriImageReturnURL);
MapServerInfo mapSvrInfo = mapSvr.getServerInfo(mapSvr.getDefaultMapName());
MapDescription mapDesc = mapSvrInfo.getDefaultMapDescription();
ImageDisplay imageDisp = new ImageDisplay(height, width, 96, mapSvrInfo.getBackgroundColor());
ImageDescription imageDesc = new ImageDescription(imageType, imageDisp);
MapImage mapImage = mapSvr.exportMapImage(mapDesc, imageDesc);
String mapUrl = mapImage.getImageURL();
if (mapUrl == null || mapUrl.equalsIgnoreCase("")) {
return mapImage.getImageData();
}
return loadImage(new URL(mapUrl));
} catch(Exception e) {
_logger.warn("unable to preview ags internet map", e);
return null;
}
}
public String[] getAgsWebURLs(String catalogURL) {
int svcCount = 0;
try {
URL url = new URL(catalogURL);
ServiceCatalogBindingStub servicecatalog = new ServiceCatalogBindingStub(url, null);
ServiceDescription[] sd = servicecatalog.getServiceDescriptions();
for (int i = 0; i < sd.length; i++) {
if (sd[i].getType().equalsIgnoreCase("MapServer")) {
svcCount++;
}
}
String[] agswsServices = new String[svcCount];
int m = 0;
for (int i = 0; i < sd.length; i++) {
if (sd[i].getType().equalsIgnoreCase("MapServer")) {
agswsServices[m] = sd[i].getName() + "*" + sd[i].getUrl();
m++;
}
}
return agswsServices;
} catch (Exception e) {
_logger.warn("Unable to get ags web service", e);
return null;
}
}
private byte[] loadImage(URL url) throws Exception {
InputStream is = url.openStream();
InputStreamConverter isc = new InputStreamConverter();
return isc.toByteArray(is);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -