Updated code to show legend also of ncWMS

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/gis-viewer@121791 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-12-11 14:20:38 +00:00
parent 9dd81e8683
commit 2275ff77da
3 changed files with 42 additions and 26 deletions

View File

@ -22,6 +22,7 @@ import org.gcube.portlets.user.gisviewer.client.commons.utils.ClickDataInfo;
import org.gcube.portlets.user.gisviewer.client.commons.utils.NewBrowserWindow;
import org.gcube.portlets.user.gisviewer.client.commons.utils.URLMakers;
import org.gcube.portlets.user.gisviewer.client.commons.utils.UriParamUtil;
import org.gcube.portlets.user.gisviewer.client.commons.utils.WmsParameters;
import org.gcube.portlets.user.gisviewer.client.commons.utils.WmsUrlValidator;
import org.gcube.portlets.user.gisviewer.client.datafeature.DataPanelHandler;
import org.gcube.portlets.user.gisviewer.client.datafeature.DataResultPanel;
@ -1120,7 +1121,7 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
//TODO IMPLEMENT THIS CASE
case RASTER:
l.setHasLegend(false);
// l.setHasLegend(false);
l.setBaseLayer(true);
l.setTrasparent(false);
l.setClickData(false);
@ -1141,6 +1142,13 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
l.setDefaultStyle(styles.get(0));
l.setStyle(styles.get(0));
l.setStyles(styles);
}else{
try{
WmsUrlValidator.getValueOfParameter(WmsParameters.STYLES, serverWmsRequest);
l.setHasLegend(true);
}catch(Exception e){
//
}
}
List<LayerItem> layerItems = new ArrayList<LayerItem>();

View File

@ -216,6 +216,8 @@ public class WmsUrlValidator {
*/
public static String validateValueOfParameter(WmsParameters wmsParam, String valueOfParameter, boolean fillEmptyParameterAsDefaultValue){
try{
String value = getValueOfParameter(wmsParam, valueOfParameter);
if(fillEmptyParameterAsDefaultValue && (value==null || value.isEmpty())){
@ -223,28 +225,34 @@ public class WmsUrlValidator {
value = wmsParam.getValue();
}
return value;
}catch(Exception e){
//silent
return null;
}
}
/**
* Gets the value of parameter.
*
* @param wmsParam the wms param
* @param wmsUrlParameters the url wms parameters
* @param wmsRequestParamaters the url wms parameters
* @return the value of parameter
* @throws Exception sent Exception if wmsParam not exists
*/
public static String getValueOfParameter(WmsParameters wmsParam, String wmsUrlParameters){
public static String getValueOfParameter(WmsParameters wmsParam, String wmsRequestParamaters) throws Exception{
// logger.trace("finding: "+wmsParam +" into "+url);
int index = wmsUrlParameters.toLowerCase().indexOf(wmsParam.getParameter().toLowerCase());
int index = wmsRequestParamaters.toLowerCase().indexOf(wmsParam.getParameter().toLowerCase());
// logger.trace("start index of "+wmsParam+ " is: "+index);
String value = "";
if(index > -1){
int start = index + wmsParam.getParameter().length()+1; //add +1 for char '='
String sub = wmsUrlParameters.substring(start, wmsUrlParameters.length());
String sub = wmsRequestParamaters.substring(start, wmsRequestParamaters.length());
int indexOfSeparator = sub.indexOf("&");
int end = indexOfSeparator!=-1?indexOfSeparator:sub.length();
value = sub.substring(0, end);
}
}else
throw new Exception(wmsParam.getParameter() +" not found");
// logger.trace("return value: "+value);
return value;
}
@ -254,13 +262,13 @@ public class WmsUrlValidator {
* Sets the value of parameter.
*
* @param wmsParam the wms param
* @param wmsUrlParameters the wms url parameters
* @param wmsRequestParameters the wms url parameters
* @param newValue the new value
* @param addIfNotExists add the parameter if not exists
* @return the string
*/
public static String setValueOfParameter(WmsParameters wmsParam, String wmsUrlParameters, String newValue, boolean addIfNotExists){
String toLowerWmsUrlParameters = wmsUrlParameters.toLowerCase();
public static String setValueOfParameter(WmsParameters wmsParam, String wmsRequestParameters, String newValue, boolean addIfNotExists){
String toLowerWmsUrlParameters = wmsRequestParameters.toLowerCase();
String toLowerWmsParam = wmsParam.getParameter().toLowerCase();
int index = toLowerWmsUrlParameters.indexOf(toLowerWmsParam+"="); //+ "=" SECURE TO BE PARAMETER
@ -271,12 +279,12 @@ public class WmsUrlValidator {
// logger.trace("indexOfSeparator index of "+wmsParam+ " is: "+indexOfSeparator);
int indexEndValue = indexOfSeparator!=-1?indexOfSeparator:toLowerWmsUrlParameters.length();
// logger.trace("end: "+indexEndValue);
return wmsUrlParameters.substring(0, indexStartValue) + newValue +wmsUrlParameters.substring(indexEndValue, wmsUrlParameters.length());
return wmsRequestParameters.substring(0, indexStartValue) + newValue +wmsRequestParameters.substring(indexEndValue, wmsRequestParameters.length());
}else if (addIfNotExists){
wmsUrlParameters+="&"+wmsParam.getParameter()+"="+newValue;
wmsRequestParameters+="&"+wmsParam.getParameter()+"="+newValue;
}
// logger.trace("return value: "+value);
return wmsUrlParameters;
return wmsRequestParameters;
}
/**

View File

@ -294,12 +294,12 @@ public class LayerToolsPanel extends VerticalPanel {
btnLegend.setToolTip("Show Legend");
toolbar3.add(btnLegend);
// legend list
if (layerItem.getStyles().size()==1) {
toolbar3.add(new SizedLabel(layerItem.getStyle(), 10, 18));
} else {
String defaultStyle = layerItem.getStyle();
String defaultStyle = layerItem.getStyle()!=null?layerItem.getStyle():"Unknown Style Name";
// legend list
if (layerItem.getStyles().size()==0 || layerItem.getStyles().size()==1) {
toolbar3.add(new SizedLabel(defaultStyle, 10, 18));
} else {
final Button btnStyle = new Button((defaultStyle.length()<11) ? defaultStyle : defaultStyle.substring(0, 11) + "...");
btnStyle.setToolTip("Change the style");
@ -318,8 +318,8 @@ public class LayerToolsPanel extends VerticalPanel {
}
}));
}
btnStyle.setMenu(menuStyle);
btnStyle.setMenu(menuStyle);
toolbar3.add(btnStyle);
}
@ -507,7 +507,7 @@ public class LayerToolsPanel extends VerticalPanel {
// System.out.println("layerItem.getStyle() qui "+layerItem.getStyle());
if (layerItem.getStyle().contentEquals(styleName)) {
if (layerItem.getStyle()!=null && layerItem.getStyle().contentEquals(styleName)) {
this.fieldTransect = fieldTransect;
this.tableTransect = tableTransect;
foundDefaultStyle = true;