diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java index 867b02a..39fb786 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java @@ -4,6 +4,7 @@ import java.util.List; 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.gis.MapUtils; import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerOSM; import org.gcube.portlets.user.geoportaldataviewer.client.ui.GeonaDataViewMainPanel; import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil; @@ -25,6 +26,9 @@ import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.RootPanel; +import ol.Coordinate; +import ol.OLFactory; + // TODO: Auto-generated Javadoc /** * Entry point classes define onModuleLoad(). @@ -82,6 +86,13 @@ public class GeoportalDataViewer implements EntryPoint { olMap = new OpenLayerOSM(mainPanel.getMapPanel().getElement().getId(),layerManager.getEventBus()); layerManager.setOlMap(olMap); mainPanel.setMap(olMap); + + //EPSG_4326_TO_ITALY + Coordinate centerCoordinate = OLFactory.createCoordinate(GeoportalDataViewerConstants.ITALY_CENTER_LONG, GeoportalDataViewerConstants.ITALY_CENTER_LAT); + Coordinate transformedCenterCoordinate = MapUtils.transformCoordiante(centerCoordinate, GeoportalDataViewerConstants.EPSG_4326, GeoportalDataViewerConstants.EPSG_3857); + + olMap.setCenter(transformedCenterCoordinate); + olMap.setZoom(GeoportalDataViewerConstants.ITALY_FIT_ZOOM_ON); } }); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerConstants.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerConstants.java index e422fda..7352618 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerConstants.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerConstants.java @@ -21,5 +21,12 @@ public class GeoportalDataViewerConstants { public static final int MAX_WFS_FEATURES = 5; // zero for no limit public static final String NEW_LINE_BR = "
"; + + public static final double ITALY_CENTER_LONG = 12.45; + + public static final double ITALY_CENTER_LAT = 42.98; + + public static final int ITALY_FIT_ZOOM_ON = 5; + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LightOpenLayerOSM.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LightOpenLayerOSM.java index 6e8f1cc..3ff13ba 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LightOpenLayerOSM.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LightOpenLayerOSM.java @@ -95,12 +95,12 @@ import ol.style.TextOptions; // create a view view = new View(viewOptions); - //EPSG_4326_TO_ITALY - Coordinate centerCoordinate = OLFactory.createCoordinate(12.45, 42.98); - Coordinate transformedCenterCoordinate = Projection.transform(centerCoordinate, GeoportalDataViewerConstants.EPSG_4326, GeoportalDataViewerConstants.EPSG_3857); - - view.setCenter(transformedCenterCoordinate); - view.setZoom(5); +// //EPSG_4326_TO_ITALY +// Coordinate centerCoordinate = OLFactory.createCoordinate(12.45, 42.98); +// Coordinate transformedCenterCoordinate = Projection.transform(centerCoordinate, GeoportalDataViewerConstants.EPSG_4326, GeoportalDataViewerConstants.EPSG_3857); +// +// view.setCenter(transformedCenterCoordinate); +// view.setZoom(5); // create the map MapOptions mapOptions = OLFactory.createOptions(); @@ -163,6 +163,25 @@ import ol.style.TextOptions; } + + /** + * Sets the center. + * + * @param centerCoordinate the new center + */ + public void setCenter(Coordinate centerCoordinate) { + view.setCenter(centerCoordinate); + } + + /** + * Sets the center. + * + * @param centerCoordinate the new center + */ + public void setZoom(int zoom) { + view.setZoom(zoom); + } + /** * Adds the WMS layer. * diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerOSM.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerOSM.java index dad98a7..adff42c 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerOSM.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerOSM.java @@ -112,13 +112,6 @@ public class OpenLayerOSM { // create a view view = new View(viewOptions); - - //EPSG_4326_TO_ITALY - Coordinate centerCoordinate = OLFactory.createCoordinate(12.45, 42.98); - Coordinate transformedCenterCoordinate = MapUtils.transformCoordiante(centerCoordinate, GeoportalDataViewerConstants.EPSG_4326, GeoportalDataViewerConstants.EPSG_3857); - - view.setCenter(transformedCenterCoordinate); - view.setZoom(5); // create the map MapOptions mapOptions = OLFactory.createOptions(); @@ -182,6 +175,23 @@ public class OpenLayerOSM { } + /** + * Sets the center. + * + * @param centerCoordinate the new center + */ + public void setCenter(Coordinate centerCoordinate) { + view.setCenter(centerCoordinate); + } + + /** + * Sets the center. + * + * @param centerCoordinate the new center + */ + public void setZoom(int zoom) { + view.setZoom(zoom); + } public void showPopup(String html, Coordinate coordinate) { diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/map/MapView.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/map/MapView.java index fb4b028..bd1ddc3 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/map/MapView.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/map/MapView.java @@ -61,7 +61,13 @@ import ol.OLFactory; @Override public void execute() { - olsm = new LightOpenLayerOSM(theMapId); + olsm = new LightOpenLayerOSM(theMapId); + //EPSG_4326_TO_ITALY + Coordinate centerCoordinate = OLFactory.createCoordinate(GeoportalDataViewerConstants.ITALY_CENTER_LONG, GeoportalDataViewerConstants.ITALY_CENTER_LAT); + Coordinate transformedCenterCoordinate = MapUtils.transformCoordiante(centerCoordinate, GeoportalDataViewerConstants.EPSG_4326, GeoportalDataViewerConstants.EPSG_3857); + + olsm.setCenter(transformedCenterCoordinate); + olsm.setZoom(GeoportalDataViewerConstants.ITALY_FIT_ZOOM_ON); } }); }