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> |
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; |
|
import org.geotools.renderer.shape.TransitionShapefileRenderer; |
|
|
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; |
|
68 |
import org.opengis.filter.FilterFactory2; |
import org.opengis.filter.FilterFactory2; |
69 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
70 |
|
|
71 |
|
import schmitzm.geotools.JTSUtil; |
72 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
73 |
|
|
74 |
import com.vividsolutions.jts.geom.Coordinate; |
import com.vividsolutions.jts.geom.Coordinate; |
77 |
|
|
78 |
public class JMapPane extends JPanel implements MouseListener, |
public class JMapPane extends JPanel implements MouseListener, |
79 |
MouseMotionListener, PropertyChangeListener, MapLayerListListener { |
MouseMotionListener, PropertyChangeListener, MapLayerListListener { |
80 |
private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName()); |
private static Logger LOGGER = Logger.getLogger(JMapPane.class); |
81 |
|
|
82 |
private static final long serialVersionUID = -8647971481359690499L; |
private static final long serialVersionUID = -8647971481359690499L; |
83 |
|
|
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 |
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 |
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 |
} |
} |
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 |
|
//MS: Apply hint also for ShapeFileRenderer |
234 |
if (renderer instanceof StreamingRenderer || renderer instanceof TransitionShapefileRenderer) { |
// if (renderer instanceof StreamingRenderer) { |
235 |
hints = renderer.getRendererHints(); |
hints = renderer.getRendererHints(); |
236 |
if (hints == null) { |
if (hints == null) { |
237 |
hints = new HashMap(); |
hints = new HashMap<Object, Object>(); |
238 |
} |
} |
239 |
if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) { |
if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) { |
240 |
labelCache = (LabelCache) hints |
labelCache = (LabelCache) hints |
244 |
} |
} |
245 |
|
|
246 |
hints.put("memoryPreloadingEnabled", Boolean.TRUE); |
hints.put("memoryPreloadingEnabled", Boolean.TRUE); |
|
|
|
|
renderer.setRendererHints(hints); |
|
|
} |
|
|
|
|
|
// this.highlightRenderer = new StreamingRenderer(); |
|
|
// this.selectionRenderer = new StreamingRenderer(); |
|
247 |
|
|
248 |
// highlightRenderer.setRendererHints(hints); |
renderer.setRendererHints(hints); |
249 |
// selectionRenderer.setRendererHints(hints); |
// } |
|
|
|
|
// renderer.setRendererHints(hints); |
|
250 |
|
|
251 |
if (this.context != null) { |
if (this.context != null) { |
252 |
this.renderer.setContext(this.context); |
this.renderer.setContext(this.context); |
299 |
this.zoomFactor = zoomFactor; |
this.zoomFactor = zoomFactor; |
300 |
} |
} |
301 |
|
|
|
|
|
302 |
protected void paintComponent(final Graphics g) { |
protected void paintComponent(final Graphics g) { |
303 |
super.paintComponent(g); |
super.paintComponent(g); |
304 |
|
|
324 |
reset = false; /* forget about the reset */ |
reset = false; /* forget about the reset */ |
325 |
oldRect = r; /* store what the current size is */ |
oldRect = r; /* store what the current size is */ |
326 |
|
|
327 |
mapArea = fixAspectRatio(r, mapArea); |
mapArea = JTSUtil.fixAspectRatio(r, mapArea, false); |
328 |
} |
} |
329 |
} |
} |
330 |
|
|
337 |
.getCoordinateReferenceSystem()); |
.getCoordinateReferenceSystem()); |
338 |
} |
} |
339 |
|
|
340 |
if (changed ) { /* if the map changed then redraw */ |
if (changed) { /* if the map changed then redraw */ |
341 |
changed = false; |
changed = false; |
342 |
baseImage = new BufferedImage(dr.width, dr.height, |
baseImage = new BufferedImage(dr.width, dr.height, |
343 |
BufferedImage.TYPE_INT_ARGB); |
BufferedImage.TYPE_INT_ARGB); |
344 |
|
|
345 |
final Graphics2D ig = baseImage.createGraphics(); |
final Graphics2D ig = baseImage.createGraphics(); |
346 |
/* System.out.println("rendering"); */ |
/* System.out.println("rendering"); */ |
347 |
if (renderer.getContext() != null) |
if (renderer.getContext() != null) |
348 |
renderer.setContext(context); |
renderer.setContext(context); |
349 |
labelCache.clear(); // work around anoying labelcache bug |
labelCache.clear(); // work around anoying labelcache bug |
350 |
|
|
360 |
((Graphics2D) g).drawImage(baseImage, 0, 0, this); |
((Graphics2D) g).drawImage(baseImage, 0, 0, this); |
361 |
} |
} |
362 |
|
|
|
private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea) { |
|
|
|
|
|
final double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
|
|
final double mapHeight = mapArea.getHeight(); |
|
|
final double scaleX = r.getWidth() / mapArea.getWidth(); /* |
|
|
* calculate the new |
|
|
* scale |
|
|
*/ |
|
|
|
|
|
final double scaleY = r.getHeight() / mapArea.getHeight(); |
|
|
double scale = 1.0; // stupid compiler! |
|
|
|
|
|
if (scaleX < scaleY) { /* pick the smaller scale */ |
|
|
scale = scaleX; |
|
|
} else { |
|
|
scale = scaleY; |
|
|
} |
|
|
|
|
|
/* calculate the difference in width and height of the new extent */ |
|
|
final double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth); |
|
|
final double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight); |
|
|
|
|
|
/* |
|
|
* System.out.println("delta x " + deltaX); |
|
|
* System.out.println("delta y " + deltaY); |
|
|
*/ |
|
|
|
|
|
/* create the new extent */ |
|
|
final Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0), |
|
|
mapArea.getMinY() - (deltaY / 2.0)); |
|
|
final Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0), |
|
|
mapArea.getMaxY() + (deltaY / 2.0)); |
|
|
|
|
|
return new Envelope(ll, ur); |
|
|
} |
|
|
|
|
|
// 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; |
|
|
// } |
|
|
|
|
363 |
public void mouseClicked(final MouseEvent e) { |
public void mouseClicked(final MouseEvent e) { |
364 |
if (mapArea == null) return; |
if (mapArea == null) |
365 |
|
return; |
366 |
// System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+" |
// System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+" |
367 |
// h:"+mapArea.getHeight()); |
// h:"+mapArea.getHeight()); |
368 |
final Rectangle bounds = this.getBounds(); |
final Rectangle bounds = this.getBounds(); |
376 |
final double width2 = width / 2.0; |
final double width2 = width / 2.0; |
377 |
final double height2 = height / 2.0; |
final double height2 = height / 2.0; |
378 |
// xulu.ec |
// xulu.ec |
379 |
final double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX(); |
final double mapX = ((x * width) / (double) bounds.width) |
380 |
|
+ mapArea.getMinX(); |
381 |
final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height) |
final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height) |
382 |
+ mapArea.getMinY(); |
+ mapArea.getMinY(); |
383 |
|
|
408 |
zlevel = 1.0 / zoomFactor; |
zlevel = 1.0 / zoomFactor; |
409 |
|
|
410 |
break; |
break; |
411 |
// |
// |
412 |
// case Select: |
// case Select: |
413 |
// doSelection(mapX, mapY, selectionLayer); |
// doSelection(mapX, mapY, selectionLayer); |
414 |
// |
// |
415 |
// return; |
// return; |
416 |
|
|
417 |
default: |
default: |
418 |
return; |
return; |
484 |
// System.out.println("translate "+dx+","+dy); |
// System.out.println("translate "+dx+","+dy); |
485 |
final Graphics2D g2 = panningImage.createGraphics(); |
final Graphics2D g2 = panningImage.createGraphics(); |
486 |
g2.setBackground(new Color(240, 240, 240)); // TODO richtige |
g2.setBackground(new Color(240, 240, 240)); // TODO richtige |
487 |
// farbe? am besten |
// farbe? am besten |
488 |
// vom L&F die |
// vom L&F die |
489 |
// hintergrundfarbe |
// hintergrundfarbe |
490 |
// auslesen... |
// auslesen... |
491 |
|
|
492 |
g2.clearRect(0, 0, this.getWidth(), this.getHeight()); |
g2.clearRect(0, 0, this.getWidth(), this.getHeight()); |
493 |
g2.drawImage(baseImage, dx, dy, this); |
g2.drawImage(baseImage, dx, dy, this); |
494 |
graphics.drawImage(panningImage, 0, 0, this); |
graphics.drawImage(panningImage, 0, 0, this); |
510 |
lastX = x; |
lastX = x; |
511 |
lastY = y; |
lastY = y; |
512 |
drawRectangle(graphics); |
drawRectangle(graphics); |
513 |
} |
} |
514 |
// else if (state == JMapPane.Select && selectionLayer != null) { |
// else if (state == JMapPane.Select && selectionLayer != null) { |
515 |
// |
// |
516 |
// // construct a new bbox filter |
// // construct a new bbox filter |
517 |
// final Rectangle bounds = this.getBounds(); |
// final Rectangle bounds = this.getBounds(); |
518 |
// |
// |
519 |
// final double mapWidth = mapArea.getWidth(); |
// final double mapWidth = mapArea.getWidth(); |
520 |
// final double mapHeight = mapArea.getHeight(); |
// final double mapHeight = mapArea.getHeight(); |
521 |
// |
// |
522 |
// final double x1 = ((this.startX * mapWidth) / (double) bounds.width) |
// final double x1 = ((this.startX * mapWidth) / (double) bounds.width) |
523 |
// + mapArea.getMinX(); |
// + mapArea.getMinX(); |
524 |
// final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height) |
// final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / |
525 |
// + mapArea.getMinY(); |
// (double) bounds.height) |
526 |
// final double x2 = ((x * mapWidth) / (double) bounds.width) |
// + mapArea.getMinY(); |
527 |
// + mapArea.getMinX(); |
// final double x2 = ((x * mapWidth) / (double) bounds.width) |
528 |
// final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height) |
// + mapArea.getMinX(); |
529 |
// + mapArea.getMinY(); |
// final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) |
530 |
// final double left = Math.min(x1, x2); |
// bounds.height) |
531 |
// final double right = Math.max(x1, x2); |
// + mapArea.getMinY(); |
532 |
// final double bottom = Math.min(y1, y2); |
// final double left = Math.min(x1, x2); |
533 |
// final double top = Math.max(y1, y2); |
// final double right = Math.max(x1, x2); |
534 |
// |
// final double bottom = Math.min(y1, y2); |
535 |
// String name = selectionLayer.getFeatureSource().getSchema() |
// final double top = Math.max(y1, y2); |
536 |
// .getDefaultGeometry().getName(); |
// |
537 |
// |
// String name = selectionLayer.getFeatureSource().getSchema() |
538 |
// if (name == "") { |
// .getDefaultGeometry().getName(); |
539 |
// name = "the_geom"; |
// |
540 |
// } |
// if (name == "") { |
541 |
// final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top, |
// name = "the_geom"; |
542 |
// getContext().getCoordinateReferenceSystem().toString()); |
// } |
543 |
// if (selectionManager != null) { |
// final Filter bb = ff.bbox(ff.property(name), left, bottom, right, |
544 |
// selectionManager.selectionChanged(this, bb); |
// top, |
545 |
// } |
// getContext().getCoordinateReferenceSystem().toString()); |
546 |
// |
// if (selectionManager != null) { |
547 |
// graphics.setXORMode(Color.green); |
// selectionManager.selectionChanged(this, bb); |
548 |
// |
// } |
549 |
// /* |
// |
550 |
// * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); } |
// graphics.setXORMode(Color.green); |
551 |
// */ |
// |
552 |
// |
// /* |
553 |
// // draw new box |
// * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); } |
554 |
// lastX = x; |
// */ |
555 |
// lastY = y; |
// |
556 |
// drawRectangle(graphics); |
// // draw new box |
557 |
// } |
// lastX = x; |
558 |
|
// lastY = y; |
559 |
|
// drawRectangle(graphics); |
560 |
|
// } |
561 |
|
|
562 |
} |
} |
563 |
|
|
567 |
protected void processDrag(final int x1, final int y1, final int x2, |
protected void processDrag(final int x1, final int y1, final int x2, |
568 |
final int y2, final MouseEvent e) { |
final int y2, final MouseEvent e) { |
569 |
|
|
570 |
|
|
571 |
/**** |
/**** |
572 |
* If no layer is availabe we dont want a NullPointerException |
* If no layers exist, we ignore the drag. |
573 |
*/ |
*/ |
574 |
if (mapArea == null) |
if (context.getLayerCount() <= 0) { |
575 |
return; |
return; |
576 |
|
} |
577 |
|
|
578 |
// System.out.println("processing drag from " + x1 + "," + y1 + " -> " |
// System.out.println("processing drag from " + x1 + "," + y1 + " -> " |
579 |
// + x2 + "," + y2); |
// + x2 + "," + y2); |
580 |
if ((x1 == x2) && (y1 == y2)) { |
if ((x1 == x2) && (y1 == y2)) { |
620 |
final Coordinate ur = new Coordinate(right, top); |
final Coordinate ur = new Coordinate(right, top); |
621 |
// xulu.sc |
// xulu.sc |
622 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
623 |
setMapArea(fixAspectRatio(this.getBounds(), new Envelope(ll, ur))); |
|
624 |
|
|
625 |
|
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
626 |
// xulu.ec |
// xulu.ec |
627 |
} else if (state == JMapPane.ZoomIn) { |
} else if (state == JMapPane.ZoomIn) { |
628 |
|
|
646 |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
647 |
|
|
648 |
// sk.sc |
// sk.sc |
649 |
// { |
// { |
650 |
// // SK tries to paint a preview of the zoom ;-9 aha.... well |
// // SK tries to paint a preview of the zoom ;-9 aha.... well |
651 |
// Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics(); |
// Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics(); |
652 |
// graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
// graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
653 |
// RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
// RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
654 |
// graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
// graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
655 |
// RenderingHints.VALUE_ANTIALIAS_OFF); |
// RenderingHints.VALUE_ANTIALIAS_OFF); |
656 |
// graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
// graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
657 |
// RenderingHints.VALUE_RENDER_SPEED); |
// RenderingHints.VALUE_RENDER_SPEED); |
658 |
// graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(), |
// graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(), |
659 |
// JMapPane.this.getHeight(), x1, y1, x2, y2, null); |
// JMapPane.this.getHeight(), x1, y1, x2, y2, null); |
660 |
// } |
// } |
661 |
// xulu.ec |
// xulu.ec |
662 |
} else if (state == JMapPane.ZoomOut) { |
} else if (state == JMapPane.ZoomOut) { |
663 |
drawRectangle(this.getGraphics()); |
drawRectangle(this.getGraphics()); |
686 |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
687 |
|
|
688 |
// xulu.ec |
// xulu.ec |
689 |
} |
} |
690 |
// else if (state == JMapPane.Select && selectionLayer != null) { |
// else if (state == JMapPane.Select && selectionLayer != null) { |
691 |
// final double left = Math.min(startX, endX); |
// final double left = Math.min(startX, endX); |
692 |
// final double right = Math.max(startX, endX); |
// final double right = Math.max(startX, endX); |
693 |
// final double bottom = Math.min(startY, endY); |
// final double bottom = Math.min(startY, endY); |
694 |
// final double top = Math.max(startY, endY); |
// final double top = Math.max(startY, endY); |
695 |
// |
// |
696 |
// String name = selectionLayer.getFeatureSource().getSchema() |
// String name = selectionLayer.getFeatureSource().getSchema() |
697 |
// .getDefaultGeometry().getLocalName(); |
// .getDefaultGeometry().getLocalName(); |
698 |
// |
// |
699 |
// if (name == "") { |
// if (name == "") { |
700 |
// name = "the_geom"; |
// name = "the_geom"; |
701 |
// } |
// } |
702 |
// final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top, |
// final Filter bb = ff.bbox(ff.property(name), left, bottom, right, |
703 |
// getContext().getCoordinateReferenceSystem().toString()); |
// top, |
704 |
// // System.out.println(bb.toString()); |
// getContext().getCoordinateReferenceSystem().toString()); |
705 |
// if (selectionManager != null) { |
// // System.out.println(bb.toString()); |
706 |
// selectionManager.selectionChanged(this, bb); |
// if (selectionManager != null) { |
707 |
// } |
// selectionManager.selectionChanged(this, bb); |
708 |
// /* |
// } |
709 |
// * FeatureCollection fc; selection = null; try { fc = |
// /* |
710 |
// * selectionLayer.getFeatureSource().getFeatures(bb); selection = |
// * FeatureCollection fc; selection = null; try { fc = |
711 |
// * fc; } catch (IOException e) { e.printStackTrace(); } |
// * selectionLayer.getFeatureSource().getFeatures(bb); selection = |
712 |
// */ |
// * fc; } catch (IOException e) { e.printStackTrace(); } |
713 |
// } |
// */ |
714 |
|
// } |
715 |
|
|
716 |
// xulu.so |
// xulu.so |
717 |
// setMapArea(mapArea); |
// setMapArea(mapArea); |
723 |
return clickable; |
return clickable; |
724 |
} |
} |
725 |
|
|
726 |
private org.geotools.styling.Style setupStyle(final int type, final Color color) { |
// |
727 |
final StyleFactory sf = org.geotools.factory.CommonFactoryFinder |
// private org.geotools.styling.Style setupStyle(final int type, final Color |
728 |
.getStyleFactory(null); |
// color) { |
729 |
final StyleBuilder sb = new StyleBuilder(); |
// final StyleFactory sf = org.geotools.factory.CommonFactoryFinder |
730 |
|
// .getStyleFactory(null); |
731 |
org.geotools.styling.Style s = sf.createStyle(); |
// final StyleBuilder sb = new StyleBuilder(); |
732 |
s.setTitle("selection"); |
// |
733 |
|
// org.geotools.styling.Style s = sf.createStyle(); |
734 |
// TODO parameterise the color |
// s.setTitle("selection"); |
735 |
final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color); |
// |
736 |
ps.setStroke(sb.createStroke(color)); |
// // TODO parameterise the color |
737 |
|
// final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color); |
738 |
final LineSymbolizer ls = sb.createLineSymbolizer(color); |
// ps.setStroke(sb.createStroke(color)); |
739 |
final Graphic h = sb.createGraphic(); |
// |
740 |
h.setMarks(new Mark[] { sb.createMark("square", color) }); |
// final LineSymbolizer ls = sb.createLineSymbolizer(color); |
741 |
|
// final Graphic h = sb.createGraphic(); |
742 |
final PointSymbolizer pts = sb.createPointSymbolizer(h); |
// h.setMarks(new Mark[] { sb.createMark("square", color) }); |
743 |
|
// |
744 |
// Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts}); |
// final PointSymbolizer pts = sb.createPointSymbolizer(h); |
745 |
switch (type) { |
// |
746 |
case POLYGON: |
// // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts}); |
747 |
s = sb.createStyle(ps); |
// switch (type) { |
748 |
|
// case POLYGON: |
749 |
break; |
// s = sb.createStyle(ps); |
750 |
|
// |
751 |
case POINT: |
// break; |
752 |
s = sb.createStyle(pts); |
// |
753 |
|
// case POINT: |
754 |
break; |
// s = sb.createStyle(pts); |
755 |
|
// |
756 |
case LINE: |
// break; |
757 |
s = sb.createStyle(ls); |
// |
758 |
} |
// case LINE: |
759 |
|
// s = sb.createStyle(ls); |
760 |
return s; |
// } |
761 |
} |
// |
762 |
|
// return s; |
763 |
|
// } |
764 |
|
|
765 |
public void propertyChange(final PropertyChangeEvent evt) { |
public void propertyChange(final PropertyChangeEvent evt) { |
766 |
final String prop = evt.getPropertyName(); |
final String prop = evt.getPropertyName(); |
844 |
public void mouseMoved(final MouseEvent e) { |
public void mouseMoved(final MouseEvent e) { |
845 |
} |
} |
846 |
|
|
|
|
|
|
|
|
847 |
// xulu.sn |
// xulu.sn |
848 |
/** |
/** |
849 |
* Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste |
* Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste |
862 |
if (env == null) |
if (env == null) |
863 |
return env; |
return env; |
864 |
|
|
865 |
|
Envelope newArea = null; |
866 |
|
|
867 |
/** |
/** |
868 |
* Correct the aspect Ratio before we check the rest. Otherwise we might |
* Correct the aspect Ratio before we check the rest. Otherwise we might |
869 |
* easily fail. |
* easily fail. We allow to grow here, because we don't check against the maxExtend |
870 |
*/ |
*/ |
871 |
env = fixAspectRatio(this.getBounds(), env); |
env = JTSUtil.fixAspectRatio(this.getBounds(), env, true); |
872 |
|
|
873 |
final double scale = env.getWidth() / getWidth(); |
final double scale = env.getWidth() / getWidth(); |
874 |
final double centerX = env.getMinX() + env.getWidth() / 2.; |
final double centerX = env.getMinX() + env.getWidth() / 2.; |
875 |
final double centerY = env.getMinY() + env.getHeight() / 2.; |
final double centerY = env.getMinY() + env.getHeight() / 2.; |
876 |
double newWidth2; |
double newWidth2 = 0; |
877 |
double newHeight2; |
double newHeight2 = 0; |
878 |
if (scale < getMaxZoomScale()) { |
if (scale < getMaxZoomScale()) { |
879 |
// **************************************************************************** |
// **************************************************************************** |
880 |
// Wir zoomen weiter rein als erlaubt => Anpassen des envelope |
// Wir zoomen weiter rein als erlaubt => Anpassen des envelope |
891 |
// **************************************************************************** |
// **************************************************************************** |
892 |
// Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen |
// Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen |
893 |
// **************************************************************************** |
// **************************************************************************** |
894 |
return env; |
newArea = env; |
895 |
|
} |
896 |
|
|
897 |
|
if (newArea == null) { |
898 |
|
|
899 |
|
final Coordinate ll = new Coordinate(centerX - newWidth2, centerY |
900 |
|
- newHeight2); |
901 |
|
final Coordinate ur = new Coordinate(centerX + newWidth2, centerY |
902 |
|
+ newHeight2); |
903 |
|
|
904 |
|
newArea = new Envelope(ll, ur); |
905 |
} |
} |
906 |
|
|
907 |
final Coordinate ll = new Coordinate(centerX - newWidth2, centerY |
Envelope maxAllowedExtend = getMaxExtend(); |
908 |
- newHeight2); |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) && newArea != null && !newArea.isNull() && !Double.isNaN(newArea.getMinX()) && !Double.isNaN(newArea.getMaxX()) && !Double.isNaN(newArea.getMinY()) && !Double.isNaN(newArea.getMaxY()) ) { |
909 |
final Coordinate ur = new Coordinate(centerX + newWidth2, centerY |
/* |
910 |
+ newHeight2); |
* If a maxExtend is set, we have to honour that... |
911 |
|
*/ |
912 |
|
|
913 |
|
// Exceeds top? Move down and maybe cut |
914 |
|
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
915 |
|
double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY(); |
916 |
|
// LOGGER.debug("Moving area down by " + divY); |
917 |
|
|
918 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
919 |
|
newArea.getMinY() - divY), new Coordinate(newArea |
920 |
|
.getMaxX(), newArea.getMaxY() - divY)); |
921 |
|
|
922 |
|
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
923 |
|
// LOGGER.debug("Now it exeeds the bottom border.. cut!"); |
924 |
|
// And cut the bottom if it moved out of the area |
925 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
926 |
|
maxAllowedExtend.getMinY()), new Coordinate(newArea |
927 |
|
.getMaxX(), newArea.getMaxY())); |
928 |
|
|
929 |
|
// LOGGER.debug("and fix aspect ratio"); |
930 |
|
|
931 |
|
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, false); |
932 |
|
} |
933 |
|
} |
934 |
|
|
935 |
|
// Exceeds bottom? Move up and maybe cut |
936 |
|
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
937 |
|
double divY = newArea.getMinY() - maxAllowedExtend.getMinY(); |
938 |
|
// LOGGER.debug("Moving area up by " + divY); |
939 |
|
|
940 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
941 |
|
newArea.getMinY() - divY), new Coordinate(newArea |
942 |
|
.getMaxX(), newArea.getMaxY() - divY)); |
943 |
|
|
944 |
|
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
945 |
|
// LOGGER.debug("Now it exeeds the top border.. cut!"); |
946 |
|
// And cut the bottom if it moved out of the area |
947 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
948 |
|
newArea.getMinY()), new Coordinate(newArea |
949 |
|
.getMaxX(), maxAllowedExtend.getMaxY())); |
950 |
|
|
951 |
|
// LOGGER.debug("and fix aspect ratio"); |
952 |
|
|
953 |
|
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, false); |
954 |
|
} |
955 |
|
} |
956 |
|
|
957 |
|
// Exceeds to the right? move and maybe cut |
958 |
|
if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) { |
959 |
|
|
960 |
|
// Move left.. |
961 |
|
double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX(); |
962 |
|
// LOGGER.debug("Moving area left by " + divX); |
963 |
|
|
964 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX() - divX, |
965 |
|
newArea.getMinY()), new Coordinate(newArea.getMaxX() |
966 |
|
- divX, newArea.getMaxY())); |
967 |
|
|
968 |
|
if (newArea.getMinX() < maxAllowedExtend.getMinX()) { |
969 |
|
// LOGGER.debug("Now it exeeds the left border.. cut!"); |
970 |
|
// And cut the left if it moved out of the area |
971 |
|
newArea = new Envelope(new Coordinate(maxAllowedExtend.getMinX(), |
972 |
|
newArea.getMinY()), new Coordinate(newArea |
973 |
|
.getMaxX(), newArea.getMaxY())); |
974 |
|
|
975 |
return new Envelope(ll, ur); |
// LOGGER.debug("and fix aspect ratio"); |
976 |
|
|
977 |
|
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, false); |
978 |
|
} |
979 |
|
} |
980 |
|
|
981 |
|
// Exceeds to the left? move and maybe cut |
982 |
|
if (newArea.getMinX() < maxAllowedExtend.getMinX()) { |
983 |
|
|
984 |
|
// Move right.. |
985 |
|
double divX = newArea.getMinX() - maxAllowedExtend.getMinX(); |
986 |
|
// LOGGER.debug("Moving area right by " + divX); |
987 |
|
|
988 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX() - divX, |
989 |
|
newArea.getMinY()), new Coordinate(newArea.getMaxX() |
990 |
|
- divX, newArea.getMaxY())); |
991 |
|
|
992 |
|
if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) { |
993 |
|
// LOGGER.debug("Now it exeeds the right border.. cut!"); |
994 |
|
// And cut the left if it moved out of the area |
995 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
996 |
|
newArea.getMinY()), new Coordinate(maxAllowedExtend |
997 |
|
.getMaxX(), newArea.getMaxY())); |
998 |
|
|
999 |
|
// LOGGER.debug("and fix aspect ratio"); |
1000 |
|
|
1001 |
|
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, false); |
1002 |
|
} |
1003 |
|
} |
1004 |
|
|
1005 |
|
} |
1006 |
|
|
1007 |
|
return newArea; |
1008 |
} |
} |
1009 |
|
|
1010 |
/** |
/** |
1037 |
* Krüger</a> |
* Krüger</a> |
1038 |
*/ |
*/ |
1039 |
public void setMaxZoomScale(final Double maxZoomScale) { |
public void setMaxZoomScale(final Double maxZoomScale) { |
|
// System.out.println("setting max scale to "+maxZoomScale); |
|
1040 |
this.maxZoomScale = maxZoomScale; |
this.maxZoomScale = maxZoomScale; |
1041 |
} |
} |
1042 |
|
|
1050 |
public void setMinZoomScale(final Double minZoomScale) { |
public void setMinZoomScale(final Double minZoomScale) { |
1051 |
this.minZoomScale = minZoomScale; |
this.minZoomScale = minZoomScale; |
1052 |
} |
} |
1053 |
// xulu.en |
|
1054 |
|
/** |
1055 |
|
* Defines an evelope of the viwable area. The JMapPane will never show |
1056 |
|
* anything outside of this extend. |
1057 |
|
* |
1058 |
|
* @param maxExtend |
1059 |
|
* <code>null</code> to not have this restriction. |
1060 |
|
*/ |
1061 |
|
public void setMaxExtend(Envelope maxExtend) { |
1062 |
|
this.maxExtend = maxExtend; |
1063 |
|
} |
1064 |
|
|
1065 |
|
/** |
1066 |
|
* Returns the evelope of the viewable area. The JMapPane will never show |
1067 |
|
* anything outside of this extend. If this has been set to |
1068 |
|
* <code>null</code> via {@link #setMaxExtend(Envelope)}, it tries to return |
1069 |
|
* quickly the context's bounds. It it takes to long to determine the |
1070 |
|
* context bounds, <code>null</code> is returned. |
1071 |
|
* |
1072 |
|
* @param maxExtend |
1073 |
|
* <code>null</code> to not have this restriction. |
1074 |
|
*/ |
1075 |
|
|
1076 |
|
public Envelope getMaxExtend() { |
1077 |
|
if (maxExtend == null) { |
1078 |
|
try { |
1079 |
|
return JTSUtil.fixAspectRatio( |
1080 |
|
this.getBounds(), |
1081 |
|
// Kartenbereich um 10% vergroessern |
1082 |
|
JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1), |
1083 |
|
true |
1084 |
|
); |
1085 |
|
} catch (IOException e) { |
1086 |
|
LOGGER.warn( |
1087 |
|
"maxExtend == null; failed to getLayerBounds of context", |
1088 |
|
e); |
1089 |
|
} |
1090 |
|
} |
1091 |
|
return maxExtend; |
1092 |
|
} |
1093 |
|
|
1094 |
} |
} |