public String getWMSLegendUrl(String urlServerWMS, String layerId, String stylesName) { String legendUrl = ""; org.gvsig.remoteclient.wms.WMSStyle layerStyle = null; org.gvsig.remoteclient.wms.WMSStyle layerStyleDefault = null; // Create conexion with server WMS try { WMSClient wms = new WMSClient(urlServerWMS); wms.connect(null); WMSLayer layer = wms.getLayer(layerId); if (layer != null) { List<org.gvsig.remoteclient.wms.WMSStyle> lstStyles = layer.getStyles(); if (StringUtils.isNotEmpty(stylesName)) { List<String> styList = Arrays.asList(stylesName.split(",")); for (org.gvsig.remoteclient.wms.WMSStyle wmsStyle : lstStyles) { // default not if (styList.contains(wmsStyle.getName()) && wmsStyle.getName().toLowerCase() != "default") { layerStyle = wmsStyle; break; } else { if (wmsStyle.getName().toLowerCase() == "default") { layerStyleDefault = wmsStyle; } } } // if layer style isn't defined on parameter, set default style // or the first if (layerStyle == null) { if (layerStyleDefault == null && !lstStyles.isEmpty()) { layerStyle = lstStyles.get(0); } else { layerStyle = layerStyleDefault; } } } else { // if haven't styles, get the first if (!lstStyles.isEmpty()) { layerStyle = lstStyles.get(0); } } if (layerStyle != null) { legendUrl = layerStyle.getLegendURLOnlineResourceHRef(); } } } catch (Exception exc) { // Show exception in log logger.error("Exception on getWMSLegendUrl", exc); } return legendUrl; }
/** * Get the four coordinates that represent the bounding box which includes all the layers * indicated for a WMS Server * * @param urlServer Url of the WMS server to connect and get the data * @param crs CRS of the bounding box * @param layers List of layers to include in the bounding box calculated * @return A list of coordinates that represents the bounding box calculated (minX, minY, maxX, * maxY). null if haven't valid bounding box */ private List<String> getWMSLayersBoundingBox( String urlServer, String crs, TreeSet<String> layers) { List<String> boundingBox = new ArrayList<String>(); double xMax = 0; double xMin = 0; double yMin = 0; double yMax = 0; BoundaryBox bbox = null; try { WMSClient wms = new WMSClient(urlServer); wms.connect(null); if (layers != null) { Iterator<String> iterLayers = layers.iterator(); // get the first element WMSLayer layer = wms.getLayer(iterLayers.next()); if (layer != null) { bbox = layer.getBbox(crs); if (bbox != null) { xMax = bbox.getXmax(); yMax = bbox.getYmax(); xMin = bbox.getXmin(); yMin = bbox.getYmin(); } } while (iterLayers.hasNext()) { layer = wms.getLayer(iterLayers.next()); bbox = layer.getBbox(crs); if (bbox != null) { // if getXmax is greater than xMax if (Double.compare(xMax, bbox.getXmax()) < 0) { xMax = bbox.getXmax(); } // if getYmax is greater than yMax if (Double.compare(yMax, bbox.getYmax()) < 0) { yMax = bbox.getYmax(); } // if getXmin is less than xMin if (Double.compare(xMin, bbox.getXmin()) > 0) { xMin = bbox.getXmin(); } // if getYmin is less than yMin if (Double.compare(yMin, bbox.getYmin()) > 0) { yMin = bbox.getYmin(); } } } if (bbox != null) { boundingBox.add(String.valueOf(xMin)); boundingBox.add(String.valueOf(yMin)); boundingBox.add(String.valueOf(xMax)); boundingBox.add(String.valueOf(yMax)); } } } catch (Exception exc) { // Show exception in log and create ServerGeoException which is // captured on controller and puts message to ajax response logger.error("Exception on getWMSLayersBoundingBox", exc); throw new ServerGeoException(); } return boundingBox; }