001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/portal/standard/wms/control/AbstractMapListener.java $
002 /*----------------------------------------------------------------------------
003 This file is part of deegree, http://deegree.org/
004 Copyright (C) 2001-2009 by:
005 Department of Geography, University of Bonn
006 and
007 lat/lon GmbH
008
009 This library is free software; you can redistribute it and/or modify it under
010 the terms of the GNU Lesser General Public License as published by the Free
011 Software Foundation; either version 2.1 of the License, or (at your option)
012 any later version.
013 This library is distributed in the hope that it will be useful, but WITHOUT
014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016 details.
017 You should have received a copy of the GNU Lesser General Public License
018 along with this library; if not, write to the Free Software Foundation, Inc.,
019 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020
021 Contact information:
022
023 lat/lon GmbH
024 Aennchenstr. 19, 53177 Bonn
025 Germany
026 http://lat-lon.de/
027
028 Department of Geography, University of Bonn
029 Prof. Dr. Klaus Greve
030 Postfach 1147, 53001 Bonn
031 Germany
032 http://www.geographie.uni-bonn.de/deegree/
033
034 e-mail: info@deegree.org
035 ----------------------------------------------------------------------------*/
036 package org.deegree.portal.standard.wms.control;
037
038 import java.io.UnsupportedEncodingException;
039 import java.net.URLDecoder;
040 import java.util.HashMap;
041 import java.util.StringTokenizer;
042
043 import javax.servlet.http.HttpServletRequest;
044 import javax.servlet.http.HttpSession;
045
046 import org.deegree.enterprise.control.AbstractListener;
047 import org.deegree.enterprise.control.FormEvent;
048 import org.deegree.framework.util.CharsetUtils;
049 import org.deegree.ogcwebservices.wms.operation.GetMap;
050 import org.deegree.portal.context.ViewContext;
051
052 /**
053 * Basic class for all listerens that shall be notified if a map cliented raises an action/event.
054 * <p>
055 * </p>
056 * There are several predefined listeres for actions that most map clients support:
057 * <ul>
058 * <li><tt>ZoomInListener</tt> for handling zoomin actions. supported are zooming via point or vie rectangle.
059 * <li><tt>ZoomOutListener</tt> for handling zoomout action.
060 * <li><tt>PanListener</tt> for handling of pan action. supported is panning to eight directions.
061 * <li><tt>RecenterListener</tt> recenters the map to a specified point. This can be interpreted as a special versio
062 * of zooming
063 * <li><tt>RefreshListener</tt> reloads the map without any change
064 * <li><tt>ResetListener</tt> recovers the initial status of the map
065 * <li><tt>InfoListener</tt> will be notified if a feature info request should be send.
066 * </ul>
067 * The user can additional listeners/action by extending the <tt>AbstractActionListener</tt> class or one of the
068 * predefined listener.
069 * <p>
070 * </p>
071 * Each Listerner have to be registered to the <tt>MapListener</tt> which is the class that will be informed about
072 * each event/action within a map client. To register a class as listener it has to stored within the
073 * MapListener.ConfigurationFile.
074 *
075 * <p>
076 * ---------------------------------------------------------------------
077 * </p>
078 *
079 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
080 * @author last edited by: $Author: mays$
081 *
082 * @version $Revision: 18195 $ $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
083 */
084 abstract class AbstractMapListener extends AbstractListener {
085
086 /**
087 * @param event
088 */
089 @Override
090 public void actionPerformed( FormEvent event ) {
091
092 HttpSession session = ( (HttpServletRequest) getRequest() ).getSession();
093 // get configuration from the users session
094 ViewContext vc = (ViewContext) session.getAttribute( "DefaultMapContext" );
095
096 this.getRequest().setAttribute( "MapContext", vc );
097
098 }
099
100 /**
101 * maps a string representation of a request to a <tt>HashMap</tt>
102 */
103 protected HashMap<String, String> toMap( String request ) {
104 int p = request.indexOf( '?' );
105 if ( p >= 0 ) {
106 request = request.substring( p + 1, request.length() );
107 }
108 StringTokenizer st = new StringTokenizer( request, "&" );
109 HashMap<String, String> map = new HashMap<String, String>();
110
111 while ( st.hasMoreTokens() ) {
112 String s = st.nextToken();
113 int pos = s.indexOf( '=' );
114 String s1 = s.substring( 0, pos );
115 String s2 = s.substring( pos + 1, s.length() );
116 try {
117 map.put( s1.toUpperCase(), URLDecoder.decode( s2, CharsetUtils.getSystemCharset() ) );
118 } catch ( UnsupportedEncodingException e ) {
119 e.printStackTrace();
120 }
121 }
122
123 return map;
124 }
125
126 /**
127 * the method returns the scale of the map defined as diagonal size of a pixel at the center of the map.
128 */
129 protected double getScale( GetMap mrm ) {
130 double minx = mrm.getBoundingBox().getMin().getX();
131 double maxx = mrm.getBoundingBox().getMax().getX();
132 double miny = mrm.getBoundingBox().getMin().getY();
133 double maxy = mrm.getBoundingBox().getMax().getY();
134 double width = mrm.getWidth();
135 double height = mrm.getHeight();
136
137 double sx = Math.sqrt( Math.pow( maxx - minx, 2 ) + Math.pow( maxy - miny, 2 ) );
138 double px = Math.sqrt( width * width + height * height );
139
140 return sx / px;
141 }
142 }