/[schmitzm]/trunk/src/skrueger/geotools/XMapPane.java
ViewVC logotype

Diff of /trunk/src/skrueger/geotools/XMapPane.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 431 by alfonx, Sun Oct 4 16:55:52 2009 UTC revision 493 by mojays, Fri Oct 23 14:09:27 2009 UTC
# Line 65  import org.geotools.renderer.GTRenderer; Line 65  import org.geotools.renderer.GTRenderer;
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;
# Line 77  import com.vividsolutions.jts.geom.Geome Line 77  import com.vividsolutions.jts.geom.Geome
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    
# Line 230  public class JMapPane extends JPanel imp Line 230  public class JMapPane extends JPanel imp
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>();
# Line 247  public class JMapPane extends JPanel imp Line 246  public class JMapPane extends JPanel imp
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);
# Line 379  public class JMapPane extends JPanel imp Line 370  public class JMapPane extends JPanel imp
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 */
# Line 963  public class JMapPane extends JPanel imp Line 959  public class JMapPane extends JPanel imp
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                           */                           */
# Line 971  public class JMapPane extends JPanel imp Line 967  public class JMapPane extends JPanel imp
967                          // Exceeds top? Move down and maybe cut                          // Exceeds top? Move down and maybe cut
968                          if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {                          if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
969                                  double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY();                                  double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY();
970                                  LOGGER.debug("Moving area down by " + divY);  //                              LOGGER.debug("Moving area down by " + divY);
971    
972                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),
973                                                  newArea.getMinY() - divY), new Coordinate(newArea                                                  newArea.getMinY() - divY), new Coordinate(newArea
974                                                  .getMaxX(), newArea.getMaxY() - divY));                                                  .getMaxX(), newArea.getMaxY() - divY));
975    
976                                  if (newArea.getMinY() < maxAllowedExtend.getMinY()) {                                  if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
977                                          LOGGER.debug("Now it exeeds the bottom border.. cut!");  //                                      LOGGER.debug("Now it exeeds the bottom border.. cut!");
978                                          // And cut the bottom if it moved out of the area                                          // And cut the bottom if it moved out of the area
979                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),
980                                                          maxAllowedExtend.getMinY()), new Coordinate(newArea                                                          maxAllowedExtend.getMinY()), new Coordinate(newArea
981                                                          .getMaxX(), newArea.getMaxY()));                                                          .getMaxX(), newArea.getMaxY()));
982    
983                                          LOGGER.debug("and fix aspect ratio");  //                                      LOGGER.debug("and fix aspect ratio");
984    
985                                          newArea = fixAspectRatio(this.getBounds(), newArea, false);                                          newArea = fixAspectRatio(this.getBounds(), newArea, false);
986                                  }                                  }
# Line 993  public class JMapPane extends JPanel imp Line 989  public class JMapPane extends JPanel imp
989                          // Exceeds bottom? Move up and maybe cut                          // Exceeds bottom? Move up and maybe cut
990                          if (newArea.getMinY() < maxAllowedExtend.getMinY()) {                          if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
991                                  double divY = newArea.getMinY() - maxAllowedExtend.getMinY();                                  double divY = newArea.getMinY() - maxAllowedExtend.getMinY();
992                                  LOGGER.debug("Moving area up by " + divY);  //                              LOGGER.debug("Moving area up by " + divY);
993    
994                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),
995                                                  newArea.getMinY() - divY), new Coordinate(newArea                                                  newArea.getMinY() - divY), new Coordinate(newArea
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                                  }                                  }
# Line 1017  public class JMapPane extends JPanel imp Line 1013  public class JMapPane extends JPanel imp
1013    
1014                                  // Move left..                                  // Move left..
1015                                  double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX();                                  double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX();
1016                                  LOGGER.debug("Moving area left by " + divX);  //                              LOGGER.debug("Moving area left by " + divX);
1017    
1018                                  newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,                                  newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
1019                                                  newArea.getMinY()), new Coordinate(newArea.getMaxX()                                                  newArea.getMinY()), new Coordinate(newArea.getMaxX()
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                                  }                                  }
# Line 1041  public class JMapPane extends JPanel imp Line 1037  public class JMapPane extends JPanel imp
1037    
1038                                  // Move right..                                  // Move right..
1039                                  double divX = newArea.getMinX() - maxAllowedExtend.getMinX();                                  double divX = newArea.getMinX() - maxAllowedExtend.getMinX();
1040                                  LOGGER.debug("Moving area right by " + divX);  //                              LOGGER.debug("Moving area right by " + divX);
1041    
1042                                  newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,                                  newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
1043                                                  newArea.getMinY()), new Coordinate(newArea.getMaxX()                                                  newArea.getMinY()), new Coordinate(newArea.getMaxX()
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                                  }                                  }
# Line 1134  public class JMapPane extends JPanel imp Line 1130  public class JMapPane extends JPanel imp
1130          public Envelope getMaxExtend() {          public Envelope getMaxExtend() {
1131                  if (maxExtend == null) {                  if (maxExtend == null) {
1132                          try {                          try {
1133                                  return fixAspectRatio(this.getBounds(), context.getLayerBounds(), true);                                  return fixAspectRatio(
1134                                        this.getBounds(),
1135                            // Kartenbereich um 10% vergroessern
1136                                        JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1),
1137                                        true
1138                                    );
1139                          } catch (IOException e) {                          } catch (IOException e) {
1140                                  LOGGER                                  LOGGER.warn(
1141                                                  .warn(                                                                  "maxExtend == null; failed to getLayerBounds of context",
                                                                 "maxExtend == null; faild to getLayerBounds of context",  
1142                                                                  e);                                                                  e);
1143                          }                          }
1144                  }                  }

Legend:
Removed from v.431  
changed lines
  Added in v.493

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26