/[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

branches/1.0-gt2-2.6/src/org/geotools/gui/swing/JMapPane.java revision 320 by mojays, Wed Aug 26 13:49:19 2009 UTC branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java revision 445 by alfonx, Wed Oct 7 13:17:02 2009 UTC
# Line 13  Line 13 
13   *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *    Lesser General Public License for more details.   *    Lesser General Public License for more details.
15   */   */
16  package org.geotools.gui.swing;  package gtmig.org.geotools.swing;
17    
18  /**  /**
19   * <b>Xulu:<br>   * <b>Xulu:<br>
# Line 58  import java.util.Map; Line 58  import java.util.Map;
58  import javax.swing.JPanel;  import javax.swing.JPanel;
59    
60  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
 import org.geotools.feature.FeatureCollection;  
 import org.geotools.filter.IllegalFilterException;  
 import org.geotools.map.DefaultMapContext;  
61  import org.geotools.map.MapContext;  import org.geotools.map.MapContext;
 import org.geotools.map.MapLayer;  
62  import org.geotools.map.event.MapLayerListEvent;  import org.geotools.map.event.MapLayerListEvent;
63  import org.geotools.map.event.MapLayerListListener;  import org.geotools.map.event.MapLayerListListener;
 import org.geotools.referencing.crs.DefaultGeographicCRS;  
64  import org.geotools.renderer.GTRenderer;  import org.geotools.renderer.GTRenderer;
65    import org.geotools.renderer.label.LabelCacheImpl;
66  import org.geotools.renderer.lite.LabelCache;  import org.geotools.renderer.lite.LabelCache;
 import org.geotools.renderer.lite.LabelCacheDefault;  
67  import org.geotools.renderer.lite.StreamingRenderer;  import org.geotools.renderer.lite.StreamingRenderer;
68  import org.geotools.renderer.shape.TransitionShapefileRenderer;  import org.geotools.renderer.shape.ShapefileRenderer;
 import org.geotools.styling.Graphic;  
 import org.geotools.styling.LineSymbolizer;  
 import org.geotools.styling.Mark;  
 import org.geotools.styling.PointSymbolizer;  
 import org.geotools.styling.PolygonSymbolizer;  
 import org.geotools.styling.Style;  
 import org.geotools.styling.StyleBuilder;  
 import org.geotools.styling.StyleFactory;  
 import org.opengis.filter.Filter;  
69  import org.opengis.filter.FilterFactory2;  import org.opengis.filter.FilterFactory2;
70  import org.opengis.referencing.crs.CoordinateReferenceSystem;  import org.opengis.referencing.crs.CoordinateReferenceSystem;
71    
72    import schmitzm.geotools.JTSUtil;
73  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
74    
 import com.sun.jini.jeri.internal.runtime.SelectionManager;  
75  import com.vividsolutions.jts.geom.Coordinate;  import com.vividsolutions.jts.geom.Coordinate;
76  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
 import com.vividsolutions.jts.geom.Geometry;  
77  import com.vividsolutions.jts.geom.GeometryFactory;  import com.vividsolutions.jts.geom.GeometryFactory;
78    
79  public class JMapPane extends JPanel implements MouseListener,  public class JMapPane extends JPanel implements MouseListener,
80                  MouseMotionListener, HighlightChangeListener, SelectionChangeListener,                  MouseMotionListener, PropertyChangeListener, MapLayerListListener {
                 PropertyChangeListener, MapLayerListListener {  
81          private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName());          private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName());
82    
83          private static final long serialVersionUID = -8647971481359690499L;          private static final long serialVersionUID = -8647971481359690499L;
# Line 108  public class JMapPane extends JPanel imp Line 92  public class JMapPane extends JPanel imp
92    
93          public static final int Select = 4;          public static final int Select = 4;
94    
         private static final int POLYGON = 0;  
   
         private static final int LINE = 1;  
   
         private static final int POINT = 2;  
   
95          /**          /**
96           * what renders the map           * what renders the map
97           */           */
98          GTRenderer renderer;          GTRenderer renderer;
99    
         private GTRenderer highlightRenderer, selectionRenderer;  
   
100          /**          /**
101           * the map context to render           * the map context to render
102           */           */
103          MapContext context;          MapContext context;
104    
         private MapContext selectionContext;  
   
105          /**          /**
106           * the area of the map to draw           * the area of the map to draw
107           */           */
         // xulu.sc  
         // Envelope mapArea;  
108          protected Envelope mapArea;          protected Envelope mapArea;
         // xulu.ec  
109    
110          /**          /**
111           * the size of the pane last time we drew           * the size of the pane last time we drew
112           */           */
         // xulu.sc  
         // private Rectangle oldRect = null;  
113          protected Rectangle oldRect = null;          protected Rectangle oldRect = null;
         // xulu.ec  
114    
115          /**          /**
116           * the last map area drawn.           * the last map area drawn.
117           */           */
         // xulu.sc  
         // private Envelope oldMapArea = null;  
118          protected Envelope oldMapArea = null;          protected Envelope oldMapArea = null;
         // xulu.ec  
119    
120          /**          /**
121           * the base image of the map           * the base image of the map
122           */           */
123          protected BufferedImage baseImage, panningImage;          protected BufferedImage baseImage, panningImage;
         // SK: private BufferedImage baseImage, panningImage;  
   
         /**  
          * image of selection  
          */  
         private BufferedImage selectImage;  
   
         /**  
          * style for selected items  
          */  
         private Style selectionStyle;  
   
         /**  
          * layer that selection works on  
          */  
         private MapLayer selectionLayer;  
   
         /**  
          * layer that highlight works on  
          */  
         private MapLayer highlightLayer;  
   
         /**  
          * the object which manages highlighting  
          */  
         private HighlightManager highlightManager;  
   
         /**  
          * is highlighting on or off  
          */  
         private boolean highlight = true;  
124    
125          /**          /**
126           * a factory for filters           * a factory for filters
# Line 198  public class JMapPane extends JPanel imp Line 132  public class JMapPane extends JPanel imp
132           */           */
133          GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null);          GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null);
134    
         /**  
          * the collections of features to be selected or highlighted  
          */  
         FeatureCollection selection;  
   
         /**  
          * the collections of features to be selected or highlighted  
          */  
         FeatureCollection highlightFeature;  
   
