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); |
370 |
boolean grow) { |
boolean grow) { |
371 |
|
|
372 |
if (mapArea == null) { |
if (mapArea == null) { |
373 |
LOGGER.warn("mapArea has been null in method fixAspectRatio, returning an unmodified "); |
LOGGER.warn("mapArea has been null in method fixAspectRatio, returning also NULL"); |
374 |
|
return null; |
375 |
|
} |
376 |
|
if ( r == null || r.width == 0 || r.height == 0 ) { |
377 |
|
LOGGER.warn("Empty rectangle in method fixAspectRatio, returning an unmodified mapArea!"); |
378 |
|
return mapArea; |
379 |
} |
} |
380 |
|
|
381 |
final double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
final double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
959 |
} |
} |
960 |
|
|
961 |
Envelope maxAllowedExtend = getMaxExtend(); |
Envelope maxAllowedExtend = getMaxExtend(); |
962 |
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()) ) { |
963 |
/* |
/* |
964 |
* If a maxExtend is set, we have to honour that... |
* If a maxExtend is set, we have to honour that... |
965 |
*/ |
*/ |
996 |
.getMaxX(), newArea.getMaxY() - divY)); |
.getMaxX(), newArea.getMaxY() - divY)); |
997 |
|
|
998 |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
999 |
LOGGER.debug("Now it exeeds the top border.. cut!"); |
// LOGGER.debug("Now it exeeds the top border.. cut!"); |
1000 |
// And cut the bottom if it moved out of the area |
// And cut the bottom if it moved out of the area |
1001 |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
1002 |
newArea.getMinY()), new Coordinate(newArea |
newArea.getMinY()), new Coordinate(newArea |
1003 |
.getMaxX(), maxAllowedExtend.getMaxY())); |
.getMaxX(), maxAllowedExtend.getMaxY())); |
1004 |
|
|
1005 |
LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
1006 |
|
|
1007 |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
1008 |
} |
} |
1020 |
- divX, newArea.getMaxY())); |
- divX, newArea.getMaxY())); |
1021 |
|
|
1022 |
if (newArea.getMinX() < maxAllowedExtend.getMinX()) { |
if (newArea.getMinX() < maxAllowedExtend.getMinX()) { |
1023 |
LOGGER.debug("Now it exeeds the left border.. cut!"); |
// LOGGER.debug("Now it exeeds the left border.. cut!"); |
1024 |
// And cut the left if it moved out of the area |
// And cut the left if it moved out of the area |
1025 |
newArea = new Envelope(new Coordinate(maxAllowedExtend.getMinX(), |
newArea = new Envelope(new Coordinate(maxAllowedExtend.getMinX(), |
1026 |
newArea.getMinY()), new Coordinate(newArea |
newArea.getMinY()), new Coordinate(newArea |
1027 |
.getMaxX(), newArea.getMaxY())); |
.getMaxX(), newArea.getMaxY())); |
1028 |
|
|
1029 |
LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
1030 |
|
|
1031 |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
1032 |
} |
} |
1044 |
- divX, newArea.getMaxY())); |
- divX, newArea.getMaxY())); |
1045 |
|
|
1046 |
if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) { |
if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) { |
1047 |
LOGGER.debug("Now it exeeds the right border.. cut!"); |
// LOGGER.debug("Now it exeeds the right border.. cut!"); |
1048 |
// And cut the left if it moved out of the area |
// And cut the left if it moved out of the area |
1049 |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
1050 |
newArea.getMinY()), new Coordinate(maxAllowedExtend |
newArea.getMinY()), new Coordinate(maxAllowedExtend |
1051 |
.getMaxX(), newArea.getMaxY())); |
.getMaxX(), newArea.getMaxY())); |
1052 |
|
|
1053 |
LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
1054 |
|
|
1055 |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
1056 |
} |
} |
1138 |
); |
); |
1139 |
} catch (IOException e) { |
} catch (IOException e) { |
1140 |
LOGGER.warn( |
LOGGER.warn( |
1141 |
"maxExtend == null; faild to getLayerBounds of context", |
"maxExtend == null; failed to getLayerBounds of context", |
1142 |
e); |
e); |
1143 |
} |
} |
1144 |
} |
} |