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