Searching facility integrated with CQL filter

This commit is contained in:
Francesco Mangiacrapa 2021-12-14 15:26:09 +01:00
parent fb827a6913
commit 342d40fdf9
10 changed files with 263 additions and 38 deletions

View File

@ -3,6 +3,7 @@ package org.gcube.portlets.user.geoportaldataviewer.client;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile;
@ -29,6 +30,8 @@ import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetai
import org.gcube.portlets.user.geoportaldataviewer.client.events.MapExtentToEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.MapExtentToEventHandler;
import org.gcube.portlets.user.geoportaldataviewer.client.events.QueryDataEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.SearchPerformedEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.SearchPerformedEventHandler;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEventHandler;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowPopupOnCentroiEvent;
@ -59,6 +62,7 @@ import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import ol.Coordinate;
import ol.layer.Image;
/**
* Entry point classes define <code>onModuleLoad()</code>.
@ -532,6 +536,41 @@ public class GeoportalDataViewer implements EntryPoint {
}
});
applicationBus.addHandler(SearchPerformedEvent.TYPE, new SearchPerformedEventHandler() {
@Override
public void onSearchDone(SearchPerformedEvent searchPerformedEvent) {
if(searchPerformedEvent!=null) {
LinkedHashMap<String, Image> wmsMap = olMapMng.getOLMap().getWmsLayerMap();
String firstWMSKey = wmsMap.keySet().iterator().next();
List<ConcessioneDV> result = searchPerformedEvent.getData();
if(result!=null && result.size()>0) {
String cqlFilter = "product_id IN(";
for (ConcessioneDV concessioneDV : result) {
cqlFilter+="'"+concessioneDV.getItemId()+"',";
}
cqlFilter = cqlFilter.substring(0,cqlFilter.length()-1)+")";
olMapMng.getOLMap().setCQLFilterToWMSLayer(firstWMSKey, cqlFilter);
}else {
olMapMng.getOLMap().setCQLFilterToWMSLayer(firstWMSKey, null);
}
if(searchPerformedEvent.isSearchReset()) {
olMapMng.getOLMap().setCQLFilterToWMSLayer(firstWMSKey, null);
}
}
}
});
}

View File

@ -0,0 +1,71 @@
package org.gcube.portlets.user.geoportaldataviewer.client.events;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import com.google.gwt.event.shared.GwtEvent;
/**
* The Class SearchPerformedEvent.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Dec 14, 2021
*/
public class SearchPerformedEvent extends GwtEvent<SearchPerformedEventHandler> {
public static Type<SearchPerformedEventHandler> TYPE = new Type<SearchPerformedEventHandler>();
private List<ConcessioneDV> data;
private boolean searchReset;
/**
* Instantiates a new search performed event.
*
* @param data the data
* @param searchReset the search reset
*/
public SearchPerformedEvent(List<ConcessioneDV> data, boolean searchReset) {
this.data = data;
this.searchReset = searchReset;
}
/**
* Gets the associated type.
*
* @return the associated type
*/
@Override
public Type<SearchPerformedEventHandler> getAssociatedType() {
return TYPE;
}
/**
* Dispatch.
*
* @param handler the handler
*/
@Override
protected void dispatch(SearchPerformedEventHandler handler) {
handler.onSearchDone(this);
}
/**
* Gets the data.
*
* @return the data
*/
public List<ConcessioneDV> getData() {
return data;
}
/**
* Checks if is search reset.
*
* @return true, if is search reset
*/
public boolean isSearchReset() {
return searchReset;
}
}

View File

@ -0,0 +1,20 @@
package org.gcube.portlets.user.geoportaldataviewer.client.events;
import com.google.gwt.event.shared.EventHandler;
/**
* The Interface SearchPerformedEventHandler.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Dec 14, 2021
*/
public interface SearchPerformedEventHandler extends EventHandler {
/**
* On search done.
*
* @param searchPerformedEvent the search performed event
*/
void onSearchDone(SearchPerformedEvent searchPerformedEvent);
}

View File