135          private int state = ZoomIn;          private int state = ZoomIn;
136    
137          /**          /**
# Line 215  public class JMapPane extends JPanel imp Line 139  public class JMapPane extends JPanel imp
139           */           */
140          private double zoomFactor = 2.0;          private double zoomFactor = 2.0;
141    
         Style lineHighlightStyle;  
   
         Style pointHighlightStyle;  
   
         Style polygonHighlightStyle;  
   
         Style polygonSelectionStyle;  
   
         Style pointSelectionStyle;  
   
         Style lineSelectionStyle;  
   
142          boolean changed = true;          boolean changed = true;
143    
144          LabelCache labelCache = new LabelCacheDefault();          LabelCache labelCache = new LabelCacheImpl();
145    
         // xulu.sc  
         // private boolean reset = false;  
146          protected boolean reset = false;          protected boolean reset = false;
         // xulu.ec  
147    
148          int startX;          int startX;
149    
150          int startY;          int startY;
151    
152            /**
153             * If not <code>null</code>, the {@link JMapPane} will not allow to zoom/pan
154             * out of that area
155             **/
156            private Envelope maxExtend = null;
157    
158            // /**
159            // * Is max. 1 or 0 of the 2 axised allowed to extend the maxExtend? If
160            // * <code>true</code> the extends has to be fully inside maxExtend
161            // **/
162            // boolean maxExtendForceMode = true;
163    
164          private boolean clickable;          private boolean clickable;
165    
166          int lastX;          int lastX;
167    
168          int lastY;          int lastY;
169    
         private SelectionManager selectionManager;  
         // xulu.sn  
170          private Double maxZoomScale = Double.MIN_VALUE;          private Double maxZoomScale = Double.MIN_VALUE;
171          private Double minZoomScale = Double.MAX_VALUE;          private Double minZoomScale = Double.MAX_VALUE;
         // xulu.en  
172    
         // sk.sn  
