// see if we can merge this layer with the previous one
boolean merged = false;
if (mapContext.getLayerCount() > 0) {
MapLayer lastLayer = mapContext.getLayer(mapContext.getLayerCount() - 1);
if (lastLayer instanceof WMSMapLayer) {
WMSMapLayer lastWMS = (WMSMapLayer) lastLayer;
WebMapServer otherWMS = lastWMS.getWebMapServer();
if (otherWMS.equals(wms)) {
lastWMS.addLayer(gt2Layer);
merged = true;
}
}
}
if (!merged) {
WMSMapLayer mapLayer = new WMSMapLayer(wms, gt2Layer);
mapLayer.setTitle(wmsLayer.getPrefixedName());
mapContext.addLayer(mapLayer);
}
} else {
throw new IllegalArgumentException("Unkown layer type " + layerType);
}