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

trunk/src/org/geotools/gui/swing/JMapPane.java revision 127 by mojays, Sat May 30 14:29:58 2009 UTC branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java revision 436 by mojays, Mon Oct 5 11:54:12 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;
61  import org.geotools.feature.FeatureCollection;  import org.geotools.geometry.jts.ReferencedEnvelope;
 import org.geotools.filter.IllegalFilterException;  
 import org.geotools.gui.swing.event.HighlightChangeListener;  
 import org.geotools.gui.swing.event.HighlightChangedEvent;  
 import org.geotools.gui.swing.event.SelectionChangeListener;  
 import org.geotools.gui.swing.event.SelectionChangedEvent;  
 import org.geotools.map.DefaultMapContext;  
62  import org.geotools.map.MapContext;  import org.geotools.map.MapContext;
 import org.geotools.map.MapLayer;  
63  import org.geotools.map.event.MapLayerListEvent;  import org.geotools.map.event.MapLayerListEvent;
64  import org.geotools.map.event.MapLayerListListener;  import org.geotools.map.event.MapLayerListListener;
 import org.geotools.referencing.crs.DefaultGeographicCRS;  
65  import org.geotools.renderer.GTRenderer;  import org.geotools.renderer.GTRenderer;
66    import org.geotools.renderer.label.LabelCacheImpl;
67  import org.geotools.renderer.lite.LabelCache;  import org.geotools.renderer.lite.LabelCache;
 import org.geotools.renderer.lite.LabelCacheDefault;  
68  import org.geotools.renderer.lite.StreamingRenderer;  import org.geotools.renderer.lite.StreamingRenderer;
69  import org.geotools.styling.Graphic;  import org.geotools.renderer.shape.ShapefileRenderer;
 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;  
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    
73    import schmitzm.geotools.JTSUtil;
74  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
75    
76  import com.vividsolutions.jts.geom.Coordinate;  import com.vividsolutions.jts.geom.Coordinate;
77  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
 import com.vividsolutions.jts.geom.Geometry;  
78  import com.vividsolutions.jts.geom.GeometryFactory;  import com.vividsolutions.jts.geom.GeometryFactory;
79    
80  public class JMapPane extends JPanel implements MouseListener,  public class JMapPane extends JPanel implements MouseListener,
81          MouseMotionListener, HighlightChangeListener,SelectionChangeListener, PropertyChangeListener,                  MouseMotionListener, PropertyChangeListener, MapLayerListListener {
82          MapLayerListListener {          private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName());
     private static Logger LOGGER = Logger.getLogger( JMapPane.class.getName() );  
    /**  
      *  
      */  
     private static final long serialVersionUID = -8647971481359690499L;  
83    
84      public static final int Reset = 0;          private static final long serialVersionUID = -8647971481359690499L;
85    
86      public static final int ZoomIn = 1;          public static final int Reset = 0;
87    
88      public static final int ZoomOut = 2;          public static final int ZoomIn = 1;
89    
90      public static final int Pan = 3;          public static final int ZoomOut = 2;
91    
92      public static final int Select = 4;          public static final int Pan = 3;
93    
94      private static final int POLYGON = 0;          public static final int Select = 4;
95    
96      private static final int LINE = 1;          /**
97             * what renders the map
98             */
99            GTRenderer renderer;
100    
101      private static final int POINT = 2;          /**
102             * the map context to render
103             */
104            MapContext context;
105    
106      /**          /**
107       * what renders the map           * the area of the map to draw
108       */           */
109      GTRenderer renderer;          protected Envelope mapArea;
110    
111      private GTRenderer highlightRenderer, selectionRenderer;          /**
112             * the size of the pane last time we drew
113             */
114            protected Rectangle oldRect = null;
115    
116      /**          /**
117       * the map context to render           * the last map area drawn.
118       */           */
119      MapContext context;          protected Envelope oldMapArea = null;
120    
121      private MapContext selectionContext;          /**
122             * the base image of the map
123             */
124            protected BufferedImage baseImage, panningImage;
125    
126      /**          /**
127       * the area of the map to draw           * a factory for filters
128       */           */
129  //xulu.sc          FilterFactory2 ff;
 //    Envelope mapArea;  
     protected Envelope mapArea;  
 //xulu.ec  
130    
131      /**          /**
132       * the size of the pane last time we drew           * a factory for geometries
133       */           */
134  //xulu.sc          GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null);
 //    private Rectangle oldRect = null;  
     protected Rectangle oldRect = null;  
 //xulu.ec  
135    
136      /**          private int state = ZoomIn;
      * the last map area drawn.  
      */  
 //xulu.sc  
 //    private Envelope oldMapArea = null;  
     protected Envelope oldMapArea = null;  
 //xulu.ec  
137    
138      /**          /**
139       * the base image of the map           * how far to zoom in or out
140       */           */
141      protected  BufferedImage baseImage, panningImage;          private double zoomFactor = 2.0;
     // SK: private BufferedImage baseImage, panningImage;  
142    
143      /**          boolean changed = true;
      * image of selection  
      */  
     private BufferedImage selectImage;  
144    
145      /**          LabelCache labelCache = new LabelCacheImpl();
      * style for selected items  
      */  
     private Style selectionStyle;  
146    
147      /**          protected boolean reset = false;
      * layer that selection works on  
      */  
     private MapLayer selectionLayer;  
148    
149      /**          int startX;
      * layer that highlight works on  
      */  
     private MapLayer highlightLayer;  
150    
151      /**          int startY;
      * the object which manages highlighting  
      */  
     private HighlightManager highlightManager;  
152    
153      /**          /**
154       * is highlighting on or off           * If not <code>null</code>, the {@link JMapPane} will not allow to zoom/pan
155       */           * out of that area
156      private boolean highlight = true;           **/
157            private Envelope maxExtend = null;
158    
159      /**          // /**
160       * a factory for filters          // * Is max. 1 or 0 of the 2 axised allowed to extend the maxExtend? If
161       */          // * <code>true</code> the extends has to be fully inside maxExtend
162      FilterFactory2 ff;          // **/
163            // boolean maxExtendForceMode = true;
164    
165      /**          private boolean clickable;
      * a factory for geometries  
      */  
     GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null);  
166    
167      /**          int lastX;
      * the collections of features to be selected or highlighted  
      */  
     FeatureCollection selection;  
168    
169      /**          int lastY;
      * the collections of features to be selected or highlighted  
      */  
     FeatureCollection highlightFeature;  
