2020-11-19 15:19:27 +01:00
|
|
|
package org.gcube.portlets.user.geoportaldataviewer.client.ui.map;
|
|
|
|
|
2021-08-02 15:20:01 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.gis.BoundsMap;
|
2020-11-19 15:19:27 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
|
2021-09-01 12:51:06 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION;
|
2020-11-19 15:19:27 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.gis.ExtentWrapped;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.gis.LightOpenLayerOSM;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.gis.MapUtils;
|
2021-09-01 12:51:06 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.ExtentMapUtil.Location;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.ExtentMapUtil.PLACE;
|
2020-11-19 15:19:27 +01:00
|
|
|
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
|
|
import com.google.gwt.core.client.Scheduler;
|
|
|
|
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
|
|
|
|
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
|
import com.google.gwt.uibinder.client.UiField;
|
|
|
|
import com.google.gwt.user.client.Random;
|
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
|
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
|
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
|
|
|
import ol.Coordinate;
|
|
|
|
import ol.OLFactory;
|
|
|
|
|
2021-09-02 18:15:15 +02:00
|
|
|
/**
|
|
|
|
* The Class MapView.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
|
|
|
*
|
|
|
|
* Nov 11, 2020
|
|
|
|
*/
|
|
|
|
public class MapView extends Composite {
|
2020-11-19 15:19:27 +01:00
|
|
|
|
|
|
|
private static MapViewUiBinder uiBinder = GWT.create(MapViewUiBinder.class);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Interface MapViewUiBinder.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
|
|
|
*
|
2021-09-02 18:15:15 +02:00
|
|
|
* Nov 11, 2020
|
2020-11-19 15:19:27 +01:00
|
|
|
*/
|
|
|
|
interface MapViewUiBinder extends UiBinder<Widget, MapView> {
|
|
|
|
}
|
2021-09-02 18:15:15 +02:00
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
@UiField
|
|
|
|
HTMLPanel theMap;
|
2021-09-02 18:15:15 +02:00
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
@UiField
|
|
|
|
HorizontalPanel coordinatePanel;
|
2021-09-02 18:15:15 +02:00
|
|
|
|
|
|
|
private LightOpenLayerOSM lightOLSM;
|
|
|
|
|
2021-09-03 18:22:42 +02:00
|
|
|
private String theMapId = null;
|
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
/**
|
|
|
|
* Instantiates a new map view.
|
2020-11-24 11:26:05 +01:00
|
|
|
*
|
|
|
|
* @param centerTo the center to
|
2021-09-02 18:15:15 +02:00
|
|
|
* @param zoom the zoom
|
2020-11-19 15:19:27 +01:00
|
|
|
*/
|
2021-01-15 15:12:03 +01:00
|
|
|
public MapView(Coordinate centerTo, int zoom, String internalMapWidth, String internalMapHeight) {
|
2020-11-19 15:19:27 +01:00
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
2021-09-03 18:22:42 +02:00
|
|
|
theMapId = "map" + Random.nextInt();
|
2020-11-19 15:19:27 +01:00
|
|
|
theMap.getElement().setId(theMapId);
|
2021-01-15 15:12:03 +01:00
|
|
|
theMap.setWidth(internalMapWidth);
|
|
|
|
theMap.setHeight(internalMapHeight);
|
2021-09-02 18:15:15 +02:00
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void execute() {
|
2021-09-02 18:15:15 +02:00
|
|
|
lightOLSM = new LightOpenLayerOSM(theMapId);
|
|
|
|
|
|
|
|
// EPSG_3857 LOCATION TO ITALY
|
2021-09-01 12:51:06 +02:00
|
|
|
Location italyLocation = ExtentMapUtil.getLocation(PLACE.ITALY);
|
|
|
|
Coordinate transformedCenterCoordinate = italyLocation.getCoordinate(MAP_PROJECTION.EPSG_3857);
|
2021-09-02 18:15:15 +02:00
|
|
|
lightOLSM.setCenter(transformedCenterCoordinate);
|
|
|
|
lightOLSM.setZoom(GeoportalDataViewerConstants.LIGHT_MAP_ITALY_FIT_ZOOM_ON);
|
2020-11-24 11:26:05 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-09-02 18:15:15 +02:00
|
|
|
|
2020-11-24 11:26:05 +01:00
|
|
|
private void setMapSize() {
|
|
|
|
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void execute() {
|
|
|
|
int width = theMap.getParent().getOffsetWidth();
|
|
|
|
int height = theMap.getParent().getOffsetHeight();
|
2021-09-02 18:15:15 +02:00
|
|
|
if (width == 0)
|
2020-11-24 11:26:05 +01:00
|
|
|
width = 300;
|
2021-09-02 18:15:15 +02:00
|
|
|
|
|
|
|
if (height == 0)
|
2020-11-24 11:26:05 +01:00
|
|
|
height = 300;
|
2021-09-02 18:15:15 +02:00
|
|
|
|
|
|
|
GWT.log("Internal Map w: " + width + ", h: " + height);
|
|
|
|
theMap.setSize(width + "px", height + "px");
|
2020-11-19 15:19:27 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-09-02 18:15:15 +02:00
|
|
|
|
2021-09-03 18:22:42 +02:00
|
|
|
public String getPanelMapElementId() {
|
|
|
|
return theMapId;
|
|
|
|
}
|
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
/**
|
|
|
|
* Adds the marker.
|
|
|
|
*
|
2021-09-02 18:15:15 +02:00
|
|
|
* @param coordinate the coordinate
|
2020-11-19 15:19:27 +01:00
|
|
|
* @param showCoordinateText the show coordinate text
|
|
|
|
*/
|
2021-09-02 18:15:15 +02:00
|
|
|
public void addMarker(Coordinate coordinate, boolean showCoordinateText) {
|
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void execute() {
|
2021-09-02 18:15:15 +02:00
|
|
|
if (lightOLSM != null) {
|
|
|
|
lightOLSM.addPoint(coordinate, showCoordinateText, true);
|
|
|
|
lightOLSM.getMap().getView().setCenter(coordinate);
|
2020-11-19 15:19:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-09-02 18:15:15 +02:00
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
/**
|
|
|
|
* Adds the WMS layer.
|
|
|
|
*
|
|
|
|
* @param mapServerHost the map server host
|
|
|
|
* @param layerName the layer name
|
|
|
|
* @param bbox the bbox
|
|
|
|
*/
|
|
|
|
public void addWMSLayer(String mapServerHost, String layerName, BoundsMap bbox) {
|
|
|
|
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void execute() {
|
2021-09-02 18:15:15 +02:00
|
|
|
|
2020-12-09 14:28:32 +01:00
|
|
|
ExtentWrapped ew = null;
|
|
|
|
BoundsMap theBBOX = bbox;
|
2021-09-02 18:15:15 +02:00
|
|
|
|
2020-12-09 14:28:32 +01:00
|
|
|
if (bbox != null) {
|
2021-09-02 18:15:15 +02:00
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
Coordinate lower = OLFactory.createCoordinate(bbox.getLowerLeftX(), bbox.getLowerLeftY());
|
2021-09-01 12:51:06 +02:00
|
|
|
Coordinate lowerCoord = MapUtils.transformCoordiante(lower, MAP_PROJECTION.EPSG_4326.getName(),
|
|
|
|
MAP_PROJECTION.EPSG_3857.getName());
|
2020-11-19 15:19:27 +01:00
|
|
|
|
|
|
|
Coordinate upper = OLFactory.createCoordinate(bbox.getUpperRightX(), bbox.getUpperRightY());
|
2021-09-01 12:51:06 +02:00
|
|
|
Coordinate upperCoord = MapUtils.transformCoordiante(upper, MAP_PROJECTION.EPSG_4326.getName(),
|
|
|
|
MAP_PROJECTION.EPSG_3857.getName());
|
2021-09-02 18:15:15 +02:00
|
|
|
|
2020-12-09 14:28:32 +01:00
|
|
|
ew = new ExtentWrapped(lowerCoord.getX(), lowerCoord.getY(), upperCoord.getX(), upperCoord.getY());
|
2021-09-02 18:15:15 +02:00
|
|
|
theBBOX = new BoundsMap(lowerCoord.getX(), lowerCoord.getY(), upperCoord.getX(), upperCoord.getY(),
|
|
|
|
null);
|
2020-12-09 14:28:32 +01:00
|
|
|
}
|
2021-09-02 18:15:15 +02:00
|
|
|
|
|
|
|
lightOLSM.addWMSLayer(mapServerHost, layerName, theBBOX);
|
2020-12-09 14:28:32 +01:00
|
|
|
|
|
|
|
if (ew != null) {
|
2021-09-02 18:15:15 +02:00
|
|
|
|
|
|
|
lightOLSM.getMap().getView().fit(ew);
|
2020-11-19 15:19:27 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2021-09-02 18:15:15 +02:00
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
}
|
2021-09-02 18:15:15 +02:00
|
|
|
|
|
|
|
public LightOpenLayerOSM getLightOLSM() {
|
|
|
|
return lightOLSM;
|
|
|
|
}
|
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
}
|