/[schmitzm]/trunk/src/skrueger/geotools/XMapPane.java
ViewVC logotype

Diff of /trunk/src/skrueger/geotools/XMapPane.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

branches/1.0-gt2-2.6/src/org/geotools/gui/swing/JMapPane.java revision 341 by alfonx, Mon Aug 31 10:16:40 2009 UTC branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java revision 415 by alfonx, Thu Sep 24 17:58:32 2009 UTC
# Line 13  Line 13 
13   *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *    Lesser General Public License for more details.   *    Lesser General Public License for more details.
15   */   */
16  package org.geotools.gui.swing;  package gtmig.org.geotools.swing;
17    
18  /**  /**
19   * <b>Xulu:<br>   * <b>Xulu:<br>
# Line 65  import org.geotools.renderer.GTRenderer; Line 65  import org.geotools.renderer.GTRenderer;
65  import org.geotools.renderer.label.LabelCacheImpl;  import org.geotools.renderer.label.LabelCacheImpl;
66  import org.geotools.renderer.lite.LabelCache;  import org.geotools.renderer.lite.LabelCache;
67  import org.geotools.renderer.lite.StreamingRenderer;  import org.geotools.renderer.lite.StreamingRenderer;
68  import org.geotools.renderer.shape.TransitionShapefileRenderer;  import org.geotools.renderer.shape.ShapefileRenderer;
 import org.geotools.styling.Graphic;  
 import org.geotools.styling.LineSymbolizer;  
 import org.geotools.styling.Mark;  
 import org.geotools.styling.PointSymbolizer;  
 import org.geotools.styling.PolygonSymbolizer;  
 import org.geotools.styling.StyleBuilder;  
 import org.geotools.styling.StyleFactory;  
69  import org.opengis.filter.FilterFactory2;  import org.opengis.filter.FilterFactory2;
70  import org.opengis.referencing.crs.CoordinateReferenceSystem;  import org.opengis.referencing.crs.CoordinateReferenceSystem;
71    
# Line 98  public class JMapPane extends JPanel imp Line 91  public class JMapPane extends JPanel imp
91    
92          public static final int Select = 4;          public static final int Select = 4;
93    
         private static final int POLYGON = 0;  
   
         private static final int LINE = 1;  
   
         private static final int POINT = 2;  
   
94          /**          /**
95           * what renders the map           * what renders the map
96           */           */
97          GTRenderer renderer;          GTRenderer renderer;
98    
         private GTRenderer highlightRenderer, selectionRenderer;  
   
99          /**          /**
100           * the map context to render           * the map context to render
101           */           */
102          MapContext context;          MapContext context;
103    
         private MapContext selectionContext;  
   
104          /**          /**
105           * the area of the map to draw           * the area of the map to draw
106           */           */
         // xulu.sc  
         // Envelope mapArea;  
107          protected Envelope mapArea;          protected Envelope mapArea;
         // xulu.ec  
108    
109          /**          /**
110           * the size of the pane last time we drew           * the size of the pane last time we drew
111           */           */
         // xulu.sc  
         // private Rectangle oldRect = null;  
112          protected Rectangle oldRect = null;          protected Rectangle oldRect = null;
         // xulu.ec  
113    
114          /**          /**
115           * the last map area drawn.           * the last map area drawn.
116           */           */
         // xulu.sc  
         // private Envelope oldMapArea = null;  
117          protected Envelope oldMapArea = null;          protected Envelope oldMapArea = null;
         // xulu.ec  
118    
119          /**          /**
120           * the base image of the map           * the base image of the map
121           */           */
122          protected BufferedImage baseImage, panningImage;          protected BufferedImage baseImage, panningImage;
         // SK: private BufferedImage baseImage, panningImage;  
123    
124          /**          /**
125           * a factory for filters           * a factory for filters
# Line 169  public class JMapPane extends JPanel imp Line 142  public class JMapPane extends JPanel imp
142    
143          LabelCache labelCache = new LabelCacheImpl();          LabelCache labelCache = new LabelCacheImpl();
144    
         // xulu.sc  
         // private boolean reset = false;  
145          protected boolean reset = false;          protected boolean reset = false;
         // xulu.ec  
146    
147          int startX;          int startX;
148    
149          int startY;          int startY;
150    
151            /**
152             * If not <code>null</code>, the {@link JMapPane} will not allow to zoom/pan
153             * out of that area
154             **/
155            private Envelope maxExtend = null;
156    
157            // /**
158            // * Is max. 1 or 0 of the 2 axised allowed to extend the maxExtend? If
159            // * <code>true</code> the extends has to be fully inside maxExtend
160            // **/
161            // boolean maxExtendForceMode = true;
162    
163          private boolean clickable;          private boolean clickable;
164    
165          int lastX;          int lastX;
166    
167          int lastY;          int lastY;
168    
         // xulu.sn  