173          /**          /**
174           * Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses           * Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses
175           * Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu           * Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu
# Line 260  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    
         // sk.en  
   
180          public JMapPane() {          public JMapPane() {
181                  this(null, true, null, null);                  this(null, true, null, null);
182          }          }
# Line 302  public class JMapPane extends JPanel imp Line 217  public class JMapPane extends JPanel imp
217    
218                  this.addMouseListener(this);                  this.addMouseListener(this);
219                  this.addMouseMotionListener(this);                  this.addMouseMotionListener(this);
                 setHighlightManager(new HighlightManager(highlightLayer));  
                 setSelectionManager(new SelectionManager(selectionLayer));  
                 lineHighlightStyle = setupStyle(LINE, Color.red);  
   
                 pointHighlightStyle = setupStyle(POINT, Color.red);  
   
                 polygonHighlightStyle = setupStyle(POLYGON, Color.red);  
   
                 polygonSelectionStyle = setupStyle(POLYGON, Color.cyan);  
   
                 pointSelectionStyle = setupStyle(POINT, Color.cyan);  
   
                 lineSelectionStyle = setupStyle(LINE, Color.cyan);  
220                  setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));                  setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
221          }          }
222    
# Line 326  public class JMapPane extends JPanel imp Line 228  public class JMapPane extends JPanel imp
228          }          }
229    
230          public void setRenderer(final GTRenderer renderer) {          public void setRenderer(final GTRenderer renderer) {
231                  Map hints = new HashMap();                  Map<Object, Object> hints = new HashMap<Object, Object>();
232                    
233                  this.renderer = renderer;                  this.renderer = renderer;
234                    
235                  if (renderer instanceof StreamingRenderer || renderer instanceof TransitionShapefileRenderer) {                  if (renderer instanceof StreamingRenderer
236                                    || renderer instanceof ShapefileRenderer) {
237                          hints = renderer.getRendererHints();                          hints = renderer.getRendererHints();
238                          if (hints == null) {                          if (hints == null) {
239                                  hints = new HashMap();                                  hints = new HashMap<Object, Object>();
240                          }                          }
241                          if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {                          if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {
242                                  labelCache = (LabelCache) hints                                  labelCache = (LabelCache) hints
# Line 343  public class JMapPane extends JPanel imp Line 246  public class JMapPane extends JPanel imp
246                          }                          }
247    
248                          hints.put("memoryPreloadingEnabled", Boolean.TRUE);                          hints.put("memoryPreloadingEnabled", Boolean.TRUE);
249                            
250                          renderer.setRendererHints(hints);                          renderer.setRendererHints(hints);
251                  }                  }
252    
 //              this.highlightRenderer = new StreamingRenderer();  
 //              this.selectionRenderer = new StreamingRenderer();  
   
 //              highlightRenderer.setRendererHints(hints);  
 //              selectionRenderer.setRendererHints(hints);  
                   
 //              renderer.setRendererHints(hints);  
   
253                  if (this.context != null) {                  if (this.context != null) {
254                          this.renderer.setContext(this.context);                          this.renderer.setContext(this.context);
255                  }                  }
# Line 406  public class JMapPane extends JPanel imp Line 301  public class JMapPane extends JPanel imp
301                  this.zoomFactor = zoomFactor;                  this.zoomFactor = zoomFactor;
302          }          }
303    
         public MapLayer getSelectionLayer() {  
                 return selectionLayer;  
         }  
   
         public void setSelectionLayer(final MapLayer selectionLayer) {  
                 this.selectionLayer = selectionLayer;  
                 if (selectionManager != null) {  
                         selectionManager.setSelectionLayer(selectionLayer);  
                 }  
         }  
   
         public boolean isHighlight() {  
                 return highlight;  
         }  
   
         public void setHighlight(final boolean highlight) {  
                 this.highlight = highlight;  
         }  
   
         public MapLayer getHighlightLayer() {  
                 return highlightLayer;  
         }  
   
         public void setHighlightLayer(final MapLayer highlightLayer) {  
                 this.highlightLayer = highlightLayer;  
   
                 if (highlightManager != null) {  
                         highlightManager.setHighlightLayer(highlightLayer);  
                 }  
         }  
   
         public HighlightManager getHighlightManager() {  
                 return highlightManager;  
         }  
   
         public void setHighlightManager(final HighlightManager highlightManager) {  
                 this.highlightManager = highlightManager;  
                 this.highlightManager.addHighlightChangeListener(this);  
                 this.addMouseMotionListener(this.highlightManager);  
         }  
   
         public Style getLineHighlightStyle() {  
                 return lineHighlightStyle;  
         }  
   
         public void setLineHighlightStyle(final Style lineHighlightStyle) {  
                 this.lineHighlightStyle = lineHighlightStyle;  
         }  
   
         public Style getLineSelectionStyle() {  
                 return lineSelectionStyle;  
         }  
   
         public void setLineSelectionStyle(final Style lineSelectionStyle) {  
                 this.lineSelectionStyle = lineSelectionStyle;  
         }  
   
         public Style getPointHighlightStyle() {  
                 return pointHighlightStyle;  
         }  
   
         public void setPointHighlightStyle(final Style pointHighlightStyle) {  
                 this.pointHighlightStyle = pointHighlightStyle;  
         }  
   
         public Style getPointSelectionStyle() {  
                 return pointSelectionStyle;  
         }  
   
         public void setPointSelectionStyle(final Style pointSelectionStyle) {  
                 this.pointSelectionStyle = pointSelectionStyle;  
         }  
   
         public Style getPolygonHighlightStyle() {  
                 return polygonHighlightStyle;  
         }  
   
         public void setPolygonHighlightStyle(final Style polygonHighlightStyle) {  
                 this.polygonHighlightStyle = polygonHighlightStyle;  
         }  
   
         public Style getPolygonSelectionStyle() {  
                 return polygonSelectionStyle;  
         }  
   
         public void setPolygonSelectionStyle(final Style polygonSelectionStyle) {  
                 this.polygonSelectionStyle = polygonSelectionStyle;  
         }  
   
304          protected void paintComponent(final Graphics g) {          protected void paintComponent(final Graphics g) {
305                  super.paintComponent(g);                  super.paintComponent(g);
306    
# Line 510  public class JMapPane extends JPanel imp Line 316  public class JMapPane extends JPanel imp
316                                  try {                                  try {
317                                          mapArea = context.getLayerBounds();                                          mapArea = context.getLayerBounds();
318                                  } catch (final IOException e) {                                  } catch (final IOException e) {
319                                          // TODO Auto-generated catch block                                          LOGGER.warn("context.getLayerBounds()", e);
                                         e.printStackTrace();  
320                                  }                                  }
321                          }                          }
322    
# Line 521  public class JMapPane extends JPanel imp Line 326  public class JMapPane extends JPanel imp
326                                  reset = false; /* forget about the reset */                                  reset = false; /* forget about the reset */
327                                  oldRect = r; /* store what the current size is */                                  oldRect = r; /* store what the current size is */
328    
329                                  mapArea = fixAspectRatio(r, mapArea);                                  mapArea = fixAspectRatio(r, mapArea, false);
330                          }                          }
331                  }                  }
332    
# Line 534  public class JMapPane extends JPanel imp Line 339  public class JMapPane extends JPanel imp
339                                          .getCoordinateReferenceSystem());                                          .getCoordinateReferenceSystem());
340                  }                  }
341    
342                  if (changed ) { /* if the map changed then redraw */                  if (changed) { /* if the map changed then redraw */
343                          changed = false;                          changed = false;
344                          baseImage = new BufferedImage(dr.width, dr.height,                          baseImage = new BufferedImage(dr.width, dr.height,
345                                          BufferedImage.TYPE_INT_ARGB);                                          BufferedImage.TYPE_INT_ARGB);
346    
347                          final Graphics2D ig = baseImage.createGraphics();                          final Graphics2D ig = baseImage.createGraphics();
348                          /* System.out.println("rendering"); */                          /* System.out.println("rendering"); */
349                          if (renderer.getContext() != null)                          if (renderer.getContext() != null)
350                                  renderer.setContext(context);                                  renderer.setContext(context);
351                          labelCache.clear(); // work around anoying labelcache bug                          labelCache.clear(); // work around anoying labelcache bug
352    
# Line 555  public class JMapPane extends JPanel imp Line 360  public class JMapPane extends JPanel imp
360                  }                  }
361    
362                  ((Graphics2D) g).drawImage(baseImage, 0, 0, this);                  ((Graphics2D) g).drawImage(baseImage, 0, 0, this);
   
                 if ((selection != null) && (selection.size() > 0)) {  
                         // paint selection  
   
                         String type = selectionLayer.getFeatureSource().getSchema()  
                                         .getDefaultGeometry().getType().getName();  
                         /* String type = selection.getDefaultGeometry().getGeometryType(); */  
                         /* System.out.println(type); */  
                         if (type == null)  
                                 type = "polygon";  
   
                         /* String type = "point"; */  
   
                         if (type.toLowerCase().endsWith("polygon")) {  
                                 selectionStyle = polygonSelectionStyle;  
                         } else if (type.toLowerCase().endsWith("point")) {  
                                 selectionStyle = pointSelectionStyle;  
                         } else if (type.toLowerCase().endsWith("line")) {  
                                 selectionStyle = lineSelectionStyle;  
                         }  
   
                         selectionContext = new DefaultMapContext(DefaultGeographicCRS.WGS84);  
   
                         selectionContext.addLayer(selection, selectionStyle);  
                         selectionRenderer.setContext(selectionContext);  
   
                         selectImage = new BufferedImage(dr.width, dr.height,  
                                         BufferedImage.TYPE_INT_ARGB);  
   
                         final Graphics2D ig = selectImage.createGraphics();  
                         /* System.out.println("rendering selection"); */  
                         selectionRenderer.paint((Graphics2D) ig, dr, mapArea);  
   
                         ((Graphics2D) g).drawImage(selectImage, 0, 0, this);  
                 }  
   
                 if (highlight && (highlightFeature != null)  
                                 && (highlightFeature.size() > 0)) {  
                         /*  
                          * String type = selection.getDefaultGeometry().getGeometryType();  
                          * System.out.println(type); if(type==null) type="polygon";  
                          */  
                         String type = highlightLayer.getFeatureSource().getSchema()  
                                         .getDefaultGeometry().getType().getName();  
                         /* String type = selection.getDefaultGeometry().getGeometryType(); */  
                         // System.out.println(type);  
                         if (type == null)  
                                 type = "polygon";  
   
                         /* String type = "point"; */  
                         Style highlightStyle = null;  
                         if (type.toLowerCase().endsWith("polygon")) {  
                                 highlightStyle = polygonHighlightStyle;  
                         } else if (type.toLowerCase().endsWith("point")) {  
                                 highlightStyle = pointHighlightStyle;  
                         } else if (type.toLowerCase().endsWith("line")) {  
                                 highlightStyle = lineHighlightStyle;  
                         }  
   
                         final MapContext highlightContext = new DefaultMapContext(  
                                         DefaultGeographicCRS.WGS84);  
   
                         highlightContext.addLayer(highlightFeature, highlightStyle);  
                         highlightRenderer.setContext(highlightContext);  
   
                         /* System.out.println("rendering highlight"); */  
                         highlightRenderer.paint((Graphics2D) g, dr, mapArea);  
                 }  
