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