📄 mappreviewaction.java
字号:
}
// we now have a bounding box in the same CRS as the layer
if ((bbox.getWidth() == 0) || (bbox.getHeight() == 0)) {
bbox.expandBy(0.1);
}
if (layer.isEnabled()) {
// prepare strings for web output
ftList.add(layer.getNameSpace().getPrefix() + "_"
+ layer.getFeatureType().getTypeName()); // FeatureType name
ftnsList.add(layer.getNameSpace().getPrefix() + ":"
+ layer.getFeatureType().getTypeName());
dsList.add(layer.getDataStoreInfo().getId()); // DataStore info
// bounding box of the FeatureType
// expand bbox by 5% to allow large symbolizers to fit the map
bbox.expandBy(bbox.getWidth() / 20, bbox.getHeight() / 20);
bboxList.add(bbox.getMinX() + "," + bbox.getMinY() + "," + bbox.getMaxX() + ","
+ bbox.getMaxY());
srsList.add("EPSG:" + layer.getSRS());
int[] imageBox = getMapWidthHeight(bbox);
widthList.add(String.valueOf(imageBox[0]));
heightList.add(String.valueOf(imageBox[1]));
}
// not a coverage
coverageStatus.add(LAYER_IS_VECTOR);
}
// 3.5) Go through each *Coverage* and collect its info
for (Iterator it = ctypes.iterator(); it.hasNext();) {
CoverageInfo layer = (CoverageInfo) it.next();
// upper right corner? lower left corner? Who knows?! Better naming conventions needed guys.
double[] lowerLeft = layer.getEnvelope().getLowerCorner().getCoordinates();
double[] upperRight = layer.getEnvelope().getUpperCorner().getCoordinates();
Envelope bbox = new Envelope(lowerLeft[0], upperRight[0], lowerLeft[1], upperRight[1]);
if (layer.isEnabled()) {
// prepare strings for web output
String shortLayerName = layer.getName().split(":")[1]; // we don't want the namespace prefix
ftList.add(layer.getNameSpace().getPrefix() + "_" + shortLayerName); // Coverage name
ftnsList.add(layer.getNameSpace().getPrefix() + ":" + shortLayerName);
dsList.add(layer.getFormatInfo().getId()); // DataStore info
// bounding box of the Coverage
bboxList.add(bbox.getMinX() + "," + bbox.getMinY() + "," + bbox.getMaxX() + ","
+ bbox.getMaxY());
srsList.add(layer.getSrsName());
int[] imageBox = getMapWidthHeight(bbox);
widthList.add(String.valueOf(imageBox[0]));
heightList.add(String.valueOf(imageBox[1]));
// this layer is a coverage, all right
coverageStatus.add(LAYER_IS_COVERAGE);
}
}
// 3.6) Go thru base map layers
Locale locale = (Locale) request.getLocale();
MessageResources messages = getResources(request);
String baseMap = messages.getMessage(locale, "label.baseMap");
for (Iterator it = bmtypes.iterator(); it.hasNext();) {
String baseMapTitle = (String) it.next();
ftList.add(baseMapTitle);
ftnsList.add(baseMapTitle);
dsList.add(baseMap);
GeneralEnvelope bmBbox = ((GeneralEnvelope) wms.getBaseMapEnvelopes().get(baseMapTitle));
Envelope bbox = new Envelope(bmBbox.getMinimum(0), bmBbox.getMaximum(0), bmBbox.getMinimum(1), bmBbox.getMaximum(1));
bboxList.add(bbox.getMinX() + "," + bbox.getMinY() + "," + bbox.getMaxX() + ","
+ bbox.getMaxY());
srsList.add(CRS.lookupIdentifier(bmBbox.getCoordinateReferenceSystem(), null, false) );
int[] imageBox = getMapWidthHeight(bbox);
widthList.add(String.valueOf(imageBox[0]));
heightList.add(String.valueOf(imageBox[1]));
// this depends on the composition, we raise the flag if the layer has at least
// one coverage
coverageStatus.add(computeGroupCoverageStatus(wms, baseMapTitle));
}
// 4) send off gathered information to the .jsp
DynaActionForm myForm = (DynaActionForm) form;
myForm.set("DSNameList", dsList.toArray(new String[dsList.size()]));
myForm.set("FTNameList", ftList.toArray(new String[ftList.size()]));
myForm.set("BBoxList", bboxList.toArray(new String[bboxList.size()]));
myForm.set("SRSList", srsList.toArray(new String[srsList.size()]));
myForm.set("WidthList", widthList.toArray(new String[widthList.size()]));
myForm.set("HeightList", heightList.toArray(new String[heightList.size()]));
myForm.set("FTNamespaceList", ftnsList.toArray(new String[ftnsList.size()]));
myForm.set("CoverageStatus", coverageStatus.toArray(new Integer[coverageStatus.size()]));
String proxifiedBaseUrl = RequestUtils.baseURL(request);
GeoServer gs = (GeoServer)GeoServerExtensions.extensions(GeoServer.class).get(0);
proxifiedBaseUrl = RequestUtils.proxifiedBaseURL(proxifiedBaseUrl, gs.getProxyBaseUrl());
myForm.set("BaseUrl", proxifiedBaseUrl );
return mapping.findForward("success");
}
/**
* Computes the coverage status flag for the specified layer
* @param baseMapTitle
* @return
*/
private Integer computeGroupCoverageStatus(WMS wms, String baseMapTitle) {
String layerParam = (String) wms.getBaseMapLayers().get(baseMapTitle);
String[] layers = layerParam.split(",");
int coverageCount = 0;
for (int i = 0; i < layers.length; i++) {
if(wms.getData().getLayerType(layers[i]) == Data.TYPE_RASTER)
coverageCount++;
}
if(coverageCount == 0)
return LAYER_IS_VECTOR;
else if(coverageCount < layers.length)
return LAYER_HAS_COVERAGE;
else
return LAYER_IS_COVERAGE;
}
private int[] getMapWidthHeight(Envelope bbox) {
int width;
int height;
double ratio = bbox.getHeight() / bbox.getWidth();
if (ratio < 1) {
width = 750;
height = (int) Math.round(750 * ratio);
} else {
width = (int) Math.round(550 / ratio);
height = 550;
}
// make sure we reach some minimal dimensions (300 pixels is more or less
// the height of the zoom bar)
if (width < 300) {
width = 300;
}
if (height < 300) {
height = 300;
}
// add 50 pixels horizontally to account for the zoom bar
return new int[] { width + 50, height };
}
private static class FeatureTypeInfoNameComparator implements Comparator {
public int compare(Object o1, Object o2) {
FeatureTypeInfo ft1 = (FeatureTypeInfo) o1;
FeatureTypeInfo ft2 = (FeatureTypeInfo) o2;
String ft1Name = ft1.getNameSpace().getPrefix() + ft1.getName();
String ft2Name = ft2.getNameSpace().getPrefix() + ft2.getName();
return ft1Name.compareTo(ft2Name);
}
}
private static class CoverageInfoNameComparator implements Comparator {
public int compare(Object o1, Object o2) {
CoverageInfo c1 = (CoverageInfo) o1;
CoverageInfo c2 = (CoverageInfo) o2;
String ft1Name = c1.getNameSpace().getPrefix() + c1.getName();
String ft2Name = c2.getNameSpace().getPrefix() + c2.getName();
return ft1Name.compareTo(ft2Name);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -