[Schmitzm-commits] r727 - in trunk/src: schmitzm/geotools/feature skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Feb 25 20:59:03 CET 2010


Author: alfonx
Date: 2010-02-25 20:59:02 +0100 (Thu, 25 Feb 2010)
New Revision: 727

Modified:
   trunk/src/schmitzm/geotools/feature/FeatureUtil.java
   trunk/src/skrueger/geotools/XMapPane.java
   trunk/src/skrueger/geotools/XMapPaneAction_Zoom.java
Log:
Trying to make raster clicks blink too.

Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-02-25 18:53:58 UTC (rev 726)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-02-25 19:59:02 UTC (rev 727)
@@ -286,7 +286,8 @@
 	 *            a map layer
 	 */
 	public static GeometryForm getGeometryForm(MapLayer layer) {
-		return getGeometryForm((SimpleFeatureType) layer.getFeatureSource().getSchema());
+		return getGeometryForm((SimpleFeatureType) layer.getFeatureSource()
+				.getSchema());
 	}
 
 	/**
@@ -521,7 +522,7 @@
 					if (includeNullFeatures || f != null)
 						fv.add(f);
 				} catch (Exception e) {
-					LOGGER.info("error reading a feature, but continuing",e);
+					LOGGER.info("error reading a feature, but continuing", e);
 					// If reading one features fails (as it happens a lot with
 					// OSM data, we still want the others to appear
 					// Caused by: java.lang.IllegalArgumentException: Points of
@@ -545,7 +546,6 @@
 
 		return fv.toArray(new SimpleFeature[0]);
 	}
-	
 
 	/**
 	 * Clones an {@link SimpleFeatureType}.
@@ -614,70 +614,80 @@
 				aType.getType().getBinding(), nillable, restrictions,
 				defaultValue, metaData);
 	}
-	
-    /**
-     * Applies the following restrictions to an attribute name.
-     * <ul>
-     *   <li>Truncates white spaces at start and end.</li>
-     *   <li>Truncates name to 10 characters</li>
-     *   <li>Transforms name to upper case letters</li>
-     * </ul>
-     * @param attrName an attribute name
-     * @see #checkAttributeNameRestrictionsAndError(String)
-     */
-    public static String applyAttributeNameRestrictions(String attrName) {
-      // NULL not allowed
-      if ( attrName != null ) {
-        attrName = attrName.trim();
-        attrName = attrName.toUpperCase();
-        if ( attrName.length() > 10 )
-          attrName = attrName.substring(0,10);
-      }
-      return attrName;
-    }
-    
-    /**
-     * Throws an exception if an attribute name does not satisfy all of
-     * the following restrictions.
-     * <ul>
-     *   <li>{@code null} and empty string not allowed</li>
-     *   <li>Maximum of 10 characters</li>
-     *   <li>Starting with a letter (a-z,A-Z)</li>
-     *   <li>Only combination of letters (a-z,A-Z), digits (0-9) and '_'</li>
-     * </ul>
-     * @param attrName an attribute name
-     * @see #checkAttributeNameRestrictionsAndError(String)
-     */
-	public static void checkAttributeNameRestrictionsAndError(String attrName) throws Exception {
-	  // NULL not allowed
-	  if ( attrName == null || attrName.trim().equals("") )
-	    throw new Exception( RESOURCE.getString("org.geotools.err.attr.name.null") );
-	  // Maximum 10 characters
-	  if ( attrName.length() > 10 )
-	    throw new Exception( RESOURCE.getString("org.geotools.err.attr.name.length") );
-	  // Digit not allowed as first character
-	  if ( !attrName.matches("[a-zA-Z].*") )
-	    throw new Exception( RESOURCE.getString("org.geotools.err.attr.name.start") );
-      // Only "normal" characters, digits and '_' allowed
-      if ( !attrName.matches("\\w+") )
-        throw new Exception( RESOURCE.getString("org.geotools.err.attr.name.chars") );
+
+	/**
+	 * Applies the following restrictions to an attribute name.
+	 * <ul>
+	 * <li>Truncates white spaces at start and end.</li>
+	 * <li>Truncates name to 10 characters</li>
+	 * <li>Transforms name to upper case letters</li>
+	 * </ul>
+	 * 
+	 * @param attrName
+	 *            an attribute name
+	 * @see #checkAttributeNameRestrictionsAndError(String)
+	 */
+	public static String applyAttributeNameRestrictions(String attrName) {
+		// NULL not allowed
+		if (attrName != null) {
+			attrName = attrName.trim();
+			attrName = attrName.toUpperCase();
+			if (attrName.length() > 10)
+				attrName = attrName.substring(0, 10);
+		}
+		return attrName;
 	}
 
 	/**
+	 * Throws an exception if an attribute name does not satisfy all of the
+	 * following restrictions.
+	 * <ul>
+	 * <li>{@code null} and empty string not allowed</li>
+	 * <li>Maximum of 10 characters</li>
+	 * <li>Starting with a letter (a-z,A-Z)</li>
+	 * <li>Only combination of letters (a-z,A-Z), digits (0-9) and '_'</li>
+	 * </ul>
+	 * 
+	 * @param attrName
+	 *            an attribute name
+	 * @see #checkAttributeNameRestrictionsAndError(String)
+	 */
+	public static void checkAttributeNameRestrictionsAndError(String attrName)
+			throws Exception {
+		// NULL not allowed
+		if (attrName == null || attrName.trim().equals(""))
+			throw new Exception(RESOURCE
+					.getString("org.geotools.err.attr.name.null"));
+		// Maximum 10 characters
+		if (attrName.length() > 10)
+			throw new Exception(RESOURCE
+					.getString("org.geotools.err.attr.name.length"));
+		// Digit not allowed as first character
+		if (!attrName.matches("[a-zA-Z].*"))
+			throw new Exception(RESOURCE
+					.getString("org.geotools.err.attr.name.start"));
+		// Only "normal" characters, digits and '_' allowed
+		if (!attrName.matches("\\w+"))
+			throw new Exception(RESOURCE
+					.getString("org.geotools.err.attr.name.chars"));
+	}
+
+	/**
 	 * Checks whether an attribute name satisfies all restrictions.
-	 * @param attrName an attribute name
+	 * 
+	 * @param attrName
+	 *            an attribute name
 	 * @see #checkAttributeNameRestrictionsAndError(String)
 	 */
 	public static boolean checkAttributeNameRestrictions(String attrName) {
-	  try {
-	    checkAttributeNameRestrictionsAndError(attrName);
-	  } catch (Exception err) {
-	    return false;
-	  }
-	  return true;
+		try {
+			checkAttributeNameRestrictionsAndError(attrName);
+		} catch (Exception err) {
+			return false;
+		}
+		return true;
 	}
 
-	
 	/**
 	 * Erweitert das Schema einer {@link FeatureCollection} um eine Reihe von
 	 * Attributen.
@@ -1656,19 +1666,40 @@
 	}
 
 	/**
-	 * Creates a default {@link SimpleFeatureType} for a given Geometry class
+	 * Creates a default {@link SimpleFeatureType} for a given {@link Geometry}
+	 * class. The {@link CoordinateReferenceSystem} of the geometry property
+	 * will be null.
 	 * 
 	 * @param geomType
 	 *            LineString.class, Point.class or Polygon.class from com.jts...
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
 	 *         Kr&uuml;ger</a>
 	 */
+
 	public static SimpleFeatureType createFeatureType(final Class<?> geomType) {
+		return createFeatureType(geomType, null);
+	}
+
+	/**
+	 * Creates a default {@link SimpleFeatureType} for a given {@link Geometry}
+	 * class
+	 * 
+	 * @param geomType
+	 *            LineString.class, Point.class or Polygon.class from com.jts...
+	 *            
+	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+	 *         Kr&uuml;ger</a>
+	 */
+	public static SimpleFeatureType createFeatureType(final Class<?> geomType,
+			CoordinateReferenceSystem crs) {
 		// Create the only attribute
 		final AttributeDescriptor geometryAttribut = AttributeTypeFactory
 				.newAttributeType("the_geom", geomType);
+		
 		// Create the FeatureType with the only attribute
 		final SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
+		builder.setCRS(crs);
+		CoordinateReferenceSystem crs2 = builder.getCRS();
 		builder.setName(geomType.getSimpleName());
 		builder.add(geometryAttribut);
 		return builder.buildFeatureType();
@@ -1864,10 +1895,10 @@
 			Object... values) {
 		SimpleFeature sampleFeature;
 
-		//MS: Sind keine Attribut-Werte angegeben, Standard-Werte (insb.
-		//    fuer die etwaige Geometrie generieren)
-		if ( values.length == 0 )
-		  values = getDefaultAttributeValues(schema);
+		// MS: Sind keine Attribut-Werte angegeben, Standard-Werte (insb.
+		// fuer die etwaige Geometrie generieren)
+		if (values.length == 0)
+			values = getDefaultAttributeValues(schema);
 
 		try {
 			SimpleFeatureBuilder builder = new SimpleFeatureBuilder(schema);

Modified: trunk/src/skrueger/geotools/XMapPane.java
===================================================================
--- trunk/src/skrueger/geotools/XMapPane.java	2010-02-25 18:53:58 UTC (rev 726)
+++ trunk/src/skrueger/geotools/XMapPane.java	2010-02-25 19:59:02 UTC (rev 727)
@@ -2533,8 +2533,9 @@
 	 *            position in window coordinates
 	 * @param zoomFaktor
 	 *            > 1 for zoom out, < 1 for zoom in. Default is .5
+	 * @retun <code>true</code> if {@link #mapArea} has changed and a repaint is triggered
 	 */
-	public void zoomTo(Point center, Double zoomFaktor) {
+	public boolean zoomTo(Point center, Double zoomFaktor) {
 		if (zoomFaktor == null || zoomFaktor == 0.)
 			zoomFaktor = .5;
 
@@ -2547,7 +2548,7 @@
 
 		) {
 			// Not inside valid CRS area! cancel
-			return;
+			return false;
 		}
 
 		final Envelope mapArea = getMapArea();
@@ -2562,9 +2563,46 @@
 				.getY()
 				- mapArea.centre().y);
 
-		setMapArea(newMapArea);
+		return setMapArea(newMapArea);
 	}
+	
+	/**
+	 * Zooms in or out in a way, that the given {@link Point} on the map stays at the same positino in screen coordinates.
+	 * @param point fixed {@link Point} that will be at the same screen poistion after zoom.
+	 */
+	public boolean zoomTowards(Point point, Double zFactor) {
+//        int units = wheelEvt.getUnitsToScroll();
+        // 
+        // Negativer Wert --> Zoom out --> Faktir > 1
 
+        // SK: 9.9.2007 zoom jetzt wie bei GoogleEarth
+//        double zFactor = units > 0 ? 1.3 : 1 / 1.3;
+        // vorher double zFactor = units > 0 ? 1/1.2 : 1.2;
+
+        // Fenster-Koordinaten zu Karten-Koordinaten transformieren
+//        Point2D mapCoord = XMapPane.getMapCoordinatesFromEvent(wheelEvt);
+        // Relative Position des Mauszeigers zum Kartenausschnitt
+        // -> Nach Zoom soll dieselbe Kartenposition unterhalb des Mauszeigers
+        // erscheinen, wie vor dem Zoom
+		final Point2D mapCoord = getScreenToWorld().transform(point, null);
+		
+        double relX = (mapCoord.getX() - getMapArea().getMinX())
+                / getMapArea().getWidth();
+        double relY = (mapCoord.getY() - getMapArea().getMinY())
+                / getMapArea().getHeight();
+
+        // Neuen Karten-Ausschnitt berechnen
+        Coordinate ll = new Coordinate(mapCoord.getX()
+                - getMapArea().getWidth() * relX * zFactor, mapCoord.getY()
+                - getMapArea().getHeight() * relY * zFactor);
+        Coordinate ur = new Coordinate(mapCoord.getX()
+                + getMapArea().getWidth() * (1 - relX) * zFactor, mapCoord
+                .getY()
+                + getMapArea().getHeight() * (1 - relY) * zFactor);
+        
+        return setMapArea(new Envelope(ll, ur));
+	}
+
 	/**
 	 * Shall non-fatal rendering exceptions be reported in the mappane or be
 	 * dropped quitely.

Modified: trunk/src/skrueger/geotools/XMapPaneAction_Zoom.java
===================================================================
--- trunk/src/skrueger/geotools/XMapPaneAction_Zoom.java	2010-02-25 18:53:58 UTC (rev 726)
+++ trunk/src/skrueger/geotools/XMapPaneAction_Zoom.java	2010-02-25 19:59:02 UTC (rev 727)
@@ -4,7 +4,6 @@
 import java.awt.Rectangle;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseWheelEvent;
-import java.awt.geom.Point2D;
 
 import org.opengis.geometry.DirectPosition;
 
@@ -34,40 +33,39 @@
 		public void performClick(XMapPane mapPane, MouseEvent ev,
 				DirectPosition coord) {
 
-			mapPane.zoomTo(ev.getPoint(), 1 / 2.);
+//			mapPane.zoomTo(ev.getPoint(), 1 / 2.);
+			
+			mapPane.zoomTowards(ev.getPoint(), 1/1.3);
 		}
 
 		@Override
 		public void performWheel(XMapPane mapPane, MouseWheelEvent wheelEvt,
 				DirectPosition coord) {
-
-	        int units = wheelEvt.getUnitsToScroll();
-	        // Positiver Wert --> Zoom in --> Faktor < 1
-	        // Negativer Wert --> Zoom out --> Faktir > 1
-
-	        // SK: 9.9.2007 zoom jetzt wie bei GoogleEarth
-	        double zFactor = units > 0 ? 1.3 : 1 / 1.3;
-	        // vorher double zFactor = units > 0 ? 1/1.2 : 1.2;
-
-	        // Fenster-Koordinaten zu Karten-Koordinaten transformieren
-	        Point2D mapCoord = XMapPane.getMapCoordinatesFromEvent(wheelEvt);
-	        // Relative Position des Mauszeigers zum Kartenausschnitt
-	        // -> Nach Zoom soll dieselbe Kartenposition unterhalb des Mauszeigers
-	        // erscheinen, wie vor dem Zoom
-	        double relX = (mapCoord.getX() - mapPane.getMapArea().getMinX())
-	                / mapPane.getMapArea().getWidth();
-	        double relY = (mapCoord.getY() - mapPane.getMapArea().getMinY())
-	                / mapPane.getMapArea().getHeight();
-
-	        // Neuen Karten-Ausschnitt berechnen
-	        Coordinate ll = new Coordinate(mapCoord.getX()
-	                - mapPane.getMapArea().getWidth() * relX * zFactor, mapCoord.getY()
-	                - mapPane.getMapArea().getHeight() * relY * zFactor);
-	        Coordinate ur = new Coordinate(mapCoord.getX()
-	                + mapPane.getMapArea().getWidth() * (1 - relX) * zFactor, mapCoord
-	                .getY()
-	                + mapPane.getMapArea().getHeight() * (1 - relY) * zFactor);
-	        mapPane.setMapArea(new Envelope(ll, ur));
+			
+	        double zFactor = wheelEvt.getUnitsToScroll() > 0 ? 1.3 : 1 / 1.3;
+	        mapPane.zoomTowards(wheelEvt.getPoint(), zFactor);
+	        
+//	        // vorher double zFactor = units > 0 ? 1/1.2 : 1.2;
+//
+//	        // Fenster-Koordinaten zu Karten-Koordinaten transformieren
+//	        Point2D mapCoord = XMapPane.getMapCoordinatesFromEvent(wheelEvt);
+//	        // Relative Position des Mauszeigers zum Kartenausschnitt
+//	        // -> Nach Zoom soll dieselbe Kartenposition unterhalb des Mauszeigers
+//	        // erscheinen, wie vor dem Zoom
+//	        double relX = (mapCoord.getX() - mapPane.getMapArea().getMinX())
+//	                / mapPane.getMapArea().getWidth();
+//	        double relY = (mapCoord.getY() - mapPane.getMapArea().getMinY())
+//	                / mapPane.getMapArea().getHeight();
+//
+//	        // Neuen Karten-Ausschnitt berechnen
+//	        Coordinate ll = new Coordinate(mapCoord.getX()
+//	                - mapPane.getMapArea().getWidth() * relX * zFactor, mapCoord.getY()
+//	                - mapPane.getMapArea().getHeight() * relY * zFactor);
+//	        Coordinate ur = new Coordinate(mapCoord.getX()
+//	                + mapPane.getMapArea().getWidth() * (1 - relX) * zFactor, mapCoord
+//	                .getY()
+//	                + mapPane.getMapArea().getHeight() * (1 - relY) * zFactor);
+//	        mapPane.setMapArea(new Envelope(ll, ur));
 		}
 
 		@Override
@@ -139,39 +137,45 @@
 		public void performClick(XMapPane mapPane, MouseEvent ev,
 				DirectPosition coord) {
 
-			mapPane.zoomTo(ev.getPoint(), 2.);
+//			mapPane.zoomTo(ev.getPoint(), 2.);
+			
+			mapPane.zoomTowards(ev.getPoint(), 1.3);
 		}
 
 		@Override
 		public void performWheel(XMapPane mapPane, MouseWheelEvent wheelEvt,
 				DirectPosition coord) {
-          int units = wheelEvt.getUnitsToScroll();
-          // Positiver Wert --> Zoom in --> Faktor < 1
-          // Negativer Wert --> Zoom out --> Faktir > 1
+			
+	        double zFactor = wheelEvt.getUnitsToScroll() > 0 ? 1.3 : 1 / 1.3;
+	        mapPane.zoomTowards(wheelEvt.getPoint(), zFactor);
 
-          // SK: 9.9.2007 zoom jetzt wie bei GoogleEarth
-          double zFactor = units > 0 ? 1.3 : 1 / 1.3;
-          // vorher double zFactor = units > 0 ? 1/1.2 : 1.2;
-
-          // Fenster-Koordinaten zu Karten-Koordinaten transformieren
-          Point2D mapCoord = XMapPane.getMapCoordinatesFromEvent(wheelEvt);
-          // Relative Position des Mauszeigers zum Kartenausschnitt
-          // -> Nach Zoom soll dieselbe Kartenposition unterhalb des Mauszeigers
-          // erscheinen, wie vor dem Zoom
-          double relX = (mapCoord.getX() - mapPane.getMapArea().getMinX())
-                  / mapPane.getMapArea().getWidth();
-          double relY = (mapCoord.getY() - mapPane.getMapArea().getMinY())
-                  / mapPane.getMapArea().getHeight();
-
-          // Neuen Karten-Ausschnitt berechnen
-          Coordinate ll = new Coordinate(mapCoord.getX()
-                  - mapPane.getMapArea().getWidth() * relX * zFactor, mapCoord.getY()
-                  - mapPane.getMapArea().getHeight() * relY * zFactor);
-          Coordinate ur = new Coordinate(mapCoord.getX()
-                  + mapPane.getMapArea().getWidth() * (1 - relX) * zFactor, mapCoord
-                  .getY()
-                  + mapPane.getMapArea().getHeight() * (1 - relY) * zFactor);
-          mapPane.setMapArea(new Envelope(ll, ur));
+//          int units = wheelEvt.getUnitsToScroll();
+//          // Positiver Wert --> Zoom in --> Faktor < 1
+//          // Negativer Wert --> Zoom out --> Faktir > 1
+//
+//          // SK: 9.9.2007 zoom jetzt wie bei GoogleEarth
+//          double zFactor = units > 0 ? 1.3 : 1 / 1.3;
+//          // vorher double zFactor = units > 0 ? 1/1.2 : 1.2;
+//
+//          // Fenster-Koordinaten zu Karten-Koordinaten transformieren
+//          Point2D mapCoord = XMapPane.getMapCoordinatesFromEvent(wheelEvt);
+//          // Relative Position des Mauszeigers zum Kartenausschnitt
+//          // -> Nach Zoom soll dieselbe Kartenposition unterhalb des Mauszeigers
+//          // erscheinen, wie vor dem Zoom
+//          double relX = (mapCoord.getX() - mapPane.getMapArea().getMinX())
+//                  / mapPane.getMapArea().getWidth();
+//          double relY = (mapCoord.getY() - mapPane.getMapArea().getMinY())
+//                  / mapPane.getMapArea().getHeight();
+//
+//          // Neuen Karten-Ausschnitt berechnen
+//          Coordinate ll = new Coordinate(mapCoord.getX()
+//                  - mapPane.getMapArea().getWidth() * relX * zFactor, mapCoord.getY()
+//                  - mapPane.getMapArea().getHeight() * relY * zFactor);
+//          Coordinate ur = new Coordinate(mapCoord.getX()
+//                  + mapPane.getMapArea().getWidth() * (1 - relX) * zFactor, mapCoord
+//                  .getY()
+//                  + mapPane.getMapArea().getHeight() * (1 - relY) * zFactor);
+//          mapPane.setMapArea(new Envelope(ll, ur));
 		}
 
 



More information about the Schmitzm-commits mailing list