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; |
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; |
85 |
|
|
86 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
87 |
|
|
88 |
|
import com.sun.jini.jeri.internal.runtime.SelectionManager; |
89 |
import com.vividsolutions.jts.geom.Coordinate; |
import com.vividsolutions.jts.geom.Coordinate; |
90 |
import com.vividsolutions.jts.geom.Envelope; |
import com.vividsolutions.jts.geom.Envelope; |
91 |
import com.vividsolutions.jts.geom.Geometry; |
import com.vividsolutions.jts.geom.Geometry; |
274 |
* @param context |
* @param context |
275 |
* - the map context to display |
* - the map context to display |
276 |
*/ |
*/ |
277 |
public JMapPane(GTRenderer render, MapContext context) { |
public JMapPane(final GTRenderer render, final MapContext context) { |
278 |
this(null, true, render, context); |
this(null, true, render, context); |
279 |
} |
} |
280 |
|
|
290 |
* @param context |
* @param context |
291 |
* - what to draw |
* - what to draw |
292 |
*/ |
*/ |
293 |
public JMapPane(LayoutManager layout, boolean isDoubleBuffered, |
public JMapPane(final LayoutManager layout, final boolean isDoubleBuffered, |
294 |
GTRenderer render, MapContext context) { |
final GTRenderer render, final MapContext context) { |
295 |
super(layout, isDoubleBuffered); |
super(layout, isDoubleBuffered); |
296 |
|
|
297 |
ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder |
ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder |
325 |
return renderer; |
return renderer; |
326 |
} |
} |
327 |
|
|
328 |
public void setRenderer(GTRenderer renderer) { |
public void setRenderer(final GTRenderer renderer) { |
329 |
Map hints = new HashMap(); |
Map hints = new HashMap(); |
330 |
if (renderer instanceof StreamingRenderer) { |
|
331 |
|
this.renderer = renderer; |
332 |
|
|
333 |
|
if (renderer instanceof StreamingRenderer || renderer instanceof TransitionShapefileRenderer) { |
334 |
hints = renderer.getRendererHints(); |
hints = renderer.getRendererHints(); |
335 |
if (hints == null) { |
if (hints == null) { |
336 |
hints = new HashMap(); |
hints = new HashMap(); |
341 |
} else { |
} else { |
342 |
hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache); |
hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache); |
343 |
} |
} |
344 |
|
|
345 |
|
hints.put("memoryPreloadingEnabled", Boolean.TRUE); |
346 |
|
|
347 |
renderer.setRendererHints(hints); |
renderer.setRendererHints(hints); |
348 |
} |
} |
349 |
|
|
|
this.renderer = renderer; |
|
350 |
// this.highlightRenderer = new StreamingRenderer(); |
// this.highlightRenderer = new StreamingRenderer(); |
351 |
// this.selectionRenderer = new StreamingRenderer(); |
// this.selectionRenderer = new StreamingRenderer(); |
352 |
|
|
|
hints.put("memoryPreloadingEnabled", Boolean.FALSE); |
|
353 |
// highlightRenderer.setRendererHints(hints); |
// highlightRenderer.setRendererHints(hints); |
354 |
// selectionRenderer.setRendererHints(hints); |
// selectionRenderer.setRendererHints(hints); |
355 |
|
|
356 |
|
// renderer.setRendererHints(hints); |
357 |
|
|
358 |
if (this.context != null) { |
if (this.context != null) { |
359 |
this.renderer.setContext(this.context); |
this.renderer.setContext(this.context); |
364 |
return context; |
return context; |
365 |
} |
} |
366 |
|
|
367 |
public void setContext(MapContext context) { |
public void setContext(final MapContext context) { |
368 |
if (this.context != null) { |
if (this.context != null) { |
369 |
this.context.removeMapLayerListListener(this); |
this.context.removeMapLayerListListener(this); |
370 |
} |
} |
384 |
return mapArea; |
return mapArea; |
385 |
} |
} |
386 |
|
|
387 |
public void setMapArea(Envelope mapArea) { |
public void setMapArea(final Envelope mapArea) { |
388 |
this.mapArea = mapArea; |
this.mapArea = mapArea; |
389 |
} |
} |
390 |
|
|
392 |
return state; |
return state; |
393 |
} |
} |
394 |
|
|
395 |
public void setState(int state) { |
public void setState(final int state) { |
396 |
this.state = state; |
this.state = state; |
397 |
|
|
398 |
// System.out.println("State: " + state); |
// System.out.println("State: " + state); |
402 |
return zoomFactor; |
return zoomFactor; |
403 |
} |
} |
404 |
|
|
405 |
public void setZoomFactor(double zoomFactor) { |
public void setZoomFactor(final double zoomFactor) { |
406 |
this.zoomFactor = zoomFactor; |
this.zoomFactor = zoomFactor; |
407 |
} |
} |
408 |
|
|
410 |
return selectionLayer; |
return selectionLayer; |
411 |
} |
} |
412 |
|
|
413 |
public void setSelectionLayer(MapLayer selectionLayer) { |
public void setSelectionLayer(final MapLayer selectionLayer) { |
414 |
this.selectionLayer = selectionLayer; |
this.selectionLayer = selectionLayer; |
415 |
if (selectionManager != null) { |
if (selectionManager != null) { |
416 |
selectionManager.setSelectionLayer(selectionLayer); |
selectionManager.setSelectionLayer(selectionLayer); |
421 |
return highlight; |
return highlight; |
422 |
} |
} |
423 |
|
|
424 |
public void setHighlight(boolean highlight) { |
public void setHighlight(final boolean highlight) { |
425 |
this.highlight = highlight; |
this.highlight = highlight; |
426 |
} |
} |
427 |
|
|
429 |
return highlightLayer; |
return highlightLayer; |
430 |
} |
} |
431 |
|
|
432 |
public void setHighlightLayer(MapLayer highlightLayer) { |
public void setHighlightLayer(final MapLayer highlightLayer) { |
433 |
this.highlightLayer = highlightLayer; |
this.highlightLayer = highlightLayer; |
434 |
|
|
435 |
if (highlightManager != null) { |
if (highlightManager != null) { |
441 |
return highlightManager; |
return highlightManager; |
442 |
} |
} |
443 |
|
|
444 |
public void setHighlightManager(HighlightManager highlightManager) { |
public void setHighlightManager(final HighlightManager highlightManager) { |
445 |
this.highlightManager = highlightManager; |
this.highlightManager = highlightManager; |
446 |
this.highlightManager.addHighlightChangeListener(this); |
this.highlightManager.addHighlightChangeListener(this); |
447 |
this.addMouseMotionListener(this.highlightManager); |
this.addMouseMotionListener(this.highlightManager); |
451 |
return lineHighlightStyle; |
return lineHighlightStyle; |
452 |
} |
} |
453 |
|
|
454 |
public void setLineHighlightStyle(Style lineHighlightStyle) { |
public void setLineHighlightStyle(final Style lineHighlightStyle) { |
455 |
this.lineHighlightStyle = lineHighlightStyle; |
this.lineHighlightStyle = lineHighlightStyle; |
456 |
} |
} |
457 |
|
|
459 |
return lineSelectionStyle; |
return lineSelectionStyle; |
460 |
} |
} |
461 |
|
|
462 |
public void setLineSelectionStyle(Style lineSelectionStyle) { |
public void setLineSelectionStyle(final Style lineSelectionStyle) { |
463 |
this.lineSelectionStyle = lineSelectionStyle; |
this.lineSelectionStyle = lineSelectionStyle; |
464 |
} |
} |
465 |
|
|
467 |
return pointHighlightStyle; |
return pointHighlightStyle; |
468 |
} |
} |
469 |
|
|
470 |
public void setPointHighlightStyle(Style pointHighlightStyle) { |
public void setPointHighlightStyle(final Style pointHighlightStyle) { |
471 |
this.pointHighlightStyle = pointHighlightStyle; |
this.pointHighlightStyle = pointHighlightStyle; |
472 |
} |
} |
473 |
|
|
475 |
return pointSelectionStyle; |
return pointSelectionStyle; |
476 |
} |
} |
477 |
|
|
478 |
public void setPointSelectionStyle(Style pointSelectionStyle) { |
public void setPointSelectionStyle(final Style pointSelectionStyle) { |
479 |
this.pointSelectionStyle = pointSelectionStyle; |
this.pointSelectionStyle = pointSelectionStyle; |
480 |
} |
} |
481 |
|
|
483 |
return polygonHighlightStyle; |
return polygonHighlightStyle; |
484 |
} |
} |
485 |
|
|
486 |
public void setPolygonHighlightStyle(Style polygonHighlightStyle) { |
public void setPolygonHighlightStyle(final Style polygonHighlightStyle) { |
487 |
this.polygonHighlightStyle = polygonHighlightStyle; |
this.polygonHighlightStyle = polygonHighlightStyle; |
488 |
} |
} |
489 |
|
|
491 |
return polygonSelectionStyle; |
return polygonSelectionStyle; |
492 |
} |
} |
493 |
|
|
494 |
public void setPolygonSelectionStyle(Style polygonSelectionStyle) { |
public void setPolygonSelectionStyle(final Style polygonSelectionStyle) { |
495 |
this.polygonSelectionStyle = polygonSelectionStyle; |
this.polygonSelectionStyle = polygonSelectionStyle; |
496 |
} |
} |
497 |
|
|
498 |
protected void paintComponent(Graphics g) { |
protected void paintComponent(final Graphics g) { |
499 |
super.paintComponent(g); |
super.paintComponent(g); |
500 |
|
|
501 |
if ((renderer == null) || (mapArea == null)) { |
if ((renderer == null) || (mapArea == null)) { |
502 |
return; |
return; |
503 |
} |
} |
504 |
|
|
505 |
Rectangle r = getBounds(); |
final Rectangle r = getBounds(); |
506 |
Rectangle dr = new Rectangle(r.width, r.height); |
final Rectangle dr = new Rectangle(r.width, r.height); |
507 |
|
|
508 |
if (!r.equals(oldRect) || reset) { |
if (!r.equals(oldRect) || reset) { |
509 |
if (!r.equals(oldRect) && (mapArea == null)) { |
if (!r.equals(oldRect) && (mapArea == null)) { |
510 |
try { |
try { |
511 |
mapArea = context.getLayerBounds(); |
mapArea = context.getLayerBounds(); |
512 |
} catch (IOException e) { |
} catch (final IOException e) { |
513 |
// TODO Auto-generated catch block |
// TODO Auto-generated catch block |
514 |
e.printStackTrace(); |
e.printStackTrace(); |
515 |
} |
} |
539 |
baseImage = new BufferedImage(dr.width, dr.height, |
baseImage = new BufferedImage(dr.width, dr.height, |
540 |
BufferedImage.TYPE_INT_ARGB); |
BufferedImage.TYPE_INT_ARGB); |
541 |
|
|
542 |
Graphics2D ig = baseImage.createGraphics(); |
final Graphics2D ig = baseImage.createGraphics(); |
543 |
/* System.out.println("rendering"); */ |
/* System.out.println("rendering"); */ |
544 |
renderer.setContext(context); |
if (renderer.getContext() != null) |
545 |
|
renderer.setContext(context); |
546 |
labelCache.clear(); // work around anoying labelcache bug |
labelCache.clear(); // work around anoying labelcache bug |
547 |
|
|
548 |
// draw the map |
// draw the map |
584 |
selectImage = new BufferedImage(dr.width, dr.height, |
selectImage = new BufferedImage(dr.width, dr.height, |
585 |
BufferedImage.TYPE_INT_ARGB); |
BufferedImage.TYPE_INT_ARGB); |
586 |
|
|
587 |
Graphics2D ig = selectImage.createGraphics(); |
final Graphics2D ig = selectImage.createGraphics(); |
588 |
/* System.out.println("rendering selection"); */ |
/* System.out.println("rendering selection"); */ |
589 |
selectionRenderer.paint((Graphics2D) ig, dr, mapArea); |
selectionRenderer.paint((Graphics2D) ig, dr, mapArea); |
590 |
|
|
614 |
highlightStyle = lineHighlightStyle; |
highlightStyle = lineHighlightStyle; |
615 |
} |
} |
616 |
|
|
617 |
MapContext highlightContext = new DefaultMapContext( |
final MapContext highlightContext = new DefaultMapContext( |
618 |
DefaultGeographicCRS.WGS84); |
DefaultGeographicCRS.WGS84); |
619 |
|
|
620 |
highlightContext.addLayer(highlightFeature, highlightStyle); |
highlightContext.addLayer(highlightFeature, highlightStyle); |
625 |
} |
} |
626 |
} |
} |
627 |
|
|
628 |
private Envelope fixAspectRatio(Rectangle r, Envelope mapArea) { |
private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea) { |
629 |
|
|
630 |
double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
final double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
631 |
double mapHeight = mapArea.getHeight(); |
final double mapHeight = mapArea.getHeight(); |
632 |
double scaleX = r.getWidth() / mapArea.getWidth(); /* |
final double scaleX = r.getWidth() / mapArea.getWidth(); /* |
633 |
* calculate the new |
* calculate the new |
634 |
* scale |
* scale |
635 |
*/ |
*/ |
636 |
|
|
637 |
double scaleY = r.getHeight() / mapArea.getHeight(); |
final double scaleY = r.getHeight() / mapArea.getHeight(); |
638 |
double scale = 1.0; // stupid compiler! |
double scale = 1.0; // stupid compiler! |
639 |
|
|
640 |
if (scaleX < scaleY) { /* pick the smaller scale */ |
if (scaleX < scaleY) { /* pick the smaller scale */ |
644 |
} |
} |
645 |
|
|
646 |
/* calculate the difference in width and height of the new extent */ |
/* calculate the difference in width and height of the new extent */ |
647 |
double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth); |
final double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth); |
648 |
double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight); |
final double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight); |
649 |
|
|
650 |
/* |
/* |
651 |
* System.out.println("delta x " + deltaX); |
* System.out.println("delta x " + deltaX); |
653 |
*/ |
*/ |
654 |
|
|
655 |
/* create the new extent */ |
/* create the new extent */ |
656 |
Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0), |
final Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0), |
657 |
mapArea.getMinY() - (deltaY / 2.0)); |
mapArea.getMinY() - (deltaY / 2.0)); |
658 |
Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0), |
final Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0), |
659 |
mapArea.getMaxY() + (deltaY / 2.0)); |
mapArea.getMaxY() + (deltaY / 2.0)); |
660 |
|
|
661 |
return new Envelope(ll, ur); |
return new Envelope(ll, ur); |
662 |
} |
} |
663 |
|
|
664 |
public void doSelection(double x, double y, MapLayer layer) { |
public void doSelection(final double x, final double y, final MapLayer layer) { |
665 |
|
|
666 |
Geometry geometry = gf.createPoint(new Coordinate(x, y)); |
final Geometry geometry = gf.createPoint(new Coordinate(x, y)); |
667 |
|
|
668 |
// org.opengis.geometry.Geometry geometry = new Point(); |
// org.opengis.geometry.Geometry geometry = new Point(); |
669 |
|
|
678 |
* - the index of the layer to search |
* - the index of the layer to search |
679 |
* @throws IndexOutOfBoundsException |
* @throws IndexOutOfBoundsException |
680 |
*/ |
*/ |
681 |
private void findFeature(Geometry geometry, MapLayer layer) |
private void findFeature(final Geometry geometry, final MapLayer layer) |
682 |
throws IndexOutOfBoundsException { |
throws IndexOutOfBoundsException { |
683 |
org.opengis.filter.spatial.BinarySpatialOperator f = null; |
org.opengis.filter.spatial.BinarySpatialOperator f = null; |
684 |
|
|
701 |
selectionManager.selectionChanged(this, f); |
selectionManager.selectionChanged(this, f); |
702 |
|
|
703 |
} |
} |
704 |
} catch (IllegalFilterException e) { |
} catch (final IllegalFilterException e) { |
705 |
// TODO Auto-generated catch block |
// TODO Auto-generated catch block |
706 |
e.printStackTrace(); |
e.printStackTrace(); |
707 |
} |
} |
726 |
*/ |
*/ |
727 |
|
|
728 |
/* |
/* |
729 |
* Iterator fi = fc.iterator(); while (fi.hasNext()) { Feature feat |
* Iterator fi = fc.iterator(); while (fi.hasNext()) { SimpleFeature feat |
730 |
* = (Feature) fi.next(); System.out.println("selected " + |
* = (SimpleFeature) fi.next(); System.out.println("selected " + |
731 |
* feat.getAttribute("STATE_NAME")); } |
* feat.getAttribute("STATE_NAME")); } |
732 |
*/ |
*/ |
733 |
} catch (IllegalFilterException e) { |
} catch (final IllegalFilterException e) { |
734 |
// TODO Auto-generated catch block |
// TODO Auto-generated catch block |
735 |
e.printStackTrace(); |
e.printStackTrace(); |
736 |
} |
} |
737 |
return; |
return; |
738 |
} |
} |
739 |
|
|
740 |
public void mouseClicked(MouseEvent e) { |
public void mouseClicked(final MouseEvent e) { |
741 |
if (mapArea == null) return; |
if (mapArea == null) return; |
742 |
// System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+" |
// System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+" |
743 |
// h:"+mapArea.getHeight()); |
// h:"+mapArea.getHeight()); |
744 |
Rectangle bounds = this.getBounds(); |
final Rectangle bounds = this.getBounds(); |
745 |
double x = (double) (e.getX()); |
final double x = (double) (e.getX()); |
746 |
double y = (double) (e.getY()); |
final double y = (double) (e.getY()); |
747 |
double width = mapArea.getWidth(); |
final double width = mapArea.getWidth(); |
748 |
double height = mapArea.getHeight(); |
final double height = mapArea.getHeight(); |
749 |
// xulu.sc |
// xulu.sc |
750 |
// double width2 = mapArea.getWidth() / 2.0; |
// double width2 = mapArea.getWidth() / 2.0; |
751 |
// double height2 = mapArea.getHeight() / 2.0; |
// double height2 = mapArea.getHeight() / 2.0; |
752 |
double width2 = width / 2.0; |
final double width2 = width / 2.0; |
753 |
double height2 = height / 2.0; |
final double height2 = height / 2.0; |
754 |
// xulu.ec |
// xulu.ec |
755 |
double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX(); |
final double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX(); |
756 |
double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height) |
final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height) |
757 |
+ mapArea.getMinY(); |
+ mapArea.getMinY(); |
758 |
|
|
759 |
/* |
/* |
793 |
return; |
return; |
794 |
} |
} |
795 |
|
|
796 |
Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY |
final Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY |
797 |
- (height2 / zlevel)); |
- (height2 / zlevel)); |
798 |
Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY |
final Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY |
799 |
+ (height2 / zlevel)); |
+ (height2 / zlevel)); |
800 |
// xulu.sc SK: Check for min/max scale |
// xulu.sc SK: Check for min/max scale |
801 |
// mapArea = new Envelope(ll, ur); |
// mapArea = new Envelope(ll, ur); |
810 |
repaint(); |
repaint(); |
811 |
} |
} |
812 |
|
|
813 |
public void mouseEntered(MouseEvent e) { |
public void mouseEntered(final MouseEvent e) { |
814 |
} |
} |
815 |
|
|
816 |
public void mouseExited(MouseEvent e) { |
public void mouseExited(final MouseEvent e) { |
817 |
} |
} |
818 |
|
|
819 |
public void mousePressed(MouseEvent e) { |
public void mousePressed(final MouseEvent e) { |
820 |
startX = e.getX(); |
startX = e.getX(); |
821 |
startY = e.getY(); |
startY = e.getY(); |
822 |
lastX = 0; |
lastX = 0; |
823 |
lastY = 0; |
lastY = 0; |
824 |
} |
} |
825 |
|
|
826 |
public void mouseReleased(MouseEvent e) { |
public void mouseReleased(final MouseEvent e) { |
827 |
int endX = e.getX(); |
final int endX = e.getX(); |
828 |
int endY = e.getY(); |
final int endY = e.getY(); |
829 |
|
|
830 |
processDrag(startX, startY, endX, endY, e); |
processDrag(startX, startY, endX, endY, e); |
831 |
lastX = 0; |
lastX = 0; |
837 |
panning_started = false; |
panning_started = false; |
838 |
} |
} |
839 |
|
|
840 |
public void mouseDragged(MouseEvent e) { |
public void mouseDragged(final MouseEvent e) { |
841 |
Graphics graphics = this.getGraphics(); |
final Graphics graphics = this.getGraphics(); |
842 |
int x = e.getX(); |
final int x = e.getX(); |
843 |
int y = e.getY(); |
final int y = e.getY(); |
844 |
|
|
845 |
if ((state == JMapPane.Pan) |
if ((state == JMapPane.Pan) |
846 |
|| ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
|| ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
854 |
|
|
855 |
// move the image with the mouse |
// move the image with the mouse |
856 |
if ((lastX > 0) && (lastY > 0)) { |
if ((lastX > 0) && (lastY > 0)) { |
857 |
int dx = lastX - startX; |
final int dx = lastX - startX; |
858 |
int dy = lastY - startY; |
final int dy = lastY - startY; |
859 |
// System.out.println("translate "+dx+","+dy); |
// System.out.println("translate "+dx+","+dy); |
860 |
final Graphics2D g2 = panningImage.createGraphics(); |
final Graphics2D g2 = panningImage.createGraphics(); |
861 |
g2.setBackground(new Color(240, 240, 240)); // TODO richtige |
g2.setBackground(new Color(240, 240, 240)); // TODO richtige |
888 |
} else if (state == JMapPane.Select && selectionLayer != null) { |
} else if (state == JMapPane.Select && selectionLayer != null) { |
889 |
|
|
890 |
// construct a new bbox filter |
// construct a new bbox filter |
891 |
Rectangle bounds = this.getBounds(); |
final Rectangle bounds = this.getBounds(); |
892 |
|
|
893 |
double mapWidth = mapArea.getWidth(); |
final double mapWidth = mapArea.getWidth(); |
894 |
double mapHeight = mapArea.getHeight(); |
final double mapHeight = mapArea.getHeight(); |
895 |
|
|
896 |
double x1 = ((this.startX * mapWidth) / (double) bounds.width) |
final double x1 = ((this.startX * mapWidth) / (double) bounds.width) |
897 |
+ mapArea.getMinX(); |
+ mapArea.getMinX(); |
898 |
double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height) |
final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height) |
899 |
+ mapArea.getMinY(); |
+ mapArea.getMinY(); |
900 |
double x2 = ((x * mapWidth) / (double) bounds.width) |
final double x2 = ((x * mapWidth) / (double) bounds.width) |
901 |
+ mapArea.getMinX(); |
+ mapArea.getMinX(); |
902 |
double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height) |
final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height) |
903 |
+ mapArea.getMinY(); |
+ mapArea.getMinY(); |
904 |
double left = Math.min(x1, x2); |
final double left = Math.min(x1, x2); |
905 |
double right = Math.max(x1, x2); |
final double right = Math.max(x1, x2); |
906 |
double bottom = Math.min(y1, y2); |
final double bottom = Math.min(y1, y2); |
907 |
double top = Math.max(y1, y2); |
final double top = Math.max(y1, y2); |
908 |
|
|
909 |
String name = selectionLayer.getFeatureSource().getSchema() |
String name = selectionLayer.getFeatureSource().getSchema() |
910 |
.getDefaultGeometry().getName(); |
.getDefaultGeometry().getName(); |
912 |
if (name == "") { |
if (name == "") { |
913 |
name = "the_geom"; |
name = "the_geom"; |
914 |
} |
} |
915 |
Filter bb = ff.bbox(ff.property(name), left, bottom, right, top, |
final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top, |
916 |
getContext().getCoordinateReferenceSystem().toString()); |
getContext().getCoordinateReferenceSystem().toString()); |
917 |
if (selectionManager != null) { |
if (selectionManager != null) { |
918 |
selectionManager.selectionChanged(this, bb); |
selectionManager.selectionChanged(this, bb); |
936 |
// private void processDrag(int x1, int y1, int x2, int y2) { |
// private void processDrag(int x1, int y1, int x2, int y2) { |
937 |
// sk.ce |
// sk.ce |
938 |
protected void processDrag(final int x1, final int y1, final int x2, |
protected void processDrag(final int x1, final int y1, final int x2, |
939 |
final int y2, MouseEvent e) { |
final int y2, final MouseEvent e) { |
940 |
|
|
941 |
/**** |
/**** |
942 |
* If no layer is availabe we dont want a NullPointerException |
* If no layer is availabe we dont want a NullPointerException |
955 |
return; |
return; |
956 |
} |
} |
957 |
|
|
958 |
Rectangle bounds = this.getBounds(); |
final Rectangle bounds = this.getBounds(); |
959 |
|
|
960 |
double mapWidth = mapArea.getWidth(); |
final double mapWidth = mapArea.getWidth(); |
961 |
double mapHeight = mapArea.getHeight(); |
final double mapHeight = mapArea.getHeight(); |
962 |
|
|
963 |
double startX = ((x1 * mapWidth) / (double) bounds.width) |
final double startX = ((x1 * mapWidth) / (double) bounds.width) |
964 |
+ mapArea.getMinX(); |
+ mapArea.getMinX(); |
965 |
double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height) |
final double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height) |
966 |
+ mapArea.getMinY(); |
+ mapArea.getMinY(); |
967 |
double endX = ((x2 * mapWidth) / (double) bounds.width) |
final double endX = ((x2 * mapWidth) / (double) bounds.width) |
968 |
+ mapArea.getMinX(); |
+ mapArea.getMinX(); |
969 |
double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height) |
final double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height) |
970 |
+ mapArea.getMinY(); |
+ mapArea.getMinY(); |
971 |
|
|
972 |
if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) { |
if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) { |
973 |
// move the image with the mouse |
// move the image with the mouse |
974 |
// calculate X offsets from start point to the end Point |
// calculate X offsets from start point to the end Point |
975 |
double deltaX1 = endX - startX; |
final double deltaX1 = endX - startX; |
976 |
|
|
977 |
// System.out.println("deltaX " + deltaX1); |
// System.out.println("deltaX " + deltaX1); |
978 |
// new edges |
// new edges |
979 |
double left = mapArea.getMinX() - deltaX1; |
final double left = mapArea.getMinX() - deltaX1; |
980 |
double right = mapArea.getMaxX() - deltaX1; |
final double right = mapArea.getMaxX() - deltaX1; |
981 |
|
|
982 |
// now for Y |
// now for Y |
983 |
double deltaY1 = endY - startY; |
final double deltaY1 = endY - startY; |
984 |
|
|
985 |
// System.out.println("deltaY " + deltaY1); |
// System.out.println("deltaY " + deltaY1); |
986 |
double bottom = mapArea.getMinY() - deltaY1; |
final double bottom = mapArea.getMinY() - deltaY1; |
987 |
double top = mapArea.getMaxY() - deltaY1; |
final double top = mapArea.getMaxY() - deltaY1; |
988 |
Coordinate ll = new Coordinate(left, bottom); |
final Coordinate ll = new Coordinate(left, bottom); |
989 |
Coordinate ur = new Coordinate(right, top); |
final Coordinate ur = new Coordinate(right, top); |
990 |
// xulu.sc |
// xulu.sc |
991 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
992 |
setMapArea(fixAspectRatio(this.getBounds(), new Envelope(ll, ur))); |
setMapArea(fixAspectRatio(this.getBounds(), new Envelope(ll, ur))); |
1001 |
|
|
1002 |
drawRectangle(this.getGraphics()); |
drawRectangle(this.getGraphics()); |
1003 |
// make the dragged rectangle (in map coords) the new BBOX |
// make the dragged rectangle (in map coords) the new BBOX |
1004 |
double left = Math.min(startX, endX); |
final double left = Math.min(startX, endX); |
1005 |
double right = Math.max(startX, endX); |
final double right = Math.max(startX, endX); |
1006 |
double bottom = Math.min(startY, endY); |
final double bottom = Math.min(startY, endY); |
1007 |
double top = Math.max(startY, endY); |
final double top = Math.max(startY, endY); |
1008 |
Coordinate ll = new Coordinate(left, bottom); |
final Coordinate ll = new Coordinate(left, bottom); |
1009 |
Coordinate ur = new Coordinate(right, top); |
final Coordinate ur = new Coordinate(right, top); |
1010 |
// xulu.sc |
// xulu.sc |
1011 |
|
|
1012 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
1030 |
drawRectangle(this.getGraphics()); |
drawRectangle(this.getGraphics()); |
1031 |
|
|
1032 |
// make the dragged rectangle in screen coords the new map size? |
// make the dragged rectangle in screen coords the new map size? |
1033 |
double left = Math.min(startX, endX); |
final double left = Math.min(startX, endX); |
1034 |
double right = Math.max(startX, endX); |
final double right = Math.max(startX, endX); |
1035 |
double bottom = Math.min(startY, endY); |
final double bottom = Math.min(startY, endY); |
1036 |
double top = Math.max(startY, endY); |
final double top = Math.max(startY, endY); |
1037 |
double nWidth = (mapWidth * mapWidth) / (right - left); |
final double nWidth = (mapWidth * mapWidth) / (right - left); |
1038 |
double nHeight = (mapHeight * mapHeight) / (top - bottom); |
final double nHeight = (mapHeight * mapHeight) / (top - bottom); |
1039 |
double deltaX1 = left - mapArea.getMinX(); |
final double deltaX1 = left - mapArea.getMinX(); |
1040 |
double nDeltaX1 = (deltaX1 * nWidth) / mapWidth; |
final double nDeltaX1 = (deltaX1 * nWidth) / mapWidth; |
1041 |
double deltaY1 = bottom - mapArea.getMinY(); |
final double deltaY1 = bottom - mapArea.getMinY(); |
1042 |
double nDeltaY1 = (deltaY1 * nHeight) / mapHeight; |
final double nDeltaY1 = (deltaY1 * nHeight) / mapHeight; |
1043 |
Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1, |
final Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1, |
1044 |
mapArea.getMinY() - nDeltaY1); |
mapArea.getMinY() - nDeltaY1); |
1045 |
double deltaX2 = mapArea.getMaxX() - right; |
final double deltaX2 = mapArea.getMaxX() - right; |
1046 |
double nDeltaX2 = (deltaX2 * nWidth) / mapWidth; |
final double nDeltaX2 = (deltaX2 * nWidth) / mapWidth; |
1047 |
double deltaY2 = mapArea.getMaxY() - top; |
final double deltaY2 = mapArea.getMaxY() - top; |
1048 |
double nDeltaY2 = (deltaY2 * nHeight) / mapHeight; |
final double nDeltaY2 = (deltaY2 * nHeight) / mapHeight; |
1049 |
Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2, |
final Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2, |
1050 |
mapArea.getMaxY() + nDeltaY2); |
mapArea.getMaxY() + nDeltaY2); |
1051 |
// xulu.sc |
// xulu.sc |
1052 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
1054 |
|
|
1055 |
// xulu.ec |
// xulu.ec |
1056 |
} else if (state == JMapPane.Select && selectionLayer != null) { |
} else if (state == JMapPane.Select && selectionLayer != null) { |
1057 |
double left = Math.min(startX, endX); |
final double left = Math.min(startX, endX); |
1058 |
double right = Math.max(startX, endX); |
final double right = Math.max(startX, endX); |
1059 |
double bottom = Math.min(startY, endY); |
final double bottom = Math.min(startY, endY); |
1060 |
double top = Math.max(startY, endY); |
final double top = Math.max(startY, endY); |
1061 |
|
|
1062 |
String name = selectionLayer.getFeatureSource().getSchema() |
String name = selectionLayer.getFeatureSource().getSchema() |
1063 |
.getDefaultGeometry().getLocalName(); |
.getDefaultGeometry().getLocalName(); |
1065 |
if (name == "") { |
if (name == "") { |
1066 |
name = "the_geom"; |
name = "the_geom"; |
1067 |
} |
} |
1068 |
Filter bb = ff.bbox(ff.property(name), left, bottom, right, top, |
final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top, |
1069 |
getContext().getCoordinateReferenceSystem().toString()); |
getContext().getCoordinateReferenceSystem().toString()); |
1070 |
// System.out.println(bb.toString()); |
// System.out.println(bb.toString()); |
1071 |
if (selectionManager != null) { |
if (selectionManager != null) { |
1088 |
return clickable; |
return clickable; |
1089 |
} |
} |
1090 |
|
|
1091 |
private org.geotools.styling.Style setupStyle(int type, Color color) { |
private org.geotools.styling.Style setupStyle(final int type, final Color color) { |
1092 |
StyleFactory sf = org.geotools.factory.CommonFactoryFinder |
final StyleFactory sf = org.geotools.factory.CommonFactoryFinder |
1093 |
.getStyleFactory(null); |
.getStyleFactory(null); |
1094 |
StyleBuilder sb = new StyleBuilder(); |
final StyleBuilder sb = new StyleBuilder(); |
1095 |
|
|
1096 |
org.geotools.styling.Style s = sf.createStyle(); |
org.geotools.styling.Style s = sf.createStyle(); |
1097 |
s.setTitle("selection"); |
s.setTitle("selection"); |
1098 |
|
|
1099 |
// TODO parameterise the color |
// TODO parameterise the color |
1100 |
PolygonSymbolizer ps = sb.createPolygonSymbolizer(color); |
final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color); |
1101 |
ps.setStroke(sb.createStroke(color)); |
ps.setStroke(sb.createStroke(color)); |
1102 |
|
|
1103 |
LineSymbolizer ls = sb.createLineSymbolizer(color); |
final LineSymbolizer ls = sb.createLineSymbolizer(color); |
1104 |
Graphic h = sb.createGraphic(); |
final Graphic h = sb.createGraphic(); |
1105 |
h.setMarks(new Mark[] { sb.createMark("square", color) }); |
h.setMarks(new Mark[] { sb.createMark("square", color) }); |
1106 |
|
|
1107 |
PointSymbolizer pts = sb.createPointSymbolizer(h); |
final PointSymbolizer pts = sb.createPointSymbolizer(h); |
1108 |
|
|
1109 |
// Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts}); |
// Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts}); |
1110 |
switch (type) { |
switch (type) { |
1125 |
return s; |
return s; |
1126 |
} |
} |
1127 |
|
|
1128 |
public void highlightChanged(HighlightChangedEvent e) { |
public void highlightChanged(final HighlightChangedEvent e) { |
1129 |
org.opengis.filter.Filter f = e.getFilter(); |
final org.opengis.filter.Filter f = e.getFilter(); |
1130 |
|
|
1131 |
try { |
try { |
1132 |
highlightFeature = highlightLayer.getFeatureSource().getFeatures(f); |
highlightFeature = highlightLayer.getFeatureSource().getFeatures(f); |
1133 |
} catch (IOException e1) { |
} catch (final IOException e1) { |
1134 |
// TODO Auto-generated catch block |
// TODO Auto-generated catch block |
1135 |
e1.printStackTrace(); |
e1.printStackTrace(); |
1136 |
} |
} |
1138 |
repaint(); |
repaint(); |
1139 |
} |
} |
1140 |
|
|
1141 |
public void propertyChange(PropertyChangeEvent evt) { |
public void propertyChange(final PropertyChangeEvent evt) { |
1142 |
String prop = evt.getPropertyName(); |
final String prop = evt.getPropertyName(); |
1143 |
|
|
1144 |
if (prop.equalsIgnoreCase("crs")) { |
if (prop.equalsIgnoreCase("crs")) { |
1145 |
context.setAreaOfInterest(context.getAreaOfInterest(), |
context.setAreaOfInterest(context.getAreaOfInterest(), |
1151 |
return reset; |
return reset; |
1152 |
} |
} |
1153 |
|
|
1154 |
public void setReset(boolean reset) { |
public void setReset(final boolean reset) { |
1155 |
this.reset = reset; |
this.reset = reset; |
1156 |
} |
} |
1157 |
|
|
1158 |
public void layerAdded(MapLayerListEvent event) { |
public void layerAdded(final MapLayerListEvent event) { |
1159 |
changed = true; |
changed = true; |
1160 |
|
|
1161 |
if (context.getLayers().length == 1) { // the first one |
if (context.getLayers().length == 1) { // the first one |
1167 |
if (mapArea == null) |
if (mapArea == null) |
1168 |
mapArea = context.getLayerBounds(); |
mapArea = context.getLayerBounds(); |
1169 |
// xulu.ec |
// xulu.ec |
1170 |
} catch (IOException e) { |
} catch (final IOException e) { |
1171 |
// TODO Auto-generated catch block |
// TODO Auto-generated catch block |
1172 |
e.printStackTrace(); |
e.printStackTrace(); |
1173 |
} |
} |
1178 |
repaint(); |
repaint(); |
1179 |
} |
} |
1180 |
|
|
1181 |
public void layerRemoved(MapLayerListEvent event) { |
public void layerRemoved(final MapLayerListEvent event) { |
1182 |
changed = true; |
changed = true; |
1183 |
repaint(); |
repaint(); |
1184 |
} |
} |
1185 |
|
|
1186 |
public void layerChanged(MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
1187 |
changed = true; |
changed = true; |
1188 |
// System.out.println("layer changed - repaint"); |
// System.out.println("layer changed - repaint"); |
1189 |
repaint(); |
repaint(); |
1190 |
} |
} |
1191 |
|
|
1192 |
public void layerMoved(MapLayerListEvent event) { |
public void layerMoved(final MapLayerListEvent event) { |
1193 |
changed = true; |
changed = true; |
1194 |
repaint(); |
repaint(); |
1195 |
} |
} |
1196 |
|
|
1197 |
protected void drawRectangle(Graphics graphics) { |
protected void drawRectangle(final Graphics graphics) { |
1198 |
// undraw last box/draw new box |
// undraw last box/draw new box |
1199 |
int left = Math.min(startX, lastX); |
final int left = Math.min(startX, lastX); |
1200 |
int right = Math.max(startX, lastX); |
final int right = Math.max(startX, lastX); |
1201 |
int top = Math.max(startY, lastY); |
final int top = Math.max(startY, lastY); |
1202 |
int bottom = Math.min(startY, lastY); |
final int bottom = Math.min(startY, lastY); |
1203 |
int width = right - left; |
final int width = right - left; |
1204 |
int height = top - bottom; |
final int height = top - bottom; |
1205 |
// System.out.println("drawing rect("+left+","+bottom+","+ width+","+ |
// System.out.println("drawing rect("+left+","+bottom+","+ width+","+ |
1206 |
// height+")"); |
// height+")"); |
1207 |
graphics.drawRect(left, bottom, width, height); |
graphics.drawRect(left, bottom, width, height); |
1213 |
* |
* |
1214 |
* @param clickable |
* @param clickable |
1215 |
*/ |
*/ |
1216 |
public void setClickable(boolean clickable) { |
public void setClickable(final boolean clickable) { |
1217 |
this.clickable = clickable; |
this.clickable = clickable; |
1218 |
} |
} |
1219 |
|
|
1220 |
public void mouseMoved(MouseEvent e) { |
public void mouseMoved(final MouseEvent e) { |
1221 |
} |
} |
1222 |
|
|
1223 |
public FeatureCollection getSelection() { |
public FeatureCollection getSelection() { |
1224 |
return selection; |
return selection; |
1225 |
} |
} |
1226 |
|
|
1227 |
public void setSelection(FeatureCollection selection) { |
public void setSelection(final FeatureCollection selection) { |
1228 |
this.selection = selection; |
this.selection = selection; |
1229 |
repaint(); |
repaint(); |
1230 |
} |
} |
1236 |
* org.geotools.gui.swing.event.SelectionChangeListener#selectionChanged |
* org.geotools.gui.swing.event.SelectionChangeListener#selectionChanged |
1237 |
* (org.geotools.gui.swing.event.SelectionChangedEvent) |
* (org.geotools.gui.swing.event.SelectionChangedEvent) |
1238 |
*/ |
*/ |
1239 |
public void selectionChanged(SelectionChangedEvent e) { |
public void selectionChanged(final SelectionChangedEvent e) { |
1240 |
|
|
1241 |
try { |
try { |
1242 |
selection = selectionLayer.getFeatureSource().getFeatures( |
selection = selectionLayer.getFeatureSource().getFeatures( |
1243 |
e.getFilter()); |
e.getFilter()); |
1244 |
repaint(); |
repaint(); |
1245 |
} catch (IOException e1) { |
} catch (final IOException e1) { |
1246 |
e1.printStackTrace(); |
e1.printStackTrace(); |
1247 |
} |
} |
1248 |
} |
} |
1251 |
return selectionManager; |
return selectionManager; |
1252 |
} |
} |
1253 |
|
|
1254 |
public void setSelectionManager(SelectionManager selectionManager) { |
public void setSelectionManager(final SelectionManager selectionManager) { |
1255 |
this.selectionManager = selectionManager; |
this.selectionManager = selectionManager; |
1256 |
this.selectionManager.addSelectionChangeListener(this); |
this.selectionManager.addSelectionChangeListener(this); |
1257 |
|
|
1281 |
*/ |
*/ |
1282 |
env = fixAspectRatio(this.getBounds(), env); |
env = fixAspectRatio(this.getBounds(), env); |
1283 |
|
|
1284 |
double scale = env.getWidth() / getWidth(); |
final double scale = env.getWidth() / getWidth(); |
1285 |
double centerX = env.getMinX() + env.getWidth() / 2.; |
final double centerX = env.getMinX() + env.getWidth() / 2.; |
1286 |
double centerY = env.getMinY() + env.getHeight() / 2.; |
final double centerY = env.getMinY() + env.getHeight() / 2.; |
1287 |
double newWidth2; |
double newWidth2; |
1288 |
double newHeight2; |
double newHeight2; |
1289 |
if (scale < getMaxZoomScale()) { |
if (scale < getMaxZoomScale()) { |
1305 |
return env; |
return env; |
1306 |
} |
} |
1307 |
|
|
1308 |
Coordinate ll = new Coordinate(centerX - newWidth2, centerY |
final Coordinate ll = new Coordinate(centerX - newWidth2, centerY |
1309 |
- newHeight2); |
- newHeight2); |
1310 |
Coordinate ur = new Coordinate(centerX + newWidth2, centerY |
final Coordinate ur = new Coordinate(centerX + newWidth2, centerY |
1311 |
+ newHeight2); |
+ newHeight2); |
1312 |
|
|
1313 |
return new Envelope(ll, ur); |
return new Envelope(ll, ur); |
1342 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
1343 |
* Krüger</a> |
* Krüger</a> |
1344 |
*/ |
*/ |
1345 |
public void setMaxZoomScale(Double maxZoomScale) { |
public void setMaxZoomScale(final Double maxZoomScale) { |
1346 |
// System.out.println("setting max scale to "+maxZoomScale); |
// System.out.println("setting max scale to "+maxZoomScale); |
1347 |
this.maxZoomScale = maxZoomScale; |
this.maxZoomScale = maxZoomScale; |
1348 |
} |
} |
1354 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
1355 |
* Krüger</a> |
* Krüger</a> |
1356 |
*/ |
*/ |
1357 |
public void setMinZoomScale(Double minZoomScale) { |
public void setMinZoomScale(final Double minZoomScale) { |
1358 |
this.minZoomScale = minZoomScale; |
this.minZoomScale = minZoomScale; |
1359 |
} |
} |
1360 |
// xulu.en |
// xulu.en |