[Schmitzm-commits] r541 - branches/1.0-gt2-2.6/src/skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Nov 20 22:49:01 CET 2009


Author: alfonx
Date: 2009-11-20 22:49:00 +0100 (Fri, 20 Nov 2009)
New Revision: 541

Modified:
   branches/1.0-gt2-2.6/src/skrueger/geotools/GeomFilterGenerator.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/SelectXMapPaneMouseListener.java
Log:
* Basically fixed the click bug.. now have to do some cleanup and  optimizations

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/GeomFilterGenerator.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/GeomFilterGenerator.java	2009-11-20 19:34:50 UTC (rev 540)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/GeomFilterGenerator.java	2009-11-20 21:49:00 UTC (rev 541)
@@ -135,8 +135,14 @@
 		 */
 		protected GeometryFilterImpl prepareFilter(CoordinateReferenceSystem crs) {
 			Envelope bbEnv = baseEnv;
+			
+			System.out.println("base Envv = "+baseEnv);
+			
 			if (!CRS.equalsIgnoreMetadata(baseCRS,crs))
 				bbEnv = JTSUtil.transformEnvelope(baseEnv, baseCRS, crs);
+			
+			System.out.println("thetransformed env = "+bbEnv);
+			
 			// Filter fuer Envelope zusammenstellen
 			Expression bbox = FilterUtil.FILTER_FAC.createBBoxExpression(bbEnv);
 			GeometryFilterImpl bboxFilter = (GeometryFilterImpl) FilterUtil.FILTER_FAC

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/SelectXMapPaneMouseListener.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/SelectXMapPaneMouseListener.java	2009-11-20 19:34:50 UTC (rev 540)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/SelectXMapPaneMouseListener.java	2009-11-20 21:49:00 UTC (rev 541)
@@ -54,18 +54,18 @@
 			;
 		return enabled;
 	}
-
-	/**
-	 * Default distance fraction used with line and point features. When the
-	 * user clicks on the map, this tool searches for features within a
-	 * rectangle of width w centred on the mouse location, where w is the
-	 * average map side length multiplied by the value of this constant.
-	 */
-	public static final double DEFAULT_DISTANCE_FRACTION = 0.01d;
-	
-
-    private WeakHashMap<MapLayer, InfoToolHelper> helperTable= new WeakHashMap<MapLayer, InfoToolHelper>();
 //
+//	/**
+//	 * Default distance fraction used with line and point features. When the
+//	 * user clicks on the map, this tool searches for features within a
+//	 * rectangle of width w centred on the mouse location, where w is the
+//	 * average map side length multiplied by the value of this constant.
+//	 */
+//	public static final double DEFAULT_DISTANCE_FRACTION = 0.01d;
+//	
+//
+//    private WeakHashMap<MapLayer, InfoToolHelper> helperTable= new WeakHashMap<MapLayer, InfoToolHelper>();
+////
 //	@Override
 //	public void mouseClicked2(MouseEvent event) {
 //		AffineTransform tr = xMapPane.getScreenToWorld();
@@ -187,7 +187,13 @@
 //			}
 //		}
 //	}