363          }          }
364    
365          private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea) {          /**
366             * Returns an {@link Envelope} that has the same aspect ratio as the given rectangle
367             * @param grow
368             *            If <code>true</code>, than the area will be enlarged to match
369             *            the aspect ratio. If <code>false</code>, it will only shrink.
370             */
371            private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea,
372                            boolean grow) {
373                    
374                    if (mapArea == null) {
375                            LOGGER.warn("mapArea has been null in method fixAspectRatio, returning an unmodified ");
376                    }
377    
378                  final double mapWidth = mapArea.getWidth(); /* get the extent of the map */                  final double mapWidth = mapArea.getWidth(); /* get the extent of the map */
379                  final double mapHeight = mapArea.getHeight();                  final double mapHeight = mapArea.getHeight();
380                  final double scaleX = r.getWidth() / mapArea.getWidth(); /*                  final double scaleX = r.getWidth() / mapArea.getWidth(); /*
381                                                                                                                           * calculate the new                                                                                                                                   * calculate the
382                                                                                                                           * scale                                                                                                                                   * new scale
383                                                                                                                           */                                                                                                                                   */
384    
385                  final double scaleY = r.getHeight() / mapArea.getHeight();                  final double scaleY = r.getHeight() / mapArea.getHeight();
386                  double scale = 1.0; // stupid compiler!                  double scale = 1.0; // stupid compiler!
387    
388                  if (scaleX < scaleY) { /* pick the smaller scale */                  if ((grow && scaleX < scaleY) || (!grow && scaleX > scaleY)) {
389                          scale = scaleX;                          scale = scaleX;
390                  } else {                  } else {
391                          scale = scaleY;                          scale = scaleY;
# Line 653  public class JMapPane extends JPanel imp Line 401  public class JMapPane extends JPanel imp
401                   */                   */
402    
403                  /* create the new extent */                  /* create the new extent */
404                  final Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0),                  final Coordinate ll = new Coordinate(
405                                  mapArea.getMinY() - (deltaY / 2.0));                                  mapArea.getMinX() - (deltaX / 2.0), mapArea.getMinY()
406                  final Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0),                                                  - (deltaY / 2.0));
407                                  mapArea.getMaxY() + (deltaY / 2.0));                  final Coordinate ur = new Coordinate(
408                                    mapArea.getMaxX() + (deltaX / 2.0), mapArea.getMaxY()
409                                                    + (deltaY / 2.0));
410    
411                  return new Envelope(ll, ur);                  return new Envelope(ll, ur);
412          }          }
413    
         public void doSelection(final double x, final double y, final MapLayer layer) {  
   
                 final Geometry geometry = gf.createPoint(new Coordinate(x, y));  
   
                 // org.opengis.geometry.Geometry geometry = new Point();  
   
                 findFeature(geometry, layer);  
   
         }  
   
         /**  
          * @param geometry  
          *            - a geometry to construct the filter with  
          * @param i  
          *            - the index of the layer to search  
          * @throws IndexOutOfBoundsException  
          */  
         private void findFeature(final Geometry geometry, final MapLayer layer)  
                         throws IndexOutOfBoundsException {  
                 org.opengis.filter.spatial.BinarySpatialOperator f = null;  
   
                 if ((context == null) || (layer == null)) {  
                         return;  
                 }  
   
                 try {  
                         String name = layer.getFeatureSource().getSchema()  
                                         .getDefaultGeometry().getLocalName();  
   
                         if (name == "") {  
                                 name = "the_geom";  
                         }  
   
                         try {  
                                 f = ff.contains(ff.property(name), ff.literal(geometry));  
                                 if (selectionManager != null) {  
 //                                      System.out.println("selection changed");  
                                         selectionManager.selectionChanged(this, f);  
   
                                 }  
                         } catch (final IllegalFilterException e) {  
                                 // TODO Auto-generated catch block  
                                 e.printStackTrace();  
                         }  
   
                         /*  
                          * // f.addLeftGeometry(ff.property(name)); //  
                          * System.out.println("looking with " + f); FeatureCollection fc =  
                          * layer.getFeatureSource().getFeatures(f);  
                          *  
                          *  
                          *  
                          * if (fcol == null) { fcol = fc;  
                          *  
                          * // here we should set the defaultgeom type } else {  
                          * fcol.addAll(fc); }  
                          */  
   
                         /*  
                          * GeometryAttributeType gat =  
                          * layer.getFeatureSource().getSchema().getDefaultGeometry();  
                          * fcol.setDefaultGeometry((Geometry)gat.createDefaultValue());  
                          */  
   
                         /*  
                          * Iterator fi = fc.iterator(); while (fi.hasNext()) { SimpleFeature feat  
                          * = (SimpleFeature) fi.next(); System.out.println("selected " +  
                          * feat.getAttribute("STATE_NAME")); }  
                          */  
                 } catch (final IllegalFilterException e) {  
                         // TODO Auto-generated catch block  
                         e.printStackTrace();  
                 }  
                 return;  
         }  
   