169          private Double maxZoomScale = Double.MIN_VALUE;          private Double maxZoomScale = Double.MIN_VALUE;
170          private Double minZoomScale = Double.MAX_VALUE;          private Double minZoomScale = Double.MAX_VALUE;
         // xulu.en  
171    
         // sk.sn  
172          /**          /**
173           * Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses           * Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses
174           * Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu           * Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu
# Line 197  public class JMapPane extends JPanel imp Line 176  public class JMapPane extends JPanel imp
176           */           */
177          private boolean panning_started = false;          private boolean panning_started = false;
178    
         // sk.en  
   
179          public JMapPane() {          public JMapPane() {
180                  this(null, true, null, null);                  this(null, true, null, null);
181          }          }
# Line 250  public class JMapPane extends JPanel imp Line 227  public class JMapPane extends JPanel imp
227          }          }
228    
229          public void setRenderer(final GTRenderer renderer) {          public void setRenderer(final GTRenderer renderer) {
230                  Map hints = new HashMap();                  Map<Object, Object> hints = new HashMap<Object, Object>();
231                    
232                  this.renderer = renderer;                  this.renderer = renderer;
233                    
234                  if (renderer instanceof StreamingRenderer || renderer instanceof TransitionShapefileRenderer) {                  if (renderer instanceof StreamingRenderer
235                                    || renderer instanceof ShapefileRenderer) {
236                          hints = renderer.getRendererHints();                          hints = renderer.getRendererHints();
237                          if (hints == null) {                          if (hints == null) {
238                                  hints = new HashMap();                                  hints = new HashMap<Object, Object>();
239                          }                          }
240                          if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {                          if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {
241                                  labelCache = (LabelCache) hints                                  labelCache = (LabelCache) hints
# Line 267  public class JMapPane extends JPanel imp Line 245  public class JMapPane extends JPanel imp
245                          }                          }
246    
247                          hints.put("memoryPreloadingEnabled", Boolean.TRUE);                          hints.put("memoryPreloadingEnabled", Boolean.TRUE);
248                            
249                          renderer.setRendererHints(hints);                          renderer.setRendererHints(hints);
250                  }                  }
251    
252  //              this.highlightRenderer = new StreamingRenderer();                  // this.highlightRenderer = new StreamingRenderer();
253  //              this.selectionRenderer = new StreamingRenderer();                  // this.selectionRenderer = new StreamingRenderer();
254    
255                    // highlightRenderer.setRendererHints(hints);
256                    // selectionRenderer.setRendererHints(hints);
257    
258  //              highlightRenderer.setRendererHints(hints);                  // renderer.setRendererHints(hints);
 //              selectionRenderer.setRendererHints(hints);  
                   
 //              renderer.setRendererHints(hints);  
259    
260                  if (this.context != null) {                  if (this.context != null) {
261                          this.renderer.setContext(this.context);                          this.renderer.setContext(this.context);
# Line 330  public class JMapPane extends JPanel imp Line 308  public class JMapPane extends JPanel imp
308                  this.zoomFactor = zoomFactor;                  this.zoomFactor = zoomFactor;
309          }          }
310    
   
311          protected void paintComponent(final Graphics g) {          protected void paintComponent(final Graphics g) {
312                  super.paintComponent(g);                  super.paintComponent(g);
313    
# Line 369  public class JMapPane extends JPanel imp Line 346  public class JMapPane extends JPanel imp
346                                          .getCoordinateReferenceSystem());                                          .getCoordinateReferenceSystem());
347                  }                  }
348    
349                  if (changed ) { /* if the map changed then redraw */                  if (changed) { /* if the map changed then redraw */
350                          changed = false;                          changed = false;
351                          baseImage = new BufferedImage(dr.width, dr.height,                          baseImage = new BufferedImage(dr.width, dr.height,
352                                          BufferedImage.TYPE_INT_ARGB);                                          BufferedImage.TYPE_INT_ARGB);
353    
354                          final Graphics2D ig = baseImage.createGraphics();                          final Graphics2D ig = baseImage.createGraphics();
355                          /* System.out.println("rendering"); */                          /* System.out.println("rendering"); */
356                          if (renderer.getContext() != null)                          if (renderer.getContext() != null)
357                                  renderer.setContext(context);                                  renderer.setContext(context);
358                          labelCache.clear(); // work around anoying labelcache bug                          labelCache.clear(); // work around anoying labelcache bug
359    
# Line 397  public class JMapPane extends JPanel imp Line 374  public class JMapPane extends JPanel imp
374                  final double mapWidth = mapArea.getWidth(); /* get the extent of the map */                  final double mapWidth = mapArea.getWidth(); /* get the extent of the map */
375                  final double mapHeight = mapArea.getHeight();                  final double mapHeight = mapArea.getHeight();
376                  final double scaleX = r.getWidth() / mapArea.getWidth(); /*                  final double scaleX = r.getWidth() / mapArea.getWidth(); /*
377                                                                                                                           * calculate the new                                                                                                                                   * calculate the
378                                                                                                                           * scale                                                                                                                                   * new scale
379                                                                                                                           */                                                                                                                                   */
380    
381                  final double scaleY = r.getHeight() / mapArea.getHeight();                  final double scaleY = r.getHeight() / mapArea.getHeight();
382                  double scale = 1.0; // stupid compiler!                  double scale = 1.0; // stupid compiler!
383    
384                  if (scaleX < scaleY) { /* pick the smaller scale */                  if (scaleX > scaleY) { /* pick the smaller scale */
385                          scale = scaleX;                          scale = scaleX;
386                  } else {                  } else {
387                          scale = scaleY;                          scale = scaleY;
# Line 420  public class JMapPane extends JPanel imp Line 397  public class JMapPane extends JPanel imp
397                   */                   */
398    
399                  /* create the new extent */                  /* create the new extent */
400                  final Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0),                  final Coordinate ll = new Coordinate(
401                                  mapArea.getMinY() - (deltaY / 2.0));                                  mapArea.getMinX() - (deltaX / 2.0), mapArea.getMinY()
402                  final Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0),                                                  - (deltaY / 2.0));
403                                  mapArea.getMaxY() + (deltaY / 2.0));                  final Coordinate ur = new Coordinate(
404                                    mapArea.getMaxX() + (deltaX / 2.0), mapArea.getMaxY()
405                                                    + (deltaY / 2.0));
406    
407                  return new Envelope(ll, ur);                  return new Envelope(ll, ur);
408          }          }
409    
 //      public void doSelection(final double x, final double y, final MapLayer layer) {  
 //  
 //              final Geometry geometry = gf.createPoint(new Coordinate(x, y));  
 //  
 //              // org.opengis.geometry.Geometry geometry = new Point();  
 //  
 //              findFeature(geometry, layer);  
 //  
 //      }  
 //  
 //      /**  
 //       * @param geometry  
 //       *            - a geometry to construct the filter with  
 //       * @param i  
 //       *            - the index of the layer to search  
 //       * @throws IndexOutOfBoundsException  
 //       */  
 //      private void findFeature(final Geometry geometry, final MapLayer layer)  
 //                      throws IndexOutOfBoundsException {  
 //              org.opengis.filter.spatial.BinarySpatialOperator f = null;  
 //  
 //              if ((context == null) || (layer == null)) {  
 //                      return;  
 //              }  
 //  
 //              try {  
 //                      String name = layer.getFeatureSource().getSchema()  
 //                                      .getDefaultGeometry().getLocalName();  
 //  
 //                      if (name == "") {  
 //                              name = "the_geom";  
 //                      }  
 //  
 //                      try {  
 //                              f = ff.contains(ff.property(name), ff.literal(geometry));  
 //                              if (selectionManager != null) {  
 ////                                    System.out.println("selection changed");  
 //                                      selectionManager.selectionChanged(this, f);  
 //  
 //                              }  
 //                      } catch (final IllegalFilterException e) {  
 //                              // TODO Auto-generated catch block  
 //                              e.printStackTrace();  
 //                      }  
 //  
 //                      /*  
 //                       * // f.addLeftGeometry(ff.property(name)); //  
 //                       * System.out.println("looking with " + f); FeatureCollection fc =  
 //                       * layer.getFeatureSource().getFeatures(f);  
 //                       *  
 //                       *  
 //                       *  
 //                       * if (fcol == null) { fcol = fc;  
 //                       *  
 //                       * // here we should set the defaultgeom type } else {  
 //                       * fcol.addAll(fc); }  
 //                       */  
 //  
 //                      /*  
 //                       * GeometryAttributeType gat =  
 //                       * layer.getFeatureSource().getSchema().getDefaultGeometry();  
 //                       * fcol.setDefaultGeometry((Geometry)gat.createDefaultValue());  
 //                       */  
 //  
 //                      /*  
 //                       * Iterator fi = fc.iterator(); while (fi.hasNext()) { SimpleFeature feat  
 //                       * = (SimpleFeature) fi.next(); System.out.println("selected " +  
 //                       * feat.getAttribute("STATE_NAME")); }  
 //                       */  
 //              } catch (final IllegalFilterException e) {  
 //                      // TODO Auto-generated catch block  
 //                      e.printStackTrace();  
 //              }  
 //              return;  
 //      }  
   
