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

Legend:
Removed from v.2  
changed lines
  Added in v.494

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26