/[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 436 by mojays, Mon Oct 5 11:54:12 2009 UTC revision 505 by alfonx, Sat Oct 31 10:53:43 2009 UTC
# Line 43  import java.awt.Graphics; Line 43  import java.awt.Graphics;
43  import java.awt.Graphics2D;  import java.awt.Graphics2D;
44  import java.awt.LayoutManager;  import java.awt.LayoutManager;
45  import java.awt.Rectangle;  import java.awt.Rectangle;
46    import java.awt.RenderingHints;
47  import java.awt.event.InputEvent;  import java.awt.event.InputEvent;
48  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
49  import java.awt.event.MouseListener;  import java.awt.event.MouseListener;
50  import java.awt.event.MouseMotionListener;  import java.awt.event.MouseMotionListener;
51    import java.awt.geom.AffineTransform;
52  import java.awt.image.BufferedImage;  import java.awt.image.BufferedImage;
53  import java.beans.PropertyChangeEvent;  import java.beans.PropertyChangeEvent;
54  import java.beans.PropertyChangeListener;  import java.beans.PropertyChangeListener;
# Line 58  import java.util.Map; Line 60  import java.util.Map;
60  import javax.swing.JPanel;  import javax.swing.JPanel;
61    
62  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
 import org.geotools.geometry.jts.ReferencedEnvelope;  
63  import org.geotools.map.MapContext;  import org.geotools.map.MapContext;
64  import org.geotools.map.event.MapLayerListEvent;  import org.geotools.map.event.MapLayerListEvent;
65  import org.geotools.map.event.MapLayerListListener;  import org.geotools.map.event.MapLayerListListener;
# Line 66  import org.geotools.renderer.GTRenderer; Line 67  import org.geotools.renderer.GTRenderer;
67  import org.geotools.renderer.label.LabelCacheImpl;  import org.geotools.renderer.label.LabelCacheImpl;
68  import org.geotools.renderer.lite.LabelCache;  import org.geotools.renderer.lite.LabelCache;
69  import org.geotools.renderer.lite.StreamingRenderer;  import org.geotools.renderer.lite.StreamingRenderer;
 import org.geotools.renderer.shape.ShapefileRenderer;  
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    
# Line 79  import com.vividsolutions.jts.geom.Geome Line 79  import com.vividsolutions.jts.geom.Geome
79    
80  public class JMapPane extends JPanel implements MouseListener,  public class JMapPane extends JPanel implements MouseListener,
81                  MouseMotionListener, PropertyChangeListener, MapLayerListListener {                  MouseMotionListener, PropertyChangeListener, MapLayerListListener {
82          private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName());          private static Logger LOGGER = Logger.getLogger(JMapPane.class);
83    
84          private static final long serialVersionUID = -8647971481359690499L;          private static final long serialVersionUID = -8647971481359690499L;
85    
# Line 178  public class JMapPane extends JPanel imp Line 178  public class JMapPane extends JPanel imp
178           */           */
179          private boolean panning_started = false;          private boolean panning_started = false;
180    
181            /**
182             * This color is used as the default background color when painting a map.
183             */
184            private Color mapBackgroundColor = Color.WHITE;
185    
186          public JMapPane() {          public JMapPane() {
187                  this(null, true, null, null);                  this(null, true, null, null);
188          }          }
# Line 232  public class JMapPane extends JPanel imp Line 237  public class JMapPane extends JPanel imp
237                  Map<Object, Object> hints = new HashMap<Object, Object>();                  Map<Object, Object> hints = new HashMap<Object, Object>();
238    
239                  this.renderer = renderer;                  this.renderer = renderer;
240                    // MS: Apply hint also for ShapeFileRenderer
241                  if (renderer instanceof StreamingRenderer                  // if (renderer instanceof StreamingRenderer) {
242                                  || renderer instanceof ShapefileRenderer) {                  hints = renderer.getRendererHints();
243                          hints = renderer.getRendererHints();                  if (hints == null) {
244                          if (hints == null) {                          hints = new HashMap<Object, Object>();
245                                  hints = new HashMap<Object, Object>();                  }
246                          }                  if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {
247                          if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {                          labelCache = (LabelCache) hints
248                                  labelCache = (LabelCache) hints                                          .get(StreamingRenderer.LABEL_CACHE_KEY);
249                                                  .get(StreamingRenderer.LABEL_CACHE_KEY);                  } else {
250                          } else {                          hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
                                 hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);  
                         }  
   
                         hints.put("memoryPreloadingEnabled", Boolean.TRUE);  
   
                         renderer.setRendererHints(hints);  
251                  }                  }
252    
253                  // this.highlightRenderer = new StreamingRenderer();                  hints.put("memoryPreloadingEnabled", Boolean.TRUE);
                 // this.selectionRenderer = new StreamingRenderer();  
254    
255                  // highlightRenderer.setRendererHints(hints);                  renderer.setRendererHints(hints);
256                  // selectionRenderer.setRendererHints(hints);                  // }
   
                 // renderer.setRendererHints(hints);  
257    
258                  if (this.context != null) {                  if (this.context != null) {
259                          this.renderer.setContext(this.context);                          this.renderer.setContext(this.context);
# Line 335  public class JMapPane extends JPanel imp Line 331  public class JMapPane extends JPanel imp
331                                  reset = false; /* forget about the reset */                                  reset = false; /* forget about the reset */
332                                  oldRect = r; /* store what the current size is */                                  oldRect = r; /* store what the current size is */
333    
334                                  mapArea = fixAspectRatio(r, mapArea, false);                                  mapArea = JTSUtil.fixAspectRatio(r, mapArea, false);
335                          }                          }
336                  }                  }
337    
# Line 350  public class JMapPane extends JPanel imp Line 346  public class JMapPane extends JPanel imp
346    
347                  if (changed) { /* if the map changed then redraw */                  if (changed) { /* if the map changed then redraw */
348                          changed = false;                          changed = false;
349                            
350                            // The baseImage should not have alpha
351                          baseImage = new BufferedImage(dr.width, dr.height,                          baseImage = new BufferedImage(dr.width, dr.height,
352                                          BufferedImage.TYPE_INT_ARGB);                                          BufferedImage.TYPE_INT_RGB);
353    
354                          final Graphics2D ig = baseImage.createGraphics();                          final Graphics2D ig = baseImage.createGraphics();
355                          /* System.out.println("rendering"); */                          ig.setBackground(getMapBackgroundColor());
356                            ig.fillRect(0, 0, dr.width, dr.height);
357                            
358    //                      /* System.out.println("rendering"); */
359                          if (renderer.getContext() != null)                          if (renderer.getContext() != null)
360                                  renderer.setContext(context);                                  renderer.setContext(context);
361                          labelCache.clear(); // work around anoying labelcache bug  
362                            // TODO is this clearing still needed? We already replace all that stuff whenever we change the style. Deactivated 31.10.09.. let's see
363    //                      labelCache.clear(); // work around anoying labelcache bug
364    
365                          // draw the map                          // draw the map
366                          renderer.paint((Graphics2D) ig, dr, mapArea);                          renderer.paint(ig, dr, mapArea);
367    
368                          // TODO nur machen, wenn panning beginnt                          // TODO nur machen, wenn panning beginnt
369                          panningImage = new BufferedImage(dr.width, dr.height,                          panningImage = new BufferedImage(dr.width, dr.height,
# Line 371  public class JMapPane extends JPanel imp Line 374  public class JMapPane extends JPanel imp
374                  ((Graphics2D) g).drawImage(baseImage, 0, 0, this);                  ((Graphics2D) g).drawImage(baseImage, 0, 0, this);
375          }          }
376    
         /**  
          * Returns an {@link Envelope} that has the same aspect ratio as the given rectangle  
          * @param grow  
          *            If <code>true</code>, than the area will be enlarged to match  
          *            the aspect ratio. If <code>false</code>, it will only shrink.  
          */  
         private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea,  
                         boolean grow) {  
                   
                 if (mapArea == null) {  
                         LOGGER.warn("mapArea has been null in method fixAspectRatio, returning an unmodified ");  
                 }  
   
                 final double mapWidth = mapArea.getWidth(); /* get the extent of the map */  
                 final double mapHeight = mapArea.getHeight();  
                 final double scaleX = r.getWidth() / mapArea.getWidth(); /*  
                                                                                                                                  * calculate the  
                                                                                                                                  * new scale  
                                                                                                                                  */  
   
                 final double scaleY = r.getHeight() / mapArea.getHeight();  
                 double scale = 1.0; // stupid compiler!  
   
                 if ((grow && scaleX < scaleY) || (!grow && scaleX > scaleY)) {  
                         scale = scaleX;  
                 } else {  
                         scale = scaleY;  
                 }  
   
                 /* calculate the difference in width and height of the new extent */  
                 final double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth);  
                 final double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight);  
   
                 /*  
                  * System.out.println("delta x " + deltaX);  
                  * System.out.println("delta y " + deltaY);  
                  */  
   
                 /* create the new extent */  
                 final Coordinate ll = new Coordinate(  
                                 mapArea.getMinX() - (deltaX / 2.0), mapArea.getMinY()  
                                                 - (deltaY / 2.0));  
                 final Coordinate ur = new Coordinate(  
                                 mapArea.getMaxX() + (deltaX / 2.0), mapArea.getMaxY()  
                                                 + (deltaY / 2.0));  
   
                 return new Envelope(ll, ur);  
         }  
   
377          public void mouseClicked(final MouseEvent e) {          public void mouseClicked(final MouseEvent e) {
378                  if (mapArea == null)                  if (mapArea == null)
379                          return;                          return;
# Line 543  public class JMapPane extends JPanel imp Line 497  public class JMapPane extends JPanel imp
497                                  final int dy = lastY - startY;                                  final int dy = lastY - startY;
498                                  // System.out.println("translate "+dx+","+dy);                                  // System.out.println("translate "+dx+","+dy);
499                                  final Graphics2D g2 = panningImage.createGraphics();                                  final Graphics2D g2 = panningImage.createGraphics();
500                                  g2.setBackground(new Color(240, 240, 240)); // TODO richtige                                  g2.setBackground(getMapBackgroundColor());
                                 // farbe? am besten  
                                 // vom L&F die  
                                 // hintergrundfarbe  
                                 // auslesen...  
501    
502                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());
503                                  g2.drawImage(baseImage, dx, dy, this);                                  g2.drawImage(baseImage, dx, dy, this);
# Line 627  public class JMapPane extends JPanel imp Line 577  public class JMapPane extends JPanel imp
577          protected void processDrag(final int x1, final int y1, final int x2,          protected void processDrag(final int x1, final int y1, final int x2,
578                          final int y2, final MouseEvent e) {                          final int y2, final MouseEvent e) {
579    
   
580                  /****                  /****
581                   * If no layers exist, we ignore the drag.                   * If no layers exist, we ignore the drag.
582                   */                   */
583                  if (context.getLayerCount() <= 0) {                  if (context.getLayerCount() <= 0) {
584                          return;                          return;
585                  }                  }
586                    
587                  // System.out.println("processing drag from " + x1 + "," + y1 + " -> "                  // System.out.println("processing drag from " + x1 + "," + y1 + " -> "
588                  // + x2 + "," + y2);                  // + x2 + "," + y2);
589                  if ((x1 == x2) && (y1 == y2)) {                  if ((x1 == x2) && (y1 == y2)) {
# Line 680  public class JMapPane extends JPanel imp Line 629  public class JMapPane extends JPanel imp
629                          final Coordinate ur = new Coordinate(right, top);                          final Coordinate ur = new Coordinate(right, top);
630                          // xulu.sc                          // xulu.sc
631                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
                           
632    
633                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
634                          // xulu.ec                          // xulu.ec
# Line 706  public class JMapPane extends JPanel imp Line 654  public class JMapPane extends JPanel imp
654                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
655    
656                          // sk.sc                          // sk.sc
657                          // {                           {
658                          // // SK tries to paint a preview of the zoom ;-9 aha.... well                          // // SK tries to paint a preview of the zoom ;-9 aha.... well
659                          // Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();  //                              
660                          // graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,  //                               double reductionFactor = 1/8.;
661                          // RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);  ////                            
662                          // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,  ////                     BufferedImage reducedBaseImage = new BufferedImage((int)(baseImage.getWidth()*reductionFactor), (int)(baseImage.getHeight()*reductionFactor), BufferedImage.TYPE_INT_RGB);
663                          // RenderingHints.VALUE_ANTIALIAS_OFF);  ////                     Graphics2D reducedG = (Graphics2D) reducedBaseImage.getGraphics();
664                          // graphics.setRenderingHint(RenderingHints.KEY_RENDERING,  //                       AffineTransform reductionTransform =new AffineTransform();
665                          // RenderingHints.VALUE_RENDER_SPEED);  //                       reductionTransform.scale(reductionFactor, reductionFactor);
666                          // graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),  ////                    reducedG.drawImage(baseImage, reductionTransform, null);
667                          // JMapPane.this.getHeight(), x1, y1, x2, y2, null);  //                      
668                          // }  //                       Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();
669    ////                     graphics.getTransform().scale(reductionFactor, reductionFactor);
670    //                      
671    //                       graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
672    //                       RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
673    //                       graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
674    //                       RenderingHints.VALUE_ANTIALIAS_OFF);
675    //                       graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
676    //                       RenderingHints.VALUE_RENDER_SPEED);
677    //                       graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),
678    //                       JMapPane.this.getHeight(), x1, y1, x2, y2, null);
679                             }
680                          // xulu.ec                          // xulu.ec
681                  } else if (state == JMapPane.ZoomOut) {                  } else if (state == JMapPane.ZoomOut) {
682                          drawRectangle(this.getGraphics());                          drawRectangle(this.getGraphics());
# Line 926  public class JMapPane extends JPanel imp Line 885  public class JMapPane extends JPanel imp
885    
886                  /**                  /**
887                   * Correct the aspect Ratio before we check the rest. Otherwise we might                   * Correct the aspect Ratio before we check the rest. Otherwise we might
888                   * easily fail.                   * easily fail. We allow to grow here, because we don't check against
889                     * the maxExtend
890                   */                   */
891                  env = fixAspectRatio(this.getBounds(), env, false);                  env = JTSUtil.fixAspectRatio(this.getBounds(), env, true);
892    
893                  final double scale = env.getWidth() / getWidth();                  final double scale = env.getWidth() / getWidth();
894                  final double centerX = env.getMinX() + env.getWidth() / 2.;                  final double centerX = env.getMinX() + env.getWidth() / 2.;
# Line 965  public class JMapPane extends JPanel imp Line 925  public class JMapPane extends JPanel imp
925                  }                  }
926    
927                  Envelope maxAllowedExtend = getMaxExtend();                  Envelope maxAllowedExtend = getMaxExtend();
928                  while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)) {                  while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)
929                                    && newArea != null && !newArea.isNull()
930                                    && !Double.isNaN(newArea.getMinX())
931                                    && !Double.isNaN(newArea.getMaxX())
932                                    && !Double.isNaN(newArea.getMinY())
933                                    && !Double.isNaN(newArea.getMaxY())) {
934                          /*                          /*
935                           * If a maxExtend is set, we have to honour that...                           * If a maxExtend is set, we have to honour that...
936                           */                           */
# Line 973  public class JMapPane extends JPanel imp Line 938  public class JMapPane extends JPanel imp
938                          // Exceeds top? Move down and maybe cut                          // Exceeds top? Move down and maybe cut
939                          if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {                          if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
940                                  double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY();                                  double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY();
941  //                              LOGGER.debug("Moving area down by " + divY);                                  // LOGGER.debug("Moving area down by " + divY);
942    
943                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),
944                                                  newArea.getMinY() - divY), new Coordinate(newArea                                                  newArea.getMinY() - divY), new Coordinate(newArea
945                                                  .getMaxX(), newArea.getMaxY() - divY));                                                  .getMaxX(), newArea.getMaxY() - divY));
946    
947                                  if (newArea.getMinY() < maxAllowedExtend.getMinY()) {                                  if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
948  //                                      LOGGER.debug("Now it exeeds the bottom border.. cut!");                                          // LOGGER.debug("Now it exeeds the bottom border.. cut!");
949                                          // And cut the bottom if it moved out of the area                                          // And cut the bottom if it moved out of the area
950                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),
951                                                          maxAllowedExtend.getMinY()), new Coordinate(newArea                                                          maxAllowedExtend.getMinY()), new Coordinate(newArea
952                                                          .getMaxX(), newArea.getMaxY()));                                                          .getMaxX(), newArea.getMaxY()));
953    
954  //                                      LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
955    
956                                          newArea = fixAspectRatio(this.getBounds(), newArea, false);                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,
957                                                            false);
958                                  }                                  }
959                          }                          }
960    
961                          // Exceeds bottom? Move up and maybe cut                          // Exceeds bottom? Move up and maybe cut
962                          if (newArea.getMinY() < maxAllowedExtend.getMinY()) {                          if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
963                                  double divY = newArea.getMinY() - maxAllowedExtend.getMinY();                                  double divY = newArea.getMinY() - maxAllowedExtend.getMinY();
964  //                              LOGGER.debug("Moving area up by " + divY);                                  // LOGGER.debug("Moving area up by " + divY);
965    
966                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),
967                                                  newArea.getMinY() - divY), new Coordinate(newArea                                                  newArea.getMinY() - divY), new Coordinate(newArea
968                                                  .getMaxX(), newArea.getMaxY() - divY));                                                  .getMaxX(), newArea.getMaxY() - divY));
969    
970                                  if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {                                  if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
971                                          LOGGER.debug("Now it exeeds the top border.. cut!");                                          // LOGGER.debug("Now it exeeds the top border.. cut!");
972                                          // And cut the bottom if it moved out of the area                                          // And cut the bottom if it moved out of the area
973                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),
974                                                          newArea.getMinY()), new Coordinate(newArea                                                          newArea.getMinY()), new Coordinate(newArea
975                                                          .getMaxX(), maxAllowedExtend.getMaxY()));                                                          .getMaxX(), maxAllowedExtend.getMaxY()));
976    
977                                          LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
978    
979                                          newArea = fixAspectRatio(this.getBounds(), newArea, false);                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,
980                                                            false);
981                                  }                                  }
982                          }                          }
983    
# Line 1019  public class JMapPane extends JPanel imp Line 986  public class JMapPane extends JPanel imp
986    
987                                  // Move left..                                  // Move left..
988                                  double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX();                                  double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX();
989  //                              LOGGER.debug("Moving area left by " + divX);                                  // LOGGER.debug("Moving area left by " + divX);
990    
991                                  newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,                                  newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
992                                                  newArea.getMinY()), new Coordinate(newArea.getMaxX()                                                  newArea.getMinY()), new Coordinate(newArea.getMaxX()
993                                                  - divX, newArea.getMaxY()));                                                  - divX, newArea.getMaxY()));
994    
995                                  if (newArea.getMinX() < maxAllowedExtend.getMinX()) {                                  if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
996                                          LOGGER.debug("Now it exeeds the left border.. cut!");                                          // LOGGER.debug("Now it exeeds the left border.. cut!");
997                                          // And cut the left if it moved out of the area                                          // And cut the left if it moved out of the area
998                                          newArea = new Envelope(new Coordinate(maxAllowedExtend.getMinX(),                                          newArea = new Envelope(new Coordinate(maxAllowedExtend
999                                                          newArea.getMinY()), new Coordinate(newArea                                                          .getMinX(), newArea.getMinY()), new Coordinate(
1000                                                          .getMaxX(), newArea.getMaxY()));                                                          newArea.getMaxX(), newArea.getMaxY()));
1001    
1002                                          LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
1003    
1004                                          newArea = fixAspectRatio(this.getBounds(), newArea, false);                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,
1005                                                            false);
1006                                  }                                  }
1007                          }                          }
1008    
# Line 1043  public class JMapPane extends JPanel imp Line 1011  public class JMapPane extends JPanel imp
1011    
1012                                  // Move right..                                  // Move right..
1013                                  double divX = newArea.getMinX() - maxAllowedExtend.getMinX();                                  double divX = newArea.getMinX() - maxAllowedExtend.getMinX();
1014  //                              LOGGER.debug("Moving area right by " + divX);                                  // LOGGER.debug("Moving area right by " + divX);
1015    
1016                                  newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,                                  newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
1017                                                  newArea.getMinY()), new Coordinate(newArea.getMaxX()                                                  newArea.getMinY()), new Coordinate(newArea.getMaxX()
1018                                                  - divX, newArea.getMaxY()));                                                  - divX, newArea.getMaxY()));
1019    
1020                                  if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {                                  if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
1021                                          LOGGER.debug("Now it exeeds the right border.. cut!");                                          // LOGGER.debug("Now it exeeds the right border.. cut!");
1022                                          // And cut the left if it moved out of the area                                          // And cut the left if it moved out of the area
1023                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),
1024                                                          newArea.getMinY()), new Coordinate(maxAllowedExtend                                                          newArea.getMinY()), new Coordinate(maxAllowedExtend
1025                                                          .getMaxX(), newArea.getMaxY()));                                                          .getMaxX(), newArea.getMaxY()));
1026    
1027                                          LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
1028    
1029                                          newArea = fixAspectRatio(this.getBounds(), newArea, false);                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,
1030                                                            false);
1031                                  }                                  }
1032                          }                          }
1033    
# Line 1091  public class JMapPane extends JPanel imp Line 1060  public class JMapPane extends JPanel imp
1060    
1061          /**          /**
1062           * Set the maximum allowed zoom scale. This is the smaller number value of           * Set the maximum allowed zoom scale. This is the smaller number value of
1063           * the two.           * the two. If <code>null</code> is passed, Double.MINVALUE are used which
1064             * mean there is no restriction.
1065           *           *
1066           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
1067           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
1068           */           */
1069          public void setMaxZoomScale(final Double maxZoomScale) {          public void setMaxZoomScale(final Double maxZoomScale) {
1070                  this.maxZoomScale = maxZoomScale;                  this.maxZoomScale = maxZoomScale == null ? Double.MIN_VALUE
1071                                    : maxZoomScale;
1072          }          }
1073    
1074          /**          /**
1075           * Set the minimum (nearest) allowed zoom scale. This is the bigger number           * Set the minimum (nearest) allowed zoom scale. This is the bigger number
1076           * value of the two.           * value of the two. If <code>null</code> is passed, Double.MAXVALUE are
1077             * used which mean there is no restriction.
1078             *
1079           *           *
1080           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
1081           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
1082           */           */
1083          public void setMinZoomScale(final Double minZoomScale) {          public void setMinZoomScale(final Double minZoomScale) {
1084                  this.minZoomScale = minZoomScale;                  this.minZoomScale = minZoomScale == null ? Double.MAX_VALUE
1085                                    : minZoomScale;
1086          }          }
1087    
1088          /**          /**
# Line 1136  public class JMapPane extends JPanel imp Line 1110  public class JMapPane extends JPanel imp
1110          public Envelope getMaxExtend() {          public Envelope getMaxExtend() {
1111                  if (maxExtend == null) {                  if (maxExtend == null) {
1112                          try {                          try {
1113                                  return fixAspectRatio(                                  return JTSUtil.fixAspectRatio(this.getBounds(),
1114                                      this.getBounds(),                                                  // Kartenbereich um 10% vergroessern
1115                          // Kartenbereich um 10% vergroessern                                                  JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1),
1116                                      JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1),                                                  true);
                                     true  
                                 );  
1117                          } catch (IOException e) {                          } catch (IOException e) {
1118                                  LOGGER.warn(                                  LOGGER
1119                                                                  "maxExtend == null; faild to getLayerBounds of context",                                                  .warn(
1120                                                                    "maxExtend == null; failed to getLayerBounds of context",
1121                                                                  e);                                                                  e);
1122                          }                          }
1123                  }                  }
1124                  return maxExtend;                  return maxExtend;
1125          }          }
1126    
1127            /**
1128             * Set the background color of the map.
1129             * @param if <code>null</code>, white is used.
1130             */
1131            public void setMapBackgroundColor(Color bgColor) {
1132                    if (bgColor == null) bgColor = Color.WHITE;
1133                    this.mapBackgroundColor = bgColor;
1134            }
1135    
1136            /**
1137             * Returns the background {@link Color} of the map pane. Default is white.
1138            **/
1139            public Color getMapBackgroundColor() {
1140                    return mapBackgroundColor;
1141            }
1142    
1143  }  }

Legend:
Removed from v.436  
changed lines
  Added in v.505

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26