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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26