Commit 309df8b2 authored by Fabien D'Angelo's avatar Fabien D'Angelo

add possibility to declare a remote WMS server

parent 2c518cb0
......@@ -42,6 +42,11 @@
<version>6.2.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
</dependencies>
<description>This portlet displays WebLab resources metadata.</description>
......
......@@ -20,6 +20,8 @@ package org.ow2.weblab.portlet.business.bean;
import java.util.Map;
import java.util.TreeMap;
import org.ow2.weblab.portlet.business.bean.config.map.GroupLayerConfig;
/**
* Class containing the configuration of the metadata properties to be displayed.
*
......
......@@ -20,6 +20,8 @@ package org.ow2.weblab.portlet.business.bean;
import java.util.List;
import java.util.Map;
import org.ow2.weblab.portlet.business.bean.config.map.GroupLayerConfig;
/**
* Contains edition configuration
*
......@@ -30,6 +32,7 @@ public class EditMetaConfBean {
private boolean useGeoserverExposedMap;
private GroupLayerConfig layersConfig;
private Map<String, List<String>> properties;
......@@ -60,4 +63,14 @@ public class EditMetaConfBean {
this.useGeoserverExposedMap = useGeoserverExposedMap;
}
public GroupLayerConfig getLayersConfig() {
return layersConfig;
}
public void setLayersConfig(GroupLayerConfig layersConfig) {
this.layersConfig = layersConfig;
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2016 Airbus Defence and Space
*
* This library is free software; you can redistribute it and/or modify it under the terms of
* the GNU Lesser General Public License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301 USA
*/
package org.ow2.weblab.portlet.business.bean.config.map;
import java.util.LinkedList;
import java.util.List;
public class GroupLayerConfig extends LayerConfig {
private List<LayerConfig> layers;
private static final String EPSG_4326="EPSG:4326";
private String projection = GroupLayerConfig.EPSG_4326;
public GroupLayerConfig(GroupLayerConfig glc){
this.layers = new LinkedList<LayerConfig>();
for(LayerConfig layer : glc.layers) {
this.layers.add((LayerConfig)layer.clone());
}
this.projection = glc.projection;
}
public GroupLayerConfig() {
this.layers = new LinkedList<LayerConfig>();
}
/**
* @return the layers
*/
public List<LayerConfig> getLayers() {
return this.layers;
}
/**
* @param layers
* the layers to set
*/
public void setLayers(final List<LayerConfig> layers) {
this.layers = layers;
}
/**
* @return the projection
*/
public String getProjection() {
return projection;
}
/**
* @param projection the projection to set
*/
public void setProjection(String projection) {
this.projection = projection;
}
@Override
protected Object clone() {
final GroupLayerConfig clone = new GroupLayerConfig();
this.enrichClone(clone);
clone.projection = this.projection;
if (this.getLayers() != null) {
final LinkedList<LayerConfig> clonedLayers = new LinkedList<>();
for (final LayerConfig layer : this.getLayers()) {
clonedLayers.add((LayerConfig) layer.clone());
}
clone.setLayers(clonedLayers);
}
return clone;
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2016 Airbus Defence and Space
*
* This library is free software; you can redistribute it and/or modify it under the terms of
* the GNU Lesser General Public License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301 USA
*/
package org.ow2.weblab.portlet.business.bean.config.map;
import com.google.gson.GsonBuilder;
/**
* Configuration holder for a layer used within OpenLayers. This class is abstract and has to be extended to represent special types of layers.
*/
public abstract class LayerConfig implements Cloneable {
private Double minResolution, maxResolution;
private Double opacity;
private Boolean visible;
private final String type;
private String nameKey;
/**
* @return the nameKey
*/
public String getNameKey() {
return this.nameKey;
}
/**
* @param nameKey
* the nameKey to set
*/
public void setNameKey(final String nameKey) {
this.nameKey = nameKey;
}
/**
* Default constructor that sets the type as simple class name value.
*/
public LayerConfig() {
this.type = this.getClass().getSimpleName();
}
/**
* @return the minResolution
*/
public Double getMinResolution() {
return this.minResolution;
}
/**
* @param minResolution
* the minResolution to set
*/
public void setMinResolution(final Double minResolution) {
this.minResolution = minResolution;
}
/**
* @return the maxResolution
*/
public Double getMaxResolution() {
return this.maxResolution;
}
/**
* @param maxResolution
* the maxResolution to set
*/
public void setMaxResolution(final Double maxResolution) {
this.maxResolution = maxResolution;
}
/**
* @return the opacity
*/
public Double getOpacity() {
return this.opacity;
}
/**
* @param opacity
* the opacity to set
*/
public void setOpacity(final Double opacity) {
this.opacity = opacity;
}
/**
* @return the visible
*/
public Boolean isVisible() {
return this.visible;
}
/**
* @return the visible
*/
public Boolean getVisible() {
return this.isVisible();
}
/**
* @param visible
* the visible to set
*/
public void setVisible(final Boolean visible) {
this.visible = visible;
}
/**
* @return the type
*/
public String getType() {
return this.type;
}
/**
* Copies the values of field of <code>this</code> to the <code>clone</code>.
* Only copies the values that are in <code>LayerConfig</code>.
*
* @param clone
* The clone whose properties has to be set with the value of this
*/
protected void enrichClone(final LayerConfig clone) {
clone.setMaxResolution(this.getMaxResolution());
clone.setMinResolution(this.getMinResolution());
clone.setOpacity(this.getOpacity());
clone.setVisible(this.getVisible());
clone.setNameKey(this.getNameKey());
}
@Override
protected abstract Object clone();
@Override
public String toString() {
return new GsonBuilder().create().toJson(this);
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2016 Airbus Defence and Space
*
* This library is free software; you can redistribute it and/or modify it under the terms of
* the GNU Lesser General Public License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301 USA
*/
package org.ow2.weblab.portlet.business.bean.config.map;
/**
* The WMS Source/layer configuration handler.
*/
public class WMSLayerConfig extends LayerConfig {
private static final String DEFAULT_WMS_VERSION = "1.3.0";
private String url, relativeUrl, layer, version = WMSLayerConfig.DEFAULT_WMS_VERSION;
private boolean tiled = false;
/**
* @return the tiled
*/
public boolean isTiled() {
return this.tiled;
}
/**
* @param tiled
* the tiled to set
*/
public void setTiled(final boolean tiled) {
this.tiled = tiled;
}
/**
* @return the relativeUrl
*/
public String getRelativeUrl() {
return this.relativeUrl;
}
/**
* @param relativeUrl
* the relativeUrl to set
*/
public void setRelativeUrl(final String relativeUrl) {
this.relativeUrl = relativeUrl;
}
/**
* @return the url
*/
public String getUrl() {
return this.url;
}
/**
* @param url
* the url to set
*/
public void setUrl(final String url) {
this.url = url;
}
/**
* @return the layer
*/
public String getLayer() {
return this.layer;
}
/**
* @param layer
* the layer to set
*/
public void setLayer(final String layer) {
this.layer = layer;
}
/**
* @return the version
*/
public String getVersion() {
return this.version;
}
/**
* @param version
* the version to set
*/
public void setVersion(final String version) {
this.version = version;
}
@Override
protected Object clone() {
final WMSLayerConfig clone = new WMSLayerConfig();
this.enrichClone(clone);
clone.setUrl(this.getUrl());
clone.setRelativeUrl(this.getRelativeUrl());
clone.setLayer(this.getLayer());
clone.setTiled(this.isTiled());
clone.setVersion(this.getVersion());
return clone;
}
}
......@@ -61,11 +61,14 @@ import com.liferay.portlet.PortletURLFactoryUtil;
@Controller
@RequestMapping(value = "VIEW")
@SessionAttributes({ "resource", "isEmptyModel", "isLoadedResource", "rdfProperties", "translations", "metaDisplay", "editMetaData", "timeConfig", "dataTaglib", "dataLanguage",
"useGeoserverExposedMap", "editError" })
"useGeoserverExposedMap", "layersConfig", "editError" })
public class EditMetaController {
private static final String USE_GEOSERVER_EXPOSED_MAP = "useGeoserverExposedMap";
private static final String LAYERS_CONFIG = "layersConfig";
private static final String EDIT_ERROR = "editError";
......@@ -143,6 +146,10 @@ public class EditMetaController {
if (!model.containsAttribute(EditMetaController.USE_GEOSERVER_EXPOSED_MAP)) {
model.addAttribute(EditMetaController.USE_GEOSERVER_EXPOSED_MAP, Boolean.valueOf(this.editMetaData.isUseGeoserverExposedMap()));
}
if (!model.containsAttribute(EditMetaController.LAYERS_CONFIG)) {
model.addAttribute(EditMetaController.LAYERS_CONFIG, this.editMetaData.getLayersConfig());
}
if (!model.containsAttribute(EditMetaController.EDIT_ERROR)) {
model.addAttribute(EditMetaController.EDIT_ERROR, Boolean.FALSE);
......
......@@ -129,6 +129,22 @@
<bean id="displayMeta" class="org.ow2.weblab.portlet.business.bean.DisplayMetaConfBean">
<property name="useGeoserverExposedMap" value="false" />
<property name="layersConfig">
<bean id="layerGeoserver" class="org.ow2.weblab.portlet.business.bean.config.map.GroupLayerConfig">
<property name="projection" value="EPSG:3857"/>
<property name="layers">
<list>
<bean name="baseLayerLocal" class="org.ow2.weblab.portlet.business.bean.config.map.WMSLayerConfig">
<property name="visible" value="true" />
<property name="relativeUrl" value="/geoserver-weblab/wms" />
<property name="layer" value="vtpa:HYP_HR_SR_OB_DR" />
<property name="tiled" value="true" />
<property name="nameKey" value="Legend.Layers.earthRasterLayer" />
</bean>
</list>
</property>
</bean>
</property>
<property name="properties">
<map>
<!-- Documents properties -->
......
function openLayerMap(useGeoserverExposedMap, serverUrlPrefix) {
function openLayerMap(useGeoserverExposedMap, serverUrlPrefix, layersConfig) {
if (jQuery('#longEdit').length) {
......@@ -38,33 +38,48 @@ function openLayerMap(useGeoserverExposedMap, serverUrlPrefix) {
features : [ iconFeature ]
})
});
var rasterLayer;
if (useGeoserverExposedMap) {
rasterLayer = new ol.layer.Tile({
source : new ol.source.TileWMS({
url : serverUrlPrefix + "/geoserver-weblab/wms",
params : {
'LAYERS' : "vtpa:HYP_HR_SR_OB_DR",
'TILED' : true,
'VERSION' : "1.3.0"
}
})
});
var layers = [];
if (useGeoserverExposedMap) {
for (var i = 0; i < layersConfig.layers.length; i++) {
var layer = layersConfig.layers[i];
if (layer.hasOwnProperty("relativeUrl")) {
layer.url = serverUrlPrefix + layer.relativeUrl;
}
var rasterLayer = new ol.layer.Tile({
source : new ol.source.TileWMS({
url : layer.url,
params : {
'LAYERS' : layer.layer,
'TILED' : layer.tiled,
'VERSION' : layer.version,
},
serverType : 'geoserver'
})
});
layers.push(rasterLayer);
}
} else {
rasterLayer = new ol.layer.Tile({
source : new ol.source.OSM()
})
});
layers.push(rasterLayer);
}
jQuery('.mapContener').css('width', '100%');
var view = new ol.View({
center : centerMap,
zoom : 3
zoom : 3,
projection: layersConfig.projection
});
layers.push(vectorLayer);
var map = new ol.Map({
layers : [ rasterLayer, vectorLayer ],
layers : layers,
target : canvas,
view : view,
controls : ol.control.defaults({
......
......@@ -407,7 +407,7 @@
jQuery(document).ready(
function() {
openLayerMap(${useGeoserverExposedMap}, '${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}');
openLayerMap(${useGeoserverExposedMap}, '${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}', ${layersConfig});
jQuery(".extraRow, .error").hide();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment