44 |
import org.geotools.renderer.GTRenderer; |
import org.geotools.renderer.GTRenderer; |
45 |
import org.geotools.renderer.label.LabelCacheImpl; |
import org.geotools.renderer.label.LabelCacheImpl; |
46 |
import org.geotools.renderer.lite.LabelCache; |
import org.geotools.renderer.lite.LabelCache; |
47 |
|
import org.geotools.renderer.lite.RendererUtilities; |
48 |
import org.geotools.renderer.lite.StreamingRenderer; |
import org.geotools.renderer.lite.StreamingRenderer; |
49 |
import org.geotools.swing.JMapPane; |
import org.geotools.swing.JMapPane; |
50 |
import org.geotools.swing.event.MapMouseEvent; |
import org.geotools.swing.event.MapMouseEvent; |
147 |
* Default delay (milliseconds) before the map will be redrawn when resizing |
* Default delay (milliseconds) before the map will be redrawn when resizing |
148 |
* the pane. This is to avoid flickering while drag-resizing. |
* the pane. This is to avoid flickering while drag-resizing. |
149 |
*/ |
*/ |
150 |
public static final int DEFAULT_RESIZING_PAINT_DELAY = 500; |
public static final int DEFAULT_RESIZING_PAINT_DELAY = 600; |
151 |
|
|
152 |
public static final int NONE = -123; |
public static final int NONE = -123; |
153 |
|
|
387 |
localRenderer.setContext(getContext()); |
localRenderer.setContext(getContext()); |
388 |
|
|
389 |
if (localContext.getLayers().length == 1) { // the first one |
if (localContext.getLayers().length == 1) { // the first one |
390 |
|
|
391 |
// if the Area of Interest is unset, the LayerBounds are used |
// if the Area of Interest is unset, the LayerBounds are used |
392 |
if (!setMapArea(localContext.getAreaOfInterest())) |
if (!setMapArea(localContext.getAreaOfInterest())) |
393 |
repaint(); |
repaint(); |
540 |
|
|
541 |
private final Timer resizeTimer; |
private final Timer resizeTimer; |
542 |
|
|
|
private final int resizingPaintDelay; |
|
|
|
|
543 |
/** |
/** |
544 |
* Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten |
* Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten |
545 |
* (lat/lon) |
* (lat/lon) |
620 |
* Using a ComponentListener doesn't work because, unlike a JFrame, the |
* Using a ComponentListener doesn't work because, unlike a JFrame, the |
621 |
* pane receives a stream of events during drag-resizing. |
* pane receives a stream of events during drag-resizing. |
622 |
*/ |
*/ |
623 |
resizingPaintDelay = DEFAULT_RESIZING_PAINT_DELAY; |
resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY, new ActionListener() { |
|
resizeTimer = new Timer(resizingPaintDelay, new ActionListener() { |
|
624 |
|
|
625 |
public void actionPerformed(final ActionEvent e) { |
public void actionPerformed(final ActionEvent e) { |
626 |
paneResized = true; |
paneResized = true; |
713 |
* Krüger</a> |
* Krüger</a> |
714 |
*/ |
*/ |
715 |
public Envelope bestAllowedMapArea(Envelope env) { |
public Envelope bestAllowedMapArea(Envelope env) { |
716 |
|
// return env; |
717 |
if (getWidth() == 0) |
if (getWidth() == 0) |
718 |
return env; |
return env; |
719 |
if (env == null) |
if (env == null) |
921 |
} |
} |
922 |
localExecuter.dispose(); |
localExecuter.dispose(); |
923 |
} |
} |
924 |
// |
|
|
// if (bgImage != null) { |
|
|
// bgImage = dispose(bgImage); |
|
|
// bgImage = null; |
|
|
// // LangUtil.gcTotal(); |
|
|
// } |
|
|
// |
|
|
// if (localImage != null) { |
|
|
// localImage = dispose(localImage); |
|
|
// localImage = null; |
|
|
// // LangUtil.gcTotal(); |
|
|
// } |
|
|
// |
|
|
// if (finalImage != null) { |
|
|
// finalImage = dispose(finalImage); |
|
|
// finalImage = null; |
|
|
// // LangUtil.gcTotal(); |
|
|
// } |
|
|
// |
|
|
// if (preFinalImage != null) { |
|
|
// preFinalImage = dispose(preFinalImage); |
|
|
// preFinalImage = null; |
|
|
// } |
|
925 |
disposeImages(); |
disposeImages(); |
926 |
|
|
927 |
// LangUtil.gcTotal(); |
// LangUtil.gcTotal(); |
979 |
*/ |
*/ |
980 |
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) { |
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) { |
981 |
|
|
982 |
|
if (1 == 1)return false; |
983 |
|
|
984 |
if (quickPreviewHint == 0) |
if (quickPreviewHint == 0) |
985 |
return false; |
return false; |
986 |
|
|
999 |
// Calculate the oldMapArea in the current WindowCoordinates: |
// Calculate the oldMapArea in the current WindowCoordinates: |
1000 |
final Envelope oldMapWindow = tranformGeoToWindow(oldMapArea.getMinX(), |
final Envelope oldMapWindow = tranformGeoToWindow(oldMapArea.getMinX(), |
1001 |
oldMapArea.getMinY(), oldMapArea.getMaxX(), oldMapArea |
oldMapArea.getMinY(), oldMapArea.getMaxX(), oldMapArea |
1002 |
.getMaxY(), null); |
.getMaxY()); |
1003 |
|
|
1004 |
final int xx1 = (int) Math.round(oldMapWindow.getMinX()); |
final int xx1 = (int) Math.round(oldMapWindow.getMinX()); |
1005 |
final int yy1 = (int) Math.round(oldMapWindow.getMinY()); |
final int yy1 = (int) Math.round(oldMapWindow.getMinY()); |
1104 |
if (mapArea == null) |
if (mapArea == null) |
1105 |
return null; |
return null; |
1106 |
|
|
1107 |
|
// TODO is needed at all, this should go to setMapArea maybe |
1108 |
if (localContext.getCoordinateReferenceSystem() == null) |
if (localContext.getCoordinateReferenceSystem() == null) |
1109 |
try { |
try { |
1110 |
localContext.setCoordinateReferenceSystem(GeoImportUtil |
localContext.setCoordinateReferenceSystem(GeoImportUtil |
1111 |
.getDefaultCRS()); |
.getDefaultCRS()); |
1112 |
} catch (TransformException e) { |
} catch (Exception e) { |
1113 |
// TODO Auto-generated catch block |
throw new RuntimeException("setting context CRS:", e); |
|
e.printStackTrace(); |
|
|
} catch (FactoryException e) { |
|
|
// TODO Auto-generated catch block |
|
|
e.printStackTrace(); |
|
1114 |
} |
} |
1115 |
|
|
1116 |
return new ReferencedEnvelope(mapArea, localContext |
return new ReferencedEnvelope(mapArea, localContext |
1587 |
requestStartRendering = true; |
requestStartRendering = true; |
1588 |
|
|
1589 |
} |
} |
1590 |
// |
|
1591 |
// /** |
// |
1592 |
// * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten |
// /** |
1593 |
// * neu. |
// * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten |
1594 |
// */ |
// * neu. |
1595 |
// protected void resetTransforms() { |
// */ |
1596 |
// if (getMapArea() == null || getWidth() == 0 || getHeight() == 0) |
// protected void resetTransforms() { |
1597 |
// return; |
// if (getMapArea() == null || getWidth() == 0 || getHeight() == 0) |
1598 |
// |
// return; |
1599 |
// // We store the last Transform |
// |
1600 |
// oldScreenToWorld = screenToWorld; |
// // We store the last Transform |
1601 |
// |
// oldScreenToWorld = screenToWorld; |
1602 |
// this.screenToWorld = new AffineTransform( |
// |
1603 |
// // Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten |
// this.screenToWorld = new AffineTransform( |
1604 |
// // nach rechts (Osten) hin groesser |
// // Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten |
1605 |
// // --> positive Verschiebung |
// // nach rechts (Osten) hin groesser |
1606 |
// getMapArea().getWidth() / getWidth(), |
// // --> positive Verschiebung |
1607 |
// // keine Verzerrung |
// getMapArea().getWidth() / getWidth(), |
1608 |
// 0.0, 0.0, |
// // keine Verzerrung |
1609 |
// // Waehrend die Fenster-Koordinaten nach unten hin groesser |
// 0.0, 0.0, |
1610 |
// // werden, |
// // Waehrend die Fenster-Koordinaten nach unten hin groesser |
1611 |
// // werden Latitude-Koordinaten nach Sueden hin keiner |
// // werden, |
1612 |
// // --> negative Verschiebung |
// // werden Latitude-Koordinaten nach Sueden hin keiner |
1613 |
// -getMapArea().getHeight() / getHeight(), |
// // --> negative Verschiebung |
1614 |
// // Die Longitude-Koordinaten werden nach Osten hin groesser |
// -getMapArea().getHeight() / getHeight(), |
1615 |
// // --> obere linke Ecke des Fensters hat also den Minimalwert |
// // Die Longitude-Koordinaten werden nach Osten hin groesser |
1616 |
// getMapArea().getMinX(), |
// // --> obere linke Ecke des Fensters hat also den Minimalwert |
1617 |
// // Die Latitude-Koordinaten werden nach Norden hin groesser |
// getMapArea().getMinX(), |
1618 |
// // --> obere linke Ecke des Fensters hat also den Maximalwert |
// // Die Latitude-Koordinaten werden nach Norden hin groesser |
1619 |
// getMapArea().getMaxY()); |
// // --> obere linke Ecke des Fensters hat also den Maximalwert |
1620 |
// |
// getMapArea().getMaxY()); |
1621 |
// try { |
// |
1622 |
// this.worldToScreen = screenToWorld.createInverse(); |
// try { |
1623 |
// } catch (final NoninvertibleTransformException e) { |
// this.worldToScreen = screenToWorld.createInverse(); |
1624 |
// LOGGER.error(e); |
// } catch (final NoninvertibleTransformException e) { |
1625 |
// } |
// LOGGER.error(e); |
1626 |
// } |
// } |
1627 |
|
// } |
1628 |
|
|
1629 |
|
/** |
1630 |
/** |
* Calculate the affine transforms used to convert between world and pixel |
1631 |
* Calculate the affine transforms used to convert between |
* coordinates. The calculations here are very basic and assume a cartesian |
1632 |
* world and pixel coordinates. The calculations here are very |
* reference system. |
1633 |
* basic and assume a cartesian reference system. |
* <p> |
1634 |
* <p> |
* Tne transform is calculated such that {@code envelope} will be centred in |
1635 |
* Tne transform is calculated such that {@code envelope} will |
* the display |
1636 |
* be centred in the display |
* |
1637 |
* |
* @param envelope |
1638 |
* @param envelope the current map extent (world coordinates) |
* the current map extent (world coordinates) |
1639 |
* @param paintArea the current map pane extent (screen units) |
* @param paintArea |
1640 |
*/ |
* the current map pane extent (screen units) |
1641 |
private void resetTransforms() { |
*/ |
1642 |
ReferencedEnvelope refEnv = new ReferencedEnvelope(mapArea, getContext().getCoordinateReferenceSystem()); |
private void resetTransforms() { |
1643 |
|
ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
1644 |
Rectangle paintArea = getBounds(); |
getContext().getCoordinateReferenceSystem()); |
1645 |
|
// |
1646 |
double xscale = paintArea.getWidth() / refEnv.getWidth(); |
Rectangle paintArea = getBounds(); |
1647 |
double yscale = paintArea.getHeight() / refEnv.getHeight(); |
|
1648 |
|
if (!getBounds().equals(getVisibleRect())) { |
1649 |
double scale = Math.min(xscale, yscale); |
System.out.println("did we expect that?"); |
1650 |
|
} |
1651 |
double xoff = refEnv.getMedian(0) * scale - paintArea.getCenterX(); |
// |
1652 |
double yoff = refEnv.getMedian(1) * scale + paintArea.getCenterY(); |
// double xscale = paintArea.getWidth() / refEnv.getWidth(); |
1653 |
|
// double yscale = paintArea.getHeight() / refEnv.getHeight(); |
1654 |
worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff, yoff); |
// |
1655 |
try { |
// double scale = Math.min(xscale, yscale); |
1656 |
screenToWorld = worldToScreen.createInverse(); |
// |
1657 |
|
// double xoff = refEnv.getMedian(0) * scale - paintArea.getCenterX(); |
1658 |
} catch (NoninvertibleTransformException ex) { |
// double yoff = refEnv.getMedian(1) * scale + paintArea.getCenterY(); |
1659 |
ex.printStackTrace(); |
|
1660 |
} |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
1661 |
} |
paintArea); |
1662 |
|
|
1663 |
|
// worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff, |
1664 |
|
// yoff); |
1665 |
|
try { |
1666 |
|
screenToWorld = worldToScreen.createInverse(); |
1667 |
|
|
1668 |
|
} catch (NoninvertibleTransformException ex) { |
1669 |
|
ex.printStackTrace(); |
1670 |
|
} |
1671 |
|
} |
1672 |
|
|
1673 |
public void setBgContext(final MapContext context) { |
public void setBgContext(final MapContext context) { |
1674 |
|
|
1761 |
return false; |
return false; |
1762 |
} |
} |
1763 |
|
|
1764 |
|
final Envelope candNew = bestAllowedMapArea(newMapArea); |
1765 |
|
|
1766 |
// Testing, whether the difference if just minimal |
// Testing, whether the difference if just minimal |
1767 |
if (mapArea != null) { |
if (mapArea != null) { |
|
final Envelope candNew = bestAllowedMapArea(newMapArea); |
|
1768 |
final double tolX = mapArea.getWidth() / 1000.; |
final double tolX = mapArea.getWidth() / 1000.; |
1769 |
final double tolY = mapArea.getHeight() / 1000.; |
final double tolY = mapArea.getHeight() / 1000.; |
1770 |
if ((candNew.getMinX() - tolX < mapArea.getMinX()) |
if ((candNew.getMinX() - tolX < mapArea.getMinX()) |
1784 |
} |
} |
1785 |
} |
} |
1786 |
|
|
1787 |
|
// New map are is accepted: |
1788 |
oldMapArea = mapArea; |
oldMapArea = mapArea; |
1789 |
|
mapArea = candNew; |
1790 |
this.mapArea = bestAllowedMapArea(newMapArea); |
resetTransforms(); |
1791 |
|
|
1792 |
if (localContext != null) { |
if (localContext != null) { |
1793 |
localContext.setAreaOfInterest(mapArea, localContext |
localContext.setAreaOfInterest(mapArea, localContext |
1797 |
bgContext.setAreaOfInterest(mapArea, localContext |
bgContext.setAreaOfInterest(mapArea, localContext |
1798 |
.getCoordinateReferenceSystem()); |
.getCoordinateReferenceSystem()); |
1799 |
} |
} |
|
resetTransforms(); |
|
1800 |
mapImageInvalid = true; |
mapImageInvalid = true; |
1801 |
mapAreaChanged = true; |
mapAreaChanged = true; |
1802 |
repaint(); |
repaint(); |
1803 |
|
|
1804 |
// LOGGER.debug("New maparea = " + mapArea); |
LOGGER.debug("New maparea = " + mapArea); |
1805 |
return true; |
return true; |
1806 |
} |
} |
1807 |
|
|
2021 |
* {@link #getScreenToWorld()} is used. |
* {@link #getScreenToWorld()} is used. |
2022 |
*/ |
*/ |
2023 |
public Envelope tranformGeoToWindow(final double ox, final double oy, |
public Envelope tranformGeoToWindow(final double ox, final double oy, |
2024 |
final double px, final double py, |
final double px, final double py) { |
2025 |
final AffineTransform winToGeotransform) { |
final AffineTransform at = getWorldToScreenTransform(); |
|
final AffineTransform at = winToGeotransform == null ? getScreenToWorld() |
|
|
: winToGeotransform; |
|
2026 |
Point2D geoO; |
Point2D geoO; |
2027 |
try { |
// try { |
2028 |
geoO = at.inverseTransform(new Point2D.Double(ox, oy), null); |
geoO = at.transform(new Point2D.Double(ox, oy), null); |
2029 |
final Point2D geoP = at.inverseTransform( |
final Point2D geoP = at.transform(new Point2D.Double(px, py), null); |
2030 |
new Point2D.Double(px, py), null); |
return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY()); |
2031 |
return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP |
// } catch (final NoninvertibleTransformException e) { |
2032 |
.getY()); |
// LOGGER.error(e); |
2033 |
} catch (final NoninvertibleTransformException e) { |
// return new Envelope(ox, oy, px, py); |
2034 |
LOGGER.error(e); |
// } |
|
return new Envelope(ox, oy, px, py); |
|
|
} |
|
2035 |
} |
} |
2036 |
|
|
2037 |
/** |
/** |
2051 |
final AffineTransform at = getScreenToWorld(); |
final AffineTransform at = getScreenToWorld(); |
2052 |
final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null); |
final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null); |
2053 |
final Point2D geoP = at.transform(new Point2D.Double(px, py), null); |
final Point2D geoP = at.transform(new Point2D.Double(px, py), null); |
2054 |
return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY()); |
|
2055 |
|
// Mmmmm... don't really understand why its x,x,y,y |
2056 |
|
// return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY()); |
2057 |
|
return new Envelope( new Coordinate(geoO.getX(), geoO.getY()), new Coordinate(geoP.getX(), geoP.getY())); |
2058 |
} |
} |
2059 |
|
|
2060 |
/** |
/** |
2174 |
- mapImage.getWidth() - 10, getBounds().height |
- mapImage.getWidth() - 10, getBounds().height |
2175 |
- mapImage.getHeight() - 10, null); |
- mapImage.getHeight() - 10, null); |
2176 |
} |
} |
2177 |
|
|
|
|
|
2178 |
int y = 17; |
int y = 17; |
2179 |
|
|
2180 |
// If the rendering process is still running, indicate this is the image |
// If the rendering process is still running, indicate this is the image |
2181 |
if (forceWait || bgExecuter != null && bgExecuter.isRunning() |
if (forceWait || bgExecuter != null && bgExecuter.isRunning() |
2182 |
|| localExecuter != null && localExecuter.isRunning()) { |
|| localExecuter != null && localExecuter.isRunning()) { |
2183 |
|
|
2184 |
y+=8; |
y += 8; |
2185 |
|
|
2186 |
final Color c = graphics.getColor(); |
final Color c = graphics.getColor(); |
2187 |
graphics.setFont(waitFont); |
graphics.setFont(waitFont); |
|
// String waitStr = "Wait..."; // i8n |
|
2188 |
|
|
2189 |
graphics.setColor(getMapBackgroundColor()); |
graphics.setColor(getMapBackgroundColor()); |
2190 |
graphics.drawString(waitMsg, 5, y); |
graphics.drawString(waitMsg, 5, y); |
2191 |
graphics.setColor(getMapBackgroundColor()); |
graphics.setColor(getMapBackgroundColor()); |
2192 |
graphics.drawString(waitMsg, 7, y+2); |
graphics.drawString(waitMsg, 7, y + 2); |
2193 |
graphics.setColor(Color.BLACK); |
graphics.setColor(Color.BLACK); |
2194 |
graphics.drawString(waitMsg, 6, y+1); |
graphics.drawString(waitMsg, 6, y + 1); |
2195 |
|
|
2196 |
graphics.setColor(c); |
graphics.setColor(c); |
2197 |
|
|
2198 |
y += 24; |
y += 24; |
2199 |
} |
} |
2200 |
|
|
2350 |
newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea |
newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea |
2351 |
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea |
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea |
2352 |
.getHeight()) / 2.); |
.getHeight()) / 2.); |
2353 |
|
|
2354 |
// Move the newMapArea above the new center |
// TODO we actually want that |
2355 |
newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
// // Move the newMapArea above the new center |
2356 |
.getY() |
// newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
2357 |
- mapArea.centre().y); |
// .getY() |
2358 |
|
// - mapArea.centre().y); |
2359 |
|
|
2360 |
setMapArea(newMapArea); |
setMapArea(newMapArea); |
2361 |
} |
} |