58 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
59 |
|
|
60 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
61 |
|
import org.geotools.geometry.jts.ReferencedEnvelope; |
62 |
import org.geotools.map.MapContext; |
import org.geotools.map.MapContext; |
63 |
import org.geotools.map.event.MapLayerListEvent; |
import org.geotools.map.event.MapLayerListEvent; |
64 |
import org.geotools.map.event.MapLayerListListener; |
import org.geotools.map.event.MapLayerListListener; |
70 |
import org.opengis.filter.FilterFactory2; |
import org.opengis.filter.FilterFactory2; |
71 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
72 |
|
|
73 |
|
import schmitzm.geotools.JTSUtil; |
74 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
75 |
|
|
76 |
import com.vividsolutions.jts.geom.Coordinate; |
import com.vividsolutions.jts.geom.Coordinate; |
379 |
*/ |
*/ |
380 |
private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea, |
private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea, |
381 |
boolean grow) { |
boolean grow) { |
382 |
|
|
383 |
|
if (mapArea == null) { |
384 |
|
LOGGER.warn("mapArea has been null in method fixAspectRatio, returning an unmodified "); |
385 |
|
} |
386 |
|
|
387 |
final double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
final double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
388 |
final double mapHeight = mapArea.getHeight(); |
final double mapHeight = mapArea.getHeight(); |
627 |
protected void processDrag(final int x1, final int y1, final int x2, |
protected void processDrag(final int x1, final int y1, final int x2, |
628 |
final int y2, final MouseEvent e) { |
final int y2, final MouseEvent e) { |
629 |
|
|
630 |
|
|
631 |
/**** |
/**** |
632 |
* If no layer is availabe we dont want a NullPointerException |
* If no layers exist, we ignore the drag. |
633 |
*/ |
*/ |
634 |
if (mapArea == null) |
if (context.getLayerCount() <= 0) { |
635 |
return; |
return; |
636 |
|
} |
637 |
|
|
638 |
// System.out.println("processing drag from " + x1 + "," + y1 + " -> " |
// System.out.println("processing drag from " + x1 + "," + y1 + " -> " |
639 |
// + x2 + "," + y2); |
// + x2 + "," + y2); |
640 |
if ((x1 == x2) && (y1 == y2)) { |
if ((x1 == x2) && (y1 == y2)) { |
680 |
final Coordinate ur = new Coordinate(right, top); |
final Coordinate ur = new Coordinate(right, top); |
681 |
// xulu.sc |
// xulu.sc |
682 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
683 |
|
|
684 |
|
|
685 |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
686 |
// xulu.ec |
// xulu.ec |
687 |
} else if (state == JMapPane.ZoomIn) { |
} else if (state == JMapPane.ZoomIn) { |
973 |
// Exceeds top? Move down and maybe cut |
// Exceeds top? Move down and maybe cut |
974 |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
975 |
double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY(); |
double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY(); |
976 |
LOGGER.debug("Moving area down by " + divY); |
// LOGGER.debug("Moving area down by " + divY); |
977 |
|
|
978 |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
979 |
newArea.getMinY() - divY), new Coordinate(newArea |
newArea.getMinY() - divY), new Coordinate(newArea |
980 |
.getMaxX(), newArea.getMaxY() - divY)); |
.getMaxX(), newArea.getMaxY() - divY)); |
981 |
|
|
982 |
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
983 |
LOGGER.debug("Now it exeeds the bottom border.. cut!"); |
// LOGGER.debug("Now it exeeds the bottom border.. cut!"); |
984 |
// And cut the bottom if it moved out of the area |
// And cut the bottom if it moved out of the area |
985 |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
986 |
maxAllowedExtend.getMinY()), new Coordinate(newArea |
maxAllowedExtend.getMinY()), new Coordinate(newArea |
987 |
.getMaxX(), newArea.getMaxY())); |
.getMaxX(), newArea.getMaxY())); |
988 |
|
|
989 |
LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
990 |
|
|
991 |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
992 |
} |
} |
995 |
// Exceeds bottom? Move up and maybe cut |
// Exceeds bottom? Move up and maybe cut |
996 |
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
997 |
double divY = newArea.getMinY() - maxAllowedExtend.getMinY(); |
double divY = newArea.getMinY() - maxAllowedExtend.getMinY(); |
998 |
LOGGER.debug("Moving area up by " + divY); |
// LOGGER.debug("Moving area up by " + divY); |
999 |
|
|
1000 |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
1001 |
newArea.getMinY() - divY), new Coordinate(newArea |
newArea.getMinY() - divY), new Coordinate(newArea |
1019 |
|
|
1020 |
// Move left.. |
// Move left.. |
1021 |
double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX(); |
double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX(); |
1022 |
LOGGER.debug("Moving area left by " + divX); |
// LOGGER.debug("Moving area left by " + divX); |
1023 |
|
|
1024 |
newArea = new Envelope(new Coordinate(newArea.getMinX() - divX, |
newArea = new Envelope(new Coordinate(newArea.getMinX() - divX, |
1025 |
newArea.getMinY()), new Coordinate(newArea.getMaxX() |
newArea.getMinY()), new Coordinate(newArea.getMaxX() |
1028 |
if (newArea.getMinX() < maxAllowedExtend.getMinX()) { |
if (newArea.getMinX() < maxAllowedExtend.getMinX()) { |
1029 |
LOGGER.debug("Now it exeeds the left border.. cut!"); |
LOGGER.debug("Now it exeeds the left border.. cut!"); |
1030 |
// And cut the left if it moved out of the area |
// And cut the left if it moved out of the area |
1031 |
newArea = new Envelope(new Coordinate(maxExtend.getMinX(), |
newArea = new Envelope(new Coordinate(maxAllowedExtend.getMinX(), |
1032 |
newArea.getMinY()), new Coordinate(newArea |
newArea.getMinY()), new Coordinate(newArea |
1033 |
.getMaxX(), newArea.getMaxY())); |
.getMaxX(), newArea.getMaxY())); |
1034 |
|
|
1043 |
|
|
1044 |
// Move right.. |
// Move right.. |
1045 |
double divX = newArea.getMinX() - maxAllowedExtend.getMinX(); |
double divX = newArea.getMinX() - maxAllowedExtend.getMinX(); |
1046 |
LOGGER.debug("Moving area right by " + divX); |
// LOGGER.debug("Moving area right by " + divX); |
1047 |
|
|
1048 |
newArea = new Envelope(new Coordinate(newArea.getMinX() - divX, |
newArea = new Envelope(new Coordinate(newArea.getMinX() - divX, |
1049 |
newArea.getMinY()), new Coordinate(newArea.getMaxX() |
newArea.getMinY()), new Coordinate(newArea.getMaxX() |
1136 |
public Envelope getMaxExtend() { |
public Envelope getMaxExtend() { |
1137 |
if (maxExtend == null) { |
if (maxExtend == null) { |
1138 |
try { |
try { |
1139 |
return fixAspectRatio(this.getBounds(), context.getLayerBounds(), true); |
return fixAspectRatio( |
1140 |
|
this.getBounds(), |
1141 |
|
// Kartenbereich um 10% vergroessern |
1142 |
|
JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1), |
1143 |
|
true |
1144 |
|
); |
1145 |
} catch (IOException e) { |
} catch (IOException e) { |
1146 |
LOGGER |
LOGGER.warn( |
|
.warn( |
|
1147 |
"maxExtend == null; faild to getLayerBounds of context", |
"maxExtend == null; faild to getLayerBounds of context", |
1148 |
e); |
e); |
1149 |
} |
} |