414          public void mouseClicked(final MouseEvent e) {          public void mouseClicked(final MouseEvent e) {
415                  if (mapArea == null) return;                  if (mapArea == null)
416                            return;
417                  // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"                  // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"
418                  // h:"+mapArea.getHeight());                  // h:"+mapArea.getHeight());
419                  final Rectangle bounds = this.getBounds();                  final Rectangle bounds = this.getBounds();
# Line 752  public class JMapPane extends JPanel imp Line 427  public class JMapPane extends JPanel imp
427                  final double width2 = width / 2.0;                  final double width2 = width / 2.0;
428                  final double height2 = height / 2.0;                  final double height2 = height / 2.0;
429                  // xulu.ec                  // xulu.ec
430                  final double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX();                  final double mapX = ((x * width) / (double) bounds.width)
431                                    + mapArea.getMinX();
432                  final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)                  final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)
433                                  + mapArea.getMinY();                                  + mapArea.getMinY();
434    
# Line 783  public class JMapPane extends JPanel imp Line 459  public class JMapPane extends JPanel imp
459                          zlevel = 1.0 / zoomFactor;                          zlevel = 1.0 / zoomFactor;
460    
461                          break;                          break;
462                    //
463                  case Select:                  // case Select:
464                          doSelection(mapX, mapY, selectionLayer);                  // doSelection(mapX, mapY, selectionLayer);
465                    //
466                          return;                  // return;
467    
468                  default:                  default:
469                          return;                          return;
# Line 859  public class JMapPane extends JPanel imp Line 535  public class JMapPane extends JPanel imp
535                                  // System.out.println("translate "+dx+","+dy);                                  // System.out.println("translate "+dx+","+dy);
536                                  final Graphics2D g2 = panningImage.createGraphics();                                  final Graphics2D g2 = panningImage.createGraphics();
537                                  g2.setBackground(new Color(240, 240, 240)); // TODO richtige                                  g2.setBackground(new Color(240, 240, 240)); // TODO richtige
538                                                                                                                          // farbe? am besten                                  // farbe? am besten
539                                                                                                                          // vom L&F die                                  // vom L&F die
540                                                                                                                          // hintergrundfarbe                                  // hintergrundfarbe
541                                                                                                                          // auslesen...                                  // auslesen...
542                                    
543                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());
544                                  g2.drawImage(baseImage, dx, dy, this);                                  g2.drawImage(baseImage, dx, dy, this);
545                                  graphics.drawImage(panningImage, 0, 0, this);                                  graphics.drawImage(panningImage, 0, 0, this);
# Line 885  public class JMapPane extends JPanel imp Line 561  public class JMapPane extends JPanel imp
561                          lastX = x;                          lastX = x;
562                          lastY = y;                          lastY = y;
563                          drawRectangle(graphics);                          drawRectangle(graphics);
                 } else if (state == JMapPane.Select && selectionLayer != null) {  
   
                         // construct a new bbox filter  
                         final Rectangle bounds = this.getBounds();  
   
                         final double mapWidth = mapArea.getWidth();  
                         final double mapHeight = mapArea.getHeight();  
   
                         final double x1 = ((this.startX * mapWidth) / (double) bounds.width)  
                                         + mapArea.getMinX();  
                         final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height)  
                                         + mapArea.getMinY();  
                         final double x2 = ((x * mapWidth) / (double) bounds.width)  
                                         + mapArea.getMinX();  
                         final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height)  
                                         + mapArea.getMinY();  
                         final double left = Math.min(x1, x2);  
                         final double right = Math.max(x1, x2);  
                         final double bottom = Math.min(y1, y2);  
                         final double top = Math.max(y1, y2);  
   
                         String name = selectionLayer.getFeatureSource().getSchema()  
                                         .getDefaultGeometry().getName();  
   
                         if (name == "") {  
                                 name = "the_geom";  
                         }  
                         final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,  
                                         getContext().getCoordinateReferenceSystem().toString());  
                         if (selectionManager != null) {  
                                 selectionManager.selectionChanged(this, bb);  
                         }  
   
                         graphics.setXORMode(Color.green);  
   
                         /*  
                          * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); }  
                          */  
   
                         // draw new box  
                         lastX = x;  
                         lastY = y;  
                         drawRectangle(graphics);  
