Added logic to show a testing popup on click on feature

This commit is contained in:
francesco 2020-10-30 12:19:51 +01:00
parent 86353ede48
commit ad701729ee
4 changed files with 49 additions and 7 deletions

View File

@ -3,6 +3,7 @@ package org.gcube.portlets.user.geoportaldataviewer.client;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.LayerType;
import org.gcube.portlets.user.geoportaldataviewer.client.events.QueryDataEvent;
@ -20,6 +21,8 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import ol.Coordinate;
@ -54,7 +57,7 @@ public class LayerManager {
eventBus.addHandler(QueryDataEvent.TYPE, new QueryDataEventHandler() {
@Override
public void onQueryInteraction(QueryDataEvent queryEvent) {
public void onQueryInteraction(final QueryDataEvent queryEvent) {
if(queryEvent.getGeoQuery()!=null) {
GeoQuery selectDataInfo = queryEvent.getGeoQuery();
@ -106,6 +109,33 @@ public class LayerManager {
@Override
public void onSuccess(List<GeoNaDataObject> result) {
if(result==null || result.isEmpty())
return;
GWT.log("Data result: "+result);
FlexTable flex = new FlexTable();
flex.setCellPadding(1);
flex.setCellSpacing(1);
flex.getElement().addClassName("popup-table");
for (GeoNaDataObject geoNaDataObject : result) {
Map<String, List<String>> entries = geoNaDataObject.getDataEntryFields();
for (String key : entries.keySet()) {
if(key.equalsIgnoreCase("nome")) {
flex.setHTML(0, 0, new HTML(entries.get(key).get(0)).toString());
}
else if(key.equalsIgnoreCase("descrizione")) {
flex.setText(1, 0, entries.get(key).get(0));
}else if(key.equalsIgnoreCase("date_scavo")) {
flex.setHTML(2, 0, new HTML("<code>"+entries.get(key).get(0)).toString()+"</code>");
}
}
break; //Only the first one
}
olMap.showPopup(flex.toString(), queryEvent.getoLCoordinate());
}
});
}

View File

@ -171,8 +171,6 @@ public class OpenLayerOSM {
eventBus.fireEvent(new QueryDataEvent(select,coordinate));
}
}
});

View File

@ -65,10 +65,11 @@ public class FeatureParser {
GeoNaDataObject gdo = new GeoNaDataObject();
gdo.setLayerItem(layerItem);
for (FeatureRow featureRow : rows) {
gdo.setDataEntryFields(featureRow.getMapProperties());
}
listGeonaDO.add(gdo);
}
return null;
return listGeonaDO;
}
@ -117,14 +118,22 @@ public class FeatureParser {
return listFeaturesRow;
}
JSONObject crs = json.getJSONObject("crs");
JSONObject crsProp = crs.getJSONObject("properties");
String featureCRSName = "";
try {
JSONObject crs = json.getJSONObject("crs");
JSONObject crsProp = crs.getJSONObject("properties");
featureCRSName = crsProp.getString("name");
LOG.info("Crs name found: "+featureCRSName);
}catch (Exception e) {
LOG.warn("Unable to read the field 'crs'");
}
LOG.info("Features are: "+features.length());
for (int i=0; i<features.length(); i++) {
final FeatureRow row = new FeatureRow();
row.setCrsName(featureCRSName);
JSONObject theFeature = ((JSONObject)features.get(i));
LOG.debug("Building at index: "+i);

View File

@ -37,6 +37,7 @@
width: 0;
position: absolute;
pointer-events: none;
visibility: visible;
}
.ol-popup:after {
@ -62,4 +63,8 @@
.ol-popup-closer:after {
content: "✖";
}
.popup-table div:first-child {
font-weight: bold;
}