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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26