564                  }                  }
565                    // else if (state == JMapPane.Select && selectionLayer != null) {
566                    //
567                    // // construct a new bbox filter
568                    // final Rectangle bounds = this.getBounds();
569                    //
570                    // final double mapWidth = mapArea.getWidth();
571                    // final double mapHeight = mapArea.getHeight();
572                    //
573                    // final double x1 = ((this.startX * mapWidth) / (double) bounds.width)
574                    // + mapArea.getMinX();
575                    // final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) /
576                    // (double) bounds.height)
577                    // + mapArea.getMinY();
578                    // final double x2 = ((x * mapWidth) / (double) bounds.width)
579                    // + mapArea.getMinX();
580                    // final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double)
581                    // bounds.height)
582                    // + mapArea.getMinY();
583                    // final double left = Math.min(x1, x2);
584                    // final double right = Math.max(x1, x2);
585                    // final double bottom = Math.min(y1, y2);
586                    // final double top = Math.max(y1, y2);
587                    //
588                    // String name = selectionLayer.getFeatureSource().getSchema()
589                    // .getDefaultGeometry().getName();
590                    //
591                    // if (name == "") {
592                    // name = "the_geom";
593                    // }
594                    // final Filter bb = ff.bbox(ff.property(name), left, bottom, right,
595                    // top,
596                    // getContext().getCoordinateReferenceSystem().toString());
597                    // if (selectionManager != null) {
598                    // selectionManager.selectionChanged(this, bb);
599                    // }
600                    //
601                    // graphics.setXORMode(Color.green);
602                    //
603                    // /*
604                    // * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); }
605                    // */
606                    //
607                    // // draw new box
608                    // lastX = x;
609                    // lastY = y;
610                    // drawRectangle(graphics);
611                    // }
612    
613          }          }
614    
# Line 938  public class JMapPane extends JPanel imp Line 618  public class JMapPane extends JPanel imp
618          protected void processDrag(final int x1, final int y1, final int x2,          protected void processDrag(final int x1, final int y1, final int x2,
619                          final int y2, final MouseEvent e) {                          final int y2, final MouseEvent e) {
620    
621    
622                  /****                  /****
623                   * If no layer is availabe we dont want a NullPointerException                   * If no layers exist, we ignore the drag.
624                   */                   */
625                  if (mapArea == null)                  if (context.getLayerCount() <= 0) {
626                          return;                          return;
627                    }
628                    
629                  // System.out.println("processing drag from " + x1 + "," + y1 + " -> "                  // System.out.println("processing drag from " + x1 + "," + y1 + " -> "
630                  // + x2 + "," + y2);                  // + x2 + "," + y2);
631                  if ((x1 == x2) && (y1 == y2)) {                  if ((x1 == x2) && (y1 == y2)) {
# Line 989  public class JMapPane extends JPanel imp Line 671  public class JMapPane extends JPanel imp
671                          final Coordinate ur = new Coordinate(right, top);                          final Coordinate ur = new Coordinate(right, top);
672                          // xulu.sc                          // xulu.sc
673                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
674                          setMapArea(fixAspectRatio(this.getBounds(), new Envelope(ll, ur)));                          
675    
676                            setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
677                          // xulu.ec                          // xulu.ec
678                  } else if (state == JMapPane.ZoomIn) {                  } else if (state == JMapPane.ZoomIn) {
679    
# Line 1013  public class JMapPane extends JPanel imp Line 697  public class JMapPane extends JPanel imp
697                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
698    
699                          // sk.sc                          // sk.sc
700  //                      {                          // {
701  //                      // SK tries to paint a preview of the zoom ;-9 aha.... well                          // // SK tries to paint a preview of the zoom ;-9 aha.... well
702  //                      Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();                          // Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();
703  //                      graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,                          // graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
704  //                                      RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);                          // RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
705  //                      graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,                          // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
706  //                                      RenderingHints.VALUE_ANTIALIAS_OFF);                          // RenderingHints.VALUE_ANTIALIAS_OFF);
707  //                      graphics.setRenderingHint(RenderingHints.KEY_RENDERING,                          // graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
708  //                                      RenderingHints.VALUE_RENDER_SPEED);                          // RenderingHints.VALUE_RENDER_SPEED);
709  //                      graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),                          // graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),
710  //                                      JMapPane.this.getHeight(), x1, y1, x2, y2, null);                          // JMapPane.this.getHeight(), x1, y1, x2, y2, null);
711  //                      }                          // }
712                          // xulu.ec                          // xulu.ec
713                  } else if (state == JMapPane.ZoomOut) {                  } else if (state == JMapPane.ZoomOut) {
714                          drawRectangle(this.getGraphics());                          drawRectangle(this.getGraphics());
# Line 1053  public class JMapPane extends JPanel imp Line 737  public class JMapPane extends JPanel imp
737                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
738    
739                          // xulu.ec                          // xulu.ec
                 } else if (state == JMapPane.Select && selectionLayer != null) {  
                         final double left = Math.min(startX, endX);  
                         final double right = Math.max(startX, endX);  
                         final double bottom = Math.min(startY, endY);  
                         final double top = Math.max(startY, endY);  
   
                         String name = selectionLayer.getFeatureSource().getSchema()  
                                         .getDefaultGeometry().getLocalName();  
   
                         if (name == "") {  
                                 name = "the_geom";  
                         }  
                         final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,  
                                         getContext().getCoordinateReferenceSystem().toString());  
                         // System.out.println(bb.toString());  
                         if (selectionManager != null) {  
                                 selectionManager.selectionChanged(this, bb);  
                         }  
                         /*  
                          * FeatureCollection fc; selection = null; try { fc =  
                          * selectionLayer.getFeatureSource().getFeatures(bb); selection =  
                          * fc; } catch (IOException e) { e.printStackTrace(); }  
                          */  
740                  }                  }
741                    // else if (state == JMapPane.Select && selectionLayer != null) {
742                    // final double left = Math.min(startX, endX);
743                    // final double right = Math.max(startX, endX);
744                    // final double bottom = Math.min(startY, endY);
745                    // final double top = Math.max(startY, endY);
746                    //
747                    // String name = selectionLayer.getFeatureSource().getSchema()
748                    // .getDefaultGeometry().getLocalName();
749                    //
750                    // if (name == "") {
751                    // name = "the_geom";
752                    // }
753                    // final Filter bb = ff.bbox(ff.property(name), left, bottom, right,
754                    // top,
755                    // getContext().getCoordinateReferenceSystem().toString());
756                    // // System.out.println(bb.toString());
757                    // if (selectionManager != null) {
758                    // selectionManager.selectionChanged(this, bb);
759                    // }
760                    // /*
761                    // * FeatureCollection fc; selection = null; try { fc =
762                    // * selectionLayer.getFeatureSource().getFeatures(bb); selection =
763                    // * fc; } catch (IOException e) { e.printStackTrace(); }
764                    // */
765                    // }
766    
767                  // xulu.so                  // xulu.so
768                  // setMapArea(mapArea);                  // setMapArea(mapArea);
# Line 1088  public class JMapPane extends JPanel imp Line 774  public class JMapPane extends JPanel imp
774                  return clickable;                  return clickable;
775          }          }
776    
777          private org.geotools.styling.Style setupStyle(final int type, final Color color) {          //
778                  final StyleFactory sf = org.geotools.factory.CommonFactoryFinder          // private org.geotools.styling.Style setupStyle(final int type, final Color
779                                  .getStyleFactory(null);          // color) {
780                  final StyleBuilder sb = new StyleBuilder();          // final StyleFactory sf = org.geotools.factory.CommonFactoryFinder
781            // .getStyleFactory(null);
782                  org.geotools.styling.Style s = sf.createStyle();          // final StyleBuilder sb = new StyleBuilder();
783                  s.setTitle("selection");          //
784            // org.geotools.styling.Style s = sf.createStyle();
785                  // TODO parameterise the color          // s.setTitle("selection");
786                  final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);          //
787                  ps.setStroke(sb.createStroke(color));          // // TODO parameterise the color
788            // final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);
789                  final LineSymbolizer ls = sb.createLineSymbolizer(color);          // ps.setStroke(sb.createStroke(color));
790                  final Graphic h = sb.createGraphic();          //
791                  h.setMarks(new Mark[] { sb.createMark("square", color) });          // final LineSymbolizer ls = sb.createLineSymbolizer(color);
792            // final Graphic h = sb.createGraphic();
793                  final PointSymbolizer pts = sb.createPointSymbolizer(h);          // h.setMarks(new Mark[] { sb.createMark("square", color) });
794            //
795                  // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});          // final PointSymbolizer pts = sb.createPointSymbolizer(h);
796                  switch (type) {          //
797                  case POLYGON:          // // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});
798                          s = sb.createStyle(ps);          // switch (type) {
799            // case POLYGON:
800                          break;          // s = sb.createStyle(ps);
801            //
802                  case POINT:          // break;
803                          s = sb.createStyle(pts);          //
804            // case POINT:
805                          break;          // s = sb.createStyle(pts);
806            //
807                  case LINE:          // break;
808                          s = sb.createStyle(ls);          //
809                  }          // case LINE:
810            // s = sb.createStyle(ls);
811                  return s;          // }
812          }          //
813            // return s;
814          public void highlightChanged(final HighlightChangedEvent e) {          // }
                 final org.opengis.filter.Filter f = e.getFilter();  
   
                 try {  
                         highlightFeature = highlightLayer.getFeatureSource().getFeatures(f);  
                 } catch (final IOException e1) {  
                         // TODO Auto-generated catch block  
                         e1.printStackTrace();  
                 }  
   
                 repaint();  
         }  
