added download layer
This commit is contained in:
parent
6900a988f2
commit
30ab1b9185
|
@ -14,9 +14,6 @@ import com.google.gwt.i18n.client.DateTimeFormat;
|
|||
*/
|
||||
public class GeoportalDataViewerConstants {
|
||||
|
||||
// public static final String EPSG_4326 = "EPSG:4326";
|
||||
// public static final String EPSG_3857 = "EPSG:3857";
|
||||
|
||||
public static final String MAP_DIV = "map";
|
||||
|
||||
public static final String GET_WMS_PARAMETER = "wmsrequest";
|
||||
|
@ -82,4 +79,23 @@ public class GeoportalDataViewerConstants {
|
|||
console.log("js console: " + msg);
|
||||
}-*/;
|
||||
|
||||
/**
|
||||
* Prints the.
|
||||
*
|
||||
* @param msg the msg
|
||||
*/
|
||||
public static native void printJsObj(Object object)/*-{
|
||||
console.log("js obj: "+JSON.stringify(object, null, 4));
|
||||
}-*/;
|
||||
|
||||
|
||||
/**
|
||||
* Prints the.
|
||||
*
|
||||
* @param msg the msg
|
||||
*/
|
||||
public static native String toJsonObj(Object object)/*-{
|
||||
return JSON.stringify(object);
|
||||
}-*/;
|
||||
|
||||
}
|
||||
|
|
|
@ -126,14 +126,6 @@ public class OLMapManager {
|
|||
|
||||
};
|
||||
|
||||
// EPSG_4326_TO_ITALY
|
||||
// Coordinate centerCoordinate = OLFactory.createCoordinate(GeoportalDataViewerConstants.ITALY_CENTER_LONG,
|
||||
// GeoportalDataViewerConstants.ITALY_CENTER_LAT);
|
||||
// Coordinate transformedCenterCoordinate = MapUtils.transformCoordiante(centerCoordinate,
|
||||
// MAP_PROJECTION.EPSG_4326.getName(), MAP_PROJECTION.EPSG_3857.getName());
|
||||
// olMap.setCenter(transformedCenterCoordinate);
|
||||
// olMap.setZoom(GeoportalDataViewerConstants.MAP_ITALY_FIT_ZOOM_ON);
|
||||
|
||||
Location italyLocation = ExtentMapUtil.getLocation(PLACE.ITALY);
|
||||
Coordinate transformedCenterCoordinate = italyLocation.getCoordinate(MAP_PROJECTION.EPSG_3857);
|
||||
olMap.setCenter(transformedCenterCoordinate);
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
package org.gcube.portlets.user.geoportaldataviewer.client.gis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.application.geoportalcommon.shared.gis.BoundsMap;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.resources.Images;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoQuery;
|
||||
|
@ -8,7 +13,12 @@ import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoQuery.TYPE;
|
|||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.i18n.client.NumberFormat;
|
||||
import com.google.gwt.json.client.JSONObject;
|
||||
import com.google.gwt.json.client.JSONParser;
|
||||
import com.google.gwt.json.client.JSONString;
|
||||
import com.google.gwt.json.client.JSONValue;
|
||||
|
||||
import ol.Collection;
|
||||
import ol.Coordinate;
|
||||
import ol.Feature;
|
||||
import ol.Map;
|
||||
|
@ -22,6 +32,7 @@ import ol.event.EventListener;
|
|||
import ol.geom.Point;
|
||||
import ol.interaction.KeyboardPan;
|
||||
import ol.interaction.KeyboardZoom;
|
||||
import ol.layer.Base;
|
||||
import ol.layer.Image;
|
||||
import ol.layer.LayerOptions;
|
||||
import ol.layer.Tile;
|
||||
|
@ -32,6 +43,7 @@ import ol.source.ImageWms;
|
|||
import ol.source.ImageWmsOptions;
|
||||
import ol.source.ImageWmsParams;
|
||||
import ol.source.Osm;
|
||||
import ol.source.Source;
|
||||
import ol.source.XyzOptions;
|
||||
import ol.style.Icon;
|
||||
import ol.style.IconOptions;
|
||||
|
@ -172,7 +184,7 @@ public class LightOpenLayerOSM {
|
|||
*
|
||||
* @param mapServerHost the map server host
|
||||
* @param layerName the layer name
|
||||
* @param bbox
|
||||
* @param bbox the bbox
|
||||
* @return the image
|
||||
*/
|
||||
public Image addWMSLayer(String mapServerHost, String layerName, BoundsMap bbox) {
|
||||
|
@ -214,6 +226,83 @@ public class LightOpenLayerOSM {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the layers.
|
||||
*
|
||||
* @return the layers
|
||||
*/
|
||||
public List<String> getLayers() {
|
||||
Collection<Base> layers = map.getLayers();
|
||||
List<String> layerNames = null;
|
||||
if (layers != null) {
|
||||
Base[] layersArr = layers.getArray();
|
||||
layerNames = new ArrayList<String>(layersArr.length);
|
||||
for (int i = 0; i < layersArr.length; i++) {
|
||||
Base layer = layersArr[i];
|
||||
if (layer instanceof Image) {
|
||||
Image layerImage = (Image) layer;
|
||||
|
||||
Source source = layerImage.getSource();
|
||||
// GWT.log("source: "+source.toString());
|
||||
GeoportalDataViewerConstants.printJsObj(source);
|
||||
String sorceRootObj = GeoportalDataViewerConstants.toJsonObj(source);
|
||||
JSONValue jsonObj = JSONParser.parseStrict(sorceRootObj);
|
||||
// GWT.log("jsonObj: " + jsonObj.toString());
|
||||
JSONObject jsonSourceObj = (JSONObject) jsonObj;
|
||||
|
||||
JSONObject jsonParamsObj = (JSONObject) jsonSourceObj.get("params_");
|
||||
// GWT.log("jsonParamsObj is: "+jsonParamsObj);
|
||||
JSONValue jsonLayers = jsonParamsObj.get("LAYERS");
|
||||
GWT.log("theLayerName name is: " + jsonLayers);
|
||||
layerNames.add(jsonLayers.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return layerNames;
|
||||
}
|
||||
|
||||
public java.util.Map<String, String> getLayerURLsProperty() {
|
||||
|
||||
Collection<Base> layers = map.getLayers();
|
||||
java.util.Map<String, String> mapLayerNameURL = new HashMap<String, String>();
|
||||
if (layers != null) {
|
||||
Base[] layersArr = layers.getArray();
|
||||
for (int i = 0; i < layersArr.length; i++) {
|
||||
Base layer = layersArr[i];
|
||||
// GeoportalDataViewerConstants.printJsObj(layer);
|
||||
if (layer instanceof Image) {
|
||||
Image layerImage = (Image) layer;
|
||||
|
||||
Source source = layerImage.getSource();
|
||||
// GWT.log("source: "+source.toString());
|
||||
// GeoportalDataViewerConstants.printJsObj(source);
|
||||
String sorceRootObj = GeoportalDataViewerConstants.toJsonObj(source);
|
||||
JSONValue jsonObj = JSONParser.parseStrict(sorceRootObj);
|
||||
// GWT.log("jsonObj: " + jsonObj.toString());
|
||||
JSONObject jsonSourceObj = (JSONObject) jsonObj;
|
||||
|
||||
JSONObject jsonParamsObj = (JSONObject) jsonSourceObj.get("params_");
|
||||
// GWT.log("jsonParamsObj is: "+jsonParamsObj);
|
||||
JSONString jsonLayers = (JSONString) jsonParamsObj.get("LAYERS");
|
||||
String layerName = jsonLayers.stringValue();
|
||||
GWT.log("jsonLayers is: " + layerName);
|
||||
// GWT.log("theLayerName name is: " + jsonLayers);
|
||||
|
||||
JSONValue jsonImage = jsonSourceObj.get("image_");
|
||||
// GWT.log("jsonImage: " + jsonImage.toString());
|
||||
JSONObject jsonImageObj = (JSONObject) jsonImage;
|
||||
JSONString jsonSrc = (JSONString) jsonImageObj.get("src_");
|
||||
String layerURL = jsonSrc.stringValue();
|
||||
GWT.log("jsonSrc: " + layerURL);
|
||||
mapLayerNameURL.put(layerName, layerURL);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
GWT.log("returning mapLayerNameURL: "+mapLayerNameURL);
|
||||
return mapLayerNameURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the point.
|
||||
*
|
||||
|
|
|
@ -403,8 +403,12 @@ public abstract class OpenLayerOSM {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the all detail layers.
|
||||
*/
|
||||
public void removeAllDetailLayers() {
|
||||
|
||||
//NOT NEEDED ANYMORE.. I'M USING MIN/MAX LAYER RESOLUTION
|
||||
|
||||
/*
|
||||
if (wmsDetailsLayerMap == null)
|
||||
|
@ -422,32 +426,6 @@ public abstract class OpenLayerOSM {
|
|||
|
||||
}
|
||||
|
||||
// public void addGeometry(Geometry theGeom) {
|
||||
//
|
||||
// if(theGeom==null)
|
||||
// return;
|
||||
//
|
||||
// if(geometryLayer==null) {
|
||||
// geometryLayer = new Vector("Feature selected");
|
||||
// geometryLayer.setDisplayInLayerSwitcher(false);
|
||||
// map.addLayer(geometryLayer);
|
||||
// }else {
|
||||
// geometryLayer.removeAllFeatures();
|
||||
// }
|
||||
// Style style = new Style();
|
||||
// style.setFillColor("#00FF00");
|
||||
// style.setGraphicName("circle");
|
||||
// style.setPointRadius(10);
|
||||
// VectorFeature vf = new VectorFeature(theGeom, style);
|
||||
// geometryLayer.addFeature(vf);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// protected void removeGeometries() {
|
||||
// if(geometryLayer!=null)
|
||||
// geometryLayer.removeAllFeatures();
|
||||
// }
|
||||
|
||||
/**
|
||||
* Adds the vector.
|
||||
*
|
||||
|
@ -588,7 +566,7 @@ public abstract class OpenLayerOSM {
|
|||
for (int i = 0; i < layersArr.length; i++) {
|
||||
Base layer = layersArr[i];
|
||||
String theLayerName = (String) layer.get("name");
|
||||
GWT.log("The Layer name is: " + layerName);
|
||||
GWT.log("The Layer name is: " + theLayerName);
|
||||
if (theLayerName != null && theLayerName.equals(layerName))
|
||||
return true;
|
||||
}
|
||||
|
@ -597,6 +575,32 @@ public abstract class OpenLayerOSM {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the layer property.
|
||||
*
|
||||
* @param layerName the layer name
|
||||
* @param property the property
|
||||
* @return the layer property
|
||||
*/
|
||||
public String getLayerProperty(String layerName, String property) {
|
||||
|
||||
Collection<Base> layers = map.getLayers();
|
||||
|
||||
if (layers != null) {
|
||||
Base[] layersArr = layers.getArray();
|
||||
for (int i = 0; i < layersArr.length; i++) {
|
||||
Base layer = layersArr[i];
|
||||
String theLayerName = (String) layer.get("name");
|
||||
GWT.log("The Layer name is: " + layerName);
|
||||
if (theLayerName != null && theLayerName.equals(layerName))
|
||||
return layer.get(property);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the projection code.
|
||||
*
|
||||
|
|
|
@ -50,7 +50,7 @@ import ol.OLFactory;
|
|||
@UiField
|
||||
HorizontalPanel coordinatePanel;
|
||||
|
||||
private LightOpenLayerOSM olsm;
|
||||
private LightOpenLayerOSM lightOLSM;
|
||||
|
||||
/**
|
||||
* Instantiates a new map view.
|
||||
|
@ -69,21 +69,13 @@ import ol.OLFactory;
|
|||
|
||||
@Override
|
||||
public void execute() {
|
||||
olsm = new LightOpenLayerOSM(theMapId);
|
||||
lightOLSM = new LightOpenLayerOSM(theMapId);
|
||||
|
||||
// EPSG_3857 LOCATION TO ITALY
|
||||
Location italyLocation = ExtentMapUtil.getLocation(PLACE.ITALY);
|
||||
Coordinate transformedCenterCoordinate = italyLocation.getCoordinate(MAP_PROJECTION.EPSG_3857);
|
||||
olsm.setCenter(transformedCenterCoordinate);
|
||||
olsm.setZoom(GeoportalDataViewerConstants.LIGHT_MAP_ITALY_FIT_ZOOM_ON);
|
||||
|
||||
// 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.LIGHT_MAP_ITALY_FIT_ZOOM_ON);
|
||||
|
||||
//setMapSize();
|
||||
|
||||
lightOLSM.setCenter(transformedCenterCoordinate);
|
||||
lightOLSM.setZoom(GeoportalDataViewerConstants.LIGHT_MAP_ITALY_FIT_ZOOM_ON);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -119,9 +111,9 @@ import ol.OLFactory;
|
|||
|
||||
@Override
|
||||
public void execute() {
|
||||
if(olsm!=null) {
|
||||
olsm.addPoint(coordinate, showCoordinateText, true);
|
||||
olsm.getMap().getView().setCenter(coordinate);
|
||||
if (lightOLSM != null) {
|
||||
lightOLSM.addPoint(coordinate, showCoordinateText, true);
|
||||
lightOLSM.getMap().getView().setCenter(coordinate);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -154,14 +146,15 @@ import ol.OLFactory;
|
|||
MAP_PROJECTION.EPSG_3857.getName());
|
||||
|
||||
ew = new ExtentWrapped(lowerCoord.getX(), lowerCoord.getY(), upperCoord.getX(), upperCoord.getY());
|
||||
theBBOX = new BoundsMap(lowerCoord.getX(), lowerCoord.getY(), upperCoord.getX(), upperCoord.getY(), null);
|
||||
theBBOX = new BoundsMap(lowerCoord.getX(), lowerCoord.getY(), upperCoord.getX(), upperCoord.getY(),
|
||||
null);
|
||||
}
|
||||
|
||||
olsm.addWMSLayer(mapServerHost, layerName, theBBOX);
|
||||
lightOLSM.addWMSLayer(mapServerHost, layerName, theBBOX);
|
||||
|
||||
if (ew != null) {
|
||||
|
||||
olsm.getMap().getView().fit(ew);
|
||||
lightOLSM.getMap().getView().fit(ew);
|
||||
|
||||
}
|
||||
|
||||
|
@ -170,4 +163,8 @@ import ol.OLFactory;
|
|||
|
||||
}
|
||||
|
||||
public LightOpenLayerOSM getLightOLSM() {
|
||||
return lightOLSM;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -266,16 +266,16 @@ public class ConcessioneView extends Composite {
|
|||
if(listLayersDV==null)
|
||||
return;
|
||||
|
||||
for (LayerConcessioneDV layer : listLayersDV) {
|
||||
for (LayerConcessioneDV layerDV : listLayersDV) {
|
||||
|
||||
if(layer.getPolicy()==null || layer.getPolicy().equalsIgnoreCase("OPEN")) {
|
||||
if(layerDV.getPolicy()==null || layerDV.getPolicy().equalsIgnoreCase("OPEN")) {
|
||||
piantaFineScavoPanel.setVisible(true);
|
||||
piantaFineScavoPanel.add(new LayerConcessioneView(layer));
|
||||
piantaFineScavoPanel.add(new LayerConcessioneView(layerDV));
|
||||
}else {
|
||||
//I need to be authenticated to show the fields according to POLICY
|
||||
if(myLogin!=null) {
|
||||
piantaFineScavoPanel.setVisible(true);
|
||||
piantaFineScavoPanel.add(new LayerConcessioneView(layer));
|
||||
piantaFineScavoPanel.add(new LayerConcessioneView(layerDV));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.gcube.portlets.user.geoportaldataviewer.client.ui.products.concessioni;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.application.geoportalcommon.shared.products.model.LayerConcessioneDV;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION;
|
||||
|
@ -8,11 +10,15 @@ import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.ExtentMapUtil.L
|
|||
import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.ExtentMapUtil.PLACE;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.MapView;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.ui.util.CustomFlexTable;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.DropdownButton;
|
||||
import com.github.gwtbootstrap.client.ui.NavLink;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.HTMLPanel;
|
||||
|
@ -49,10 +55,6 @@ public class LayerConcessioneView extends Composite {
|
|||
GWT.log("WMS LINK: " + layerDV.getWmsLink());
|
||||
if (layerDV.getLayerName() != null && layerDV.getWmsLink() != null) {
|
||||
|
||||
String pngWMSLink = URLUtil.setValueOfParameter("FORMAT", layerDV.getWmsLink(), "image/png", true);
|
||||
|
||||
customTable.addNextKeyWidget("Layer", new HTML("<a href=\"" + pngWMSLink + "\">download image</a>"));
|
||||
|
||||
Location italyLocation = ExtentMapUtil.getLocation(PLACE.ITALY);
|
||||
Coordinate transformedCenterCoordinate = italyLocation.getCoordinate(MAP_PROJECTION.EPSG_3857);
|
||||
// Coordinate centerCoordinate = OLFactory.createCoordinate(GeoportalDataViewerConstants.ITALY_CENTER_LONG, GeoportalDataViewerConstants.ITALY_CENTER_LAT);
|
||||
|
@ -64,8 +66,72 @@ public class LayerConcessioneView extends Composite {
|
|||
String mapServerHost = layerDV.getWmsLink().contains("?")
|
||||
? layerDV.getWmsLink().substring(0, layerDV.getWmsLink().indexOf("?"))
|
||||
: layerDV.getWmsLink();
|
||||
|
||||
DropdownButton downloadButt = new DropdownButton("download as...");
|
||||
NavLink navLink = new NavLink("PNG");
|
||||
HTML html = new HTML("<a id=\"image-download\" download=\"map.png\"></a>");
|
||||
navLink.getElement().appendChild(html.getElement());
|
||||
navLink.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
Map<String, String> mapLayerURLs = mapView.getLightOLSM().getLayerURLsProperty();
|
||||
|
||||
String layerURL = mapLayerURLs.get(layerDV.getLayerName());
|
||||
GWT.log("layerDV name is: " + layerDV.getLayerName());
|
||||
if (layerURL != null)
|
||||
Window.open(layerURL, "_blank", null);
|
||||
|
||||
//downloadMap(mapView.getLightOLSM().getMap());
|
||||
}
|
||||
});
|
||||
|
||||
downloadButt.add(navLink);
|
||||
customTable.addNextKeyWidget("Layer", downloadButt);
|
||||
mapView.addWMSLayer(mapServerHost, layerDV.getLayerName(), layerDV.getBbox());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the.
|
||||
*
|
||||
* @param msg the msg
|
||||
*/
|
||||
public static native void downloadMap(ol.Map map)/*-{
|
||||
console.log("map: " + map);
|
||||
map.once('rendercomplete', function() {
|
||||
var mapCanvas = document.createElement('canvas');
|
||||
var size = map.getSize();
|
||||
mapCanvas.width = size[0];
|
||||
mapCanvas.height = size[1];
|
||||
var mapContext = mapCanvas.getContext('2d');
|
||||
Array.prototype.forEach.call(document
|
||||
.querySelectorAll('.ol-layer canvas'), function(canvas) {
|
||||
if (canvas.width > 0) {
|
||||
var opacity = canvas.parentNode.style.opacity;
|
||||
mapContext.globalAlpha = opacity === '' ? 1
|
||||
: Number(opacity);
|
||||
var transform = canvas.style.transform;
|
||||
// Get the transform parameters from the style's transform matrix
|
||||
var matrix = transform.match(/^matrix\(([^\(]*)\)$/)[1]
|
||||
.split(',').map(Number);
|
||||
// Apply the transform to the export map context
|
||||
CanvasRenderingContext2D.prototype.setTransform.apply(
|
||||
mapContext, matrix);
|
||||
mapContext.drawImage(canvas, 0, 0);
|
||||
}
|
||||
});
|
||||
if (navigator.msSaveBlob) {
|
||||
// link download attribute does not work on MS browsers
|
||||
navigator.msSaveBlob(mapCanvas.msToBlob(), 'map.png');
|
||||
} else {
|
||||
console.log('qui');
|
||||
// var link = document.getElementById('image-download');
|
||||
// link.href = mapCanvas.toDataURL();
|
||||
window.open(mapCanvas.toDataURL(),'_blank');
|
||||
}
|
||||
});
|
||||
map.renderSync();
|
||||
}-*/;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue