/[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 506 by alfonx, Sat Oct 31 12:15:37 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 113  public class JMapPane extends JPanel imp Line 113  public class JMapPane extends JPanel imp
113           */           */
114          protected Rectangle oldRect = null;          protected Rectangle oldRect = null;
115    
116          /**          /** We store the old mapArea for a moment to use it for the
117           * the last map area drawn.          "quick scaled preview" in case of ZoomOut **/
          */  
118          protected Envelope oldMapArea = null;          protected Envelope oldMapArea = null;
119    
120          /**          /**
# Line 178  public class JMapPane extends JPanel imp Line 177  public class JMapPane extends JPanel imp
177           */           */
178          private boolean panning_started = false;          private boolean panning_started = false;
179    
180            /**
181             * This color is used as the default background color when painting a map.
182             */
183            private Color mapBackgroundColor = Color.WHITE;
184    
185          public JMapPane() {          public JMapPane() {
186                  this(null, true, null, null);                  this(null, true, null, null);
187          }          }
# Line 232  public class JMapPane extends JPanel imp Line 236  public class JMapPane extends JPanel imp
236                  Map<Object, Object> hints = new HashMap<Object, Object>();                  Map<Object, Object> hints = new HashMap<Object, Object>();
237    
238                  this.renderer = renderer;                  this.renderer = renderer;
239                    // MS: Apply hint also for ShapeFileRenderer
240                  if (renderer instanceof StreamingRenderer                  // if (renderer instanceof StreamingRenderer) {
241                                  || renderer instanceof ShapefileRenderer) {                  hints = renderer.getRendererHints();
242                          hints = renderer.getRendererHints();                  if (hints == null) {
243                          if (hints == null) {                          hints = new HashMap<Object, Object>();
244                                  hints = new HashMap<Object, Object>();                  }
245                          }                  if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {
246                          if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {                          labelCache = (LabelCache) hints
247                                  labelCache = (LabelCache) hints                                          .get(StreamingRenderer.LABEL_CACHE_KEY);
248                                                  .get(StreamingRenderer.LABEL_CACHE_KEY);                  } else {
249                          } else {                          hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
                                 hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);  
                         }  
   
                         hints.put("memoryPreloadingEnabled", Boolean.TRUE);  
   
                         renderer.setRendererHints(hints);  
250                  }                  }
251    
252                  // this.highlightRenderer = new StreamingRenderer();                  hints.put("memoryPreloadingEnabled", Boolean.TRUE);
                 // this.selectionRenderer = new StreamingRenderer();  
   
                 // highlightRenderer.setRendererHints(hints);  
                 // selectionRenderer.setRendererHints(hints);  
253    
254                  // renderer.setRendererHints(hints);                  renderer.setRendererHints(hints);
255                    // }
256    
257                  if (this.context != null) {                  if (this.context != null) {
258                          this.renderer.setContext(this.context);                          this.renderer.setContext(this.context);
# Line 335  public class JMapPane extends JPanel imp Line 330  public class JMapPane extends JPanel imp
330                                  reset = false; /* forget about the reset */                                  reset = false; /* forget about the reset */
331                                  oldRect = r; /* store what the current size is */                                  oldRect = r; /* store what the current size is */
332    
333                                  mapArea = fixAspectRatio(r, mapArea, false);                                  mapArea = JTSUtil.fixAspectRatio(r, mapArea, false);
334                          }                          }
335                  }                  }
336    
# Line 350  public class JMapPane extends JPanel imp Line 345  public class JMapPane extends JPanel imp
345    
346                  if (changed) { /* if the map changed then redraw */                  if (changed) { /* if the map changed then redraw */
347                          changed = false;                          changed = false;
348                            
349                            // The baseImage should not have alpha
350                          baseImage = new BufferedImage(dr.width, dr.height,                          baseImage = new BufferedImage(dr.width, dr.height,
351                                          BufferedImage.TYPE_INT_ARGB);                                          BufferedImage.TYPE_INT_RGB);
352    
353                          final Graphics2D ig = baseImage.createGraphics();                          final Graphics2D ig = baseImage.createGraphics();
354                          /* System.out.println("rendering"); */                          ig.setBackground(getMapBackgroundColor());
355                            ig.fillRect(0, 0, dr.width, dr.height);
356                            
357    //                      /* System.out.println("rendering"); */
358                          if (renderer.getContext() != null)                          if (renderer.getContext() != null)
359                                  renderer.setContext(context);                                  renderer.setContext(context);
360                          labelCache.clear(); // work around anoying labelcache bug  
361                            // TODO is this clearing still needed? We already replace all that stuff whenever we change the style. Deactivated 31.10.09.. let's see
362    //                      labelCache.clear(); // work around anoying labelcache bug
363    
364                          // draw the map                          // draw the map
365                          renderer.paint((Graphics2D) ig, dr, mapArea);                          renderer.paint(ig, dr, mapArea);
366    
367                          // TODO nur machen, wenn panning beginnt                          panningImage = new BufferedImage(dr.width, dr.height, BufferedImage.TYPE_INT_RGB);
                         panningImage = new BufferedImage(dr.width, dr.height,  
                                         BufferedImage.TYPE_INT_RGB);  
368    
369                  }                  }
370    
371                  ((Graphics2D) g).drawImage(baseImage, 0, 0, this);                  ((Graphics2D) g).drawImage(baseImage, 0, 0, this);
372          }          }
373    
         /**  
          * 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);  
         }  
   
374          public void mouseClicked(final MouseEvent e) {          public void mouseClicked(final MouseEvent e) {
375                  if (mapArea == null)                  if (mapArea == null)
376                          return;                          return;
# Line 543  public class JMapPane extends JPanel imp Line 494  public class JMapPane extends JPanel imp
494                                  final int dy = lastY - startY;                                  final int dy = lastY - startY;
495                                  // System.out.println("translate "+dx+","+dy);                                  // System.out.println("translate "+dx+","+dy);
496                                  final Graphics2D g2 = panningImage.createGraphics();                                  final Graphics2D g2 = panningImage.createGraphics();
497                                  g2.setBackground(new Color(240, 240, 240)); // TODO richtige                                  g2.setBackground(getMapBackgroundColor());
                                 // farbe? am besten  
                                 // vom L&F die  
                                 // hintergrundfarbe  
                                 // auslesen...  
498    
499                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());
500                                  g2.drawImage(baseImage, dx, dy, this);                                  g2.drawImage(baseImage, dx, dy, this);
# Line 627  public class JMapPane extends JPanel imp Line 574  public class JMapPane extends JPanel imp
574          protected void processDrag(final int x1, final int y1, final int x2,          protected void processDrag(final int x1, final int y1, final int x2,
575                          final int y2, final MouseEvent e) {                          final int y2, final MouseEvent e) {
576    
   
577                  /****                  /****
578                   * If no layers exist, we ignore the drag.                   * If no layers exist, we ignore the drag.
579                   */                   */
580                  if (context.getLayerCount() <= 0) {                  if (context.getLayerCount() <= 0) {
581                          return;                          return;
582                  }                  }
583                    
584                  // System.out.println("processing drag from " + x1 + "," + y1 + " -> "                  // System.out.println("processing drag from " + x1 + "," + y1 + " -> "
585                  // + x2 + "," + y2);                  // + x2 + "," + y2);
586                  if ((x1 == x2) && (y1 == y2)) {                  if ((x1 == x2) && (y1 == y2)) {
# Line 669  public class JMapPane extends JPanel imp Line 615  public class JMapPane extends JPanel imp
615                          // new edges                          // new edges
616                          final double left = mapArea.getMinX() - deltaX1;                          final double left = mapArea.getMinX() - deltaX1;
617                          final double right = mapArea.getMaxX() - deltaX1;                          final double right = mapArea.getMaxX() - deltaX1;
   
                         // now for Y  
618                          final double deltaY1 = endY - startY;                          final double deltaY1 = endY - startY;
619    
620                          // System.out.println("deltaY " + deltaY1);                          // System.out.println("deltaY " + deltaY1);
# Line 680  public class JMapPane extends JPanel imp Line 624  public class JMapPane extends JPanel imp
624                          final Coordinate ur = new Coordinate(right, top);                          final Coordinate ur = new Coordinate(right, top);
625                          // xulu.sc                          // xulu.sc
626                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
                           
627    
628                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
629                          // xulu.ec                          // xulu.ec
# Line 705  public class JMapPane extends JPanel imp Line 648  public class JMapPane extends JPanel imp
648                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
649                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
650    
                         // sk.sc  
                         // {  
                         // // SK tries to paint a preview of the zoom ;-9 aha.... well  
                         // Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();  
                         // graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,  
                         // RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);  
                         // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,  
                         // RenderingHints.VALUE_ANTIALIAS_OFF);  
                         // graphics.setRenderingHint(RenderingHints.KEY_RENDERING,  
                         // RenderingHints.VALUE_RENDER_SPEED);  
                         // graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),  
                         // JMapPane.this.getHeight(), x1, y1, x2, y2, null);  
                         // }  
                         // xulu.ec  
651                  } else if (state == JMapPane.ZoomOut) {                  } else if (state == JMapPane.ZoomOut) {
652                          drawRectangle(this.getGraphics());                          drawRectangle(this.getGraphics());
653    
# Line 783  public class JMapPane extends JPanel imp Line 712  public class JMapPane extends JPanel imp
712                  return clickable;                  return clickable;
713          }          }
714    
         //  
         // private org.geotools.styling.Style setupStyle(final int type, final Color  
         // color) {  
         // final StyleFactory sf = org.geotools.factory.CommonFactoryFinder  
         // .getStyleFactory(null);  
         // final StyleBuilder sb = new StyleBuilder();  
         //  
         // org.geotools.styling.Style s = sf.createStyle();  
         // s.setTitle("selection");  
         //  
         // // TODO parameterise the color  
         // final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);  
         // ps.setStroke(sb.createStroke(color));  
         //  
         // final LineSymbolizer ls = sb.createLineSymbolizer(color);  
         // final Graphic h = sb.createGraphic();  
         // h.setMarks(new Mark[] { sb.createMark("square", color) });  
         //  
         // final PointSymbolizer pts = sb.createPointSymbolizer(h);  
         //  
         // // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});  
         // switch (type) {  
         // case POLYGON:  
         // s = sb.createStyle(ps);  
         //  
         // break;  
         //  
         // case POINT:  
         // s = sb.createStyle(pts);  
         //  
         // break;  
         //  
         // case LINE:  
         // s = sb.createStyle(ls);  
         // }  
         //  
         // return s;  
         // }  
   
715          public void propertyChange(final PropertyChangeEvent evt) {          public void propertyChange(final PropertyChangeEvent evt) {
716                  final String prop = evt.getPropertyName();                  final String prop = evt.getPropertyName();
717    
# Line 852  public class JMapPane extends JPanel imp Line 742  public class JMapPane extends JPanel imp
742                                          mapArea = context.getLayerBounds();                                          mapArea = context.getLayerBounds();
743                                  // xulu.ec                                  // xulu.ec
744                          } catch (final IOException e) {                          } catch (final IOException e) {
745                                  // TODO Auto-generated catch block                                  LOGGER.error(e);
                                 e.printStackTrace();  
746                          }                          }
747    
748                          reset = true;                          reset = true;
# Line 926  public class JMapPane extends JPanel imp Line 815  public class JMapPane extends JPanel imp
815    
816                  /**                  /**
817                   * Correct the aspect Ratio before we check the rest. Otherwise we might                   * Correct the aspect Ratio before we check the rest. Otherwise we might
818                   * easily fail.                   * easily fail. We allow to grow here, because we don't check against
819                     * the maxExtend
820                   */                   */
821                  env = fixAspectRatio(this.getBounds(), env, false);                  env = JTSUtil.fixAspectRatio(this.getBounds(), env, true);
822    
823                  final double scale = env.getWidth() / getWidth();                  final double scale = env.getWidth() / getWidth();
824                  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 855  public class JMapPane extends JPanel imp
855                  }                  }
856    
857                  Envelope maxAllowedExtend = getMaxExtend();                  Envelope maxAllowedExtend = getMaxExtend();
858                  while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)) {                  while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)
859                                    && newArea != null && !newArea.isNull()
860                                    && !Double.isNaN(newArea.getMinX())
861                                    && !Double.isNaN(newArea.getMaxX())
862                                    && !Double.isNaN(newArea.getMinY())
863                                    && !Double.isNaN(newArea.getMaxY())) {
864                          /*                          /*
865                           * If a maxExtend is set, we have to honour that...                           * If a maxExtend is set, we have to honour that...
866                           */                           */
# Line 973  public class JMapPane extends JPanel imp Line 868  public class JMapPane extends JPanel imp
868                          // Exceeds top? Move down and maybe cut                          // Exceeds top? Move down and maybe cut
869                          if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {                          if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
870                                  double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY();                                  double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY();
871  //                              LOGGER.debug("Moving area down by " + divY);                                  // LOGGER.debug("Moving area down by " + divY);
872    
873                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),
874                                                  newArea.getMinY() - divY), new Coordinate(newArea                                                  newArea.getMinY() - divY), new Coordinate(newArea
875                                                  .getMaxX(), newArea.getMaxY() - divY));                                                  .getMaxX(), newArea.getMaxY() - divY));
876    
877                                  if (newArea.getMinY() < maxAllowedExtend.getMinY()) {                                  if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
878  //                                      LOGGER.debug("Now it exeeds the bottom border.. cut!");                                          // LOGGER.debug("Now it exeeds the bottom border.. cut!");
879                                          // And cut the bottom if it moved out of the area                                          // And cut the bottom if it moved out of the area
880                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),
881                                                          maxAllowedExtend.getMinY()), new Coordinate(newArea                                                          maxAllowedExtend.getMinY()), new Coordinate(newArea
882                                                          .getMaxX(), newArea.getMaxY()));                                                          .getMaxX(), newArea.getMaxY()));
883    
884  //                                      LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
885    
886                                          newArea = fixAspectRatio(this.getBounds(), newArea, false);                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,
887                                                            false);
888                                  }                                  }
889                          }                          }
890    
891                          // Exceeds bottom? Move up and maybe cut                          // Exceeds bottom? Move up and maybe cut
892                          if (newArea.getMinY() < maxAllowedExtend.getMinY()) {                          if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
893                                  double divY = newArea.getMinY() - maxAllowedExtend.getMinY();                                  double divY = newArea.getMinY() - maxAllowedExtend.getMinY();
894  //                              LOGGER.debug("Moving area up by " + divY);                                  // LOGGER.debug("Moving area up by " + divY);
895    
896                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),                                  newArea = new Envelope(new Coordinate(newArea.getMinX(),
897                                                  newArea.getMinY() - divY), new Coordinate(newArea                                                  newArea.getMinY() - divY), new Coordinate(newArea
898                                                  .getMaxX(), newArea.getMaxY() - divY));                                                  .getMaxX(), newArea.getMaxY() - divY));
899    
900                                  if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {                                  if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
901                                          LOGGER.debug("Now it exeeds the top border.. cut!");                                          // LOGGER.debug("Now it exeeds the top border.. cut!");
902                                          // And cut the bottom if it moved out of the area                                          // And cut the bottom if it moved out of the area
903                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),
904                                                          newArea.getMinY()), new Coordinate(newArea                                                          newArea.getMinY()), new Coordinate(newArea
905                                                          .getMaxX(), maxAllowedExtend.getMaxY()));                                                          .getMaxX(), maxAllowedExtend.getMaxY()));
906    
907                                          LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
908    
909                                          newArea = fixAspectRatio(this.getBounds(), newArea, false);                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,
910                                                            false);
911                                  }                                  }
912                          }                          }
913    
# Line 1019  public class JMapPane extends JPanel imp Line 916  public class JMapPane extends JPanel imp
916    
917                                  // Move left..                                  // Move left..
918                                  double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX();                                  double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX();
919  //                              LOGGER.debug("Moving area left by " + divX);                                  // LOGGER.debug("Moving area left by " + divX);
920    
921                                  newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,                                  newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
922                                                  newArea.getMinY()), new Coordinate(newArea.getMaxX()                                                  newArea.getMinY()), new Coordinate(newArea.getMaxX()
923                                                  - divX, newArea.getMaxY()));                                                  - divX, newArea.getMaxY()));
924    
925                                  if (newArea.getMinX() < maxAllowedExtend.getMinX()) {                                  if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
926                                          LOGGER.debug("Now it exeeds the left border.. cut!");                                          // LOGGER.debug("Now it exeeds the left border.. cut!");
927                                          // And cut the left if it moved out of the area                                          // And cut the left if it moved out of the area
928                                          newArea = new Envelope(new Coordinate(maxAllowedExtend.getMinX(),                                          newArea = new Envelope(new Coordinate(maxAllowedExtend
929                                                          newArea.getMinY()), new Coordinate(newArea                                                          .getMinX(), newArea.getMinY()), new Coordinate(
930                                                          .getMaxX(), newArea.getMaxY()));                                                          newArea.getMaxX(), newArea.getMaxY()));
931    
932                                          LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
933    
934                                          newArea = fixAspectRatio(this.getBounds(), newArea, false);                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,
935                                                            false);
936                                  }                                  }
937                          }                          }
938    
# Line 1043  public class JMapPane extends JPanel imp Line 941  public class JMapPane extends JPanel imp
941    
942                                  // Move right..                                  // Move right..
943                                  double divX = newArea.getMinX() - maxAllowedExtend.getMinX();                                  double divX = newArea.getMinX() - maxAllowedExtend.getMinX();
944  //                              LOGGER.debug("Moving area right by " + divX);                                  // LOGGER.debug("Moving area right by " + divX);
945    
946                                  newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,                                  newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
947                                                  newArea.getMinY()), new Coordinate(newArea.getMaxX()                                                  newArea.getMinY()), new Coordinate(newArea.getMaxX()
948                                                  - divX, newArea.getMaxY()));                                                  - divX, newArea.getMaxY()));
949    
950                                  if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {                                  if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
951                                          LOGGER.debug("Now it exeeds the right border.. cut!");                                          // LOGGER.debug("Now it exeeds the right border.. cut!");
952                                          // And cut the left if it moved out of the area                                          // And cut the left if it moved out of the area
953                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),                                          newArea = new Envelope(new Coordinate(newArea.getMinX(),
954                                                          newArea.getMinY()), new Coordinate(maxAllowedExtend                                                          newArea.getMinY()), new Coordinate(maxAllowedExtend
955                                                          .getMaxX(), newArea.getMaxY()));                                                          .getMaxX(), newArea.getMaxY()));
956    
957                                          LOGGER.debug("and fix aspect ratio");                                          // LOGGER.debug("and fix aspect ratio");
958    
959                                          newArea = fixAspectRatio(this.getBounds(), newArea, false);                                          newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea,
960                                                            false);
961                                  }                                  }
962                          }                          }
963    
# Line 1091  public class JMapPane extends JPanel imp Line 990  public class JMapPane extends JPanel imp
990    
991          /**          /**
992           * 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
993           * the two.           * the two. If <code>null</code> is passed, Double.MINVALUE are used which
994             * mean there is no restriction.
995           *           *
996           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
997           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
998           */           */
999          public void setMaxZoomScale(final Double maxZoomScale) {          public void setMaxZoomScale(final Double maxZoomScale) {
1000                  this.maxZoomScale = maxZoomScale;                  this.maxZoomScale = maxZoomScale == null ? Double.MIN_VALUE
1001                                    : maxZoomScale;
1002          }          }
1003    
1004          /**          /**
1005           * Set the minimum (nearest) allowed zoom scale. This is the bigger number           * Set the minimum (nearest) allowed zoom scale. This is the bigger number
1006           * value of the two.           * value of the two. If <code>null</code> is passed, Double.MAXVALUE are
1007             * used which mean there is no restriction.
1008             *
1009           *           *
1010           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
1011           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
1012           */           */
1013          public void setMinZoomScale(final Double minZoomScale) {          public void setMinZoomScale(final Double minZoomScale) {
1014                  this.minZoomScale = minZoomScale;                  this.minZoomScale = minZoomScale == null ? Double.MAX_VALUE
1015                                    : minZoomScale;
1016          }          }
1017    
1018          /**          /**
# Line 1136  public class JMapPane extends JPanel imp Line 1040  public class JMapPane extends JPanel imp
1040          public Envelope getMaxExtend() {          public Envelope getMaxExtend() {
1041                  if (maxExtend == null) {                  if (maxExtend == null) {
1042                          try {                          try {
1043                                  return fixAspectRatio(                                  return JTSUtil.fixAspectRatio(this.getBounds(),
1044                                      this.getBounds(),                                                  // Kartenbereich um 10% vergroessern
1045                          // Kartenbereich um 10% vergroessern                                                  JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1),
1046                                      JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1),                                                  true);
                                     true  
                                 );  
1047                          } catch (IOException e) {                          } catch (IOException e) {
1048                                  LOGGER.warn(                                  LOGGER
1049                                                                  "maxExtend == null; faild to getLayerBounds of context",                                                  .warn(
1050                                                                    "maxExtend == null; failed to getLayerBounds of context",
1051                                                                  e);                                                                  e);
1052                          }                          }
1053                  }                  }
1054                  return maxExtend;                  return maxExtend;
1055          }          }
1056    
1057            /**
1058             * Set the background color of the map.
1059             * @param if <code>null</code>, white is used.
1060             */
1061            public void setMapBackgroundColor(Color bgColor) {
1062                    if (bgColor == null) bgColor = Color.WHITE;
1063                    this.mapBackgroundColor = bgColor;
1064            }
1065    
1066            /**
1067             * Returns the background {@link Color} of the map pane. Default is white.
1068            **/
1069            public Color getMapBackgroundColor() {
1070                    return mapBackgroundColor;
1071            }
1072    
1073  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26