170    
171      private int state = ZoomIn;          private Double maxZoomScale = Double.MIN_VALUE;
172            private Double minZoomScale = Double.MAX_VALUE;
173    
174      /**          /**
175       * how far to zoom in or out           * Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses
176       */           * Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu
177      private double zoomFactor = 2.0;           * setzen.
178             */
179            private boolean panning_started = false;
180    
181      Style lineHighlightStyle;          public JMapPane() {
182                    this(null, true, null, null);
183            }
184    
185      Style pointHighlightStyle;          /**
186             * create a basic JMapPane
187             *
188             * @param render
189             *            - how to draw the map
190             * @param context
191             *            - the map context to display
192             */
193            public JMapPane(final GTRenderer render, final MapContext context) {
194                    this(null, true, render, context);
195            }
196    
197      Style polygonHighlightStyle;          /**
198             * full constructor extending JPanel
199             *
200             * @param layout
201             *            - layout (probably shouldn't be set)
202             * @param isDoubleBuffered
203             *            - a Swing thing I don't really understand
204             * @param render
205             *            - what to draw the map with
206             * @param context
207             *            - what to draw
208             */
209            public JMapPane(final LayoutManager layout, final boolean isDoubleBuffered,
210                            final GTRenderer render, final MapContext context) {
211                    super(layout, isDoubleBuffered);
212    
213                    ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder
214                                    .getFilterFactory(null);
215                    setRenderer(render);
216    
217                    setContext(context);
218    
219                    this.addMouseListener(this);
220                    this.addMouseMotionListener(this);
221                    setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
222            }
223    
224      Style polygonSelectionStyle;          /**
225             * get the renderer
226             */
227            public GTRenderer getRenderer() {
228                    return renderer;
229            }
230    
231      Style pointSelectionStyle;          public void setRenderer(final GTRenderer renderer) {
232                    Map<Object, Object> hints = new HashMap<Object, Object>();
233    
234      Style lineSelectionStyle;                  this.renderer = renderer;
235    
236      boolean changed = true;                  if (renderer instanceof StreamingRenderer
237                                    || renderer instanceof ShapefileRenderer) {
238                            hints = renderer.getRendererHints();
239                            if (hints == null) {
240                                    hints = new HashMap<Object, Object>();
241                            }
242                            if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {
243                                    labelCache = (LabelCache) hints
244                                                    .get(StreamingRenderer.LABEL_CACHE_KEY);
245                            } else {
246                                    hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
247                            }
248    
249      LabelCache labelCache = new LabelCacheDefault();                          hints.put("memoryPreloadingEnabled", Boolean.TRUE);
250    
251  //xulu.sc                          renderer.setRendererHints(hints);
252  //    private boolean reset = false;                  }
     protected boolean reset = false;  
 //xulu.ec  
253    
254      int startX;                  // this.highlightRenderer = new StreamingRenderer();
255                    // this.selectionRenderer = new StreamingRenderer();
256    
257      int startY;                  // highlightRenderer.setRendererHints(hints);
258                    // selectionRenderer.setRendererHints(hints);
259    
260      private boolean clickable;                  // renderer.setRendererHints(hints);
261    
262      int lastX;                  if (this.context != null) {
263                            this.renderer.setContext(this.context);
264                    }
265            }
266    
267      int lastY;          public MapContext getContext() {
268                    return context;
269            }
270    
271      private SelectionManager selectionManager;          public void setContext(final MapContext context) {
272  //xulu.sn                  if (this.context != null) {
273      private Double maxZoomScale = Double.MIN_VALUE;                          this.context.removeMapLayerListListener(this);
274      private Double minZoomScale = Double.MAX_VALUE;                  }
 //xulu.en  
275    
276  // sk.sn                      this.context = context;
277      /**  
278       * Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu setzen.                  if (context != null) {
279       */                          this.context.addMapLayerListListener(this);
280          private boolean panning_started = false;                  }
281  // sk.en          
282                    if (renderer != null) {
283                            renderer.setContext(this.context);
284                    }
285            }
286    
287            public Envelope getMapArea() {
288                    return mapArea;
289            }
290    
291            public void setMapArea(final Envelope mapArea) {
292                    this.mapArea = mapArea;
293            }
294    
295            public int getState() {
296                    return state;
297            }
298    
299            public void setState(final int state) {
300                    this.state = state;
301    
302                    // System.out.println("State: " + state);
303            }
304    
305            public double getZoomFactor() {
306                    return zoomFactor;
307            }
308    
309            public void setZoomFactor(final double zoomFactor) {
310                    this.zoomFactor = zoomFactor;
311            }
312    
313            protected void paintComponent(final Graphics g) {
314                    super.paintComponent(g);
315    
316                    if ((renderer == null) || (mapArea == null)) {
317                            return;
318                    }
319    
320                    final Rectangle r = getBounds();
321                    final Rectangle dr = new Rectangle(r.width, r.height);
322    
323                    if (!r.equals(oldRect) || reset) {
324                            if (!r.equals(oldRect) && (mapArea == null)) {
325                                    try {
326                                            mapArea = context.getLayerBounds();
327                                    } catch (final IOException e) {
328                                            LOGGER.warn("context.getLayerBounds()", e);
329                                    }
330                            }
331    
332                            if (mapArea != null) {
333                                    /* either the viewer size has changed or we've done a reset */
334                                    changed = true; /* note we need to redraw */
335                                    reset = false; /* forget about the reset */
336                                    oldRect = r; /* store what the current size is */
337    
338                                    mapArea = fixAspectRatio(r, mapArea, false);
339                            }
340                    }
341    
342                    if (!mapArea.equals(oldMapArea)) { /* did the map extent change? */
343                            changed = true;
344                            oldMapArea = mapArea;
345                            // when we tell the context that the bounds have changed WMSLayers
346                            // can refresh them selves
347                            context.setAreaOfInterest(mapArea, context
348                                            .getCoordinateReferenceSystem());
349                    }
350    
351                    if (changed) { /* if the map changed then redraw */
352                            changed = false;
353                            baseImage = new BufferedImage(dr.width, dr.height,
354                                            BufferedImage.TYPE_INT_ARGB);
355    
356                            final Graphics2D ig = baseImage.createGraphics();
357                            /* System.out.println("rendering"); */
358                            if (renderer.getContext() != null)
359                                    renderer.setContext(context);
360                            labelCache.clear(); // work around anoying labelcache bug
361    
362                            // draw the map
363                            renderer.paint((Graphics2D) ig, dr, mapArea);
364    
365                            // TODO nur machen, wenn panning beginnt
366                            panningImage = new BufferedImage(dr.width, dr.height,
367                                            BufferedImage.TYPE_INT_RGB);
368    
369                    }
370    
371                    ((Graphics2D) g).drawImage(baseImage, 0, 0, this);
372            }
373    
374            /**
375             * Returns an {@link Envelope} that has the same aspect ratio as the given rectangle
376             * @param grow
377             *            If <code>true</code>, than the area will be enlarged to match
378             *            the aspect ratio. If <code>false</code>, it will only shrink.
379             */
380            private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea,
381                            boolean grow) {
382                    
383                    if (mapArea == null) {
384                            LOGGER.warn("mapArea has been null in method fixAspectRatio, returning an unmodified ");
385                    }
386    
387                    final double mapWidth = mapArea.getWidth(); /* get the extent of the map */
388                    final double mapHeight = mapArea.getHeight();
389                    final double scaleX = r.getWidth() / mapArea.getWidth(); /*
390                                                                                                                                     * calculate the
391                                                                                                                                     * new scale
392                                                                                                                                     */
393    
394                    final double scaleY = r.getHeight() / mapArea.getHeight();
395                    double scale = 1.0; // stupid compiler!
396    
397                    if ((grow && scaleX < scaleY) || (!grow && scaleX > scaleY)) {
398                            scale = scaleX;
399                    } else {
400                            scale = scaleY;
401                    }
402    
403                    /* calculate the difference in width and height of the new extent */
404                    final double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth);
405                    final double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight);
406    
407                    /*
408                     * System.out.println("delta x " + deltaX);
409                     * System.out.println("delta y " + deltaY);
410                     */
411    
412                    /* create the new extent */
413                    final Coordinate ll = new Coordinate(
414                                    mapArea.getMinX() - (deltaX / 2.0), mapArea.getMinY()
415                                                    - (deltaY / 2.0));
416                    final Coordinate ur = new Coordinate(
417                                    mapArea.getMaxX() + (deltaX / 2.0), mapArea.getMaxY()
418                                                    + (deltaY / 2.0));
419    
420                    return new Envelope(ll, ur);
421            }
422    
423            public void mouseClicked(final MouseEvent e) {
424                    if (mapArea == null)
425                            return;
426                    // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"
427                    // h:"+mapArea.getHeight());
428                    final Rectangle bounds = this.getBounds();
429                    final double x = (double) (e.getX());
430                    final double y = (double) (e.getY());
431                    final double width = mapArea.getWidth();
432                    final double height = mapArea.getHeight();
433                    // xulu.sc
434                    // double width2 = mapArea.getWidth() / 2.0;
435                    // double height2 = mapArea.getHeight() / 2.0;
436                    final double width2 = width / 2.0;
437                    final double height2 = height / 2.0;
438                    // xulu.ec
439                    final double mapX = ((x * width) / (double) bounds.width)
440                                    + mapArea.getMinX();
441                    final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)
442                                    + mapArea.getMinY();
443    
444                    /*
445                     * System.out.println(""+x+"->"+mapX);
446                     * System.out.println(""+y+"->"+mapY);
447                     */
448    
449                    /*
450                     * Coordinate ll = new Coordinate(mapArea.getMinX(), mapArea.getMinY());
451                     * Coordinate ur = new Coordinate(mapArea.getMaxX(), mapArea.getMaxY());
452                     */
453                    double zlevel = 1.0;
454    
455                    switch (state) {
456                    case Pan:
457                            zlevel = 1.0;
458                            // xulu.sc SK: return here.. a mouselistener is managing the PANNING
459                            // break;
460                            return;
461                            // xulu.ec
462                    case ZoomIn:
463                            zlevel = zoomFactor;
464    
465                            break;
466    
467                    case ZoomOut:
468                            zlevel = 1.0 / zoomFactor;
469    
470                            break;
471                    //
472                    // case Select:
473                    // doSelection(mapX, mapY, selectionLayer);
474                    //
475                    // return;
476    
477                    default:
478                            return;
479                    }
480    
481                    final Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY
482                                    - (height2 / zlevel));
483                    final Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY
484                                    + (height2 / zlevel));
485                    // xulu.sc SK: Check for min/max scale
486                    // mapArea = new Envelope(ll, ur);
487                    final Envelope newMapArea = new Envelope(ll, ur);
488                    setMapArea(bestAllowedMapArea(newMapArea));
489                    // xulu.ec
490    
491                    // sk.ec
492    
493                    // System.out.println("after area "+mapArea+"\nw:"+mapArea.getWidth()+"
494                    // h:"+mapArea.getHeight());
495                    repaint();
496            }
497    
498            public void mouseEntered(final MouseEvent e) {
499            }
500    
501            public void mouseExited(final MouseEvent e) {
502            }
503    
504            public void mousePressed(final MouseEvent e) {
505                    startX = e.getX();
506                    startY = e.getY();
507                    lastX = 0;
508                    lastY = 0;
509            }
510    
511            public void mouseReleased(final MouseEvent e) {
512                    final int endX = e.getX();
513                    final int endY = e.getY();
514    
515                    processDrag(startX, startY, endX, endY, e);
516                    lastX = 0;
517                    lastY = 0;
518    
519                    /**
520                     * Es wird nicht (mehr) gepannt!
521                     */
522                    panning_started = false;
523            }
524    
525            public void mouseDragged(final MouseEvent e) {
526                    final Graphics graphics = this.getGraphics();
527                    final int x = e.getX();
528                    final int y = e.getY();
529    
530                    if ((state == JMapPane.Pan)
531                                    || ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {
532                            /**
533                             * SK: Der Cursor wird auf PANNING gesetzt.
534                             */
535                            if (panning_started == false) {
536                                    panning_started = true;
537                                    setCursor(SwingUtil.PANNING_CURSOR);
538                            }
539    
540                            // move the image with the mouse
541                            if ((lastX > 0) && (lastY > 0)) {
542                                    final int dx = lastX - startX;
543                                    final int dy = lastY - startY;
544                                    // System.out.println("translate "+dx+","+dy);
545                                    final Graphics2D g2 = panningImage.createGraphics();
546                                    g2.setBackground(new Color(240, 240, 240)); // TODO richtige
547                                    // farbe? am besten
548                                    // vom L&F die
549                                    // hintergrundfarbe
550                                    // auslesen...
551    
     public JMapPane() {  
         this(null, true, null, null);  
     }  
   
     /**  
      * create a basic JMapPane  
      *  
      * @param render -  
      *            how to draw the map  
      * @param context -  
      *            the map context to display  
      */  
     public JMapPane(GTRenderer render, MapContext context) {  
         this(null, true, render, context);  
     }  
   
     /**  
      * full constructor extending JPanel  
      *  
      * @param layout -  
      *            layout (probably shouldn't be set)  
      * @param isDoubleBuffered -  
      *            a Swing thing I don't really understand  
      * @param render -  
      *            what to draw the map with  
      * @param context -  
      *            what to draw  
      */  
     public JMapPane(LayoutManager layout, boolean isDoubleBuffered,  
             GTRenderer render, MapContext context) {  
         super(layout, isDoubleBuffered);  
   
         ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder  
                 .getFilterFactory(null);  
         setRenderer(render);  
   
         setContext(context);  
   
         this.addMouseListener(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);  
         setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));  
     }  
   
     /**  
      * get the renderer  
      */  
     public GTRenderer getRenderer() {  
         return renderer;  
     }  
   
     public void setRenderer(GTRenderer renderer) {  
         Map hints = new HashMap();  
         if (renderer instanceof StreamingRenderer) {  
             hints = renderer.getRendererHints();  
             if (hints == null) {  
                 hints = new HashMap();  
             }  
             if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {  
                 labelCache = (LabelCache) hints  
                         .get(StreamingRenderer.LABEL_CACHE_KEY);  
             } else {  
                 hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);  
             }  
             renderer.setRendererHints(hints);  
         }  
   
         this.renderer = renderer;  
         this.highlightRenderer = new StreamingRenderer();  
         this.selectionRenderer = new StreamingRenderer();  
   
         hints.put("memoryPreloadingEnabled", Boolean.FALSE);  
         highlightRenderer.setRendererHints(hints);  
         selectionRenderer.setRendererHints(hints);  
   
         if (this.context != null) {  
             this.renderer.setContext(this.context);  
         }  
     }  
   
     public MapContext getContext() {  
         return context;  
     }  
   
     public void setContext(MapContext context) {  
         if (this.context != null) {  
             this.context.removeMapLayerListListener(this);  
         }  
   
         this.context = context;  
   
         if (context != null) {  
             this.context.addMapLayerListListener(this);  
         }  
   
         if (renderer != null) {  
             renderer.setContext(this.context);  
         }  
     }  
   
     public Envelope getMapArea() {  
         return mapArea;  
     }  
   
     public void setMapArea(Envelope mapArea) {  
         this.mapArea = mapArea;  
     }  
   
     public int getState() {  
         return state;  
     }  
   
     public void setState(int state) {  
         this.state = state;  
   
         // System.out.println("State: " + state);  
     }  
   
     public double getZoomFactor() {  
         return zoomFactor;  
     }  
   
     public void setZoomFactor(double zoomFactor) {  
         this.zoomFactor = zoomFactor;  
     }  
   
     public MapLayer getSelectionLayer() {  
         return selectionLayer;  
     }  
   
     public void setSelectionLayer(MapLayer selectionLayer) {  
         this.selectionLayer = selectionLayer;  
         if(selectionManager!=null) {  
             selectionManager.setSelectionLayer(selectionLayer);  
         }  
     }  
   
     public boolean isHighlight() {  
         return highlight;  
     }  
   
     public void setHighlight(boolean highlight) {  
         this.highlight = highlight;  
     }  
   
     public MapLayer getHighlightLayer() {  
         return highlightLayer;  
     }  
   
     public void setHighlightLayer(MapLayer highlightLayer) {  
         this.highlightLayer = highlightLayer;  
   
         if (highlightManager != null) {  
             highlightManager.setHighlightLayer(highlightLayer);  
         }  
     }  
   
     public HighlightManager getHighlightManager() {  
         return highlightManager;  
     }  
   
     public void setHighlightManager(HighlightManager highlightManager) {  
         this.highlightManager = highlightManager;  
         this.highlightManager.addHighlightChangeListener(this);  
         this.addMouseMotionListener(this.highlightManager);  
     }  
   
     public Style getLineHighlightStyle() {  
         return lineHighlightStyle;  
     }  
   
     public void setLineHighlightStyle(Style lineHighlightStyle) {  
         this.lineHighlightStyle = lineHighlightStyle;  
     }  
   
     public Style getLineSelectionStyle() {  
         return lineSelectionStyle;  
     }  
   
     public void setLineSelectionStyle(Style lineSelectionStyle) {  
         this.lineSelectionStyle = lineSelectionStyle;  
     }  
   
     public Style getPointHighlightStyle() {  
         return pointHighlightStyle;  
     }  
   
     public void setPointHighlightStyle(Style pointHighlightStyle) {  
         this.pointHighlightStyle = pointHighlightStyle;  
     }  
   
     public Style getPointSelectionStyle() {  
         return pointSelectionStyle;  
     }  
   
     public void setPointSelectionStyle(Style pointSelectionStyle) {  
         this.pointSelectionStyle = pointSelectionStyle;  
     }  
   
     public Style getPolygonHighlightStyle() {  
         return polygonHighlightStyle;  
     }  
   
     public void setPolygonHighlightStyle(Style polygonHighlightStyle) {  
         this.polygonHighlightStyle = polygonHighlightStyle;  
     }  
   
     public Style getPolygonSelectionStyle() {  
         return polygonSelectionStyle;  
     }  
   
     public void setPolygonSelectionStyle(Style polygonSelectionStyle) {  
         this.polygonSelectionStyle = polygonSelectionStyle;  
     }  
   
     protected void paintComponent(Graphics g) {  
         super.paintComponent(g);  
   
         if ((renderer == null) || (mapArea == null)  ) {  
             return;  
         }  
   
         Rectangle r = getBounds();  
         Rectangle dr = new Rectangle(r.width, r.height);  
   
         if (!r.equals(oldRect) || reset) {  
                 if(!r.equals(oldRect) && (mapArea == null)) {  
                         try {  
                                         mapArea=context.getLayerBounds();  
                                 } catch (IOException e) {  
                                         // TODO Auto-generated catch block  
                                         e.printStackTrace();  
                                 }  
                 }  
                   
                 if (mapArea != null){  
                         /* either the viewer size has changed or we've done a reset */  
                         changed = true; /* note we need to redraw */  
                         reset = false; /* forget about the reset */  
                         oldRect = r; /* store what the current size is */  
                           
                         mapArea = fixAspectRatio(r, mapArea);  
                 }  
         }  
   
         if (!mapArea.equals(oldMapArea)) { /* did the map extent change? */  
             changed = true;  
             oldMapArea = mapArea;  
 //          when we tell the context that the bounds have changed WMSLayers  
             // can refresh them selves  
             context.setAreaOfInterest(mapArea, context  
                     .getCoordinateReferenceSystem());  
         }  
   
         if (changed) { /* if the map changed then redraw */  
             changed = false;  
             baseImage = new BufferedImage(dr.width, dr.height,  
                     BufferedImage.TYPE_INT_ARGB);  
   
             Graphics2D ig = baseImage.createGraphics();  
             /* System.out.println("rendering"); */  
             renderer.setContext(context);  
             labelCache.clear(); // work around anoying labelcache bug  
   
   
             // draw the map  
             renderer.paint((Graphics2D) ig, dr, mapArea);  
   
             // TODO , nur machen, wenn panning beginnt  
             panningImage = new BufferedImage(dr.width, dr.height,  
                         BufferedImage.TYPE_INT_RGB);  
               
         }  
   
         ((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);  
   
             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;  
             }  
   
   
   
   
             MapContext highlightContext = new DefaultMapContext(  
                     DefaultGeographicCRS.WGS84);  
   
             highlightContext.addLayer(highlightFeature, highlightStyle);  
             highlightRenderer.setContext(highlightContext);  
   
             /* System.out.println("rendering highlight"); */  
             highlightRenderer.paint((Graphics2D) g, dr, mapArea);  
         }  
     }  
   
     private Envelope fixAspectRatio(Rectangle r, Envelope mapArea) {  
           
         double mapWidth = mapArea.getWidth(); /* get the extent of the map */  
         double mapHeight = mapArea.getHeight();  
         double scaleX = r.getWidth() / mapArea.getWidth(); /*  
                                                              * calculate the new  
                                                              * scale  
                                                              */  
   
         double scaleY = r.getHeight() / mapArea.getHeight();  
         double scale = 1.0; // stupid compiler!  
   
         if (scaleX < scaleY) { /* pick the smaller scale */  
             scale = scaleX;  
         } else {  
             scale = scaleY;  
         }  
   
         /* calculate the difference in width and height of the new extent */  
         double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth);  
         double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight);  
   
         /*  
          * System.out.println("delta x " + deltaX); System.out.println("delta y " +  
          * deltaY);  
          */  
   
         /* create the new extent */  
         Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0),  
                 mapArea.getMinY() - (deltaY / 2.0));  
         Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0),  
                 mapArea.getMaxY() + (deltaY / 2.0));  
   
         return new Envelope(ll, ur);  
     }  
   
     public void doSelection(double x, double y, MapLayer layer) {  
   
         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(Geometry geometry, MapLayer layer)  
             throws IndexOutOfBoundsException {  
         org.opengis.filter.spatial.BinarySpatialOperator f = null;  
   
   
         if ((context == null) || (layer==null)) {  
             return ;  
         }  
   
   
   
         try {  
             String name = layer.getFeatureSource().getSchema()  
                     .getDefaultGeometry().getName();  
   
             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 (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()) { Feature feat =  
              * (Feature) fi.next(); System.out.println("selected " +  
              * feat.getAttribute("STATE_NAME")); }  
              */  
         } catch (IllegalFilterException e) {  
             // TODO Auto-generated catch block  
             e.printStackTrace();  
         }  
         return ;  
     }  
   
     public void mouseClicked(MouseEvent e) {  
         // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"  
         // h:"+mapArea.getHeight());  
         Rectangle bounds = this.getBounds();  
         double x = (double) (e.getX());  
         double y = (double) (e.getY());  
         double width = mapArea.getWidth();  
         double height = mapArea.getHeight();  
 //xulu.sc  
 //        double width2 = mapArea.getWidth() / 2.0;  
 //        double height2 = mapArea.getHeight() / 2.0;  
         double width2 = width / 2.0;  
         double height2 = height / 2.0;  
 //xulu.ec  
         double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX();  
         double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)  
                 + mapArea.getMinY();  
   
         /*  
          * System.out.println(""+x+"->"+mapX);  
          * System.out.println(""+y+"->"+mapY);  
          */  
   
         /*  
          * Coordinate ll = new Coordinate(mapArea.getMinX(), mapArea.getMinY());  
          * Coordinate ur = new Coordinate(mapArea.getMaxX(), mapArea.getMaxY());  
          */  
         double zlevel = 1.0;  
   
         switch (state) {  
         case Pan:  
             zlevel = 1.0;  
 //xulu.sc SK: return here.. a mouselistener is maanaging the PANNING  
 //            break;  
             return;  
 //xulu.ec  
         case ZoomIn:  
             zlevel = zoomFactor;  
   
             break;  
   
         case ZoomOut:  
             zlevel = 1.0 / zoomFactor;  
   
             break;  
   
         case Select:  
             doSelection(mapX, mapY, selectionLayer);  
   
   
             return;  
   
         default:  
             return;  
         }  
   
         Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY  
                 - (height2 / zlevel));  
         Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY  
                 + (height2 / zlevel));  
 //xulu.sc SK: Check for min/max scale  
 //        mapArea = new Envelope(ll, ur);  
         final Envelope newMapArea = new Envelope(ll, ur);  
         setMapArea( bestAllowedMapArea( newMapArea ) );  
 //xulu.ec  
   
         // System.out.println("after area "+mapArea+"\nw:"+mapArea.getWidth()+"  
         // h:"+mapArea.getHeight());  
         repaint();  
     }  
   
     public void mouseEntered(MouseEvent e) {  
     }  
   
     public void mouseExited(MouseEvent e) {  
     }  
   
     public void mousePressed(MouseEvent e) {  
         startX = e.getX();  
         startY = e.getY();  
         lastX = 0;  
         lastY = 0;  
     }  
       
     public void mouseReleased(MouseEvent e) {  
         int endX = e.getX();  
         int endY = e.getY();  
           
         processDrag(startX, startY, endX, endY, e);  
         lastX = 0;  
         lastY = 0;  
           
         /**  
          * Es wird nicht (mehr) gepannt!  
          */  
         panning_started = false;  
     }  
   
     public void mouseDragged(MouseEvent e) {  
         Graphics graphics = this.getGraphics();  
         int x = e.getX();  
         int y = e.getY();  
           
   
         if ( (state == JMapPane.Pan) || ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0))  {  
             /**  
              * SK:  
              * Der Cursor wird auf PANNING gesetzt.  
              */  
                 if (panning_started == false){  
                         panning_started = true;  
                         setCursor( SwingUtil.PANNING_CURSOR );  
                 }  
                   
                   
             // move the image with the mouse  
             if ((lastX > 0) && (lastY > 0)) {  
                 int dx = lastX - startX;  
                 int dy = lastY - startY;  
                 // System.out.println("translate "+dx+","+dy);  
                 final Graphics2D g2 = panningImage.createGraphics();  
                 g2.setBackground( new Color(240,240,240) ); //TODO richtige farbe? am besten vom L&F die hintergrundfarbe auslesen...  
552                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());
553                                  g2.drawImage(baseImage, dx, dy, this);                                  g2.drawImage(baseImage, dx, dy, this);
554                  graphics.drawImage(panningImage, 0, 0, this);                                  graphics.drawImage(panningImage, 0, 0, this);
555              }                          }
556    
557                            lastX = x;
558                            lastY = y;
559                    } else
560    
561                    if ((state == JMapPane.ZoomIn) || (state == JMapPane.ZoomOut)) {
562    
563                            graphics.setXORMode(Color.WHITE);
564    
565                            if ((lastX > 0) && (lastY > 0)) {
566                                    drawRectangle(graphics);
567                            }
568    
569                            // draw new box
570                            lastX = x;
571                            lastY = y;
572                            drawRectangle(graphics);
573                    }
574                    // else if (state == JMapPane.Select && selectionLayer != null) {
575                    //
576                    // // construct a new bbox filter
577                    // final Rectangle bounds = this.getBounds();
578                    //
579                    // final double mapWidth = mapArea.getWidth();
580                    // final double mapHeight = mapArea.getHeight();
581                    //
582                    // final double x1 = ((this.startX * mapWidth) / (double) bounds.width)
583                    // + mapArea.getMinX();
584                    // final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) /
585                    // (double) bounds.height)
586                    // + mapArea.getMinY();
587                    // final double x2 = ((x * mapWidth) / (double) bounds.width)
588                    // + mapArea.getMinX();
589                    // final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double)
590                    // bounds.height)
591                    // + mapArea.getMinY();
592                    // final double left = Math.min(x1, x2);
593                    // final double right = Math.max(x1, x2);
594                    // final double bottom = Math.min(y1, y2);
595                    // final double top = Math.max(y1, y2);
596                    //
597                    // String name = selectionLayer.getFeatureSource().getSchema()
598                    // .getDefaultGeometry().getName();
599                    //
600                    // if (name == "") {
601                    // name = "the_geom";
602                    // }
603                    // final Filter bb = ff.bbox(ff.property(name), left, bottom, right,
604                    // top,
605                    // getContext().getCoordinateReferenceSystem().toString());
606                    // if (selectionManager != null) {
607                    // selectionManager.selectionChanged(this, bb);
608                    // }
609                    //
610                    // graphics.setXORMode(Color.green);
611                    //
612                    // /*
613                    // * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); }
614                    // */
615                    //
616                    // // draw new box
617                    // lastX = x;
618                    // lastY = y;
619                    // drawRectangle(graphics);
620                    // }
621    
622            }
623    
624            // sk.cs
625            // private void processDrag(int x1, int y1, int x2, int y2) {
626            // sk.ce
627            protected void processDrag(final int x1, final int y1, final int x2,
628                            final int y2, final MouseEvent e) {
629    
             lastX = x;  
             lastY = y;  
         } else  
                   
         if ((state == JMapPane.ZoomIn) || (state == JMapPane.ZoomOut)) {  
           
           
             graphics.setXORMode(Color.WHITE);  
   
             if ((lastX > 0) && (lastY > 0)) {  
                 drawRectangle(graphics);  
             }  
   
             // draw new box  
             lastX = x;  
             lastY = y;  
             drawRectangle(graphics);  
         } else if (state == JMapPane.Select && selectionLayer != null) {  
   
             // construct a new bbox filter  
             Rectangle bounds = this.getBounds();  
   
             double mapWidth = mapArea.getWidth();  
             double mapHeight = mapArea.getHeight();  
   
             double x1 = ((this.startX * mapWidth) / (double) bounds.width)  
                     + mapArea.getMinX();  
             double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height)  
                     + mapArea.getMinY();  
             double x2 = ((x * mapWidth) / (double) bounds.width)  
                     + mapArea.getMinX();  
             double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height)  
                     + mapArea.getMinY();  
             double left = Math.min(x1, x2);  
             double right = Math.max(x1, x2);  
             double bottom = Math.min(y1, y2);  
             double top = Math.max(y1, y2);  
   
   
             String name = selectionLayer.getFeatureSource().getSchema()  
                     .getDefaultGeometry().getName();  
   
             if (name == "") {  
                 name = "the_geom";  
             }  
             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);  
        }  
       
     }  
   
     // sk.cs  
 //    private void processDrag(int x1, int y1, int x2, int y2) {  
     // sk.ce  
     protected void processDrag(int x1, int y1, int x2, int y2, MouseEvent e) {  
           
         /****  
          * If no layer is availabe we dont want a NullPointerException  
          */  
         if (mapArea == null) return;  
           
         // System.out.println("processing drag from " + x1 + "," + y1 + " -> "  
         // + x2 + "," + y2);  
         if ((x1 == x2) && (y1 == y2)) {  
             if (isClickable()) {  
                 mouseClicked(new MouseEvent(this, 0, new Date().getTime(), 0,  
                         x1, y1, y2, false));  
             }  
   
             return;  
         }  
           
         Rectangle bounds = this.getBounds();  
   
         double mapWidth = mapArea.getWidth();  
         double mapHeight = mapArea.getHeight();  
   
         double startX = ((x1 * mapWidth) / (double) bounds.width)  
                 + mapArea.getMinX();  
         double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height)  
                 + mapArea.getMinY();  
         double endX = ((x2 * mapWidth) / (double) bounds.width)  
                 + mapArea.getMinX();  
         double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height)  
                 + mapArea.getMinY();  
   
         if (  (state == JMapPane.Pan) || (e.getButton()== MouseEvent.BUTTON3)) {  
             // move the image with the mouse  
             // calculate X offsets from start point to the end Point  
             double deltaX1 = endX - startX;  
   
             // System.out.println("deltaX " + deltaX1);  
             // new edges  
             double left = mapArea.getMinX() - deltaX1;  
             double right = mapArea.getMaxX() - deltaX1;  
   
             // now for Y  
             double deltaY1 = endY - startY;  
   
             // System.out.println("deltaY " + deltaY1);  
             double bottom = mapArea.getMinY() - deltaY1;  
             double top = mapArea.getMaxY() - deltaY1;  
             Coordinate ll = new Coordinate(left, bottom);  
             Coordinate ur = new Coordinate(right, top);  
 //xulu.sc  
 //            mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));  
             setMapArea( fixAspectRatio(this.getBounds(), new Envelope(ll, ur)) );  
 //xulu.ec  
         } else if (state == JMapPane.ZoomIn) {  
                   
   
                 // Zu kleine Flächen sollen nicht gezoomt werden.  
                 //sk.bc  
                 if ( (Math.abs(x1-x2) * Math.abs(y2-y1) )<100 ) return;  
                 // sk.ec  
                   
                 drawRectangle(this.getGraphics());  
             // make the dragged rectangle (in map coords) the new BBOX  
             double left = Math.min(startX, endX);  
             double right = Math.max(startX, endX);  
             double bottom = Math.min(startY, endY);  
             double top = Math.max(startY, endY);  
             Coordinate ll = new Coordinate(left, bottom);  
             Coordinate ur = new Coordinate(right, top);  
 //xulu.sc  
 //            mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));  
             setMapArea( fixAspectRatio(this.getBounds(), new Envelope(ll, ur)) );  
 //xulu.ec  
         } else if (state == JMapPane.ZoomOut) {  
                 drawRectangle(this.getGraphics());  
                   
                 // make the dragged rectangle in screen coords the new map size?  
             double left = Math.min(startX, endX);  
             double right = Math.max(startX, endX);  
             double bottom = Math.min(startY, endY);  
             double top = Math.max(startY, endY);  
             double nWidth = (mapWidth * mapWidth) / (right - left);  
             double nHeight = (mapHeight * mapHeight) / (top - bottom);  
             double deltaX1 = left - mapArea.getMinX();  
             double nDeltaX1 = (deltaX1 * nWidth) / mapWidth;  
             double deltaY1 = bottom - mapArea.getMinY();  
             double nDeltaY1 = (deltaY1 * nHeight) / mapHeight;  
             Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1,  
                     mapArea.getMinY() - nDeltaY1);  
             double deltaX2 = mapArea.getMaxX() - right;  
             double nDeltaX2 = (deltaX2 * nWidth) / mapWidth;  
             double deltaY2 = mapArea.getMaxY() - top;  
             double nDeltaY2 = (deltaY2 * nHeight) / mapHeight;  
             Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2,  
                     mapArea.getMaxY() + nDeltaY2);  
 //xulu.sc              
 //            mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));  
             setMapArea( fixAspectRatio(this.getBounds(), new Envelope(ll, ur)) );  
 //xulu.ec  
         } else if (state == JMapPane.Select && selectionLayer !=null) {  
             double left = Math.min(startX, endX);  
             double right = Math.max(startX, endX);  
             double bottom = Math.min(startY, endY);  
             double top = Math.max(startY, endY);  
   
   
             String name = selectionLayer.getFeatureSource().getSchema()  
                     .getDefaultGeometry().getLocalName();  
   
             if (name == "") {  
                 name = "the_geom";  
             }  
             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();  
             }  
 */  
         }  
   
 //xulu.so  
 //        setMapArea(mapArea);  
 //xulu.eo  
         repaint();  
     }  
   
     private boolean isClickable() {  
         return clickable;  
     }  
   
     private org.geotools.styling.Style setupStyle(int type, Color color) {  
         StyleFactory sf = org.geotools.factory.CommonFactoryFinder  
                 .getStyleFactory(null);  
         StyleBuilder sb = new StyleBuilder();  
   
         org.geotools.styling.Style s = sf.createStyle();  
         s.setTitle("selection");  
   
         // TODO parameterise the color  
         PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);  
         ps.setStroke(sb.createStroke(color));  
   
         LineSymbolizer ls = sb.createLineSymbolizer(color);  
         Graphic h = sb.createGraphic();  
         h.setMarks(new Mark[] { sb.createMark("square", color) });  
   
         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;  
     }  
   
     public void highlightChanged(HighlightChangedEvent e) {  
         org.opengis.filter.Filter f = e.getFilter();  
   
         try {  
             highlightFeature = highlightLayer.getFeatureSource().getFeatures(f);  
         } catch (IOException e1) {  
             // TODO Auto-generated catch block  
             e1.printStackTrace();  
         }  
   
         repaint();  
     }  
   
     public void propertyChange(PropertyChangeEvent evt) {  
         String prop = evt.getPropertyName();  
   
         if (prop.equalsIgnoreCase("crs")) {  
             context.setAreaOfInterest(context.getAreaOfInterest(),  
                     (CoordinateReferenceSystem) evt.getNewValue());  
         }  
     }  
   
     public boolean isReset() {  
         return reset;  
     }  
   
     public void setReset(boolean reset) {  
         this.reset = reset;  
     }  
   
     public void layerAdded(MapLayerListEvent event) {  
         changed = true;  
   
         if (context.getLayers().length == 1) { // the first one  
   
             try {  
 //xulu.sc      
 //            mapArea = context.getLayerBounds();  
               mapArea = context.getAreaOfInterest();  
               if ( mapArea == null )  
                 mapArea = context.getLayerBounds();  
 //xulu.ec  
             } catch (IOException e) {  
                 // TODO Auto-generated catch block  
                 e.printStackTrace();  
             }  
   
             reset = true;  
         }  
   
         repaint();  
     }  
   
     public void layerRemoved(MapLayerListEvent event) {  
         changed = true;  
         repaint();  
     }  
   
     public void layerChanged(MapLayerListEvent event) {  
         changed = true;  
         // System.out.println("layer changed - repaint");  
         repaint();  
     }  
   
     public void layerMoved(MapLayerListEvent event) {  
         changed = true;  
         repaint();  
     }  
   
     protected void drawRectangle(Graphics graphics) {  
         // undraw last box/draw new box  
         int left = Math.min(startX, lastX);  
         int right = Math.max(startX, lastX);  
         int top = Math.max(startY, lastY);  
         int bottom = Math.min(startY, lastY);  
         int width = right - left;  
         int height = top - bottom;  
         // System.out.println("drawing rect("+left+","+bottom+","+ width+","+  
         // height+")");  
         graphics.drawRect(left, bottom, width, height);  
     }  
   
     /**  
      * if clickable is set to true then a single click on the map pane will zoom  
      * or pan the map.  
      *  
      * @param clickable  
      */  
     public void setClickable(boolean clickable) {  
         this.clickable = clickable;  
     }  
   
     public void mouseMoved(MouseEvent e) {  
     }  
   
     public FeatureCollection getSelection() {  
         return selection;  
     }  
   
     public void setSelection(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(SelectionChangedEvent e) {  
   
         try {  
             selection = selectionLayer.getFeatureSource().getFeatures(e.getFilter());  
             repaint();  
         } catch (IOException e1) {  
             e1.printStackTrace();  
         }  
     }  
   
     public SelectionManager getSelectionManager() {  
         return selectionManager;  
     }  
   
     public void setSelectionManager(SelectionManager selectionManager) {  
         this.selectionManager = selectionManager;  
         this.selectionManager.addSelectionChangeListener(this);  
630    
631      }                  /****
632                     * If no layers exist, we ignore the drag.
633                     */
634                    if (context.getLayerCount() <= 0) {
635                            return;
636                    }
637                    
638                    // System.out.println("processing drag from " + x1 + "," + y1 + " -> "
639                    // + x2 + "," + y2);
640                    if ((x1 == x2) && (y1 == y2)) {
641                            if (isClickable()) {
642                                    mouseClicked(new MouseEvent(this, 0, new Date().getTime(), 0,
643                                                    x1, y1, y2, false));
644                            }
645    
646                            return;
647                    }
648    
649                    final Rectangle bounds = this.getBounds();
650    
651                    final double mapWidth = mapArea.getWidth();
652                    final double mapHeight = mapArea.getHeight();
653    
654                    final double startX = ((x1 * mapWidth) / (double) bounds.width)
655                                    + mapArea.getMinX();
656                    final double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height)
657                                    + mapArea.getMinY();
658                    final double endX = ((x2 * mapWidth) / (double) bounds.width)
659                                    + mapArea.getMinX();
660                    final double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height)
661                                    + mapArea.getMinY();
662    
663                    if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) {
664                            // move the image with the mouse
665                            // calculate X offsets from start point to the end Point
666                            final double deltaX1 = endX - startX;
667    
668                            // System.out.println("deltaX " + deltaX1);
669                            // new edges
670                            final double left = mapArea.getMinX() - deltaX1;
671                            final double right = mapArea.getMaxX() - deltaX1;
672    
673                            // now for Y
674                            final double deltaY1 = endY - startY;
675    
676                            // System.out.println("deltaY " + deltaY1);
677                            final double bottom = mapArea.getMinY() - deltaY1;
678                            final double top = mapArea.getMaxY() - deltaY1;
679                            final Coordinate ll = new Coordinate(left, bottom);
680                            final Coordinate ur = new Coordinate(right, top);
681                            // xulu.sc
682                            // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
683                            
684    
685                            setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
686                            // xulu.ec
687                    } else if (state == JMapPane.ZoomIn) {
688    
689                            // Zu kleine Flächen sollen nicht gezoomt werden.
690                            // sk.bc
691                            if ((Math.abs(x1 - x2) * Math.abs(y2 - y1)) < 150)
692                                    return;
693                            // sk.ec
694    
695                            drawRectangle(this.getGraphics());
696                            // make the dragged rectangle (in map coords) the new BBOX
697                            final double left = Math.min(startX, endX);
698                            final double right = Math.max(startX, endX);
699                            final double bottom = Math.min(startY, endY);
700                            final double top = Math.max(startY, endY);
701                            final Coordinate ll = new Coordinate(left, bottom);
702                            final Coordinate ur = new Coordinate(right, top);
703                            // xulu.sc
704    
705                            // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
706                            setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
707    
708                            // sk.sc
709                            // {
710                            // // SK tries to paint a preview of the zoom ;-9 aha.... well
711                            // Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();
712                            // graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
713                            // RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
714                            // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
715                            // RenderingHints.VALUE_ANTIALIAS_OFF);
716                            // graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
717                            // RenderingHints.VALUE_RENDER_SPEED);
718                            // graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),
719                            // JMapPane.this.getHeight(), x1, y1, x2, y2, null);
720                            // }
721                            // xulu.ec
722                    } else if (state == JMapPane.ZoomOut) {
723                            drawRectangle(this.getGraphics());
724    
725                            // make the dragged rectangle in screen coords the new map size?
726                            final double left = Math.min(startX, endX);
727                            final double right = Math.max(startX, endX);
728                            final double bottom = Math.min(startY, endY);
729                            final double top = Math.max(startY, endY);
730                            final double nWidth = (mapWidth * mapWidth) / (right - left);
731                            final double nHeight = (mapHeight * mapHeight) / (top - bottom);
732                            final double deltaX1 = left - mapArea.getMinX();
733                            final double nDeltaX1 = (deltaX1 * nWidth) / mapWidth;
734                            final double deltaY1 = bottom - mapArea.getMinY();
735                            final double nDeltaY1 = (deltaY1 * nHeight) / mapHeight;
736                            final Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1,
737                                            mapArea.getMinY() - nDeltaY1);
738                            final double deltaX2 = mapArea.getMaxX() - right;
739                            final double nDeltaX2 = (deltaX2 * nWidth) / mapWidth;
740                            final double deltaY2 = mapArea.getMaxY() - top;
741                            final double nDeltaY2 = (deltaY2 * nHeight) / mapHeight;
742                            final Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2,
743                                            mapArea.getMaxY() + nDeltaY2);
744                            // xulu.sc
745                            // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
746                            setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
747    
748                            // xulu.ec
749                    }
750                    // else if (state == JMapPane.Select && selectionLayer != null) {
751                    // final double left = Math.min(startX, endX);
752                    // final double right = Math.max(startX, endX);
753                    // final double bottom = Math.min(startY, endY);
754                    // final double top = Math.max(startY, endY);
755                    //
756                    // String name = selectionLayer.getFeatureSource().getSchema()
757                    // .getDefaultGeometry().getLocalName();
758                    //
759                    // if (name == "") {
760                    // name = "the_geom";
761                    // }
762                    // final Filter bb = ff.bbox(ff.property(name), left, bottom, right,
763                    // top,
764                    // getContext().getCoordinateReferenceSystem().toString());
765                    // // System.out.println(bb.toString());
766                    // if (selectionManager != null) {
767                    // selectionManager.selectionChanged(this, bb);
768                    // }
769                    // /*
770                    // * FeatureCollection fc; selection = null; try { fc =
771                    // * selectionLayer.getFeatureSource().getFeatures(bb); selection =
772                    // * fc; } catch (IOException e) { e.printStackTrace(); }
773                    // */
774                    // }
775    
776                    // xulu.so
777                    // setMapArea(mapArea);
778                    // xulu.eo
779                    repaint();
780            }
781    
782            private boolean isClickable() {
783                    return clickable;
784            }
785    
786            //
787            // private org.geotools.styling.Style setupStyle(final int type, final Color
788            // color) {
789            // final StyleFactory sf = org.geotools.factory.CommonFactoryFinder
790            // .getStyleFactory(null);
791            // final StyleBuilder sb = new StyleBuilder();
792            //
793            // org.geotools.styling.Style s = sf.createStyle();
794            // s.setTitle("selection");
795            //
796            // // TODO parameterise the color
797            // final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);
798            // ps.setStroke(sb.createStroke(color));
799            //
800            // final LineSymbolizer ls = sb.createLineSymbolizer(color);
801            // final Graphic h = sb.createGraphic();
802            // h.setMarks(new Mark[] { sb.createMark("square", color) });
803            //
804            // final PointSymbolizer pts = sb.createPointSymbolizer(h);
805            //
806            // // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});
807            // switch (type) {
808            // case POLYGON:
809            // s = sb.createStyle(ps);
810            //
811            // break;
812            //
813            // case POINT:
814            // s = sb.createStyle(pts);
815            //
816            // break;
817            //
818            // case LINE:
819            // s = sb.createStyle(ls);
820            // }
821            //
822            // return s;
823            // }
824    
825            public void propertyChange(final PropertyChangeEvent evt) {
826                    final String prop = evt.getPropertyName();
827    
828                    if (prop.equalsIgnoreCase("crs")) {
829                            context.setAreaOfInterest(context.getAreaOfInterest(),
830                                            (CoordinateReferenceSystem) evt.getNewValue());
831                    }
832            }
833    
834            public boolean isReset() {
835                    return reset;
836            }
837    
838            public void setReset(final boolean reset) {
839                    this.reset = reset;
840            }
841    
842            public void layerAdded(final MapLayerListEvent event) {
843                    changed = true;
844    
845                    if (context.getLayers().length == 1) { // the first one
846    
847                            try {
848                                    // xulu.sc
849                                    // mapArea = context.getLayerBounds();
850                                    mapArea = context.getAreaOfInterest();
851                                    if (mapArea == null)
852                                            mapArea = context.getLayerBounds();
853                                    // xulu.ec
854                            } catch (final IOException e) {
855                                    // TODO Auto-generated catch block
856                                    e.printStackTrace();
857                            }
858    
859                            reset = true;
860                    }
861    
862                    repaint();
863            }
864    
865            public void layerRemoved(final MapLayerListEvent event) {
866                    changed = true;
867                    repaint();
868            }
869    
870            public void layerChanged(final MapLayerListEvent event) {
871                    changed = true;
872                    // System.out.println("layer changed - repaint");
873                    repaint();
874            }
875    
876            public void layerMoved(final MapLayerListEvent event) {
877                    changed = true;
878                    repaint();
879            }
880    
881            protected void drawRectangle(final Graphics graphics) {
882                    // undraw last box/draw new box
883                    final int left = Math.min(startX, lastX);
884                    final int right = Math.max(startX, lastX);
885                    final int top = Math.max(startY, lastY);
886                    final int bottom = Math.min(startY, lastY);
887                    final int width = right - left;
888                    final int height = top - bottom;
889                    // System.out.println("drawing rect("+left+","+bottom+","+ width+","+
890                    // height+")");
891                    graphics.drawRect(left, bottom, width, height);
892            }
893    
894            /**
895             * if clickable is set to true then a single click on the map pane will zoom
896             * or pan the map.
897             *
898             * @param clickable
899             */
900            public void setClickable(final boolean clickable) {
901                    this.clickable = clickable;
902            }
903    
904            public void mouseMoved(final MouseEvent e) {
905            }
906    
907  //xulu.sn          // xulu.sn
908          /**          /**
909           * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste           * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste
910           * erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten           * erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten
# Line 1257  public class JMapPane extends JPanel imp Line 922  public class JMapPane extends JPanel imp
922                  if (env == null)                  if (env == null)
923                          return env;                          return env;
924    
925                    Envelope newArea = null;
926    
927                  /**                  /**
928                   * Correct the aspect Ratio before we check the rest. Otherwise we might easily fail.                   * Correct the aspect Ratio before we check the rest. Otherwise we might
929                     * easily fail.
930                   */                   */
931                  env = fixAspectRatio(this.getBounds(), env);                  env = fixAspectRatio(this.getBounds(), env, false);
932    
933                  double scale = env.getWidth() / getWidth();                  final double scale = env.getWidth() / getWidth();
934                  double centerX = env.getMinX() + env.getWidth() / 2.;                  final double centerX = env.getMinX() + env.getWidth() / 2.;
935                  double centerY = env.getMinY() + env.getHeight() / 2.;                  final double centerY = env.getMinY() + env.getHeight() / 2.;
936                  double newWidth2;                  double newWidth2 = 0;
937                  double newHeight2;                  double newHeight2 = 0;
938                  if (scale < getMaxZoomScale()) {                  if (scale < getMaxZoomScale()) {
939                          // ****************************************************************************                          // ****************************************************************************
940                          // Wir zoomen weiter rein als erlaubt => Anpassen des envelope                          // Wir zoomen weiter rein als erlaubt => Anpassen des envelope
# Line 1283  public class JMapPane extends JPanel imp Line 951  public class JMapPane extends JPanel imp
951                          // ****************************************************************************                          // ****************************************************************************
952                          // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen                          // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen
953                          // ****************************************************************************                          // ****************************************************************************
954                          return env;                          newArea = env;
955                  }                  }
956    
957                  Coordinate ll = new Coordinate(centerX - newWidth2, centerY                  if (newArea == null) {
                                 - newHeight2);  
                 Coordinate ur = new Coordinate(centerX + newWidth2, centerY  
                                 + newHeight2);  
958    
959                  return new Envelope(ll, ur);                          final Coordinate ll = new Coordinate(centerX - newWidth2, centerY
960                                            - newHeight2);
961                            final Coordinate ur = new Coordinate(centerX + newWidth2, centerY
962                                            + newHeight2);
963    
964                            newArea = new Envelope(ll, ur);
965                    }
966    
967                    Envelope maxAllowedExtend = getMaxExtend();
968                    while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)) {
969                            /*
970                             * If a maxExtend is set, we have to honour that...
971                             */
972    
973                            // Exceeds top? Move down and maybe cut
974                            if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
975                                    double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY();
976    //                              LOGGER.debug("Moving area down by " + divY);
977    
978                                    newArea = new Envelope(new Coordinate(newArea.getMinX(),
979                                                    newArea.getMinY() - divY), new Coordinate(newArea
980                                                    .getMaxX(), newArea.getMaxY() - divY));
981    
982                                    if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
983    //                                      LOGGER.debug("Now it exeeds the bottom border.. cut!");
984                                            // And cut the bottom if it moved out of the area
985                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
986                                                            maxAllowedExtend.getMinY()), new Coordinate(newArea
987                                                            .getMaxX(), newArea.getMaxY()));
988    
989    //                                      LOGGER.debug("and fix aspect ratio");
990    
991                                            newArea = fixAspectRatio(this.getBounds(), newArea, false);
992                                    }
993                            }
994    
995                            // Exceeds bottom? Move up and maybe cut
996                            if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
997                                    double divY = newArea.getMinY() - maxAllowedExtend.getMinY();
998    //                              LOGGER.debug("Moving area up by " + divY);
999    
1000                                    newArea = new Envelope(new Coordinate(newArea.getMinX(),
1001                                                    newArea.getMinY() - divY), new Coordinate(newArea
1002                                                    .getMaxX(), newArea.getMaxY() - divY));
1003    
1004                                    if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
1005                                            LOGGER.debug("Now it exeeds the top border.. cut!");
1006                                            // And cut the bottom if it moved out of the area
1007                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
1008                                                            newArea.getMinY()), new Coordinate(newArea
1009                                                            .getMaxX(), maxAllowedExtend.getMaxY()));
1010    
1011                                            LOGGER.debug("and fix aspect ratio");
1012    
1013                                            newArea = fixAspectRatio(this.getBounds(), newArea, false);
1014                                    }
1015                            }
1016    
1017                            // Exceeds to the right? move and maybe cut
1018                            if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
1019    
1020                                    // Move left..
1021                                    double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX();
1022    //                              LOGGER.debug("Moving area left by " + divX);
1023    
1024                                    newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
1025                                                    newArea.getMinY()), new Coordinate(newArea.getMaxX()
1026                                                    - divX, newArea.getMaxY()));
1027    
1028                                    if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
1029                                            LOGGER.debug("Now it exeeds the left border.. cut!");
1030                                            // And cut the left if it moved out of the area
1031                                            newArea = new Envelope(new Coordinate(maxAllowedExtend.getMinX(),
1032                                                            newArea.getMinY()), new Coordinate(newArea
1033                                                            .getMaxX(), newArea.getMaxY()));
1034    
1035                                            LOGGER.debug("and fix aspect ratio");
1036    
1037                                            newArea = fixAspectRatio(this.getBounds(), newArea, false);
1038                                    }
1039                            }
1040    
1041                            // Exceeds to the left? move and maybe cut
1042                            if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
1043    
1044                                    // Move right..
1045                                    double divX = newArea.getMinX() - maxAllowedExtend.getMinX();
1046    //                              LOGGER.debug("Moving area right by " + divX);
1047    
1048                                    newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
1049                                                    newArea.getMinY()), new Coordinate(newArea.getMaxX()
1050                                                    - divX, newArea.getMaxY()));
1051    
1052                                    if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
1053                                            LOGGER.debug("Now it exeeds the right border.. cut!");
1054                                            // And cut the left if it moved out of the area
1055                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
1056                                                            newArea.getMinY()), new Coordinate(maxAllowedExtend
1057                                                            .getMaxX(), newArea.getMaxY()));
1058    
1059                                            LOGGER.debug("and fix aspect ratio");
1060    
1061                                            newArea = fixAspectRatio(this.getBounds(), newArea, false);
1062                                    }
1063                            }
1064    
1065                    }
1066    
1067                    return newArea;
1068          }          }
1069    
1070    /**          /**
1071     * Retuns the minimum allowed zoom scale. This is the bigger number value of the two.           * Retuns the minimum allowed zoom scale. This is the bigger number value of
1072     * Defaults to {@link Double}.MAX_VALUE           * the two. Defaults to {@link Double}.MAX_VALUE
1073     *           *
1074     * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>           * @author <a href="mailto:[email protected]">Stefan Alfons
1075     */           *         Kr&uuml;ger</a>
1076    public Double getMinZoomScale() {           */
1077      return minZoomScale;          public Double getMinZoomScale() {
1078    }                  return minZoomScale;
1079            }
1080    /**  
1081     * Retuns the maximum allowed zoom scale. This is the smaller number value of the two.          /**
1082     * Defaults to {@link Double}.MIN_VALUE           * Retuns the maximum allowed zoom scale. This is the smaller number value
1083     *           * of the two. Defaults to {@link Double}.MIN_VALUE
1084     * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>           *
1085     */           * @author <a href="mailto:[email protected]">Stefan Alfons
1086    public Double getMaxZoomScale() {           *         Kr&uuml;ger</a>
1087      return maxZoomScale;           */
1088    }          public Double getMaxZoomScale() {
1089                    return maxZoomScale;
1090    /**          }
    * Set the maximum allowed zoom scale. This is the smaller number value of the two.  
    *  
    * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>  
    */  
   public void setMaxZoomScale(Double maxZoomScale) {  
     // System.out.println("setting max scale to "+maxZoomScale);  
     this.maxZoomScale = maxZoomScale;  
   }  
   
   /**  
    * Set the minimum (nearest) allowed zoom scale. This is the bigger number value of the two.  
    *  
    * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>  
    */  
   public void setMinZoomScale(Double minZoomScale) {  
     this.minZoomScale = minZoomScale;  
   }  
 //xulu.en  
1091    
1092            /**
1093             * Set the maximum allowed zoom scale. This is the smaller number value of
1094             * the two.
1095             *
1096             * @author <a href="mailto:[email protected]">Stefan Alfons
1097             *         Kr&uuml;ger</a>
1098             */
1099            public void setMaxZoomScale(final Double maxZoomScale) {
1100                    this.maxZoomScale = maxZoomScale;
1101            }
1102    
1103            /**
1104             * Set the minimum (nearest) allowed zoom scale. This is the bigger number
1105             * value of the two.
1106             *
1107             * @author <a href="mailto:[email protected]">Stefan Alfons
1108             *         Kr&uuml;ger</a>
1109             */
1110            public void setMinZoomScale(final Double minZoomScale) {
1111                    this.minZoomScale = minZoomScale;
1112            }
1113    
1114            /**
1115             * Defines an evelope of the viwable area. The JMapPane will never show
1116             * anything outside of this extend.
1117             *
1118             * @param maxExtend
1119             *            <code>null</code> to not have this restriction.
1120             */
1121            public void setMaxExtend(Envelope maxExtend) {
1122                    this.maxExtend = maxExtend;
1123            }
1124    
1125            /**
1126             * Returns the evelope of the viewable area. The JMapPane will never show
1127             * anything outside of this extend. If this has been set to
1128             * <code>null</code> via {@link #setMaxExtend(Envelope)}, it tries to return
1129             * quickly the context's bounds. It it takes to long to determine the
1130             * context bounds, <code>null</code> is returned.
1131             *
1132             * @param maxExtend
1133             *            <code>null</code> to not have this restriction.
1134             */
1135    
1136            public Envelope getMaxExtend() {
1137                    if (maxExtend == null) {
1138                            try {
1139                                    return fixAspectRatio(
1140                                        this.getBounds(),
1141                            // Kartenbereich um 10% vergroessern
1142                                        JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1),
1143                                        true
1144                                    );
1145                            } catch (IOException e) {
1146                                    LOGGER.warn(
1147                                                                    "maxExtend == null; faild to getLayerBounds of context",
1148                                                                    e);
1149                            }
1150                    }
1151                    return maxExtend;
1152            }
1153    
1154  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26