815    
816          public void propertyChange(final PropertyChangeEvent evt) {          public void propertyChange(final PropertyChangeEvent evt) {
817                  final String prop = evt.getPropertyName();                  final String prop = evt.getPropertyName();
# Line 1220  public class JMapPane extends JPanel imp Line 895  public class JMapPane extends JPanel imp
895          public void mouseMoved(final MouseEvent e) {          public void mouseMoved(final MouseEvent e) {
896          }          }
897    
         public FeatureCollection getSelection() {  
                 return selection;  
         }  
   
         public void setSelection(final FeatureCollection selection) {  
                 this.selection = selection;  
                 repaint();  
         }  
   
         /*  
          * (non-Javadoc)  
          *  
          * @see  
          * org.geotools.gui.swing.event.SelectionChangeListener#selectionChanged  
          * (org.geotools.gui.swing.event.SelectionChangedEvent)  
          */  
         public void selectionChanged(final SelectionChangedEvent e) {  
   
                 try {  
                         selection = selectionLayer.getFeatureSource().getFeatures(  
                                         e.getFilter());  
                         repaint();  
                 } catch (final IOException e1) {  
                         e1.printStackTrace();  
                 }  
         }  
   
         public SelectionManager getSelectionManager() {  
                 return selectionManager;  
         }  
   
         public void setSelectionManager(final SelectionManager selectionManager) {  
                 this.selectionManager = selectionManager;  
                 this.selectionManager.addSelectionChangeListener(this);  
   
         }  
   
898          // xulu.sn          // xulu.sn
899          /**          /**
900           * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste           * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste
# Line 1275  public class JMapPane extends JPanel imp Line 913  public class JMapPane extends JPanel imp
913                  if (env == null)                  if (env == null)
914                          return env;                          return env;
915    
916                    Envelope newArea = null;
917    
918                  /**                  /**
919                   * Correct the aspect Ratio before we check the rest. Otherwise we might                   * Correct the aspect Ratio before we check the rest. Otherwise we might
920                   * easily fail.                   * easily fail.
921                   */                   */
922                  env = fixAspectRatio(this.getBounds(), env);                  env = fixAspectRatio(this.getBounds(), env, false);
923    
924                  final double scale = env.getWidth() / getWidth();                  final double scale = env.getWidth() / getWidth();
925                  final double centerX = env.getMinX() + env.getWidth() / 2.;                  final double centerX = env.getMinX() + env.getWidth() / 2.;
926                  final double centerY = env.getMinY() + env.getHeight() / 2.;                  final double centerY = env.getMinY() + env.getHeight() / 2.;
927                  double newWidth2;                  double newWidth2 = 0;
928                  double newHeight2;                  double newHeight2 = 0;
929                  if (scale < getMaxZoomScale()) {                  if (scale < getMaxZoomScale()) {
930                          // ****************************************************************************                          // ****************************************************************************
931                          // Wir zoomen weiter rein als erlaubt => Anpassen des envelope                          // Wir zoomen weiter rein als erlaubt => Anpassen des envelope
# Line 1302  public class JMapPane extends JPanel imp Line 942  public class JMapPane extends JPanel imp
942                          // ****************************************************************************                          // ****************************************************************************
943                          // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen                          // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen
944                          // ****************************************************************************                          // ****************************************************************************
945                          return env;                          newArea = env;
946                  }                  }
947    
948                  final Coordinate ll = new Coordinate(centerX - newWidth2, centerY                  if (newArea == null) {
                                 - newHeight2);  
                 final Coordinate ur = new Coordinate(centerX + newWidth2, centerY  
                                 + newHeight2);  
949    
950                  return new Envelope(ll, ur);                          final Coordinate ll = new Coordinate(centerX - newWidth2, centerY
951                                            - newHeight2);
952                            final Coordinate ur = new Coordinate(centerX + newWidth2, centerY
953                                            + newHeight2);
954    
955                            newArea = new Envelope(ll, ur);
956                    }
957    
958                    Envelope maxAllowedExtend = getMaxExtend();
959                    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()) ) {
960                            /*
961                             * If a maxExtend is set, we have to honour that...
962                             */
963    
964                            // Exceeds top? Move down and maybe cut
965                            if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
966                                    double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY();
967    //                              LOGGER.debug("Moving area down by " + divY);
968    
969                                    newArea = new Envelope(new Coordinate(newArea.getMinX(),
970                                                    newArea.getMinY() - divY), new Coordinate(newArea
971                                                    .getMaxX(), newArea.getMaxY() - divY));
972    
973                                    if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
974    //                                      LOGGER.debug("Now it exeeds the bottom border.. cut!");
975                                            // And cut the bottom if it moved out of the area
976                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
977                                                            maxAllowedExtend.getMinY()), new Coordinate(newArea
978                                                            .getMaxX(), newArea.getMaxY()));
979    
980    //                                      LOGGER.debug("and fix aspect ratio");
981    
982                                            newArea = fixAspectRatio(this.getBounds(), newArea, false);
983                                    }
984                            }
985    
986                            // Exceeds bottom? Move up and maybe cut
987                            if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
988                                    double divY = newArea.getMinY() - maxAllowedExtend.getMinY();
989    //                              LOGGER.debug("Moving area up by " + divY);
990    
991                                    newArea = new Envelope(new Coordinate(newArea.getMinX(),
992                                                    newArea.getMinY() - divY), new Coordinate(newArea
993                                                    .getMaxX(), newArea.getMaxY() - divY));
994    
995                                    if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
996    //                                      LOGGER.debug("Now it exeeds the top border.. cut!");
997                                            // And cut the bottom if it moved out of the area
998                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
999                                                            newArea.getMinY()), new Coordinate(newArea
1000                                                            .getMaxX(), maxAllowedExtend.getMaxY()));
1001    
1002    //                                      LOGGER.debug("and fix aspect ratio");
1003    
1004                                            newArea = fixAspectRatio(this.getBounds(), newArea, false);
1005                                    }
1006                            }
1007    
1008                            // Exceeds to the right? move and maybe cut
1009                            if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
1010    
1011                                    // Move left..
1012                                    double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX();
1013    //                              LOGGER.debug("Moving area left by " + divX);
1014    
1015                                    newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
1016                                                    newArea.getMinY()), new Coordinate(newArea.getMaxX()
1017                                                    - divX, newArea.getMaxY()));
1018    
1019                                    if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
1020    //                                      LOGGER.debug("Now it exeeds the left border.. cut!");
1021                                            // And cut the left if it moved out of the area
1022                                            newArea = new Envelope(new Coordinate(maxAllowedExtend.getMinX(),
1023                                                            newArea.getMinY()), new Coordinate(newArea
1024                                                            .getMaxX(), newArea.getMaxY()));
1025    
1026    //                                      LOGGER.debug("and fix aspect ratio");
1027    
1028                                            newArea = fixAspectRatio(this.getBounds(), newArea, false);
1029                                    }
1030                            }
1031    
1032                            // Exceeds to the left? move and maybe cut
1033                            if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
1034    
1035                                    // Move right..
1036                                    double divX = newArea.getMinX() - maxAllowedExtend.getMinX();
1037    //                              LOGGER.debug("Moving area right by " + divX);
1038    
1039                                    newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
1040                                                    newArea.getMinY()), new Coordinate(newArea.getMaxX()
1041                                                    - divX, newArea.getMaxY()));
1042    
1043                                    if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
1044    //                                      LOGGER.debug("Now it exeeds the right border.. cut!");
1045                                            // And cut the left if it moved out of the area
1046                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
1047                                                            newArea.getMinY()), new Coordinate(maxAllowedExtend
1048                                                            .getMaxX(), newArea.getMaxY()));
1049    
1050    //                                      LOGGER.debug("and fix aspect ratio");
1051    
1052                                            newArea = fixAspectRatio(this.getBounds(), newArea, false);
1053                                    }
1054                            }
1055    
1056                    }
1057    
1058                    return newArea;
1059          }          }
1060    
1061          /**          /**
# Line 1343  public class JMapPane extends JPanel imp Line 1088  public class JMapPane extends JPanel imp
1088           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
1089           */           */
1090          public void setMaxZoomScale(final Double maxZoomScale) {          public void setMaxZoomScale(final Double maxZoomScale) {
                 // System.out.println("setting max scale to "+maxZoomScale);  
1091                  this.maxZoomScale = maxZoomScale;                  this.maxZoomScale = maxZoomScale;
1092          }          }
1093    
# Line 1357  public class JMapPane extends JPanel imp Line 1101  public class JMapPane extends JPanel imp
1101          public void setMinZoomScale(final Double minZoomScale) {          public void setMinZoomScale(final Double minZoomScale) {
1102                  this.minZoomScale = minZoomScale;                  this.minZoomScale = minZoomScale;
1103          }          }
1104          // xulu.en  
1105            /**
1106             * Defines an evelope of the viwable area. The JMapPane will never show
1107             * anything outside of this extend.
1108             *
1109             * @param maxExtend
1110             *            <code>null</code> to not have this restriction.
1111             */
1112            public void setMaxExtend(Envelope maxExtend) {
1113                    this.maxExtend = maxExtend;
1114            }
1115    
1116            /**
1117             * Returns the evelope of the viewable area. The JMapPane will never show
1118             * anything outside of this extend. If this has been set to
1119             * <code>null</code> via {@link #setMaxExtend(Envelope)}, it tries to return
1120             * quickly the context's bounds. It it takes to long to determine the
1121             * context bounds, <code>null</code> is returned.
1122             *
1123             * @param maxExtend
1124             *            <code>null</code> to not have this restriction.
1125             */
1126    
1127            public Envelope getMaxExtend() {
1128                    if (maxExtend == null) {
1129                            try {
1130                                    return fixAspectRatio(
1131                                        this.getBounds(),
1132                            // Kartenbereich um 10% vergroessern
1133                                        JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1),
1134                                        true
1135                                    );
1136                            } catch (IOException e) {
1137                                    LOGGER.warn(
1138                                                                    "maxExtend == null; faild to getLayerBounds of context",
1139                                                                    e);
1140                            }
1141                    }
1142                    return maxExtend;
1143            }
1144    
1145  }  }

Legend:
Removed from v.320  
changed lines
  Added in v.445

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26