@ -395,9 +395,11 @@ public abstract class OpenLayerMap {
if (layer == null) {
ImageWmsParams imageWMSParams = OLFactory.createOptions();
imageWMSParams.setLayers(layerItem.getName());
//imageWMSParams.set("CQL_FILTER", "product_id IN('6165b07202ad3d60e1d26f42','6166ff8002ad3d60e1d26fb7')");
ImageWmsOptions imageWMSOptions = OLFactory.createOptions();
imageWMSOptions.setUrl(layerItem.getMapServerHost());
imageWMSOptions.setParams(imageWMSParams);
// imageWMSOptions.setRatio(1.5f);
@ -405,6 +407,7 @@ public abstract class OpenLayerMap {
LayerOptions layerOptions = OLFactory.createOptions();
layerOptions.setSource(imageWMSSource);
// Settings MIN and MAX Resolution
if (layerItem.getMinResolution() != null) {
layerOptions.setMinResolution(layerItem.getMinResolution());
@ -414,6 +417,7 @@ public abstract class OpenLayerMap {
}
Image wmsLayer = new Image(layerOptions);
int zIndex = layerOrder.getOffset(LayerOrder.LAYER_TYPE.BASE_WMS)+wmsLayerMap.size()+1;
wmsLayer.setZIndex(zIndex);
// visibleLayerItems
@ -428,6 +432,33 @@ public abstract class OpenLayerMap {
}
}
public void setCQLFilterToWMSLayer(String key, String cqlFilterExpression) {
GWT.log("Getting key: "+key);
GWT.log("Setting CQL FILTER: "+cqlFilterExpression);
Image wmsLayer = wmsLayerMap.get(key);
GWT.log("WMS layer is: "+wmsLayer);
//map.removeLayer(wmsLayer);
ImageWms imageWMSSource = wmsLayer.getSource();
ImageWmsParams imageWMSParams = imageWMSSource.getParams();
if (cqlFilterExpression == null) {
imageWMSParams.delete("CQL_FILTER");
} else {
imageWMSParams.set("CQL_FILTER", cqlFilterExpression);
}
imageWMSSource.updateParams(imageWMSParams);
wmsLayer.setSource(imageWMSSource);
//map.addLayer(wmsLayer);
}
/**
* Adds the WMS detail layer.

View File

@ -11,7 +11,6 @@ import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerCon
import org.gcube.portlets.user.geoportaldataviewer.client.events.ChangeMapLayerEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.MapExtentToEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerMap;
import org.gcube.portlets.user.geoportaldataviewer.client.resources.GNAIcons;
import org.gcube.portlets.user.geoportaldataviewer.client.resources.GNAImages;
import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.ExtentMapUtil;
import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.ExtentMapUtil.Location;
@ -151,11 +150,12 @@ public class GeonaDataViewMainPanel extends Composite {
extentToEarth.getElement().appendChild(worldImg.getElement());
extentToEarth.setWidth("140px");
linkMap.setCustomIconStyle(GNAIcons.CustomIconType.MAP.get());
linkPresetLocation.setCustomIconStyle(GNAIcons.CustomIconType.PRESET_LOCATION.get());
linkLayers.setCustomIconStyle(GNAIcons.CustomIconType.LAYERS.get());
//linkMap.setCustomIconStyle(GNAIcons.CustomIconType.MAP.get());
//linkPresetLocation.setCustomIconStyle(GNAIcons.CustomIconType.PRESET_LOCATION.get());
//linkLayers.setCustomIconStyle(GNAIcons.CustomIconType.LAYERS.get());
searchFacility = new SearchFacilityUI(applicationBus, sortByFields, searchForFields, initialSortFilter);
searchFacility.setSearchButton(searchFacilityButton);
searchFacilityButton.setIcon(IconType.SEARCH);
searchFacilityPanel.add(searchFacility);
Scheduler.get().scheduleDeferred(new ScheduledCommand() {

View File

@ -14,6 +14,7 @@ import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerServiceAsync;
import org.gcube.portlets.user.geoportaldataviewer.client.events.SearchPerformedEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowPopupOnCentroiEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon;
@ -21,6 +22,7 @@ import org.gcube.portlets.user.geoportaldataviewer.client.util.StringUtil;
import com.github.gwtbootstrap.client.ui.Alert;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.DropdownButton;
import com.github.gwtbootstrap.client.ui.ListBox;
import com.github.gwtbootstrap.client.ui.NavLink;
import com.github.gwtbootstrap.client.ui.TextBox;
@ -46,6 +48,14 @@ import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* The Class SearchFacilityUI.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Dec 14, 2021
*/
public class SearchFacilityUI extends Composite {
private static SearchFacilityPanelUiBinder uiBinder = GWT.create(SearchFacilityPanelUiBinder.class);
@ -85,9 +95,26 @@ public class SearchFacilityUI extends Composite {
private ResultSetPaginatedData latestResult;
private DropdownButton searchFacilityButton;
/**
* The Interface SearchFacilityPanelUiBinder.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Dec 14, 2021
*/
interface SearchFacilityPanelUiBinder extends UiBinder<Widget, SearchFacilityUI> {
}
/**
* Instantiates a new search facility UI.
*
* @param appManagerBus the app manager bus
* @param sortByFields the sort by fields
* @param searchForFields the search for fields
* @param initialSortFilter the initial sort filter
*/
public SearchFacilityUI(HandlerManager appManagerBus, List<ItemField> sortByFields, List<ItemField> searchForFields,
SearchingFilter initialSortFilter) {
initWidget(uiBinder.createAndBindUi(this));
@ -98,12 +125,19 @@ public class SearchFacilityUI extends Composite {
resetSearch.setType(ButtonType.LINK);
listBoxSortBy.setWidth("130px");
listBoxSearchFor.setWidth("130px");
listBoxSortBy.setWidth("180px");
listBoxSearchFor.setWidth("140px");
bindEvents();
}
/**
* To label filter.
*
* @param itemField the item field
* @param direction the direction
* @return the string
*/
private String toLabelFilter(ItemField itemField, ORDER direction) {
String labelFilter = itemField.getDisplayName() + LABEL_FILTER_SEPARATOR + direction.name();
return labelFilter;
@ -163,20 +197,6 @@ public class SearchFacilityUI extends Composite {
}
});
// navShowOnMap.addClickHandler(new ClickHandler() {
//
// @Override
// public void onClick(ClickEvent event) {
// List<ConcessioneDV> listConcessioni = null;
// if (grpw != null && grpw.getSelectItems() != null) {
// listConcessioni = grpw.getSelectItems();
// }
// appManagerBus
// .fireEvent(new ActionOnItemEvent<ConcessioneDV>(listConcessioni, ACTION_ON_ITEM.VIEW_ON_MAP));
//
// }
// });
searchField.addKeyPressHandler(new KeyPressHandler() {
@Override
@ -194,15 +214,28 @@ public class SearchFacilityUI extends Composite {
@Override
public void onClick(ClickEvent event) {
searchField.setText("");
//appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter()));
resetSearch.setVisible(false);
panelResults.clear();
latestResult = null;
appManagerBus.fireEvent(new SearchPerformedEvent(null,true));
setSearchEnabled(false);
}
});
}
private void setSearchEnabled(boolean bool) {
if(bool) {
searchFacilityButton.getElement().addClassName("highlight-button");
}
else {
searchFacilityButton.getElement().removeClassName("highlight-button");
}
}
/**
* Search concessioni.
*/
private void searchConcessioni() {
SearchingFilter filter = getCurrentSortFilter();
@ -229,6 +262,8 @@ public class SearchFacilityUI extends Composite {
@Override
public void onSuccess(ResultSetPaginatedData result) {
appManagerBus.fireEvent(new SearchPerformedEvent(result.getData(),false));
setSearchEnabled(true);
latestResult = result;
panelResults.clear();
@ -341,7 +376,7 @@ public class SearchFacilityUI extends Composite {
/**
* To display authors.
*
* @param authors the authors
* @param listValues the list values
* @return the string
*/
private String toDisplayList(List<String> listValues) {
@ -355,6 +390,9 @@ public class SearchFacilityUI extends Composite {
return toDisplay;
}
/**
* Do search event.
*/
private void doSearchEvent() {
String searchText = searchField.getText();
if (searchText.length() < MIN_LENGHT_SERCHING_STRING) {
@ -369,6 +407,12 @@ public class SearchFacilityUI extends Composite {
searchConcessioni();
}
/**
* To sort filter.
*
* @param labelFilter the label filter
* @return the searching filter
*/
public SearchingFilter toSortFilter(String labelFilter) {
GWT.log("toSortFilter for label " + labelFilter);
String[] array = labelFilter.split(LABEL_FILTER_SEPARATOR);
@ -392,6 +436,11 @@ public class SearchFacilityUI extends Composite {
}
/**
* Built searching filter.
*
* @return the searching filter
*/
private SearchingFilter builtSearchingFilter() {
SearchingFilter searchingFilter = toSortFilter(listBoxSortBy.getSelectedValue());
String searchText = searchField.getText();
@ -419,10 +468,20 @@ public class SearchFacilityUI extends Composite {
return searchingFilter;
}
/**
* Gets the current sort filter.
*
* @return the current sort filter
*/
public SearchingFilter getCurrentSortFilter() {
currentSortFilter = builtSearchingFilter();
GWT.log("currentSortFilter: " + currentSortFilter);
return currentSortFilter;
}
public void setSearchButton(DropdownButton searchFacilityButton) {
this.searchFacilityButton = searchFacilityButton;
}
}

View File

@ -67,7 +67,7 @@ public class MapView extends Composite {
@UiField
HorizontalPanel coordinatePanel;
private LightOpenLayerMap lightOLSM;
private LightOpenLayerMap lightOLM;
private HTML attributionDiv = null;
@ -92,14 +92,14 @@ public class MapView extends Composite {
@Override
public void execute() {
lightOLSM = new LightOpenLayerMap(theMapId);
lightOLM = new LightOpenLayerMap(theMapId);
setBaseLayers();
// EPSG_3857 LOCATION TO ITALY
Location italyLocation = ExtentMapUtil.getLocation(PLACE.ITALY);
Coordinate transformedCenterCoordinate = italyLocation.getCoordinate(MAP_PROJECTION.EPSG_3857);
lightOLSM.setCenter(transformedCenterCoordinate);
lightOLSM.setZoom(GeoportalDataViewerConstants.LIGHT_MAP_ITALY_FIT_ZOOM_ON);
lightOLM.setCenter(transformedCenterCoordinate);
lightOLM.setZoom(GeoportalDataViewerConstants.LIGHT_MAP_ITALY_FIT_ZOOM_ON);
}
});
}
@ -127,7 +127,7 @@ public class MapView extends Composite {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
lightOLSM.changeBaseMap(baseMapLayer);
lightOLM.changeBaseMap(baseMapLayer);
setMapAttribution(baseMapLayer);
}
});
@ -193,9 +193,9 @@ public class MapView extends Composite {
@Override
public void execute() {
if (lightOLSM != null) {
lightOLSM.addPoint(coordinate, showCoordinateText, true);
lightOLSM.getMap().getView().setCenter(coordinate);
if (lightOLM != null) {
lightOLM.addPoint(coordinate, showCoordinateText, true);
lightOLM.getMap().getView().setCenter(coordinate);
}
}
});
@ -232,11 +232,11 @@ public class MapView extends Composite {
null);
}
lightOLSM.addWMSLayer(mapServerHost, layerName, theBBOX);
lightOLM.addWMSLayer(mapServerHost, layerName, theBBOX);
if (ew != null) {
lightOLSM.getMap().getView().fit(ew);
lightOLM.getMap().getView().fit(ew);
}
@ -245,8 +245,8 @@ public class MapView extends Composite {
}
public LightOpenLayerMap getLightOLSM() {
return lightOLSM;
public LightOpenLayerMap getLightOLM() {
return lightOLM;
}
}

View File

@ -110,7 +110,7 @@ public class LayerConcessioneView extends Composite {
}
// DOWNLOAD the OSM + layer by canvas
downloadMap(mapView.getLightOLSM().getMap(), mapView.getPanelMapElementId(), htmlLinkId,
downloadMap(mapView.getLightOLM().getMap(), mapView.getPanelMapElementId(), htmlLinkId,
filename, mimeType);
// mapExport(mapView.getLightOLSM().getMap(), mapView.getPanelMapElementId());
}

View File

@ -92,7 +92,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
* @return the geo information for WMS request
* @throws Exception the exception
*/
public static GeoInformationForWMSRequest loadGeoInfoForWmsRequest(String wmsLink, String layerName)
public GeoInformationForWMSRequest loadGeoInfoForWmsRequest(String wmsLink, String layerName)
throws Exception {
try {
WMSUrlValidator validator = new WMSUrlValidator(wmsLink, layerName);

View File

@ -495,7 +495,12 @@ body {
border-bottom: 1px solid #ccc;
}
.table-results td:nth-child(1) {
/*width: 200px;*/
.table-results td:nth-child(1) {
}
.highlight-button {
border: 2px solid #08c;
border-radius: 4px;
box-shadow: 2px 2px #08c;
}