[Schmitzm-commits] r1356 - in trunk: . src/schmitzm/geotools/feature src/schmitzm/geotools/gui src/schmitzm/geotools/map/event src/schmitzm/geotools/styling src_junit/schmitzm/geotools/gui
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Dec 20 01:46:47 CET 2010
Author: alfonx
Date: 2010-12-20 01:46:12 +0100 (Mon, 20 Dec 2010)
New Revision: 1356
Modified:
trunk/pom.xml
trunk/src/schmitzm/geotools/feature/FeatureUtil.java
trunk/src/schmitzm/geotools/gui/GeoMapPane.java
trunk/src/schmitzm/geotools/gui/ScalePane.java
trunk/src/schmitzm/geotools/gui/ScalePanel.java
trunk/src/schmitzm/geotools/gui/SelectableXMapPane.java
trunk/src/schmitzm/geotools/gui/XMapPane.java
trunk/src/schmitzm/geotools/map/event/ScaleChangedEvent.java
trunk/src/schmitzm/geotools/styling/StylingUtil.java
trunk/src_junit/schmitzm/geotools/gui/XMapPaneTest.java
Log:
AS: Improving the GUI to deal with new complexity of min & max scale denominators
AS: Now shows scale in OGC ScaleDenominator
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-12-18 22:36:54 UTC (rev 1355)
+++ trunk/pom.xml 2010-12-20 00:46:12 UTC (rev 1356)
@@ -187,15 +187,15 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
-<!---->
- <!-- <dependency> -->
- <!-- <groupId>org.slf4j</groupId> -->
- <!-- <artifactId>slf4j-log4j12</artifactId> -->
- <!-- <version>1.5.11</version> -->
- <!-- <type>jar</type> -->
- <!-- <scope>compile</scope> -->
- <!-- </dependency> -->
+<!-- <dependency>-->
+<!-- <groupId>org.slf4j</groupId>-->
+<!-- <artifactId>slf4j-log4j12</artifactId>-->
+<!-- <version>1.5.11</version>-->
+<!-- <type>jar</type>-->
+<!-- <scope>compile</scope>-->
+<!-- </dependency>-->
+
<dependency>
<!-- Logging with log4j. Die MVN dependency fuer 1.2.15 ist defekt. downgraded
to 1.2.14 http://jira.codehaus.org/browse/MEV-649 -->
Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java 2010-12-18 22:36:54 UTC (rev 1355)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java 2010-12-20 00:46:12 UTC (rev 1356)
@@ -2297,7 +2297,10 @@
LOGGER.info("avgNN for " + styledFeatures.getTitle() + " is " + avgNN
+ " in " + unit);
- double inMeter = unit.getConverterTo(SI.METER).convert(avgNN);
+ // double inMeter = unit.getConverterTo(SI.METER).convert(avgNN);
+ // TODO
+ // if (nuit )
+ double inMeter = avgNN;
double inPixels = inMeter * 100 * 10 / 0.28;
@@ -2447,11 +2450,12 @@
if (bestmatch == null && schema.getAttributeDescriptors().size() > 0) {
for (AttributeDescriptor ad : schema.getAttributeDescriptors()) {
- if (!(Geometry.class.isAssignableFrom(ad.getType().getBinding())))
+ if (!(Geometry.class
+ .isAssignableFrom(ad.getType().getBinding())))
return ad.getName();
}
}
-
+
return bestmatch;
}
Modified: trunk/src/schmitzm/geotools/gui/GeoMapPane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/GeoMapPane.java 2010-12-18 22:36:54 UTC (rev 1355)
+++ trunk/src/schmitzm/geotools/gui/GeoMapPane.java 2010-12-20 00:46:12 UTC (rev 1356)
@@ -107,7 +107,7 @@
* werden koennen.
*/
protected JPanel mapPanePanel = null;
-
+
/** Massstab-Balken */
private ScalePane scalePane = null;
/**
@@ -214,45 +214,43 @@
public void performMapPaneEvent(XMapPaneEvent e) {
if (e instanceof ScaleChangedEvent) {
ScaleChangedEvent sce = (ScaleChangedEvent) e;
-
-
// If ScalePane expects the units in METERS always. In case
// the CRS is not in meters, we convert it to EPSG:3785,
// which is meter worldwide.
-
+
CoordinateReferenceSystem mapCrs = getMapPane()
.getMapContext().getCoordinateReferenceSystem();
CoordinateSystem cs = mapCrs.getCoordinateSystem();
if (!(CRSUtilities.getUnit(cs).toString().equals("m"))) {
-// System.out.println("map cs is not m");
+ // System.out.println("map cs is not m");
try {
-
+
// mapArea in "crs" of Map
ReferencedEnvelope mapArea = getMapPane()
.getMapArea();
-// System.out.println("mapArea ° = " + mapArea);
+ // System.out.println("mapArea ° = " + mapArea);
ReferencedEnvelope transformedMeters = mapArea
.transform(GTUtil.WORLD_METER, true);
-// System.out.println("mapArea m = "
-// + transformedMeters);
+ // System.out.println("mapArea m = "
+ // + transformedMeters);
double spanMeters = transformedMeters.getSpan(0);
- getScalePane().setScale(spanMeters / getWidth());
-
-// getScalePane().setVisible(true); // TODO to often?!
+ getScalePane().setScale(spanMeters / getWidth(),
+ sce.getNewScaleDenominator());
} catch (Exception transEx) {
- getScalePane().setScale(0);
+ getScalePane().setScale(0, 0);
}
} else {
-// System.out.println("map cs is m");
- getScalePane().setScale(sce.getNewScale());
+ // System.out.println("map cs is m");
+ getScalePane().setScale(sce.getNewScale(),
+ sce.getNewScaleDenominator());
}
}
@@ -315,18 +313,20 @@
}
// XMapPane ruft setScale jetzt früh genug auf. Nicht mehr nötig
-// /**
-// * Nach dem {@code super}-Aufruf, wird der Massstab neu gesetzt (und somit
-// * neu angezeigt), falls sich der Massstab der Karte geaendert hat. Dies ist
-// * ein Workaround, damit der Massstab auch beim allerersten anzeigen korrekt
-// * angezeigt wird (ohne {@link ScaleChangedEvent}).
-// */
-// public void paint(Graphics g) {
-// super.paint(g);
-// if (getScalePane().getScaleInMeters() != mapPane.getScale()
-// && mapPane.getScale() > 0)
-// getScalePane().setScale(mapPane.getScale());
-// }
+ // /**
+ // * Nach dem {@code super}-Aufruf, wird der Massstab neu gesetzt (und somit
+ // * neu angezeigt), falls sich der Massstab der Karte geaendert hat. Dies
+ // ist
+ // * ein Workaround, damit der Massstab auch beim allerersten anzeigen
+ // korrekt
+ // * angezeigt wird (ohne {@link ScaleChangedEvent}).
+ // */
+ // public void paint(Graphics g) {
+ // super.paint(g);
+ // if (getScalePane().getScaleInMeters() != mapPane.getScale()
+ // && mapPane.getScale() > 0)
+ // getScalePane().setScale(mapPane.getScale());
+ // }
/**
* Liefert das {@link SelectableXMapPane}, in dem die Karten dargestellt
@@ -358,6 +358,7 @@
* @param color
* Hintergrundfarbe
*/
+ @Override
public void setBackground(Color color) {
setBackground(color, true);
}
@@ -366,8 +367,7 @@
* @return If dispose() has been called. If
* <code>true<(code>, further use of this {@link GeoMapPane} is undefined
*
- * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons
- * Tzeggai</a>
+ * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
*/
public boolean isDisposed() {
return disposed;
@@ -377,8 +377,7 @@
* Should be called when the {@link GeoMapPane} is not needed no more to
* help the GarbageCollector
*
- * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons
- * Tzeggai</a>
+ * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
*/
public void dispose() {
@@ -397,8 +396,7 @@
* Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht
* wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.
*
- * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons
- * Tzeggai</a>
+ * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
*/
@Override
public void print(Graphics g) {
Modified: trunk/src/schmitzm/geotools/gui/ScalePane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/ScalePane.java 2010-12-18 22:36:54 UTC (rev 1355)
+++ trunk/src/schmitzm/geotools/gui/ScalePane.java 2010-12-20 00:46:12 UTC (rev 1356)
@@ -34,6 +34,7 @@
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.text.DecimalFormat;
+import java.text.NumberFormat;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
@@ -56,7 +57,7 @@
private ScalePanel scalePanel = new ScalePanel();
/** Label in dem die Aufloesung in Meter pro Pixel angezeigt wird. */
- private JLabel scaleLabel = new JLabel("");
+ private final JLabel scaleLabel = new JLabel("");
/**
* Liefert die dargestellte Aufloesung in Pixel pro Meter.
@@ -70,32 +71,32 @@
*/
public ScalePane() {
setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
- setScale(0);
+ setScale(0, 0);
this.setLayout(new GridBagLayout());
this.add(getScalePanel(), new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
0, 0, 0, 0), 0, 0));
- this.getScaleLabel().setHorizontalAlignment(JLabel.LEFT);
- this.add(getScaleLabel(), new GridBagConstraints(0, 1, 1, 1, 0.5, 0.0,
+ this.scaleLabel.setHorizontalAlignment(JLabel.LEFT);
+ this.add(scaleLabel, new GridBagConstraints(0, 1, 1, 1, 0.5, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
}
/**
- * Returns the units used in the scale.
- * Not all possible Unit values are allowed.
+ * Returns the units used in the scale. Not all possible Unit values are
+ * allowed.
*/
public ScalePanel.ScaleUnits getUnits() {
- return scalePanel.getUnits();
+ return scalePanel.getUnits();
}
-
+
/**
- * Define the unit used in the scale.
+ * Define the unit used in the scale.
*/
public void setUnits(ScalePanel.ScaleUnits unit) {
- scalePanel.setUnits(unit);
+ scalePanel.setUnits(unit);
}
-
+
/**
* Liefert die dargestellte Aufloesung in Metern pro Pixel.
*/
@@ -109,14 +110,24 @@
*
* @param meters
* Meter, die durch einen Bildschirm-Pixel repraesentiert werden
+ * @param scaleDenominator
+ * Zoomstufe als als OGC scaleDenominator
*/
- public void setScale(double meters) {
+ public void setScale(double meters, double scaleDenominator) {
getScalePanel().setScale(meters);
// TODO i8n
- if (meters != 0)
- getScaleLabel().setText("1 pixel = " + numFormat.format(meters) + "m");
- else getScaleLabel().setText("");
+ if (isPixelEqualsLabelVisible() && meters != 0)
+ scaleLabel.setText("1 pixel = " + numFormat.format(meters) + "m ");
+ else
+ scaleLabel.setText("");
+
+ if (isOgcScaleDenominatorVisible() && scaleDenominator != 0) {
+ scaleLabel.setText(scaleLabel.getText() + "(OGC scale denominator "
+ + NumberFormat.getNumberInstance().format(scaleDenominator)
+ + ")");
+ }
+
repaint();
}
@@ -126,17 +137,26 @@
*
* @param pixels
* Anzahl an Pixeln, die einen Meter repraesentieren werden
+ * @param scaleDenominator
+ * Zoomstufe als als OGC scaleDenominator
* @exception Ill
*/
- public void setScale(long pixels) {
-
+ public void setScale(long pixels, double scaleDenominator) {
+
getScalePanel().setScale(pixels);
// TODO i8n
- if (pixels != 0)
- getScaleLabel().setText(pixels + " pixel = 1m");
- else
- getScaleLabel().setText("");
+ if (isPixelEqualsLabelVisible() && pixels != 0)
+ scaleLabel.setText(pixels + " pixel = 1m ");
+ else
+ scaleLabel.setText("");
+
+ if (isOgcScaleDenominatorVisible() && scaleDenominator != 0) {
+ scaleLabel.setText(scaleLabel.getText() + "(OGC scale denominator "
+ + NumberFormat.getNumberInstance().format(scaleDenominator)
+ + ")");
+ }
+
repaint();
}
@@ -144,8 +164,7 @@
* Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht
* wird) wird. Diese Angabe macht kaum sinn wenn gedruckt wird, oder?!
*
- * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons
- * Tzeggai</a>
+ * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
*/
@Override
public void print(Graphics g) {
@@ -164,14 +183,6 @@
// }
}
- public void setScaleLabel(JLabel scaleLabel) {
- this.scaleLabel = scaleLabel;
- }
-
- public JLabel getScaleLabel() {
- return scaleLabel;
- }
-
public void setScalePanel(ScalePanel scalePanel) {
this.scalePanel = scalePanel;
}
@@ -180,4 +191,42 @@
return scalePanel;
}
+ /**
+ * Shall a line "1 pixel = 45555m" be shown
+ */
+ public void setPixelEqualsLabelVisible(boolean pixelEqualsLabelVisible) {
+ this.pixelEqualsLabelVisible = pixelEqualsLabelVisible;
+ }
+
+ /**
+ * Shall a line "1 pixel = 45555m" be shown
+ */
+ public boolean isPixelEqualsLabelVisible() {
+ return pixelEqualsLabelVisible;
+ }
+
+ /**
+ * Shall a line "= OGC ScaleDenomitor 2341432423.23423"
+ */
+ public void setOgcScaleDenominatorVisible(boolean ogcScaleDenominatorVisible) {
+ this.ogcScaleDenominatorVisible = ogcScaleDenominatorVisible;
+ }
+
+ /**
+ * Shall a line "= OGC ScaleDenomitor 2341432423.23423"
+ */
+ public boolean isOgcScaleDenominatorVisible() {
+ return ogcScaleDenominatorVisible;
+ }
+
+ /**
+ * Shall a line "1 pixel = 45555m" be shown
+ */
+ private boolean pixelEqualsLabelVisible = true;
+
+ /**
+ * Shall a line "= OGC ScaleDenomitor 2341432423.23423"
+ */
+ private boolean ogcScaleDenominatorVisible = true;
+
}
Modified: trunk/src/schmitzm/geotools/gui/ScalePanel.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/ScalePanel.java 2010-12-18 22:36:54 UTC (rev 1355)
+++ trunk/src/schmitzm/geotools/gui/ScalePanel.java 2010-12-20 00:46:12 UTC (rev 1356)
@@ -48,121 +48,137 @@
* richtet sich nach der Groesse der Parent-Componente. Der Balken stellt immer
* <b>volle</b> 10, 100, 1000, ... Meter dar.<br>
* Diese Groesse wird rechts neben dem schwarz/weissen Balken angezeigt.
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
- * @version 1.0
+ *
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ * (University of Bonn/Germany)
+ * @version 1.1
*/
public class ScalePanel extends JPanel {
- /**
- * ScalePane can show the scale in the following units.
- */
- public static enum ScaleUnits {
- /**
- * Show units in kilometers and switch to meters when the scale becomes
- * lesser than 1km.
- **/
- METRIC,
- /**
- * Show units in miles and switch to feet when the scale becomes
- * lesser than 1mi.
- **/
- US;
-
- /**
- * Returns the main unit the scale is displayed in.
- */
- public DistanceUnit getMainUnit() {
- switch (this) {
- case METRIC: return DistanceUnit.KM;
- case US: return DistanceUnit.MILES;
- }
- throw new UnsupportedOperationException("Unexpected ScaleUnits type: "+LangUtil.getSimpleClassName(this));
- }
+ /**
+ * ScalePane can show the scale in the following units.
+ */
+ public static enum ScaleUnits {
+ /**
+ * Show units in kilometers and switch to meters when the scale becomes
+ * lesser than 1km.
+ **/
+ METRIC,
+ /**
+ * Show units in miles and switch to feet when the scale becomes lesser
+ * than 1mi.
+ **/
+ US;
- /**
- * Returns the secondary unit the scale is displayed in if
- * the scale is less than 1 in the main unit.
- */
- public DistanceUnit getSecondaryUnit() {
- switch (this) {
- case METRIC: return DistanceUnit.METERS;
- case US: return DistanceUnit.FEET;
- }
- throw new UnsupportedOperationException("Unexpected ScaleUnits type: "+LangUtil.getSimpleClassName(this));
- }
-}
+ /**
+ * Returns the main unit the scale is displayed in.
+ */
+ public DistanceUnit getMainUnit() {
+ switch (this) {
+ case METRIC:
+ return DistanceUnit.KM;
+ case US:
+ return DistanceUnit.MILES;
+ }
+ throw new UnsupportedOperationException(
+ "Unexpected ScaleUnits type: "
+ + LangUtil.getSimpleClassName(this));
+ }
- private static final DecimalFormat numFormat = new DecimalFormat("###,###,##0");
- public final static Color[] barColor = new Color[] { Color.BLACK, Color.WHITE };
+ /**
+ * Returns the secondary unit the scale is displayed in if the scale is
+ * less than 1 in the main unit.
+ */
+ public DistanceUnit getSecondaryUnit() {
+ switch (this) {
+ case METRIC:
+ return DistanceUnit.METERS;
+ case US:
+ return DistanceUnit.FEET;
+ }
+ throw new UnsupportedOperationException(
+ "Unexpected ScaleUnits type: "
+ + LangUtil.getSimpleClassName(this));
+ }
+ }
- /**
- * The units the scale will be presented in. By default meters and
- * kilometers are used.
- **/
- private ScaleUnits units = ScaleUnits.METRIC;
+ private static final DecimalFormat numFormat = new DecimalFormat(
+ "###,###,##0");
+ public final static Color[] barColor = new Color[] { Color.BLACK,
+ Color.WHITE };
- /** Beinhaltet die aktuell dargestellte Aufloesung. Der Wert entspricht den
- * Metern, die durch einen Bildschirm-Pixel dargestellt werden.*/
- protected double scale = 0;
+ /**
+ * The units the scale will be presented in. By default meters and
+ * kilometers are used.
+ **/
+ private ScaleUnits units = ScaleUnits.METRIC;
- /**
- * Erzeugt eine Mass-Stab.
- */
- public ScalePanel() {
- super();
- SwingUtil.setPreferredHeight(this,10);
- }
+ /**
+ * Beinhaltet die aktuell dargestellte Aufloesung. Der Wert entspricht den
+ * Metern, die durch einen Bildschirm-Pixel dargestellt werden.
+ */
+ protected double scale = 0;
- /**
- * Liefert die dargestellte Aufloesung in Pixel pro Meter.
- */
- public double getScaleInPixels() {
- return this.scale!=0 ? 1/this.scale : 0;
- }
+ /**
+ * Erzeugt einen Mass-Stab.
+ */
+ public ScalePanel() {
+ SwingUtil.setPreferredHeight(this, 10);
+ }
- /**
- * Liefert die dargestellte Aufloesung in Metern pro Pixel.
- */
- public double getScaleInMeters() {
- return this.scale;
- }
+ /**
+ * Liefert die dargestellte Aufloesung in Pixel pro Meter.
+ */
+ public double getScaleInPixels() {
+ return this.scale != 0 ? 1 / this.scale : 0;
+ }
- /**
- * Liefert die dargestellte Aufloesung in Meilen pro Pixel.
- */
- public double getScaleInMiles() {
- return DistanceUnit.METERS.convertDistanceTo(getScaleInMeters(),DistanceUnit.MILES);
- }
+ /**
+ * Liefert die dargestellte Aufloesung in Metern pro Pixel.
+ */
+ public double getScaleInMeters() {
+ return this.scale;
+ }
- /**
- * Returns the units used in the scale.
- * Not all possible Unit values are allowed.
- */
- public ScaleUnits getUnits() {
- return units;
- }
+ /**
+ * Liefert die dargestellte Aufloesung in Meilen pro Pixel.
+ */
+ public double getScaleInMiles() {
+ return DistanceUnit.METERS.convertDistanceTo(getScaleInMeters(),
+ DistanceUnit.MILES);
+ }
- /**
- * Define the unit used in the scale. Not all possible Unit values are
- * allowed.
- */
- public void setUnits(ScaleUnits unit) {
- this.units = unit;
- repaint();
- }
+ /**
+ * Returns the units used in the scale. Not all possible Unit values are
+ * allowed.
+ */
+ public ScaleUnits getUnits() {
+ return units;
+ }
- /**
- * Setzt die Aufloesung des Mass-Stabs und aktualisiert die Anzeige der
- * Komponente.
- * @param meters Meter, die durch einen Bildschirm-Pixel repraesentiert werden. 0
- * steht für ein CRS-Transformationsproblem und bedeutet, dass
+ /**
+ * Define the unit used in the scale. Not all possible Unit values are
+ * allowed.
+ */
+ public void setUnits(ScaleUnits unit) {
+ this.units = unit;
+ repaint();
+ }
+
+ /**
+ * Setzt die Aufloesung des Mass-Stabs und aktualisiert die Anzeige der
+ * Komponente.
+ *
+ * @param meters
+ * Meter, die durch einen Bildschirm-Pixel repraesentiert werden.
+ * 0 steht für ein CRS-Transformationsproblem und bedeutet, dass
* die Skala nicht gezeichnet werden soll.
- */
- public void setScale(final double meters) {
- if ( meters < 0 )
- throw new IllegalArgumentException("Meters must be greater zero!");
- this.scale = meters;
- repaint();
- }
+ */
+ public void setScale(final double meters) {
+ if (meters < 0)
+ throw new IllegalArgumentException("Meters must be greater zero!");
+ this.scale = meters;
+ repaint();
+ }
/**
* Setzt die Aufloesung des Mass-Stabs und aktualisiert die Anzeige der
@@ -174,98 +190,118 @@
* die Skala nicht gezeichnet werden soll.
* @exception Ill
*/
- public void setScale(final long pixels) {
- if ( pixels < 0 )
- throw new IllegalArgumentException("Count of pixels must be greater zero!");
- if (pixels == 0)
- setScale(0.);
- else setScale(1.0/pixels);
- }
+ public void setScale(final long pixels) {
+ if (pixels < 0)
+ throw new IllegalArgumentException(
+ "Count of pixels must be greater zero!");
+ if (pixels == 0)
+ setScale(0.);
+ else
+ setScale(1.0 / pixels);
+ }
- /**
- * Zeichnet den Massstab-Balken.
- * @param g Graphics
- */
- public void paint(final Graphics g) {
-
-
- if (getParent() == null )
- return;
-
- final Graphics2D g2 = (Graphics2D)g;
- g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
- g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
-
- super.paint(g2);
-
- // 0 steht für ein CRS-Transformationsproblem und bedeutet, dass die Skala nicht gezeichnet werden soll.
- if (scale == 0) return;
+ /**
+ * Zeichnet den Massstab-Balken.
+ *
+ * @param g
+ * Graphics
+ */
+ @Override
+ public void paint(final Graphics g) {
- // maximale Breite fuer Skala (abzgl. 25 Pixel fuer Meter-Angabe)
- final int maxW_pixel = getParent().getWidth() - 30;
- final double maxW_meter = maxW_pixel * getScaleInMeters();
+ if (getParent() == null)
+ return;
- // Breite in Darstellungseinheit umrechnen
- DistanceUnit dispUnit = units.getMainUnit();
- double maxW_unit = DistanceUnit.METERS.convertDistanceTo(maxW_meter, dispUnit);
- if ( maxW_unit < 1 ) {
- dispUnit = units.getSecondaryUnit();
- maxW_unit = units.getMainUnit().convertDistanceTo(maxW_unit, dispUnit);
- }
- // Pixel pro Meter umrechnen in Pixel pro Darstellungseinheit
- final double pixelsPerUnit = getScaleInPixels() / DistanceUnit.METERS.getConversionFactor(dispUnit);
-
- // Ausmasse der Skala (stellt immer volle 10/100/1000/... Einheiten dar)
- final long scaleW_unit = (long)Math.pow(10, (long)Math.log10(maxW_unit));
- final int scaleW_pixel = (int)Math.round( scaleW_unit * pixelsPerUnit );
- final int scaleH_pixel = getHeight()-1;
+ final Graphics2D g2 = (Graphics2D) g;
+ g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
+ RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+ g2.setRenderingHint(RenderingHints.KEY_RENDERING,
+ RenderingHints.VALUE_RENDER_QUALITY);
- // Aufteilung in der Skala Teil-Balken
- final int tileScaleCount = 4;
- final int tileScaleWidth = scaleW_pixel/tileScaleCount;
- final int tileScaleHeight = scaleH_pixel;
-
- int nextColorIdx = 0;
+ super.paint(g2);
- // Teilbalken malen
- for (int i = 0; i < tileScaleCount; i++) {
- g2.setColor(barColor[nextColorIdx]);
- g2.fillRect(i * tileScaleWidth, 0, tileScaleWidth, tileScaleHeight);
- nextColorIdx = 1 - nextColorIdx;
- }
- // Rahmen um alle Balken
- g2.setColor(Color.BLACK);
- g2.drawRect(0, 0, tileScaleWidth*tileScaleCount, tileScaleHeight);
- // Laengen-Angabe
-
- g2.setFont( font1 );
-
- final String scaleString = convertScaleToLabelUnit(scaleW_unit,dispUnit,units);
- g2.drawString(scaleString,scaleW_pixel+3,scaleH_pixel);
- }
-
- /** Font used for painting the "100km" or "1000ft" label **/
- final static Font font1 = new JLabel().getFont().deriveFont(Font.PLAIN).deriveFont(new JLabel().getFont().getSize2D() );
-
- /**
- * Returns a formated string containing the given distance value (meters or miles)
- * in a "nice" and displayable format.
- * @param dist distance (in meters or miles) to format
- * @param distUnits defines whether the given distance is given in meters or miles
- * @param displayUnits defines the unit to display
- * @return
- */
- public static String convertScaleToLabelUnit(double dist, DistanceUnit distUnits, ScaleUnits displayUnits) {
- DistanceUnit mainUnit = displayUnits.getMainUnit();
- DistanceUnit secUnit = displayUnits.getSecondaryUnit();
+ // 0 steht für ein CRS-Transformationsproblem und bedeutet, dass die
+ // Skala nicht gezeichnet werden soll.
+ if (scale == 0)
+ return;
- // convert given distance to display main unit
- dist = distUnits.convertDistanceTo(dist, mainUnit);
-
- if ( dist >= 1 )
- return numFormat.format(dist) + mainUnit.getAbbreviation();
-
- // fall back to the secondary unit
- return numFormat.format( mainUnit.convertDistanceTo(dist, secUnit) ) + secUnit.getAbbreviation();
- }
+ // maximale Breite fuer Skala (abzgl. 25 Pixel fuer Meter-Angabe)
+ final int maxW_pixel = getParent().getWidth() - 30;
+ final double maxW_meter = maxW_pixel * getScaleInMeters();
+
+ // Breite in Darstellungseinheit umrechnen
+ DistanceUnit dispUnit = units.getMainUnit();
+ double maxW_unit = DistanceUnit.METERS.convertDistanceTo(maxW_meter,
+ dispUnit);
+ if (maxW_unit < 1) {
+ dispUnit = units.getSecondaryUnit();
+ maxW_unit = units.getMainUnit().convertDistanceTo(maxW_unit,
+ dispUnit);
+ }
+ // Pixel pro Meter umrechnen in Pixel pro Darstellungseinheit
+ final double pixelsPerUnit = getScaleInPixels()
+ / DistanceUnit.METERS.getConversionFactor(dispUnit);
+
+ // Ausmasse der Skala (stellt immer volle 10/100/1000/... Einheiten dar)
+ final long scaleW_unit = (long) Math.pow(10,
+ (long) Math.log10(maxW_unit));
+ final int scaleW_pixel = (int) Math.round(scaleW_unit * pixelsPerUnit);
+ final int scaleH_pixel = getHeight() - 1;
+
+ // Aufteilung in der Skala Teil-Balken
+ final int tileScaleCount = 4;
+ final int tileScaleWidth = scaleW_pixel / tileScaleCount;
+ final int tileScaleHeight = scaleH_pixel;
+
+ int nextColorIdx = 0;
+
+ // Teilbalken malen
+ for (int i = 0; i < tileScaleCount; i++) {
+ g2.setColor(barColor[nextColorIdx]);
+ g2.fillRect(i * tileScaleWidth, 0, tileScaleWidth, tileScaleHeight);
+ nextColorIdx = 1 - nextColorIdx;
+ }
+ // Rahmen um alle Balken
+ g2.setColor(Color.BLACK);
+ g2.drawRect(0, 0, tileScaleWidth * tileScaleCount, tileScaleHeight);
+ // Laengen-Angabe
+
+ g2.setFont(font1);
+
+ final String scaleString = convertScaleToLabelUnit(scaleW_unit,
+ dispUnit, units);
+ g2.drawString(scaleString, scaleW_pixel + 3, scaleH_pixel);
+ }
+
+ /** Font used for painting the "100km" or "1000ft" label **/
+ final static Font font1 = new JLabel().getFont().deriveFont(Font.PLAIN)
+ .deriveFont(new JLabel().getFont().getSize2D());
+
+ /**
+ * Returns a formated string containing the given distance value (meters or
+ * miles) in a "nice" and displayable format.
+ *
+ * @param dist
+ * distance (in meters or miles) to format
+ * @param distUnits
+ * defines whether the given distance is given in meters or miles
+ * @param displayUnits
+ * defines the unit to display
+ * @return
+ */
+ public static String convertScaleToLabelUnit(double dist,
+ DistanceUnit distUnits, ScaleUnits displayUnits) {
+ DistanceUnit mainUnit = displayUnits.getMainUnit();
+ DistanceUnit secUnit = displayUnits.getSecondaryUnit();
+
+ // convert given distance to display main unit
+ dist = distUnits.convertDistanceTo(dist, mainUnit);
+
+ if (dist >= 1)
+ return numFormat.format(dist) + mainUnit.getAbbreviation();
+
+ // fall back to the secondary unit
+ return numFormat.format(mainUnit.convertDistanceTo(dist, secUnit))
+ + secUnit.getAbbreviation();
+ }
}
Modified: trunk/src/schmitzm/geotools/gui/SelectableXMapPane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/SelectableXMapPane.java 2010-12-18 22:36:54 UTC (rev 1355)
+++ trunk/src/schmitzm/geotools/gui/SelectableXMapPane.java 2010-12-20 00:46:12 UTC (rev 1356)
@@ -530,7 +530,7 @@
getBounds()), mapExtend));
try {
- sourceGrid = (GridCoverage2D) reader
+ sourceGrid = reader
.read(new GeneralParameterValue[] { readGG });
} catch (Exception e) {
LOGGER.error(
@@ -728,28 +728,6 @@
}
/**
- * Liefert die Anzahl der Einheiten, die ein Bildschirm-Pixel darstellt. Die
- * Einheit ist die Grundeinheit des CRS
- */
- public double getScale() {
-
- if (!isWellDefined())
- return 0.0;
-
- // double scale = getMapArea().getWidth() / getWidth();
- // LOGGER.debug("Scale in XMapPane = "+scale);
-
- AffineTransform worldToScreenTransform = getWorldToScreenTransform();
- if (worldToScreenTransform == null)
- return 0.0;
-
- double scale2 = 1. / worldToScreenTransform.getScaleX();
- // LOGGER.debug("Alternativ = " + scale2);
-
- return scale2;
- }
-
- /**
* Liefert oberste Layer (sichtbar oder unsichtbar).
*/
public MapLayer getTopLayer() {
Modified: trunk/src/schmitzm/geotools/gui/XMapPane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/XMapPane.java 2010-12-18 22:36:54 UTC (rev 1355)
+++ trunk/src/schmitzm/geotools/gui/XMapPane.java 2010-12-20 00:46:12 UTC (rev 1356)
@@ -63,6 +63,7 @@
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.crs.GeographicCRS;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;
@@ -1615,6 +1616,42 @@
}
/**
+ * Liefert die Anzahl der Einheiten, die ein Bildschirm-Pixel darstellt. Die
+ * Einheit ist die Grundeinheit des CRS
+ */
+ public double getScale() {
+
+ if (!isWellDefined())
+ return 0.0;
+
+ // double scale = getMapArea().getWidth() / getWidth();
+ // LOGGER.debug("Scale in XMapPane = "+scale);
+
+ AffineTransform worldToScreenTransform = getWorldToScreenTransform();
+ if (worldToScreenTransform == null)
+ return 0.0;
+
+ double scale2 = 1. / worldToScreenTransform.getScaleX();
+ // LOGGER.debug("Alternativ = " + scale2);
+
+ return scale2;
+ }
+
+ /**
+ * Liefert den OGC ScaleDenominator der der aktuellen Skale entspricht. Wenn
+ * es einen Fehler gibt 0.0
+ */
+ public double getScaleDenominator() {
+
+ if (getScale() != 0.0)
+ return RendererUtilities.calculateOGCScale(getMapArea(),
+ getWidth(), null);
+ else
+ return 0.0;
+
+ }
+
+ /**
* Called by the {@link RenderingExecutor} when rendering has been
* completed.
*
@@ -2178,7 +2215,7 @@
* rendering problems when the map pane is hidden partly by a scroll pane
* (in ISDSS).
*/
- protected Rectangle getMapPaneSize() {
+ public Rectangle getMapPaneSize() {
// return getMapPaneSize();
return new Rectangle(getWidth(), getHeight());
}
@@ -2983,4 +3020,34 @@
zoomTowards(new Point2D.Double(centre.x, centre.y), zFactor);
}
+ final static double OGC_DEGREE_TO_METERS = 6378137.0 * 2.0 * Math.PI / 360;
+
+ /**
+ * Zooms to the given Scale without changing the center of the map (if
+ * possible due to mapMaxExtend restrictions.
+ */
+ public void zoomToScaleDenominator(double scaleDenominator) {
+ // if it's geodetic, we're dealing with lat/lon unit measures
+ Double newScale = calculateScaleDenominatortoScale(scaleDenominator,
+ getMapArea().getWidth());
+
+ double zFactor = newScale / getScale();
+
+ zoomTowards(new Point2D.Double(getMapArea().getMedian(0), getMapArea()
+ .getMedian(1)), zFactor);
+
+ }
+
+ public Double calculateScaleDenominatortoScale(double scaleDenominator,
+ double width2) {
+
+ final double d = width2 / RendererUtilities.getDpi(null) * 0.0254;
+ if (getMapArea().getCoordinateReferenceSystem() instanceof GeographicCRS) {
+ return (scaleDenominator * d) / (width2 * OGC_DEGREE_TO_METERS);
+ } else {
+ return scaleDenominator * d;
+ }
+
+ }
+
}
Modified: trunk/src/schmitzm/geotools/map/event/ScaleChangedEvent.java
===================================================================
--- trunk/src/schmitzm/geotools/map/event/ScaleChangedEvent.java 2010-12-18 22:36:54 UTC (rev 1355)
+++ trunk/src/schmitzm/geotools/map/event/ScaleChangedEvent.java 2010-12-20 00:46:12 UTC (rev 1356)
@@ -33,37 +33,52 @@
import schmitzm.geotools.gui.XMapPaneEvent;
/**
- * Diese Klasse stellt ein Ereignis dar, das ein {@link SelectableXMapPane} ausloest,
- * wenn sich die Skalierung/Aufloesung der Karte aendert.
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ * Diese Klasse stellt ein Ereignis dar, das ein {@link SelectableXMapPane}
+ * ausloest, wenn sich die Skalierung/Aufloesung der Karte aendert.
+ *
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ * (University of Bonn/Germany)
* @version 1.0
*/
public class ScaleChangedEvent extends XMapPaneEvent {
- private double oldScale = 0;
- private double newScale = 0;
+ private double oldScale = 0;
+ private double newScale = 0;
+ private final double newScaleDenominator;
- /**
- * Erzeugt ein neues Ereignis.
- * @param oldScale vormalige Aufloesung
- * @param newScale neue Aufloesung
- */
- public ScaleChangedEvent(SelectableXMapPane source, double oldScale, double newScale) {
- super(source);
- this.oldScale = oldScale;
- this.newScale = newScale;
- }
+ /**
+ * Erzeugt ein neues Ereignis.
+ *
+ * @param oldScale
+ * vormalige Aufloesung
+ * @param newScale
+ * neue Aufloesung
+ */
+ public ScaleChangedEvent(SelectableXMapPane source, double oldScale,
+ double newScale) {
+ super(source);
+ this.oldScale = oldScale;
+ this.newScale = newScale;
+ this.newScaleDenominator = source.getScaleDenominator();
+ }
- /**
- * Liefert die alte Aufloesung.
- */
- public double getOldScale() {
- return oldScale;
- }
+ /**
+ * Liefert die alte Aufloesung.
+ */
+ public double getOldScale() {
+ return oldScale;
+ }
- /**
- * Liefert die neue Aufloesung.
- */
- public double getNewScale() {
- return newScale;
- }
+ /**
+ * Liefert die neue Aufloesung.
+ */
+ public double getNewScale() {
+ return newScale;
+ }
+
+ /**
+ * Liefert die neue Aufloesung als OGC ScaleDenominator.
+ */
+ public double getNewScaleDenominator() {
+ return newScaleDenominator;
+ }
}
Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java 2010-12-18 22:36:54 UTC (rev 1355)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java 2010-12-20 00:46:12 UTC (rev 1356)
@@ -1974,18 +1974,6 @@
maxScale = Math.round(maxScale / 1000) * 1000.;
LOGGER.debug("maxScale for " + avgNn + " is gerundet " + maxScale);
- //
- // switch (FeatureUtil.getGeometryForm(geometryDescriptor)) {
- // case POINT:
- // maxScale = avgNn * 10000.;
- // break;
- // case LINE:
- // maxScale = avgNn * 10000.;
- // break;
- // case POLYGON:
- // maxScale = avgNn * 10000.;
- // break;
- // }
return maxScale;
}
Modified: trunk/src_junit/schmitzm/geotools/gui/XMapPaneTest.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/gui/XMapPaneTest.java 2010-12-18 22:36:54 UTC (rev 1355)
+++ trunk/src_junit/schmitzm/geotools/gui/XMapPaneTest.java 2010-12-20 00:46:12 UTC (rev 1356)
@@ -3,18 +3,26 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.awt.Dimension;
+
+import org.geotools.data.FeatureSource;
import org.geotools.filter.function.EnvFunction;
import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.map.DefaultMapLayer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.FilterFactory2;
import org.opengis.filter.expression.Function;
import schmitzm.geotools.GTUtil;
import schmitzm.geotools.feature.FeatureUtil;
+import schmitzm.geotools.styling.StylingUtil;
import schmitzm.junit.TestingClass;
import skrueger.i8n.Translation;
+
public class XMapPaneTest extends TestingClass {
private XMapPane xMapPane;
@@ -86,4 +94,23 @@
assertEquals("fr", xMapPane.getRenderLanguage());
}
+ @Test
+ public void testScaleDenominatorToScale() throws Throwable {
+
+ FeatureSource<SimpleFeatureType, SimpleFeature> fs = schmitzm.swing.TestingUtil.TestDatasetsVector.countryShp
+ .getFeatureSource();
+
+ xMapPane.getMapContext().addLayer(
+ new DefaultMapLayer(fs, StylingUtil.createDefaultStyle(fs)));
+
+ xMapPane.setPreferredSize(new Dimension(500, 500));
+ schmitzm.swing.TestingUtil.testGui(xMapPane);
+
+ double s = xMapPane.getScale();
+
+ double sd = xMapPane.getScaleDenominator();
+ Double s2 = xMapPane.calculateScaleDenominatortoScale(sd,
+ xMapPane.getWidth());
+ assertEquals(s, s2, 0.00001);
+ }
}
More information about the Schmitzm-commits
mailing list