-
+	  /**
+     * Default distance fraction used with line and point features.
+     * When the user clicks on the map, this tool searches for features within
+     * a rectangle of width w centred on the mouse location, where w is the
+     * average map side length multiplied by the value of this constant.
+     */
+    public static final double DEFAULT_DISTANCE_FRACTION = 0.01d;
 	/**
 	 * Reagiert auf Linksklick mit der ueber {@link #setState(int)}eingestellten
 	 * Aktion und auf Rechtsklick mit Zoom-Out (sofern {@link #ZOOM_IN}-State
@@ -223,17 +229,19 @@
 				null);
 
 		// new VectorLayerHelper(layer, geomAttributeName, geomClass)
-
+//
 		com.vividsolutions.jts.geom.Point mousePoint = new GeometryFactory()
 				.createPoint(new Coordinate(geoCoord.getX(), geoCoord.getY()));
+//
+//		// Rechnet 10 Pixel in die Einheit der Karte um.
+//		final Point pAtDistance = new Point((int) e.getPoint().getX() + 10,
+//				(int) e.getPoint().getY());
+//		final Point2D geoCoordAtDistance = xMapPane.getScreenToWorld()
+//				.transform(pAtDistance, null);
+//		final Double dist = Math.abs(geoCoordAtDistance.getX()
+//				- geoCoord.getX()) / 2;
+		
 
-		// Rechnet 10 Pixel in die Einheit der Karte um.
-		final Point pAtDistance = new Point((int) e.getPoint().getX() + 10,
-				(int) e.getPoint().getY());
-		final Point2D geoCoordAtDistance = xMapPane.getScreenToWorld()
-				.transform(pAtDistance, null);
-		final Double dist = Math.abs(geoCoordAtDistance.getX()
-				- geoCoord.getX()) / 2;
 
 		// final Envelope envelope = new Envelope(geoCoord.getX(),
 		// geoCoord.getY(), geoCoord.getX(), geoCoord.getY());
@@ -254,15 +262,22 @@
 		// state, envelope);
 
 		// envelope.expandBy(dist);
-		//
-		Envelope envelope = new Envelope(geoCoord.getX() - dist, geoCoord
-				.getY()
-				- dist, geoCoord.getX() + dist, geoCoord.getY() + dist);
+//		//
+//		Envelope envelope = new Envelope(geoCoord.getX() - dist, geoCoord
+//				.getY()
+//				- dist, geoCoord.getX() + dist, geoCoord.getY() + dist);
+		double radius = DEFAULT_DISTANCE_FRACTION * (xMapPane.getMapArea().getWidth() + xMapPane.getMapArea().getHeight()) / 2;
+        ReferencedEnvelope searchBounds = new ReferencedEnvelope(
+        		geoCoord.getX() - radius,
+        		geoCoord.getX() + radius,
+        		geoCoord.getY() - radius,
+        		geoCoord.getY() + radius,
+                xMapPane.getContext().getCoordinateReferenceSystem());
 
 		Hashtable<MapLayer, FeatureCollection<SimpleFeatureType, SimpleFeature>> result = xMapPane
-				.findVisibleFeatures(new BoundingBoxFilterGenerator(envelope,
+				.findVisibleFeatures(new BoundingBoxFilterGenerator(searchBounds,
 						xMapPane.getContext().getCoordinateReferenceSystem()),
-						state, envelope);
+						state, searchBounds);
 
 		// Ein Event auslösen für das jeweils nächste Feature pro Layer
 		for (Enumeration<MapLayer> element = result.keys(); element
@@ -284,14 +299,21 @@
 
 					Iterator<SimpleFeature> fcIt = fc.iterator();
 					try {
+						
+						System.out.println("mosue = "+mousePoint);
 
 						while (fcIt.hasNext()) {
 							SimpleFeature f = fcIt.next();
-							Object obj = f.getAttribute(0);
+							Object obj = f.getDefaultGeometryProperty().getValue();
 
 							if (obj instanceof Geometry) {
-								// Bei Punkten ja noch ganz einfach:
+
+								// TODO Hier muss doch irgendwie noch CRS umgewrechnet werden... 
+								
 								Geometry featureGeometry = (Geometry) obj;
+								
+								System.out.println(f.getID()+" "+featureGeometry);
+								
 								double distance = featureGeometry
 										.distance(mousePoint);
 
@@ -299,6 +321,7 @@
 										|| (distance < nearestDist)) {
 									nearestFeature = f;
 									nearestDist = distance;
+									System.out.println("new nearest = "+f.getID()+":"+featureGeometry);
 								}
 							} else {
 								LOGGER
@@ -320,7 +343,7 @@
 					fcOne = fc;
 				}
 				xMapPane.fireMapPaneEvent(new FeatureSelectedEvent(xMapPane,
-						layer, envelope, fcOne));
+						layer, searchBounds, fcOne));
 			}
 		}
 



More information about the Schmitzm-commits mailing list