1<%-- $HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/apps/igeoportal-standard/branches/2.5_testing/modules/gazetteer/gaz_take.jsp $
2 This file is part of deegree, http://deegree.org/
3 Copyright (C) 2001-2009 by:
4 - Department of Geography, University of Bonn -
5 and
6 - lat/lon GmbH -
7
8 This library is free software; you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License as published by the Free
10 Software Foundation; either version 2.1 of the License, or (at your option)
11 any later version.
12 This library is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this library; if not, write to the Free Software Foundation, Inc.,
18 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 Contact information:
21
22 lat/lon GmbH
23 Aennchenstr. 19, 53177 Bonn
24 Germany
25 http://lat-lon.de/
26
27 Department of Geography, University of Bonn
28 Prof. Dr. Klaus Greve
29 Postfach 1147, 53001 Bonn
30 Germany
31 http://www.geographie.uni-bonn.de/deegree/
32
33 e-mail: info@deegree.org
34--%>
35<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
36<%@ page import="org.deegree.model.feature.Feature" %>
37<%@ page import="org.deegree.model.feature.FeatureCollection" %>
38<%@ page import="org.deegree.model.spatialschema.Envelope" %>
39<%@ page import="org.deegree.model.spatialschema.Geometry" %>
40<%@ page import="org.deegree.model.spatialschema.GeometryFactory"%>
41<%@ page import="org.deegree.model.spatialschema.Point"%>
42<%@ page import="org.deegree.model.spatialschema.Position"%>
43<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
44<html>
45	<head>
46		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
47		<meta name="author" content="Judit Mays, lat/lon GmbH">
48        <meta name="KeyWords" content="deegree iGeoPortal lat/lon" />
49        <title>WFS Gazetteer</title>
50        <link href="../../css/deegree.css" rel="stylesheet" type="text/css" />
51
52		<%
53	    FeatureCollection  fc = (FeatureCollection)request.getAttribute( "RESULT" );
54		Feature feature = null;
55		if ( fc.size() == 0 ) {
56		    System.out.println( "WARNING: feature is null" );
57		} else {
58		    feature = fc.getFeature(0);
59			//System.out.println( "DEBUG: feature = " + feature );
60		}
61		%>
62
63	    <script LANGUAGE='JavaScript1.2' TYPE='text/javascript' src='./javascript/event.js'></script>
64	    <script LANGUAGE='JavaScript1.2' TYPE='text/javascript' src='./javascript/envelope.js'></script>
65	    <script language="JavaScript1.2">
66		<!--
67
68		function performOnLoad() {
69			parent.ifdocument = document;
70			performZoomTo();
71		}
72
73		function close() {
74			parent.window.close();
75		}
76
77		function performZoomTo() {
78		<%
79			if ( feature != null ) {
80			    Geometry[] geoms = feature.getGeometryPropertyValues();
81
82                if ( geoms != null && geoms.length > 0 ){
83                    // FIXME calculate combining bbox for all geoms
84                    Envelope env = null;
85
86                    final double buffer = 50.0; // HINT: buffer value might need adjustment
87                    if ( geoms[0] instanceof Point ) {
88                        Point p = (Point)geoms[0];
89                        Position pos = p.getPosition();
90                        env = GeometryFactory.createEnvelope( pos.getX()-buffer, pos.getY()-buffer,
91                                                              pos.getX()+buffer, pos.getY()+buffer,
92                                                              p.getCoordinateSystem() );
93                    } else {
94                        env = geoms[0].getEnvelope();
95                    }
96
97					if ( env == null ) {
98					    out.println( "alert( 'envelope is null' )" );
99					} else {
100					    //System.out.println("before: " + env );
101					    // value "75" might need to be adjusted
102					    if( env.getWidth() < 75 || env.getHeight() < 75 ){
103							// increase envelope because it is too small
104							// factor "20" might need to be adjusted
105							final double expansionFactor = 20;
106							env = env.getBuffer( expansionFactor );
107					    }
108						//System.out.println("after: " + env );
109
110						double minx = env.getMin().getX();
111						double miny = env.getMin().getY();
112						double maxx = env.getMax().getX();
113						double maxy = env.getMax().getY();
114						// correct box width/height to the right aspect ratio
115						double factor = 1.0; //its the aspect ratio of the map. adapt it if needed.
116						if ( env.getWidth()  > ( env.getHeight() * factor ) ) {
117							double d2 = (env.getWidth()/2d)/factor;
118							double mid = miny + env.getHeight()/2d;
119							miny = mid - d2;
120							maxy = mid + d2;
121						} else {
122							double d2 = ( env.getHeight()/2d ) * factor;
123							double mid = minx + env.getWidth()/2d;
124							minx = mid - d2;
125							maxx = mid + d2;
126						}
127
128						out.println( "var env = new Envelope( " +  minx + "," + miny  + "," + maxx + "," + maxy +  " );" );
129						out.println( "var event = new Event( '', 'BBOX', env );" );
130
131                        // If you are running the gazetteer module with gazmodule.html and gazwindow.jsp
132                        // (running the module in its own window)
133                        // then you find the controller at "parent.parent.opener.parent.controller".
134                        // If you are running the gazetteer module with gazmodule_mw.html
135                        // (running the module in the portals main window)
136                        // then you find the controller at "parent.parent.parent.controller".
137						// (also including hack to force update of scale switcher)
138
139                        out.println( "if ( parent.parent.opener != null ) {" );
140							out.println( "parent.parent.opener.parent.controller.actionPerformed( event );" );
141							out.println( "parent.parent.opener.parent.controller.vScaleSwitcher.getActualScaleValue();" );
142						out.println( "} else {" );
143                        	out.println( "parent.parent.parent.controller.actionPerformed( event );" );
144							out.println( "parent.parent.parent.controller.vScaleSwitcher.getActualScaleValue();" );
145                        out.println( "}" );
146					}
147	            } else {
148	            	out.println( "alert( 'The chosen entity has no geometry.' );" );
149	            }
150			} else {
151				out.println( "alert( 'No matches found!');" );
152			}
153		%>
154		}
155
156		//-->
157		</script>
158	</head>
159	<body onload="performOnLoad();">
160		<form action="" id="form" method="post"></form>
161	</body>
162</html>
163