65 |
import org.geotools.renderer.label.LabelCacheImpl; |
import org.geotools.renderer.label.LabelCacheImpl; |
66 |
import org.geotools.renderer.lite.LabelCache; |
import org.geotools.renderer.lite.LabelCache; |
67 |
import org.geotools.renderer.lite.StreamingRenderer; |
import org.geotools.renderer.lite.StreamingRenderer; |
|
import org.geotools.renderer.shape.ShapefileRenderer; |
|
68 |
import org.opengis.filter.FilterFactory2; |
import org.opengis.filter.FilterFactory2; |
69 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
70 |
|
|
71 |
|
import schmitzm.geotools.JTSUtil; |
72 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
73 |
|
|
74 |
import com.vividsolutions.jts.geom.Coordinate; |
import com.vividsolutions.jts.geom.Coordinate; |
77 |
|
|
78 |
public class JMapPane extends JPanel implements MouseListener, |
public class JMapPane extends JPanel implements MouseListener, |
79 |
MouseMotionListener, PropertyChangeListener, MapLayerListListener { |
MouseMotionListener, PropertyChangeListener, MapLayerListListener { |
80 |
private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName()); |
private static Logger LOGGER = Logger.getLogger(JMapPane.class); |
81 |
|
|
82 |
private static final long serialVersionUID = -8647971481359690499L; |
private static final long serialVersionUID = -8647971481359690499L; |
83 |
|
|
230 |
Map<Object, Object> hints = new HashMap<Object, Object>(); |
Map<Object, Object> hints = new HashMap<Object, Object>(); |
231 |
|
|
232 |
this.renderer = renderer; |
this.renderer = renderer; |
233 |
|
//MS: Apply hint also for ShapeFileRenderer |
234 |
if (renderer instanceof StreamingRenderer |
// if (renderer instanceof StreamingRenderer) { |
|
|| renderer instanceof ShapefileRenderer) { |
|
235 |
hints = renderer.getRendererHints(); |
hints = renderer.getRendererHints(); |
236 |
if (hints == null) { |
if (hints == null) { |
237 |
hints = new HashMap<Object, Object>(); |
hints = new HashMap<Object, Object>(); |
246 |
hints.put("memoryPreloadingEnabled", Boolean.TRUE); |
hints.put("memoryPreloadingEnabled", Boolean.TRUE); |
247 |
|
|
248 |
renderer.setRendererHints(hints); |
renderer.setRendererHints(hints); |
249 |
} |
// } |
|
|
|
|
// this.highlightRenderer = new StreamingRenderer(); |
|
|
// this.selectionRenderer = new StreamingRenderer(); |
|
|
|
|
|
// highlightRenderer.setRendererHints(hints); |
|
|
// selectionRenderer.setRendererHints(hints); |
|
|
|
|
|
// renderer.setRendererHints(hints); |
|
250 |
|
|
251 |
if (this.context != null) { |
if (this.context != null) { |
252 |
this.renderer.setContext(this.context); |
this.renderer.setContext(this.context); |
368 |
*/ |
*/ |
369 |
private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea, |
private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea, |
370 |
boolean grow) { |
boolean grow) { |
371 |
|
|
372 |
|
if (mapArea == null) { |
373 |
|
LOGGER.warn("mapArea has been null in method fixAspectRatio, returning an unmodified "); |
374 |
|
} |
375 |
|
|
376 |
final double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
final double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
377 |
final double mapHeight = mapArea.getHeight(); |
final double mapHeight = mapArea.getHeight(); |
616 |
protected void processDrag(final int x1, final int y1, final int x2, |
protected void processDrag(final int x1, final int y1, final int x2, |
617 |
final int y2, final MouseEvent e) { |
final int y2, final MouseEvent e) { |
618 |
|
|
619 |
|
|
620 |
/**** |
/**** |
621 |
* If no layer is availabe we dont want a NullPointerException |
* If no layers exist, we ignore the drag. |
622 |
*/ |
*/ |
623 |
if (mapArea == null) |
if (context.getLayerCount() <= 0) { |
624 |
return; |
return; |
625 |
|
} |
626 |
|
|
627 |
// System.out.println("processing drag from " + x1 + "," + y1 + " -> " |
// System.out.println("processing drag from " + x1 + "," + y1 + " -> " |
628 |
// + x2 + "," + y2); |
// + x2 + "," + y2); |
629 |
if ((x1 == x2) && (y1 == y2)) { |
if ((x1 == x2) && (y1 == y2)) { |
669 |
final Coordinate ur = new Coordinate(right, top); |
final Coordinate ur = new Coordinate(right, top); |
670 |
// xulu.sc |
// xulu.sc |
671 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
672 |
|
|
673 |
|
|
674 |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
675 |
// xulu.ec |
// xulu.ec |
676 |
} else if (state == JMapPane.ZoomIn) { |
} else if (state == JMapPane.ZoomIn) { |
954 |
} |
} |
955 |
|
|
956 |
Envelope maxAllowedExtend = getMaxExtend(); |
Envelope maxAllowedExtend = getMaxExtend(); |
957 |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)) { |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) && newArea != null && !newArea.isNull() && !Double.isNaN(newArea.getMinX()) && !Double.isNaN(newArea.getMaxX()) && !Double.isNaN(newArea.getMinY()) && !Double.isNaN(newArea.getMaxY()) ) { |
958 |
/* |
/* |
959 |
* If a maxExtend is set, we have to honour that... |
* If a maxExtend is set, we have to honour that... |
960 |
*/ |
*/ |
962 |
// Exceeds top? Move down and maybe cut |
// Exceeds top? Move down and maybe cut |
963 |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
964 |
double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY(); |
double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY(); |
965 |
LOGGER.debug("Moving area down by " + divY); |
// LOGGER.debug("Moving area down by " + divY); |
966 |
|
|
967 |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
968 |
newArea.getMinY() - divY), new Coordinate(newArea |
newArea.getMinY() - divY), new Coordinate(newArea |
969 |
.getMaxX(), newArea.getMaxY() - divY)); |
.getMaxX(), newArea.getMaxY() - divY)); |
970 |
|
|
971 |
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
972 |
LOGGER.debug("Now it exeeds the bottom border.. cut!"); |
// LOGGER.debug("Now it exeeds the bottom border.. cut!"); |
973 |
// And cut the bottom if it moved out of the area |
// And cut the bottom if it moved out of the area |
974 |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
975 |
maxAllowedExtend.getMinY()), new Coordinate(newArea |
maxAllowedExtend.getMinY()), new Coordinate(newArea |
976 |
.getMaxX(), newArea.getMaxY())); |
.getMaxX(), newArea.getMaxY())); |
977 |
|
|
978 |
LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
979 |
|
|
980 |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
981 |
} |
} |
984 |
// Exceeds bottom? Move up and maybe cut |
// Exceeds bottom? Move up and maybe cut |
985 |
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
986 |
double divY = newArea.getMinY() - maxAllowedExtend.getMinY(); |
double divY = newArea.getMinY() - maxAllowedExtend.getMinY(); |
987 |
LOGGER.debug("Moving area up by " + divY); |
// LOGGER.debug("Moving area up by " + divY); |
988 |
|
|
989 |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
990 |
newArea.getMinY() - divY), new Coordinate(newArea |
newArea.getMinY() - divY), new Coordinate(newArea |
991 |
.getMaxX(), newArea.getMaxY() - divY)); |
.getMaxX(), newArea.getMaxY() - divY)); |
992 |
|
|
993 |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
994 |
LOGGER.debug("Now it exeeds the top border.. cut!"); |
// LOGGER.debug("Now it exeeds the top border.. cut!"); |
995 |
// And cut the bottom if it moved out of the area |
// And cut the bottom if it moved out of the area |
996 |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
997 |
newArea.getMinY()), new Coordinate(newArea |
newArea.getMinY()), new Coordinate(newArea |
998 |
.getMaxX(), maxAllowedExtend.getMaxY())); |
.getMaxX(), maxAllowedExtend.getMaxY())); |
999 |
|
|
1000 |
LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
1001 |
|
|
1002 |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
1003 |
} |
} |
1008 |
|
|
1009 |
// Move left.. |
// Move left.. |
1010 |
double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX(); |
double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX(); |
1011 |
LOGGER.debug("Moving area left by " + divX); |
// LOGGER.debug("Moving area left by " + divX); |
1012 |
|
|
1013 |
newArea = new Envelope(new Coordinate(newArea.getMinX() - divX, |
newArea = new Envelope(new Coordinate(newArea.getMinX() - divX, |
1014 |
newArea.getMinY()), new Coordinate(newArea.getMaxX() |
newArea.getMinY()), new Coordinate(newArea.getMaxX() |
1015 |
- divX, newArea.getMaxY())); |
- divX, newArea.getMaxY())); |
1016 |
|
|
1017 |
if (newArea.getMinX() < maxAllowedExtend.getMinX()) { |
if (newArea.getMinX() < maxAllowedExtend.getMinX()) { |
1018 |
LOGGER.debug("Now it exeeds the left border.. cut!"); |
// LOGGER.debug("Now it exeeds the left border.. cut!"); |
1019 |
// And cut the left if it moved out of the area |
// And cut the left if it moved out of the area |
1020 |
newArea = new Envelope(new Coordinate(maxExtend.getMinX(), |
newArea = new Envelope(new Coordinate(maxAllowedExtend.getMinX(), |
1021 |
newArea.getMinY()), new Coordinate(newArea |
newArea.getMinY()), new Coordinate(newArea |
1022 |
.getMaxX(), newArea.getMaxY())); |
.getMaxX(), newArea.getMaxY())); |
1023 |
|
|
1024 |
LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
1025 |
|
|
1026 |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
1027 |
} |
} |
1032 |
|
|
1033 |
// Move right.. |
// Move right.. |
1034 |
double divX = newArea.getMinX() - maxAllowedExtend.getMinX(); |
double divX = newArea.getMinX() - maxAllowedExtend.getMinX(); |
1035 |
LOGGER.debug("Moving area right by " + divX); |
// LOGGER.debug("Moving area right by " + divX); |
1036 |
|
|
1037 |
newArea = new Envelope(new Coordinate(newArea.getMinX() - divX, |
newArea = new Envelope(new Coordinate(newArea.getMinX() - divX, |
1038 |
newArea.getMinY()), new Coordinate(newArea.getMaxX() |
newArea.getMinY()), new Coordinate(newArea.getMaxX() |
1039 |
- divX, newArea.getMaxY())); |
- divX, newArea.getMaxY())); |
1040 |
|
|
1041 |
if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) { |
if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) { |
1042 |
LOGGER.debug("Now it exeeds the right border.. cut!"); |
// LOGGER.debug("Now it exeeds the right border.. cut!"); |
1043 |
// And cut the left if it moved out of the area |
// And cut the left if it moved out of the area |
1044 |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
1045 |
newArea.getMinY()), new Coordinate(maxAllowedExtend |
newArea.getMinY()), new Coordinate(maxAllowedExtend |
1046 |
.getMaxX(), newArea.getMaxY())); |
.getMaxX(), newArea.getMaxY())); |
1047 |
|
|
1048 |
LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
1049 |
|
|
1050 |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
1051 |
} |
} |
1125 |
public Envelope getMaxExtend() { |
public Envelope getMaxExtend() { |
1126 |
if (maxExtend == null) { |
if (maxExtend == null) { |
1127 |
try { |
try { |
1128 |
return fixAspectRatio(this.getBounds(), context.getLayerBounds(), true); |
return fixAspectRatio( |
1129 |
|
this.getBounds(), |
1130 |
|
// Kartenbereich um 10% vergroessern |
1131 |
|
JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1), |
1132 |
|
true |
1133 |
|
); |
1134 |
} catch (IOException e) { |
} catch (IOException e) { |
1135 |
LOGGER |
LOGGER.warn( |
|
.warn( |
|
1136 |
"maxExtend == null; faild to getLayerBounds of context", |
"maxExtend == null; faild to getLayerBounds of context", |
1137 |
e); |
e); |
1138 |
} |
} |