410          public void mouseClicked(final MouseEvent e) {          public void mouseClicked(final MouseEvent e) {
411                  if (mapArea == null) return;                  if (mapArea == null)
412                            return;
413                  // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"                  // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"
414                  // h:"+mapArea.getHeight());                  // h:"+mapArea.getHeight());
415                  final Rectangle bounds = this.getBounds();                  final Rectangle bounds = this.getBounds();
# Line 519  public class JMapPane extends JPanel imp Line 423  public class JMapPane extends JPanel imp
423                  final double width2 = width / 2.0;                  final double width2 = width / 2.0;
424                  final double height2 = height / 2.0;                  final double height2 = height / 2.0;
425                  // xulu.ec                  // xulu.ec
426                  final double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX();                  final double mapX = ((x * width) / (double) bounds.width)
427                                    + mapArea.getMinX();
428                  final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)                  final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)
429                                  + mapArea.getMinY();                                  + mapArea.getMinY();
430    
# Line 550  public class JMapPane extends JPanel imp Line 455  public class JMapPane extends JPanel imp
455                          zlevel = 1.0 / zoomFactor;                          zlevel = 1.0 / zoomFactor;
456    
457                          break;                          break;
458  //                  //
459  //              case Select:                  // case Select:
460  //                      doSelection(mapX, mapY, selectionLayer);                  // doSelection(mapX, mapY, selectionLayer);
461  //                  //
462  //                      return;                  // return;
463    
464                  default:                  default:
465                          return;                          return;
# Line 626  public class JMapPane extends JPanel imp Line 531  public class JMapPane extends JPanel imp
531                                  // System.out.println("translate "+dx+","+dy);                                  // System.out.println("translate "+dx+","+dy);
532                                  final Graphics2D g2 = panningImage.createGraphics();                                  final Graphics2D g2 = panningImage.createGraphics();
533                                  g2.setBackground(new Color(240, 240, 240)); // TODO richtige                                  g2.setBackground(new Color(240, 240, 240)); // TODO richtige
534                                                                                                                          // farbe? am besten                                  // farbe? am besten
535                                                                                                                          // vom L&F die                                  // vom L&F die
536                                                                                                                          // hintergrundfarbe                                  // hintergrundfarbe
537                                                                                                                          // auslesen...                                  // auslesen...
538                                    
539                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());
540                                  g2.drawImage(baseImage, dx, dy, this);                                  g2.drawImage(baseImage, dx, dy, this);
541                                  graphics.drawImage(panningImage, 0, 0, this);                                  graphics.drawImage(panningImage, 0, 0, this);
# Line 652  public class JMapPane extends JPanel imp Line 557  public class JMapPane extends JPanel imp
557                          lastX = x;                          lastX = x;
558                          lastY = y;                          lastY = y;
559                          drawRectangle(graphics);                          drawRectangle(graphics);
560                  }                  }
561  //              else if (state == JMapPane.Select && selectionLayer != null) {                  // else if (state == JMapPane.Select && selectionLayer != null) {
562  //                  //
563  //                      // construct a new bbox filter                  // // construct a new bbox filter
564  //                      final Rectangle bounds = this.getBounds();                  // final Rectangle bounds = this.getBounds();
565  //                  //
566  //                      final double mapWidth = mapArea.getWidth();                  // final double mapWidth = mapArea.getWidth();
567  //                      final double mapHeight = mapArea.getHeight();                  // final double mapHeight = mapArea.getHeight();
568  //                  //
569  //                      final double x1 = ((this.startX * mapWidth) / (double) bounds.width)                  // final double x1 = ((this.startX * mapWidth) / (double) bounds.width)
570  //                                      + mapArea.getMinX();                  // + mapArea.getMinX();
571  //                      final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height)                  // final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) /
572  //                                      + mapArea.getMinY();                  // (double) bounds.height)
573  //                      final double x2 = ((x * mapWidth) / (double) bounds.width)                  // + mapArea.getMinY();
574  //                                      + mapArea.getMinX();                  // final double x2 = ((x * mapWidth) / (double) bounds.width)
575  //                      final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height)                  // + mapArea.getMinX();
576  //                                      + mapArea.getMinY();                  // final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double)
577  //                      final double left = Math.min(x1, x2);                  // bounds.height)
578  //                      final double right = Math.max(x1, x2);                  // + mapArea.getMinY();
579  //                      final double bottom = Math.min(y1, y2);                  // final double left = Math.min(x1, x2);
580  //                      final double top = Math.max(y1, y2);                  // final double right = Math.max(x1, x2);
581  //                  // final double bottom = Math.min(y1, y2);
582  //                      String name = selectionLayer.getFeatureSource().getSchema()                  // final double top = Math.max(y1, y2);
583  //                                      .getDefaultGeometry().getName();                  //
584  //                  // String name = selectionLayer.getFeatureSource().getSchema()
585  //                      if (name == "") {                  // .getDefaultGeometry().getName();
586  //                              name = "the_geom";                  //
587  //                      }                  // if (name == "") {
588  //                      final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,                  // name = "the_geom";
589  //                                      getContext().getCoordinateReferenceSystem().toString());                  // }
590  //                      if (selectionManager != null) {                  // final Filter bb = ff.bbox(ff.property(name), left, bottom, right,
591  //                              selectionManager.selectionChanged(this, bb);                  // top,
592  //                      }                  // getContext().getCoordinateReferenceSystem().toString());
593  //                  // if (selectionManager != null) {
594  //                      graphics.setXORMode(Color.green);                  // selectionManager.selectionChanged(this, bb);
595  //                  // }
596  //                      /*                  //
597  //                       * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); }                  // graphics.setXORMode(Color.green);
598  //                       */                  //
599  //                  // /*
600  //                      // draw new box                  // * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); }
601  //                      lastX = x;                  // */
602  //                      lastY = y;                  //
603  //                      drawRectangle(graphics);                  // // draw new box
604  //              }                  // lastX = x;
605                    // lastY = y;
606                    // drawRectangle(graphics);
607                    // }
608    
609          }          }
610    
# Line 781  public class JMapPane extends JPanel imp Line 689  public class JMapPane extends JPanel imp
689                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
690    
691                          // sk.sc                          // sk.sc
692  //                      {                          // {
693  //                      // SK tries to paint a preview of the zoom ;-9 aha.... well                          // // SK tries to paint a preview of the zoom ;-9 aha.... well
694  //                      Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();                          // Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();
695  //                      graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,                          // graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
696  //                                      RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);                          // RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
697  //                      graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,                          // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
698  //                                      RenderingHints.VALUE_ANTIALIAS_OFF);                          // RenderingHints.VALUE_ANTIALIAS_OFF);
699  //                      graphics.setRenderingHint(RenderingHints.KEY_RENDERING,                          // graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
700  //                                      RenderingHints.VALUE_RENDER_SPEED);                          // RenderingHints.VALUE_RENDER_SPEED);
701  //                      graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),                          // graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),
702  //                                      JMapPane.this.getHeight(), x1, y1, x2, y2, null);                          // JMapPane.this.getHeight(), x1, y1, x2, y2, null);
703  //                      }                          // }
704                          // xulu.ec                          // xulu.ec
705                  } else if (state == JMapPane.ZoomOut) {                  } else if (state == JMapPane.ZoomOut) {
706                          drawRectangle(this.getGraphics());                          drawRectangle(this.getGraphics());
# Line 821  public class JMapPane extends JPanel imp Line 729  public class JMapPane extends JPanel imp
729                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
730    
731                          // xulu.ec                          // xulu.ec
732                  }                  }
733  //              else if (state == JMapPane.Select && selectionLayer != null) {                  // else if (state == JMapPane.Select && selectionLayer != null) {
734  //                      final double left = Math.min(startX, endX);                  // final double left = Math.min(startX, endX);
735  //                      final double right = Math.max(startX, endX);                  // final double right = Math.max(startX, endX);
736  //                      final double bottom = Math.min(startY, endY);                  // final double bottom = Math.min(startY, endY);
737  //                      final double top = Math.max(startY, endY);                  // final double top = Math.max(startY, endY);
738  //                  //
739  //                      String name = selectionLayer.getFeatureSource().getSchema()                  // String name = selectionLayer.getFeatureSource().getSchema()
740  //                                      .getDefaultGeometry().getLocalName();                  // .getDefaultGeometry().getLocalName();
741  //                  //
742  //                      if (name == "") {                  // if (name == "") {
743  //                              name = "the_geom";                  // name = "the_geom";
744  //                      }                  // }
745  //                      final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,                  // final Filter bb = ff.bbox(ff.property(name), left, bottom, right,
746  //                                      getContext().getCoordinateReferenceSystem().toString());                  // top,
747  //                      // System.out.println(bb.toString());                  // getContext().getCoordinateReferenceSystem().toString());
748  //                      if (selectionManager != null) {                  // // System.out.println(bb.toString());
749  //                              selectionManager.selectionChanged(this, bb);                  // if (selectionManager != null) {
750  //                      }                  // selectionManager.selectionChanged(this, bb);
751  //                      /*                  // }
752  //                       * FeatureCollection fc; selection = null; try { fc =                  // /*
753  //                       * selectionLayer.getFeatureSource().getFeatures(bb); selection =                  // * FeatureCollection fc; selection = null; try { fc =
754  //                       * fc; } catch (IOException e) { e.printStackTrace(); }                  // * selectionLayer.getFeatureSource().getFeatures(bb); selection =
755  //                       */                  // * fc; } catch (IOException e) { e.printStackTrace(); }
756  //              }                  // */
757                    // }
758    
759                  // xulu.so                  // xulu.so
760                  // setMapArea(mapArea);                  // setMapArea(mapArea);
# Line 857  public class JMapPane extends JPanel imp Line 766  public class JMapPane extends JPanel imp
766                  return clickable;                  return clickable;
767          }          }
768    
769          private org.geotools.styling.Style setupStyle(final int type, final Color color) {          //
770                  final StyleFactory sf = org.geotools.factory.CommonFactoryFinder          // private org.geotools.styling.Style setupStyle(final int type, final Color
771                                  .getStyleFactory(null);          // color) {
772                  final StyleBuilder sb = new StyleBuilder();          // final StyleFactory sf = org.geotools.factory.CommonFactoryFinder
773            // .getStyleFactory(null);
774                  org.geotools.styling.Style s = sf.createStyle();          // final StyleBuilder sb = new StyleBuilder();
775                  s.setTitle("selection");          //
776            // org.geotools.styling.Style s = sf.createStyle();
777                  // TODO parameterise the color          // s.setTitle("selection");
778                  final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);          //
779                  ps.setStroke(sb.createStroke(color));          // // TODO parameterise the color
780            // final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);
781                  final LineSymbolizer ls = sb.createLineSymbolizer(color);          // ps.setStroke(sb.createStroke(color));
782                  final Graphic h = sb.createGraphic();          //
783                  h.setMarks(new Mark[] { sb.createMark("square", color) });          // final LineSymbolizer ls = sb.createLineSymbolizer(color);
784            // final Graphic h = sb.createGraphic();
785                  final PointSymbolizer pts = sb.createPointSymbolizer(h);          // h.setMarks(new Mark[] { sb.createMark("square", color) });
786            //
787                  // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});          // final PointSymbolizer pts = sb.createPointSymbolizer(h);
788                  switch (type) {          //
789                  case POLYGON:          // // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});
790                          s = sb.createStyle(ps);          // switch (type) {
791            // case POLYGON:
792                          break;          // s = sb.createStyle(ps);
793            //
794                  case POINT:          // break;
795                          s = sb.createStyle(pts);          //
796            // case POINT:
797                          break;          // s = sb.createStyle(pts);
798            //
799                  case LINE:          // break;
800                          s = sb.createStyle(ls);          //
801                  }          // case LINE:
802            // s = sb.createStyle(ls);
803                  return s;          // }
804          }          //
805            // return s;
806            // }
807    
808          public void propertyChange(final PropertyChangeEvent evt) {          public void propertyChange(final PropertyChangeEvent evt) {
809                  final String prop = evt.getPropertyName();                  final String prop = evt.getPropertyName();
# Line 977  public class JMapPane extends JPanel imp Line 887  public class JMapPane extends JPanel imp
887          public void mouseMoved(final MouseEvent e) {          public void mouseMoved(final MouseEvent e) {
888          }          }
889    
   
   
890          // xulu.sn          // xulu.sn
891          /**          /**
892           * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste           * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste
# Line 997  public class JMapPane extends JPanel imp Line 905  public class JMapPane extends JPanel imp
905                  if (env == null)                  if (env == null)
906                          return env;                          return env;
907    
908                    Envelope newArea = null;
909    
910                  /**                  /**
911                   * Correct the aspect Ratio before we check the rest. Otherwise we might                   * Correct the aspect Ratio before we check the rest. Otherwise we might
912                   * easily fail.                   * easily fail.
# Line 1006  public class JMapPane extends JPanel imp Line 916  public class JMapPane extends JPanel imp
916                  final double scale = env.getWidth() / getWidth();                  final double scale = env.getWidth() / getWidth();
917                  final double centerX = env.getMinX() + env.getWidth() / 2.;                  final double centerX = env.getMinX() + env.getWidth() / 2.;
918                  final double centerY = env.getMinY() + env.getHeight() / 2.;                  final double centerY = env.getMinY() + env.getHeight() / 2.;
919                  double newWidth2;                  double newWidth2 = 0;
920                  double newHeight2;                  double newHeight2 = 0;
921                  if (scale < getMaxZoomScale()) {                  if (scale < getMaxZoomScale()) {
922                          // ****************************************************************************                          // ****************************************************************************
923                          // Wir zoomen weiter rein als erlaubt => Anpassen des envelope                          // Wir zoomen weiter rein als erlaubt => Anpassen des envelope
# Line 1024  public class JMapPane extends JPanel imp Line 934  public class JMapPane extends JPanel imp
934                          // ****************************************************************************                          // ****************************************************************************
935                          // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen                          // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen
936                          // ****************************************************************************                          // ****************************************************************************
937                          return env;                          newArea = env;
938                  }                  }
939    
940                  final Coordinate ll = new Coordinate(centerX - newWidth2, centerY                  if (newArea == null) {
                                 - newHeight2);  
                 final Coordinate ur = new Coordinate(centerX + newWidth2, centerY  
                                 + newHeight2);  
941    
942                  return new Envelope(ll, ur);                          final Coordinate ll = new Coordinate(centerX - newWidth2, centerY
943                                            - newHeight2);
944                            final Coordinate ur = new Coordinate(centerX + newWidth2, centerY
945                                            + newHeight2);
946    
947                            newArea = new Envelope(ll, ur);
948                    }
949    
950                    if (getMaxExtend() != null) {
951    
952                            while (!getMaxExtend().contains(newArea)) {
953                                    /*
954                                     * If a maxExtend is set, we have to honour that...
955                                     */
956    
957                                    // Exceeds top? Move down and maybe cut
958                                    if (newArea.getMaxY() > maxExtend.getMaxY()) {
959                                            double divY = newArea.getMaxY() - maxExtend.getMaxY();
960                                            LOGGER.debug("Moving area down by " + divY);
961    
962                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
963                                                            newArea.getMinY() - divY), new Coordinate(newArea
964                                                            .getMaxX(), newArea.getMaxY() - divY));
965    
966                                            if (newArea.getMinY() < maxExtend.getMinY()) {
967                                                    LOGGER.debug("Now it exeeds the bottom border.. cut!");
968                                                    // And cut the bottom if it moved out of the area
969                                                    newArea = new Envelope(new Coordinate(
970                                                                    newArea.getMinX(), maxExtend.getMinY()),
971                                                                    new Coordinate(newArea.getMaxX(), newArea
972                                                                                    .getMaxY()));
973    
974                                                    LOGGER.debug("and fix aspect ratio");
975    
976                                                    newArea = fixAspectRatio(this.getBounds(), newArea);
977                                            }
978                                    }
979    
980                                    // Exceeds bottom? Move up and maybe cut
981                                    if (newArea.getMinY() < maxExtend.getMinY()) {
982                                            double divY = newArea.getMinY() - maxExtend.getMinY();
983                                            LOGGER.debug("Moving area up by " + divY);
984    
985                                            newArea = new Envelope(new Coordinate(newArea.getMinX(),
986                                                            newArea.getMinY() - divY), new Coordinate(newArea
987                                                            .getMaxX(), newArea.getMaxY() - divY));
988    
989                                            if (newArea.getMaxY() > maxExtend.getMaxY()) {
990                                                    LOGGER.debug("Now it exeeds the top border.. cut!");
991                                                    // And cut the bottom if it moved out of the area
992                                                    newArea = new Envelope(new Coordinate(
993                                                                    newArea.getMinX(), newArea.getMinY()),
994                                                                    new Coordinate(newArea.getMaxX(), maxExtend
995                                                                                    .getMaxY()));
996    
997                                                    LOGGER.debug("and fix aspect ratio");
998    
999                                                    newArea = fixAspectRatio(this.getBounds(), newArea);
1000                                            }
1001                                    }
1002    
1003                                    // Exceeds to the right? move and maybe cut
1004                                    if (newArea.getMaxX() > maxExtend.getMaxX()) {
1005    
1006                                            // Move left..
1007                                            double divX = newArea.getMaxX() - maxExtend.getMaxX();
1008                                            LOGGER.debug("Moving area left by " + divX);
1009    
1010                                            newArea = new Envelope(new Coordinate(newArea.getMinX()
1011                                                            - divX, newArea.getMinY()), new Coordinate(newArea
1012                                                            .getMaxX()
1013                                                            - divX, newArea.getMaxY()));
1014    
1015                                            if (newArea.getMinX() < maxExtend.getMinX()) {
1016                                                    LOGGER.debug("Now it exeeds the left border.. cut!");
1017                                                    // And cut the left if it moved out of the area
1018                                                    newArea = new Envelope(new Coordinate(maxExtend
1019                                                                    .getMinX(), newArea.getMinY()), new Coordinate(
1020                                                                    newArea.getMaxX(), newArea.getMaxY()));
1021    
1022                                                    LOGGER.debug("and fix aspect ratio");
1023    
1024                                                    newArea = fixAspectRatio(this.getBounds(), newArea);
1025                                            }
1026                                    }
1027    
1028                                    // Exceeds to the left? move and maybe cut
1029                                    if (newArea.getMinX() < maxExtend.getMinX()) {
1030    
1031                                            // Move right..
1032                                            double divX = newArea.getMinX() - maxExtend.getMinX();
1033                                            LOGGER.debug("Moving area right by " + divX);
1034    
1035                                            newArea = new Envelope(new Coordinate(newArea.getMinX()
1036                                                            - divX, newArea.getMinY()), new Coordinate(newArea
1037                                                            .getMaxX()
1038                                                            - divX, newArea.getMaxY()));
1039    
1040                                            if (newArea.getMaxX() > maxExtend.getMaxX()) {
1041                                                    LOGGER.debug("Now it exeeds the right border.. cut!");
1042                                                    // And cut the left if it moved out of the area
1043                                                    newArea = new Envelope(new Coordinate(
1044                                                                    newArea.getMinX(), newArea.getMinY()),
1045                                                                    new Coordinate(maxExtend.getMaxX(), newArea
1046                                                                                    .getMaxY()));
1047    
1048                                                    LOGGER.debug("and fix aspect ratio");
1049    
1050                                                    newArea = fixAspectRatio(this.getBounds(), newArea);
1051                                            }
1052                                    }
1053    
1054                            }
1055    
1056                    }
1057    
1058                    return newArea;
1059          }          }
1060    
1061          /**          /**
# Line 1065  public class JMapPane extends JPanel imp Line 1088  public class JMapPane extends JPanel imp
1088           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
1089           */           */
1090          public void setMaxZoomScale(final Double maxZoomScale) {          public void setMaxZoomScale(final Double maxZoomScale) {
                 // System.out.println("setting max scale to "+maxZoomScale);  
1091                  this.maxZoomScale = maxZoomScale;                  this.maxZoomScale = maxZoomScale;
1092          }          }
1093    
# Line 1079  public class JMapPane extends JPanel imp Line 1101  public class JMapPane extends JPanel imp
1101          public void setMinZoomScale(final Double minZoomScale) {          public void setMinZoomScale(final Double minZoomScale) {
1102                  this.minZoomScale = minZoomScale;                  this.minZoomScale = minZoomScale;
1103          }          }
1104          // xulu.en  
1105            /**
1106             * Defines an evelope of the viwable area. The JMapPane will never show
1107             * anything outside of this extend.
1108             *
1109             * @param maxExtend
1110             *            <code>null</code> to not have this restriction.
1111             */
1112            public void setMaxExtend(Envelope maxExtend) {
1113                    this.maxExtend = maxExtend;
1114            }
1115    
1116            /**
1117             * Returns the evelope of the viewable area. The JMapPane will never show
1118             * anything outside of this extend.
1119             *
1120             * @param maxExtend
1121             *            <code>null</code> to not have this restriction.
1122             */
1123    
1124            public Envelope getMaxExtend() {
1125                    return maxExtend;
1126            }
1127    
1128  }  }

Legend:
Removed from v.341  
changed lines
  Added in v.415

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26