30 |
|
|
31 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
32 |
import org.geotools.feature.FeatureCollection; |
import org.geotools.feature.FeatureCollection; |
33 |
|
import org.geotools.geometry.Envelope2D; |
34 |
import org.geotools.geometry.jts.JTS; |
import org.geotools.geometry.jts.JTS; |
35 |
import org.geotools.geometry.jts.ReferencedEnvelope; |
import org.geotools.geometry.jts.ReferencedEnvelope; |
36 |
import org.geotools.map.DefaultMapContext; |
import org.geotools.map.DefaultMapContext; |
1610 |
requestStartRendering = true; |
requestStartRendering = true; |
1611 |
|
|
1612 |
} |
} |
1613 |
|
// |
1614 |
/** |
// /** |
1615 |
* Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten |
// * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten |
1616 |
* neu. |
// * neu. |
1617 |
*/ |
// */ |
1618 |
protected void resetTransforms() { |
// protected void resetTransforms() { |
1619 |
if (getMapArea() == null || getWidth() == 0 || getHeight() == 0) |
// if (getMapArea() == null || getWidth() == 0 || getHeight() == 0) |
1620 |
return; |
// return; |
1621 |
|
// |
1622 |
// We store the last Transform |
// // We store the last Transform |
1623 |
oldScreenToWorld = screenToWorld; |
// oldScreenToWorld = screenToWorld; |
1624 |
|
// |
1625 |
this.screenToWorld = new AffineTransform( |
// this.screenToWorld = new AffineTransform( |
1626 |
// Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten |
// // Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten |
1627 |
// nach rechts (Osten) hin groesser |
// // nach rechts (Osten) hin groesser |
1628 |
// --> positive Verschiebung |
// // --> positive Verschiebung |
1629 |
getMapArea().getWidth() / getWidth(), |
// getMapArea().getWidth() / getWidth(), |
1630 |
// keine Verzerrung |
// // keine Verzerrung |
1631 |
0.0, 0.0, |
// 0.0, 0.0, |
1632 |
// Waehrend die Fenster-Koordinaten nach unten hin groesser |
// // Waehrend die Fenster-Koordinaten nach unten hin groesser |
1633 |
// werden, |
// // werden, |
1634 |
// werden Latitude-Koordinaten nach Sueden hin keiner |
// // werden Latitude-Koordinaten nach Sueden hin keiner |
1635 |
// --> negative Verschiebung |
// // --> negative Verschiebung |
1636 |
-getMapArea().getHeight() / getHeight(), |
// -getMapArea().getHeight() / getHeight(), |
1637 |
// Die Longitude-Koordinaten werden nach Osten hin groesser |
// // Die Longitude-Koordinaten werden nach Osten hin groesser |
1638 |
// --> obere linke Ecke des Fensters hat also den Minimalwert |
// // --> obere linke Ecke des Fensters hat also den Minimalwert |
1639 |
getMapArea().getMinX(), |
// getMapArea().getMinX(), |
1640 |
// Die Latitude-Koordinaten werden nach Norden hin groesser |
// // Die Latitude-Koordinaten werden nach Norden hin groesser |
1641 |
// --> obere linke Ecke des Fensters hat also den Maximalwert |
// // --> obere linke Ecke des Fensters hat also den Maximalwert |
1642 |
getMapArea().getMaxY()); |
// getMapArea().getMaxY()); |
1643 |
|
// |
1644 |
try { |
// try { |
1645 |
this.worldToScreen = screenToWorld.createInverse(); |
// this.worldToScreen = screenToWorld.createInverse(); |
1646 |
} catch (final NoninvertibleTransformException e) { |
// } catch (final NoninvertibleTransformException e) { |
1647 |
LOGGER.error(e); |
// LOGGER.error(e); |
1648 |
} |
// } |
1649 |
} |
// } |
1650 |
|
|
1651 |
|
|
1652 |
|
|
1653 |
|
/** |
1654 |
|
* Calculate the affine transforms used to convert between |
1655 |
|
* world and pixel coordinates. The calculations here are very |
1656 |
|
* basic and assume a cartesian reference system. |
1657 |
|
* <p> |
1658 |
|
* Tne transform is calculated such that {@code envelope} will |
1659 |
|
* be centred in the display |
1660 |
|
* |
1661 |
|
* @param envelope the current map extent (world coordinates) |
1662 |
|
* @param paintArea the current map pane extent (screen units) |
1663 |
|
*/ |
1664 |
|
private void resetTransforms() { |
1665 |
|
ReferencedEnvelope refEnv = new ReferencedEnvelope(mapArea, getContext().getCoordinateReferenceSystem()); |
1666 |
|
|
1667 |
|
Rectangle paintArea = getBounds(); |
1668 |
|
|
1669 |
|
double xscale = paintArea.getWidth() / refEnv.getWidth(); |
1670 |
|
double yscale = paintArea.getHeight() / refEnv.getHeight(); |
1671 |
|
|
1672 |
|
double scale = Math.min(xscale, yscale); |
1673 |
|
|
1674 |
|
double xoff = refEnv.getMedian(0) * scale - paintArea.getCenterX(); |
1675 |
|
double yoff = refEnv.getMedian(1) * scale + paintArea.getCenterY(); |
1676 |
|
|
1677 |
|
worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff, yoff); |
1678 |
|
try { |
1679 |
|
screenToWorld = worldToScreen.createInverse(); |
1680 |
|
|
1681 |
|
} catch (NoninvertibleTransformException ex) { |
1682 |
|
ex.printStackTrace(); |
1683 |
|
} |
1684 |
|
} |
1685 |
|
|
1686 |
|
|
1687 |
|
|
1688 |
public void setBgContext(final MapContext context) { |
public void setBgContext(final MapContext context) { |
1689 |
|
|