Mercurial > dive4elements > gnv-client
changeset 570:cbd397712ecf
Render an OpenLayers map with the layer even published after triggering shapefile and mapfile creation.
gnv/trunk@698 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 22 Feb 2010 18:04:55 +0000 |
parents | 9a5e50e7afaa |
children | f2ba58011a2d |
files | gnv/ChangeLog gnv/src/main/java/de/intevation/gnv/action/WMSAction.java gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java gnv/src/main/java/de/intevation/gnv/util/XMLUtils.java gnv/src/main/webapp/WEB-INF/config/struts-config.xml gnv/src/main/webapp/WEB-INF/jsp/includes/display_export_inc.jsp gnv/src/main/webapp/WEB-INF/jsp/index.jsp gnv/src/main/webapp/WEB-INF/jsp/mainlayout.jsp gnv/src/main/webapp/styles/default.css |
diffstat | 10 files changed, 209 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv/ChangeLog Mon Feb 15 11:42:29 2010 +0000 +++ b/gnv/ChangeLog Mon Feb 22 18:04:55 2010 +0000 @@ -1,3 +1,34 @@ +2010-02-22 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + * src/main/webapp/WEB-INF/config/struts-config.xml: New action 'WMSAction'. + It triggers the generation of shapefiles and mapfile and sets an internal + flag to intialize an OpenLayers map. + + * src/main/java/de/intevation/gnv/action/WMSAction.java: Action which + triggers the creation of shapefiles and mapfile. An internal flag is set + to initialize an OpenLayers map with the layer even published. + + * src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java, + src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java: + Added a new method to send a request to the artifact server and start + shapefile and mapfile creation. + + * src/main/webapp/WEB-INF/jsp/mainlayout.jsp: Added javascript functions to + read url parameters and initialize OpenLayers. + + * src/main/webapp/WEB-INF/jsp/includes/display_export_inc.jsp: Call 'wms.do' + after clicking WMS button which triggers WMSAction. + + * src/main/webapp/WEB-INF/jsp/index.jsp: Added a div-container for rendering + an OpenLayers map. + + * src/main/webapp/styles/default.css: New class for styling map + div-container. + + * src/main/java/de/intevation/gnv/util/XMLUtils.java: Made method static to + be able to use it without creating an object of this class. + + 2010-02-15 Ingo Weinzierl <ingo.weinzierl@intevation.de> * src/main/webapp/WEB-INF/config/struts-config.xml: Added an action
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/WMSAction.java Mon Feb 22 18:04:55 2010 +0000 @@ -0,0 +1,66 @@ +package de.intevation.gnv.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; + +import de.intevation.gnv.action.sessionmodel.SessionModel; +import de.intevation.gnv.action.sessionmodel.SessionModelFactory; +import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient; +import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory; +import de.intevation.gnv.artifactdatabase.objects.ArtifactObject; + +/** + * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) + */ +public class WMSAction extends DescribeUIAction { + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger logger = Logger.getLogger(WMSAction.class); + + /** + * Constructor + */ + public WMSAction() { + super(); + } + + @Override + public ActionForward execute(ActionMapping mapping, ActionForm form, + HttpServletRequest request, + HttpServletResponse response) throws Exception { + logger.debug("WMSAction.execute"); + try { + SessionModel sm = SessionModelFactory.getInstance().getSessionModel( + request); + ArtifactObject artifact = sm.getCurrentArtifact(); + + ArtifactDatabaseClientFactory factory = + ArtifactDatabaseClientFactory.getInstance(); + ArtifactDatabaseClient adc = factory.getArtifactDatabaseClient( + getLocale(request)); + ArtifactObject artifactfactory = sm.getSelectedArtifactFactory(); + + // do wms publishing + String url = adc.publishWMS(artifactfactory, artifact); + request.setAttribute("layer", artifact.getId()); + + return super.execute(mapping, form, request, response); + } + catch (Exception e) { + logger.error(e, e); + request.setAttribute( + CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, + e.getMessage()); + + return super.getExceptionForward(mapping); + } + } + +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java Mon Feb 15 11:42:29 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java Mon Feb 22 18:04:55 2010 +0000 @@ -105,6 +105,14 @@ throws ArtifactDatabaseClientException; /** + * @param factory + * @param artifact + * @return URL to wms service as string + */ + public String publishWMS(ArtifactObject factory, ArtifactObject artifact); + + + /** * @param artifactFactory * @param currentArtifact * @return
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java Mon Feb 15 11:42:29 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java Mon Feb 22 18:04:55 2010 +0000 @@ -751,10 +751,31 @@ } + public String publishWMS(ArtifactObject factory, ArtifactObject artifact) { + log.debug("Start wms publishing..."); + + String target = "wms"; + String requestURL = getArtifactUrl(factory, artifact) + "/" + target; + Document request = createOutRequestBody( + artifact, target, "text/xml", null); + try { + InputStream input = doPostRequest(requestURL, request); + Document result = XMLUtils.readDocument(input); + } + catch (IOException ioe) { + log.error(ioe, ioe); + return null; + } + + // TODO Return URL to WMS service + return null; + } + public Collection<ArtifactStatisticsSet> calculateStatistics( - ArtifactObject artifactFactory, - ArtifactObject currentArtifact) - throws ArtifactDatabaseClientException { + ArtifactObject artifactFactory, + ArtifactObject currentArtifact) + throws ArtifactDatabaseClientException + { log.debug("DefaultArtifactDatabaseClient.calculateStatistics"); Collection<ArtifactStatisticsSet> resultValues = null;
--- a/gnv/src/main/java/de/intevation/gnv/util/XMLUtils.java Mon Feb 15 11:42:29 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/util/XMLUtils.java Mon Feb 22 18:04:55 2010 +0000 @@ -147,7 +147,7 @@ return s == null || s.length() == 0 ? def : s; } - public Document readDocument(InputStream inputStream) { + public static Document readDocument(InputStream inputStream) { Document returnValue = null; try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
--- a/gnv/src/main/webapp/WEB-INF/config/struts-config.xml Mon Feb 15 11:42:29 2010 +0000 +++ b/gnv/src/main/webapp/WEB-INF/config/struts-config.xml Mon Feb 22 18:04:55 2010 +0000 @@ -93,6 +93,20 @@ scope="request" validate="false"> </action> + <action path="/wms" + type="de.intevation.gnv.action.WMSAction" + scope="request" + validate="false"> + <forward + name="success" + path="/WEB-INF/jsp/mainlayout.jsp"/> + <forward + name="back" + path="/gnv/back.do"/> + <forward + name="selectfis" + path="/gnv/selectFis.do"/> + </action> <action path="/export" type="de.intevation.gnv.action.DoExportAction" scope="request"
--- a/gnv/src/main/webapp/WEB-INF/jsp/includes/display_export_inc.jsp Mon Feb 15 11:42:29 2010 +0000 +++ b/gnv/src/main/webapp/WEB-INF/jsp/includes/display_export_inc.jsp Mon Feb 22 18:04:55 2010 +0000 @@ -3,13 +3,17 @@ <%@page import="de.intevation.gnv.action.sessionmodel.SessionModel"%> <%@page import="de.intevation.gnv.action.sessionmodel.DiagrammOptions"%> <%@page import="de.intevation.gnv.artifactdatabase.objects.OutputParameter"%> +<%@page import="de.intevation.gnv.artifactdatabase.objects.ArtifactObject"%> <%@page import="java.util.Collection"%> <%@page import="java.util.Iterator"%> <%@page import="java.net.URLEncoder"%> <% SessionModel sm = SessionModelFactory.getInstance().getSessionModel(request); + ArtifactObject artifact = sm.getCurrentArtifact(); String mimeType = null; String parameterString = ""; + String wmslayer = null; + String target = "chart"; String targetCSV = "csv"; @@ -72,6 +76,7 @@ String mimeTypeWMS = null; if (supportWMS) { mimeTypeWMS = sm.getOutputMode(targetWMS).getMimeType(); + wmslayer = artifact.getId(); } %> @@ -106,7 +111,7 @@ </a> <%}%> <%if (supportWMS) { %> - <a href="<%=response.encodeURL("export.do?mimetype="+mimeTypeWMS+"&target="+targetWMS+"&uid="+System.currentTimeMillis())%>" title="<bean:message key="gnviewer.output.options.export.wms.title"/>"> + <a href="<%=response.encodeURL("wms.do?mimetype="+mimeTypeWMS+"&target="+targetWMS+"&uid="+System.currentTimeMillis()+"&layer="+wmslayer)%>" title="<bean:message key="gnviewer.output.options.export.wms.title"/>"> <img src="images/map_go.png" border="0"/> </a> <%}%>
--- a/gnv/src/main/webapp/WEB-INF/jsp/index.jsp Mon Feb 15 11:42:29 2010 +0000 +++ b/gnv/src/main/webapp/WEB-INF/jsp/index.jsp Mon Feb 22 18:04:55 2010 +0000 @@ -8,6 +8,7 @@ Object staticui = request.getAttribute("staticui"); Object statistic = request.getAttribute("statistic"); Object histogram = request.getAttribute("histogram"); + Object wms = request.getAttribute("wms"); boolean furthertargets = true; Object furthertargetsObject = request.getAttribute("furthertargets"); @@ -43,6 +44,8 @@ <%}%> </div> + <div id="map"></div> + <%-- render chart options if existing for this state --%> <jsp:include page="includes/display_diagramm_inc.jsp"></jsp:include>
--- a/gnv/src/main/webapp/WEB-INF/jsp/mainlayout.jsp Mon Feb 15 11:42:29 2010 +0000 +++ b/gnv/src/main/webapp/WEB-INF/jsp/mainlayout.jsp Mon Feb 22 18:04:55 2010 +0000 @@ -43,9 +43,56 @@ "-1.5763 58.3616))"; } </script> + <script src="http://www.openlayers.org/api/OpenLayers.js"></script> + <script type="text/javascript"> + var lon = 5; + var lat = 55; + var zoom = 5; + var map, layer; + + function init() { + if (getURLParam("target") == "wms") { + console.log("LAYER NAME: " + getURLParam("layer")); + map = new OpenLayers.Map('map'); + layer = new OpenLayers.Layer.WMS( + "MyWMS", + "http://denmark.atlas/cgi-bin/mapserv-gp?MAP=/opt/artifacts/mapfiles/mapfile.map", + { + layers: getURLParam("layer") + }, + { + singleTile: 'true' + } + ); + + map.addLayer(layer); + map.setCenter(new OpenLayers.LonLat(lon, lat), zoom); + } + } + + function getURLParam(strParamName){ + var strReturn = ""; + var strHref = window.location.href; + + if ( strHref.indexOf("?") > -1 ){ + var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase(); + var aQueryString = strQueryString.split("&"); + + for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){ + if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ) { + var aParam = aQueryString[iParam].split("="); + strReturn = aParam[1]; + break; + } + } + } + + return strReturn; + } + </script> </head> - <body id="gnviewerbody"> + <body id="gnviewerbody" onLoad="init()"> <div id="overlay"></div> <div style="width:100%;left:0;top:0;width:100%;height:100%;position:absolute"> <div id="overlayContent">
--- a/gnv/src/main/webapp/styles/default.css Mon Feb 15 11:42:29 2010 +0000 +++ b/gnv/src/main/webapp/styles/default.css Mon Feb 22 18:04:55 2010 +0000 @@ -261,6 +261,14 @@ left: 350px; } +div#map { + position: absolute; + top: 33px; + left: 350px; + width: 325px; + height: 325px; +} + div.histogram { position: absolute; top: 33px;