try {
String contextRoot = context.getContextPath();
MapDesc mapDesc = mapService.getMapDesc();
MapServiceDesc mapServiceDesc = mapService.getMapServiceDesc();
String mapName = mapDesc.getName();
String serviceName = mapService.getServiceName();
StringBuilder sb = new StringBuilder();
sb.append("<b>Layers: </b>");
sb.append("<ul>");
int layerCount = mapDesc.getLayerInfos().size();
for (int i = 0; i < layerCount; i++) {
LayerInfo layerInfo = mapDesc.getLayerInfo(i);
sb.append("<li><a href='" + contextRoot
+ "/rest/service/MapService/" + serviceName + "/" + i
+ "'>" + layerInfo.getName() + "</a>(" + i + ")</li>");
sb.append(layerInfo.isVisible() ? "[visible]" : "");
sb.append(layerInfo.isEditable() ? "[editable]" : "");
}
sb.append("</ul>");
sb.append("<b>SpatialReference: </b>");
sb.append(mapDesc.getWkid());
sb.append("<br/><br/>");
Envelope initialExtent = mapDesc.getInitialExtent();
sb.append("<b>Initial Extent: </b>");
sb.append("<br/>xmin: " + initialExtent.getMinX());
sb.append("<br/>xmax: " + initialExtent.getMaxX());
sb.append("<br/>ymin: " + initialExtent.getMinY());
sb.append("<br/>ymax: " + initialExtent.getMaxY());
sb.append("<br/><br/>");
ReferencedEnvelope fullExtent = null;
CoordinateReferenceSystem crs = null;
MapServiceInstance instance = (MapServiceInstance) mapService
.getMapServicePool().checkoutIdleInstance();
try {
fullExtent = instance.getFullExtent();
crs = instance.getMap().getMapContext()
.getCoordinateReferenceSystem();
} finally {
mapService.getMapServicePool().checkinIdelInstance(instance);
}
double xminFull = fullExtent.getMinX();
double xmaxFull = fullExtent.getMaxX();
double yminFull = fullExtent.getMinY();
double ymaxFull = fullExtent.getMaxY();
sb.append("<b>Full Extent: </b>");
sb.append("<br/>xmin: " + xminFull);
sb.append("<br/>xmax: " + xmaxFull);
sb.append("<br/>ymin: " + yminFull);
sb.append("<br/>ymax: " + ymaxFull);
sb.append("<br/><br/>");
sb.append("<b>Units: </b>");
sb.append(EsriUnitsUtil.getUnits(crs));
sb.append("<br/><br/>");
if (mapServiceDesc.isUseTile()) {
TileInfo tileInfo = mapServiceDesc.getTileInfo();
int width = tileInfo.getWidth();
int height = tileInfo.getHeight();
double originX = tileInfo.getOriginX();
double originY = tileInfo.getOriginY();
sb.append("<b>Tile Info: </b>");
sb.append("<ul>");
sb.append("<li><b>Width: </b>" + width + "</li>");
sb.append("<li><b>Height: </b>" + height + "</li>");
sb.append("<li><b>Format: </b>" + tileInfo.getFormat()
+ "</li>");
sb.append("<li><b>OriginX: </b>" + originX + "</li>");
sb.append("<li><b>OriginY: </b>" + originY + "</li>");
ArrayList<TileLodInfo> tileLodDescs = tileInfo
.getTileLodInfos();
int lodCount = tileLodDescs.size();
sb.append("<li><b>Levels: </b> (" + lodCount + ")</li>");
sb.append("<ul>");
for (int i = 0; i < lodCount; i++) {
TileLodInfo tileLodInfo = tileLodDescs.get(i);
int level = tileLodInfo.getLevel();
double resolution = tileLodInfo.getResolution();
int startRow = (int) ((originY - ymaxFull) / height / resolution);
int startCol = (int) ((xminFull - originX) / width / resolution);
int endRow = (int) ((originY - yminFull) / height / resolution);
int endCol = (int) ((xmaxFull - originX) / width / resolution);
sb.append("<li><b>Level: </b>" + level);
sb.append(" [ ");
sb.append("<a href='" + contextRoot
+ "/rest/service/MapService/" + serviceName
+ "/tile/" + level + "/" + startRow + "/"
+ startCol + "'>Start Tile</a>");
sb.append(" , ");
sb.append("<a href='" + contextRoot
+ "/rest/service/MapService/" + serviceName
+ "/tile/" + level + "/" + endRow + "/" + endCol
+ "'>End Tile</a>");
sb.append(" ]");
sb.append("<ul>");
sb.append("Resolution: " + resolution + "<br/>");
sb.append("Scale: " + tileLodInfo.getScale());
sb.append("</ul>");
sb.append("</li>");
}
sb.append("</ul>");
sb.append("</ul>");
sb.append("<br/><br/>");
}
sb.append("<b>Supported Image Formats: </b>");
sb.append("PNG/JPG/GIF/BMP");
sb.append("<br/><br/>");
sb.append("<hr/>");
sb.append("<b>Supported Operations: </b>");
if (mapServiceDesc.isNeedToken()) {
sb.append("<img src='" + contextRoot + "/image/lock.png'>");
}
sb.append(" <a href='" + contextRoot
+ "/rest/service/MapService/" + serviceName
+ "/export'>Export</a>");