예제 #1
0
    /**
     * Creates a new instance of FMapWMSStyle
     *
     * @param name
     * @param title
     * @param styleAbstract
     * @param parent
     */
    public FMapWMSStyle(WMSStyle style, WMSLayerNode parent) {

      this.name = style.getName();
      this.title = style.getTitle();
      this.styleAbstract = style.getAbstract();
      this.legendWidth = style.getLegendURLWidth();
      this.legendHeight = style.getLegendURLHeight();
      this.format = style.getLegendURLFormat();
      this.href = style.getLegendURLOnlineResourceHRef();
      this.type = style.getLegendURLOnlineResourceType();
      this.parent = parent;
    }
 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;
 }