58 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
59 |
|
|
60 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
|
import org.geotools.geometry.jts.ReferencedEnvelope; |
|
61 |
import org.geotools.map.MapContext; |
import org.geotools.map.MapContext; |
62 |
import org.geotools.map.event.MapLayerListEvent; |
import org.geotools.map.event.MapLayerListEvent; |
63 |
import org.geotools.map.event.MapLayerListListener; |
import org.geotools.map.event.MapLayerListListener; |
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 |
|
|
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); |
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 |
*/ |
*/ |
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 |
} |
} |
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(maxAllowedExtend.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 |
} |
} |
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 |
} |
} |
1133 |
); |
); |
1134 |
} catch (IOException e) { |
} catch (IOException e) { |
1135 |
LOGGER.warn( |
LOGGER.warn( |
1136 |
"maxExtend == null; faild to getLayerBounds of context", |
"maxExtend == null; failed to getLayerBounds of context", |
1137 |
e); |
e); |
1138 |
} |
} |
1139 |
} |
} |