package org.gcube.portlets.user.geoportaldataviewer.client.ui.map; import org.gcube.portlets.user.geoportaldataviewer.client.gis.ExtentWrapped; import org.gcube.portlets.user.geoportaldataviewer.client.gis.LightOpenLayerOSM; 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.Extent; import ol.layer.Image; /** * The Class MapView. * * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * * Nov 11, 2020 */ public class MapView extends Composite{ private static MapViewUiBinder uiBinder = GWT.create(MapViewUiBinder.class); /** * The Interface MapViewUiBinder. * * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * * Nov 11, 2020 */ interface MapViewUiBinder extends UiBinder { } @UiField HTMLPanel theMap; @UiField HorizontalPanel coordinatePanel; private LightOpenLayerOSM olsm; // public MapView(Double x, Double y, boolean showCoordinate) { // initWidget(uiBinder.createAndBindUi(this)); // String theMapId = "map"+Random.nextInt(); // theMap.getElement().setId(theMapId); // //theMap.setSize("300px", "300px"); // // Scheduler.get().scheduleDeferred(new ScheduledCommand() { // // @Override // public void execute() { // olsm = new LightOpenLayerOSM(theMapId); // if(x!=null && y!=null) { // Coordinate point = new Coordinate(x, y); // addPoint(point); // } // // } // }); // } /** * Instantiates a new map view. */ public MapView() { initWidget(uiBinder.createAndBindUi(this)); String theMapId = "map"+Random.nextInt(); theMap.getElement().setId(theMapId); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { olsm = new LightOpenLayerOSM(theMapId); } }); } /** * Adds the marker. * * @param coordinate the coordinate * @param showCoordinateText the show coordinate text */ public void addMarker(Coordinate coordinate, boolean showCoordinateText) { Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { if(olsm!=null) { olsm.addPoint(coordinate, showCoordinateText, true); olsm.getMap().getView().setCenter(coordinate); } } }); } /** * Adds the WMS layer. * * @param mapServerHost the map server host * @param layerName the layer name */ public void addWMSLayer(String mapServerHost, String layerName){ Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { Image layer = olsm.addWMSLayer(mapServerHost, layerName); Extent ext = layer.getExtent(); GWT.log("WMS layer extent: "+ext); if(ext!=null) { ExtentWrapped ew = new ExtentWrapped(ext.getLowerLeftX(), ext.getLowerLeftY(), ext.getUpperRightX(), ext.getUpperRightY()); Coordinate center = ew.getCenter(); olsm.getMap().getView().setCenter(center); } } }); } }