[Schmitzm-commits] r144 - trunk/src/org/geotools/gui/swing
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Jun 15 20:29:49 CEST 2009
Author: alfonx
Date: 2009-06-15 20:29:49 +0200 (Mon, 15 Jun 2009)
New Revision: 144
Modified:
trunk/src/org/geotools/gui/swing/JMapPane.java
Log:
Plaing with a upscaled preview image that is shown while the map is rendered.. but its not fast enough yet ;-) .. all commented out
Modified: trunk/src/org/geotools/gui/swing/JMapPane.java
===================================================================
--- trunk/src/org/geotools/gui/swing/JMapPane.java 2009-06-15 17:45:02 UTC (rev 143)
+++ trunk/src/org/geotools/gui/swing/JMapPane.java 2009-06-15 18:29:49 UTC (rev 144)
@@ -43,6 +43,7 @@
import java.awt.Graphics2D;
import java.awt.LayoutManager;
import java.awt.Rectangle;
+import java.awt.RenderingHints;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
@@ -94,1152 +95,1165 @@
import com.vividsolutions.jts.geom.GeometryFactory;
public class JMapPane extends JPanel implements MouseListener,
- MouseMotionListener, HighlightChangeListener,SelectionChangeListener, PropertyChangeListener,
- MapLayerListListener {
- private static Logger LOGGER = Logger.getLogger( JMapPane.class.getName() );
- /**
+ MouseMotionListener, HighlightChangeListener, SelectionChangeListener,
+ PropertyChangeListener, MapLayerListListener {
+ private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName());
+ /**
*
*/
- private static final long serialVersionUID = -8647971481359690499L;
+ private static final long serialVersionUID = -8647971481359690499L;
- public static final int Reset = 0;
+ public static final int Reset = 0;
- public static final int ZoomIn = 1;
+ public static final int ZoomIn = 1;
- public static final int ZoomOut = 2;
+ public static final int ZoomOut = 2;
- public static final int Pan = 3;
+ public static final int Pan = 3;
- public static final int Select = 4;
+ public static final int Select = 4;
- private static final int POLYGON = 0;
+ private static final int POLYGON = 0;
- private static final int LINE = 1;
+ private static final int LINE = 1;
- private static final int POINT = 2;
+ private static final int POINT = 2;
- /**
- * what renders the map
- */
- GTRenderer renderer;
+ /**
+ * what renders the map
+ */
+ GTRenderer renderer;
- private GTRenderer highlightRenderer, selectionRenderer;
+ private GTRenderer highlightRenderer, selectionRenderer;
- /**
- * the map context to render
- */
- MapContext context;
+ /**
+ * the map context to render
+ */
+ MapContext context;
- private MapContext selectionContext;
+ private MapContext selectionContext;
- /**
- * the area of the map to draw
- */
-//xulu.sc
-// Envelope mapArea;
- protected Envelope mapArea;
-//xulu.ec
+ /**
+ * the area of the map to draw
+ */
+ // xulu.sc
+ // Envelope mapArea;
+ protected Envelope mapArea;
+ // xulu.ec
- /**
- * the size of the pane last time we drew
- */
-//xulu.sc
-// private Rectangle oldRect = null;
- protected Rectangle oldRect = null;
-//xulu.ec
+ /**
+ * the size of the pane last time we drew
+ */
+ // xulu.sc
+ // private Rectangle oldRect = null;
+ protected Rectangle oldRect = null;
+ // xulu.ec
- /**
- * the last map area drawn.
- */
-//xulu.sc
-// private Envelope oldMapArea = null;
- protected Envelope oldMapArea = null;
-//xulu.ec
+ /**
+ * the last map area drawn.
+ */
+ // xulu.sc
+ // private Envelope oldMapArea = null;
+ protected Envelope oldMapArea = null;
+ // xulu.ec
- /**
- * the base image of the map
- */
- protected BufferedImage baseImage, panningImage;
- // SK: private BufferedImage baseImage, panningImage;
+ /**
+ * the base image of the map
+ */
+ protected BufferedImage baseImage, panningImage;
+ // SK: private BufferedImage baseImage, panningImage;
- /**
- * image of selection
- */
- private BufferedImage selectImage;
+ /**
+ * image of selection
+ */
+ private BufferedImage selectImage;
- /**
- * style for selected items
- */
- private Style selectionStyle;
+ /**
+ * style for selected items
+ */
+ private Style selectionStyle;
- /**
- * layer that selection works on
- */
- private MapLayer selectionLayer;
+ /**
+ * layer that selection works on
+ */
+ private MapLayer selectionLayer;
- /**
- * layer that highlight works on
- */
- private MapLayer highlightLayer;
+ /**
+ * layer that highlight works on
+ */
+ private MapLayer highlightLayer;
- /**
- * the object which manages highlighting
- */
- private HighlightManager highlightManager;
+ /**
+ * the object which manages highlighting
+ */
+ private HighlightManager highlightManager;
- /**
- * is highlighting on or off
- */
- private boolean highlight = true;
+ /**
+ * is highlighting on or off
+ */
+ private boolean highlight = true;
- /**
- * a factory for filters
- */
- FilterFactory2 ff;
+ /**
+ * a factory for filters
+ */
+ FilterFactory2 ff;
- /**
- * a factory for geometries
- */
- GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null);
+ /**
+ * a factory for geometries
+ */
+ GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null);
- /**
- * the collections of features to be selected or highlighted
- */
- FeatureCollection selection;
+ /**
+ * the collections of features to be selected or highlighted
+ */
+ FeatureCollection selection;
- /**
- * the collections of features to be selected or highlighted
- */
- FeatureCollection highlightFeature;
+ /**
+ * the collections of features to be selected or highlighted
+ */
+ FeatureCollection highlightFeature;
- private int state = ZoomIn;
+ private int state = ZoomIn;
- /**
- * how far to zoom in or out
- */
- private double zoomFactor = 2.0;
+ /**
+ * how far to zoom in or out
+ */
+ private double zoomFactor = 2.0;
- Style lineHighlightStyle;
+ Style lineHighlightStyle;
- Style pointHighlightStyle;
+ Style pointHighlightStyle;
- Style polygonHighlightStyle;
+ Style polygonHighlightStyle;
- Style polygonSelectionStyle;
+ Style polygonSelectionStyle;
- Style pointSelectionStyle;
+ Style pointSelectionStyle;
- Style lineSelectionStyle;
+ Style lineSelectionStyle;
- boolean changed = true;
+ boolean changed = true;
- LabelCache labelCache = new LabelCacheDefault();
+ LabelCache labelCache = new LabelCacheDefault();
-//xulu.sc
-// private boolean reset = false;
- protected boolean reset = false;
-//xulu.ec
+ // xulu.sc
+ // private boolean reset = false;
+ protected boolean reset = false;
+ // xulu.ec
- int startX;
+ int startX;
- int startY;
+ int startY;
- private boolean clickable;
+ private boolean clickable;
- int lastX;
+ int lastX;
- int lastY;
+ int lastY;
- private SelectionManager selectionManager;
-//xulu.sn
- private Double maxZoomScale = Double.MIN_VALUE;
- private Double minZoomScale = Double.MAX_VALUE;
-//xulu.en
+ private SelectionManager selectionManager;
+ // xulu.sn
+ private Double maxZoomScale = Double.MIN_VALUE;
+ private Double minZoomScale = Double.MAX_VALUE;
+ // xulu.en
-// sk.sn
- /**
- * Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu setzen.
- */
+ // sk.sn
+ /**
+ * Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses
+ * Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu
+ * setzen.
+ */
private boolean panning_started = false;
-// sk.en
- public JMapPane() {
- this(null, true, null, null);
- }
+ // sk.en
- /**
- * create a basic JMapPane
- *
- * @param render -
- * how to draw the map
- * @param context -
- * the map context to display
- */
- public JMapPane(GTRenderer render, MapContext context) {
- this(null, true, render, context);
- }
+ public JMapPane() {
+ this(null, true, null, null);
+ }
- /**
- * full constructor extending JPanel
- *
- * @param layout -
- * layout (probably shouldn't be set)
- * @param isDoubleBuffered -
- * a Swing thing I don't really understand
- * @param render -
- * what to draw the map with
- * @param context -
- * what to draw
- */
- public JMapPane(LayoutManager layout, boolean isDoubleBuffered,
- GTRenderer render, MapContext context) {
- super(layout, isDoubleBuffered);
+ /**
+ * create a basic JMapPane
+ *
+ * @param render
+ * - how to draw the map
+ * @param context
+ * - the map context to display
+ */
+ public JMapPane(GTRenderer render, MapContext context) {
+ this(null, true, render, context);
+ }
- ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder
- .getFilterFactory(null);
- setRenderer(render);
+ /**
+ * full constructor extending JPanel
+ *
+ * @param layout
+ * - layout (probably shouldn't be set)
+ * @param isDoubleBuffered
+ * - a Swing thing I don't really understand
+ * @param render
+ * - what to draw the map with
+ * @param context
+ * - what to draw
+ */
+ public JMapPane(LayoutManager layout, boolean isDoubleBuffered,
+ GTRenderer render, MapContext context) {
+ super(layout, isDoubleBuffered);
- setContext(context);
+ ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder
+ .getFilterFactory(null);
+ setRenderer(render);
- this.addMouseListener(this);
- this.addMouseMotionListener(this);
- setHighlightManager(new HighlightManager(highlightLayer));
- setSelectionManager(new SelectionManager(selectionLayer));
- lineHighlightStyle = setupStyle(LINE, Color.red);
+ setContext(context);
- pointHighlightStyle = setupStyle(POINT, Color.red);
+ this.addMouseListener(this);
+ this.addMouseMotionListener(this);
+ setHighlightManager(new HighlightManager(highlightLayer));
+ setSelectionManager(new SelectionManager(selectionLayer));
+ lineHighlightStyle = setupStyle(LINE, Color.red);
- polygonHighlightStyle = setupStyle(POLYGON, Color.red);
+ pointHighlightStyle = setupStyle(POINT, Color.red);
- polygonSelectionStyle = setupStyle(POLYGON, Color.cyan);
+ polygonHighlightStyle = setupStyle(POLYGON, Color.red);
- pointSelectionStyle = setupStyle(POINT, Color.cyan);
+ polygonSelectionStyle = setupStyle(POLYGON, Color.cyan);
- lineSelectionStyle = setupStyle(LINE, Color.cyan);
- setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
- }
+ pointSelectionStyle = setupStyle(POINT, Color.cyan);
- /**
- * get the renderer
- */
- public GTRenderer getRenderer() {
- return renderer;
- }
+ lineSelectionStyle = setupStyle(LINE, Color.cyan);
+ setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
+ }
- public void setRenderer(GTRenderer renderer) {
- Map hints = new HashMap();
- if (renderer instanceof StreamingRenderer) {
- hints = renderer.getRendererHints();
- if (hints == null) {
- hints = new HashMap();
- }
- if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {
- labelCache = (LabelCache) hints
- .get(StreamingRenderer.LABEL_CACHE_KEY);
- } else {
- hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
- }
- renderer.setRendererHints(hints);
- }
+ /**
+ * get the renderer
+ */
+ public GTRenderer getRenderer() {
+ return renderer;
+ }
- this.renderer = renderer;
- this.highlightRenderer = new StreamingRenderer();
- this.selectionRenderer = new StreamingRenderer();
+ public void setRenderer(GTRenderer renderer) {
+ Map hints = new HashMap();
+ if (renderer instanceof StreamingRenderer) {
+ hints = renderer.getRendererHints();
+ if (hints == null) {
+ hints = new HashMap();
+ }
+ if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) {
+ labelCache = (LabelCache) hints
+ .get(StreamingRenderer.LABEL_CACHE_KEY);
+ } else {
+ hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
+ }
+ renderer.setRendererHints(hints);
+ }
- hints.put("memoryPreloadingEnabled", Boolean.FALSE);
- highlightRenderer.setRendererHints(hints);
- selectionRenderer.setRendererHints(hints);
+ this.renderer = renderer;
+ this.highlightRenderer = new StreamingRenderer();
+ this.selectionRenderer = new StreamingRenderer();
- if (this.context != null) {
- this.renderer.setContext(this.context);
- }
- }
+ hints.put("memoryPreloadingEnabled", Boolean.FALSE);
+ highlightRenderer.setRendererHints(hints);
+ selectionRenderer.setRendererHints(hints);
- public MapContext getContext() {
- return context;
- }
+ if (this.context != null) {
+ this.renderer.setContext(this.context);
+ }
+ }
- public void setContext(MapContext context) {
- if (this.context != null) {
- this.context.removeMapLayerListListener(this);
- }
+ public MapContext getContext() {
+ return context;
+ }
- this.context = context;
+ public void setContext(MapContext context) {
+ if (this.context != null) {
+ this.context.removeMapLayerListListener(this);
+ }
- if (context != null) {
- this.context.addMapLayerListListener(this);
- }
+ this.context = context;
- if (renderer != null) {
- renderer.setContext(this.context);
- }
- }
+ if (context != null) {
+ this.context.addMapLayerListListener(this);
+ }
- public Envelope getMapArea() {
- return mapArea;
- }
+ if (renderer != null) {
+ renderer.setContext(this.context);
+ }
+ }
- public void setMapArea(Envelope mapArea) {
- this.mapArea = mapArea;
- }
+ public Envelope getMapArea() {
+ return mapArea;
+ }
- public int getState() {
- return state;
- }
+ public void setMapArea(Envelope mapArea) {
+ this.mapArea = mapArea;
+ }
- public void setState(int state) {
- this.state = state;
+ public int getState() {
+ return state;
+ }
- // System.out.println("State: " + state);
- }
+ public void setState(int state) {
+ this.state = state;
- public double getZoomFactor() {
- return zoomFactor;
- }
+ // System.out.println("State: " + state);
+ }
- public void setZoomFactor(double zoomFactor) {
- this.zoomFactor = zoomFactor;
- }
+ public double getZoomFactor() {
+ return zoomFactor;
+ }
- public MapLayer getSelectionLayer() {
- return selectionLayer;
- }
+ public void setZoomFactor(double zoomFactor) {
+ this.zoomFactor = zoomFactor;
+ }
- public void setSelectionLayer(MapLayer selectionLayer) {
- this.selectionLayer = selectionLayer;
- if(selectionManager!=null) {
- selectionManager.setSelectionLayer(selectionLayer);
- }
- }
+ public MapLayer getSelectionLayer() {
+ return selectionLayer;
+ }
- public boolean isHighlight() {
- return highlight;
- }
+ public void setSelectionLayer(MapLayer selectionLayer) {
+ this.selectionLayer = selectionLayer;
+ if (selectionManager != null) {
+ selectionManager.setSelectionLayer(selectionLayer);
+ }
+ }
- public void setHighlight(boolean highlight) {
- this.highlight = highlight;
- }
+ public boolean isHighlight() {
+ return highlight;
+ }
- public MapLayer getHighlightLayer() {
- return highlightLayer;
- }
+ public void setHighlight(boolean highlight) {
+ this.highlight = highlight;
+ }
- public void setHighlightLayer(MapLayer highlightLayer) {
- this.highlightLayer = highlightLayer;
+ public MapLayer getHighlightLayer() {
+ return highlightLayer;
+ }
- if (highlightManager != null) {
- highlightManager.setHighlightLayer(highlightLayer);
- }
- }
+ public void setHighlightLayer(MapLayer highlightLayer) {
+ this.highlightLayer = highlightLayer;
- public HighlightManager getHighlightManager() {
- return highlightManager;
- }
+ if (highlightManager != null) {
+ highlightManager.setHighlightLayer(highlightLayer);
+ }
+ }
- public void setHighlightManager(HighlightManager highlightManager) {
- this.highlightManager = highlightManager;
- this.highlightManager.addHighlightChangeListener(this);
- this.addMouseMotionListener(this.highlightManager);
- }
+ public HighlightManager getHighlightManager() {
+ return highlightManager;
+ }
- public Style getLineHighlightStyle() {
- return lineHighlightStyle;
- }
+ public void setHighlightManager(HighlightManager highlightManager) {
+ this.highlightManager = highlightManager;
+ this.highlightManager.addHighlightChangeListener(this);
+ this.addMouseMotionListener(this.highlightManager);
+ }
- public void setLineHighlightStyle(Style lineHighlightStyle) {
- this.lineHighlightStyle = lineHighlightStyle;
- }
+ public Style getLineHighlightStyle() {
+ return lineHighlightStyle;
+ }
- public Style getLineSelectionStyle() {
- return lineSelectionStyle;
- }
+ public void setLineHighlightStyle(Style lineHighlightStyle) {
+ this.lineHighlightStyle = lineHighlightStyle;
+ }
- public void setLineSelectionStyle(Style lineSelectionStyle) {
- this.lineSelectionStyle = lineSelectionStyle;
- }
+ public Style getLineSelectionStyle() {
+ return lineSelectionStyle;
+ }
- public Style getPointHighlightStyle() {
- return pointHighlightStyle;
- }
+ public void setLineSelectionStyle(Style lineSelectionStyle) {
+ this.lineSelectionStyle = lineSelectionStyle;
+ }
- public void setPointHighlightStyle(Style pointHighlightStyle) {
- this.pointHighlightStyle = pointHighlightStyle;
- }
+ public Style getPointHighlightStyle() {
+ return pointHighlightStyle;
+ }
- public Style getPointSelectionStyle() {
- return pointSelectionStyle;
- }
+ public void setPointHighlightStyle(Style pointHighlightStyle) {
+ this.pointHighlightStyle = pointHighlightStyle;
+ }
- public void setPointSelectionStyle(Style pointSelectionStyle) {
- this.pointSelectionStyle = pointSelectionStyle;
- }
+ public Style getPointSelectionStyle() {
+ return pointSelectionStyle;
+ }
- public Style getPolygonHighlightStyle() {
- return polygonHighlightStyle;
- }
+ public void setPointSelectionStyle(Style pointSelectionStyle) {
+ this.pointSelectionStyle = pointSelectionStyle;
+ }
- public void setPolygonHighlightStyle(Style polygonHighlightStyle) {
- this.polygonHighlightStyle = polygonHighlightStyle;
- }
+ public Style getPolygonHighlightStyle() {
+ return polygonHighlightStyle;
+ }
- public Style getPolygonSelectionStyle() {
- return polygonSelectionStyle;
- }
+ public void setPolygonHighlightStyle(Style polygonHighlightStyle) {
+ this.polygonHighlightStyle = polygonHighlightStyle;
+ }
- public void setPolygonSelectionStyle(Style polygonSelectionStyle) {
- this.polygonSelectionStyle = polygonSelectionStyle;
- }
+ public Style getPolygonSelectionStyle() {
+ return polygonSelectionStyle;
+ }
- protected void paintComponent(Graphics g) {
- super.paintComponent(g);
+ public void setPolygonSelectionStyle(Style polygonSelectionStyle) {
+ this.polygonSelectionStyle = polygonSelectionStyle;
+ }
- if ((renderer == null) || (mapArea == null) ) {
- return;
- }
+ protected void paintComponent(Graphics g) {
+ super.paintComponent(g);
- Rectangle r = getBounds();
- Rectangle dr = new Rectangle(r.width, r.height);
+ if ((renderer == null) || (mapArea == null)) {
+ return;
+ }
- if (!r.equals(oldRect) || reset) {
- if(!r.equals(oldRect) && (mapArea == null)) {
- try {
- mapArea=context.getLayerBounds();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- if (mapArea != null){
- /* either the viewer size has changed or we've done a reset */
- changed = true; /* note we need to redraw */
- reset = false; /* forget about the reset */
- oldRect = r; /* store what the current size is */
-
- mapArea = fixAspectRatio(r, mapArea);
- }
- }
+ Rectangle r = getBounds();
+ Rectangle dr = new Rectangle(r.width, r.height);
- if (!mapArea.equals(oldMapArea)) { /* did the map extent change? */
- changed = true;
- oldMapArea = mapArea;
-// when we tell the context that the bounds have changed WMSLayers
- // can refresh them selves
- context.setAreaOfInterest(mapArea, context
- .getCoordinateReferenceSystem());
- }
+ if (!r.equals(oldRect) || reset) {
+ if (!r.equals(oldRect) && (mapArea == null)) {
+ try {
+ mapArea = context.getLayerBounds();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
- if (changed) { /* if the map changed then redraw */
- changed = false;
- baseImage = new BufferedImage(dr.width, dr.height,
- BufferedImage.TYPE_INT_ARGB);
+ if (mapArea != null) {
+ /* either the viewer size has changed or we've done a reset */
+ changed = true; /* note we need to redraw */
+ reset = false; /* forget about the reset */
+ oldRect = r; /* store what the current size is */
- Graphics2D ig = baseImage.createGraphics();
- /* System.out.println("rendering"); */
- renderer.setContext(context);
- labelCache.clear(); // work around anoying labelcache bug
+ mapArea = fixAspectRatio(r, mapArea);
+ }
+ }
+ if (!mapArea.equals(oldMapArea)) { /* did the map extent change? */
+ changed = true;
+ oldMapArea = mapArea;
+ // when we tell the context that the bounds have changed WMSLayers
+ // can refresh them selves
+ context.setAreaOfInterest(mapArea, context
+ .getCoordinateReferenceSystem());
+ }
- // draw the map
- renderer.paint((Graphics2D) ig, dr, mapArea);
+ if (changed) { /* if the map changed then redraw */
+ changed = false;
+ baseImage = new BufferedImage(dr.width, dr.height,
+ BufferedImage.TYPE_INT_ARGB);
- // TODO , nur machen, wenn panning beginnt
- panningImage = new BufferedImage(dr.width, dr.height,
- BufferedImage.TYPE_INT_RGB);
-
- }
+ Graphics2D ig = baseImage.createGraphics();
+ /* System.out.println("rendering"); */
+ renderer.setContext(context);
+ labelCache.clear(); // work around anoying labelcache bug
- ((Graphics2D) g).drawImage(baseImage, 0, 0, this);
+ // draw the map
+ renderer.paint((Graphics2D) ig, dr, mapArea);
- if ((selection != null) && (selection.size() > 0)) {
- // paint selection
+ // TODO , nur machen, wenn panning beginnt
+ panningImage = new BufferedImage(dr.width, dr.height,
+ BufferedImage.TYPE_INT_RGB);
- String type = selectionLayer.getFeatureSource().getSchema()
- .getDefaultGeometry().getType().getName();
- /*String type = selection.getDefaultGeometry().getGeometryType();*/
- /*System.out.println(type);*/
- if (type == null)
- type = "polygon";
+ }
- /* String type = "point"; */
+ ((Graphics2D) g).drawImage(baseImage, 0, 0, this);
- if (type.toLowerCase().endsWith("polygon")) {
- selectionStyle = polygonSelectionStyle;
- } else if (type.toLowerCase().endsWith("point")) {
- selectionStyle = pointSelectionStyle;
- } else if (type.toLowerCase().endsWith("line")) {
- selectionStyle = lineSelectionStyle;
- }
+ if ((selection != null) && (selection.size() > 0)) {
+ // paint selection
- selectionContext = new DefaultMapContext(DefaultGeographicCRS.WGS84);
+ String type = selectionLayer.getFeatureSource().getSchema()
+ .getDefaultGeometry().getType().getName();
+ /* String type = selection.getDefaultGeometry().getGeometryType(); */
+ /* System.out.println(type); */
+ if (type == null)
+ type = "polygon";
- selectionContext.addLayer(selection, selectionStyle);
- selectionRenderer.setContext(selectionContext);
+ /* String type = "point"; */
- selectImage = new BufferedImage(dr.width, dr.height,
- BufferedImage.TYPE_INT_ARGB);
+ if (type.toLowerCase().endsWith("polygon")) {
+ selectionStyle = polygonSelectionStyle;
+ } else if (type.toLowerCase().endsWith("point")) {
+ selectionStyle = pointSelectionStyle;
+ } else if (type.toLowerCase().endsWith("line")) {
+ selectionStyle = lineSelectionStyle;
+ }
- Graphics2D ig = selectImage.createGraphics();
- /* System.out.println("rendering selection"); */
- selectionRenderer.paint((Graphics2D) ig, dr, mapArea);
+ selectionContext = new DefaultMapContext(DefaultGeographicCRS.WGS84);
- ((Graphics2D) g).drawImage(selectImage, 0, 0, this);
- }
+ selectionContext.addLayer(selection, selectionStyle);
+ selectionRenderer.setContext(selectionContext);
- if (highlight && (highlightFeature != null)
- && (highlightFeature.size() > 0)) {
- /*
- * String type = selection.getDefaultGeometry().getGeometryType();
- * System.out.println(type); if(type==null) type="polygon";
- */
- String type = highlightLayer.getFeatureSource().getSchema()
- .getDefaultGeometry().getType().getName();
- /*String type = selection.getDefaultGeometry().getGeometryType();*/
- //System.out.println(type);
- if (type == null)
- type = "polygon";
+ selectImage = new BufferedImage(dr.width, dr.height,
+ BufferedImage.TYPE_INT_ARGB);
- /* String type = "point"; */
- Style highlightStyle = null;
- if (type.toLowerCase().endsWith("polygon")) {
- highlightStyle = polygonHighlightStyle;
- } else if (type.toLowerCase().endsWith("point")) {
- highlightStyle = pointHighlightStyle;
- } else if (type.toLowerCase().endsWith("line")) {
- highlightStyle = lineHighlightStyle;
- }
+ Graphics2D ig = selectImage.createGraphics();
+ /* System.out.println("rendering selection"); */
+ selectionRenderer.paint((Graphics2D) ig, dr, mapArea);
+ ((Graphics2D) g).drawImage(selectImage, 0, 0, this);
+ }
+ if (highlight && (highlightFeature != null)
+ && (highlightFeature.size() > 0)) {
+ /*
+ * String type = selection.getDefaultGeometry().getGeometryType();
+ * System.out.println(type); if(type==null) type="polygon";
+ */
+ String type = highlightLayer.getFeatureSource().getSchema()
+ .getDefaultGeometry().getType().getName();
+ /* String type = selection.getDefaultGeometry().getGeometryType(); */
+ // System.out.println(type);
+ if (type == null)
+ type = "polygon";
+ /* String type = "point"; */
+ Style highlightStyle = null;
+ if (type.toLowerCase().endsWith("polygon")) {
+ highlightStyle = polygonHighlightStyle;
+ } else if (type.toLowerCase().endsWith("point")) {
+ highlightStyle = pointHighlightStyle;
+ } else if (type.toLowerCase().endsWith("line")) {
+ highlightStyle = lineHighlightStyle;
+ }
- MapContext highlightContext = new DefaultMapContext(
- DefaultGeographicCRS.WGS84);
+ MapContext highlightContext = new DefaultMapContext(
+ DefaultGeographicCRS.WGS84);
- highlightContext.addLayer(highlightFeature, highlightStyle);
- highlightRenderer.setContext(highlightContext);
+ highlightContext.addLayer(highlightFeature, highlightStyle);
+ highlightRenderer.setContext(highlightContext);
- /* System.out.println("rendering highlight"); */
- highlightRenderer.paint((Graphics2D) g, dr, mapArea);
- }
- }
+ /* System.out.println("rendering highlight"); */
+ highlightRenderer.paint((Graphics2D) g, dr, mapArea);
+ }
+ }
- private Envelope fixAspectRatio(Rectangle r, Envelope mapArea) {
-
- double mapWidth = mapArea.getWidth(); /* get the extent of the map */
- double mapHeight = mapArea.getHeight();
- double scaleX = r.getWidth() / mapArea.getWidth(); /*
- * calculate the new
- * scale
- */
+ private Envelope fixAspectRatio(Rectangle r, Envelope mapArea) {
- double scaleY = r.getHeight() / mapArea.getHeight();
- double scale = 1.0; // stupid compiler!
+ double mapWidth = mapArea.getWidth(); /* get the extent of the map */
+ double mapHeight = mapArea.getHeight();
+ double scaleX = r.getWidth() / mapArea.getWidth(); /*
+ * calculate the new
+ * scale
+ */
- if (scaleX < scaleY) { /* pick the smaller scale */
- scale = scaleX;
- } else {
- scale = scaleY;
- }
+ double scaleY = r.getHeight() / mapArea.getHeight();
+ double scale = 1.0; // stupid compiler!
- /* calculate the difference in width and height of the new extent */
- double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth);
- double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight);
+ if (scaleX < scaleY) { /* pick the smaller scale */
+ scale = scaleX;
+ } else {
+ scale = scaleY;
+ }
- /*
- * System.out.println("delta x " + deltaX); System.out.println("delta y " +
- * deltaY);
- */
+ /* calculate the difference in width and height of the new extent */
+ double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth);
+ double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight);
- /* create the new extent */
- Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0),
- mapArea.getMinY() - (deltaY / 2.0));
- Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0),
- mapArea.getMaxY() + (deltaY / 2.0));
+ /*
+ * System.out.println("delta x " + deltaX);
+ * System.out.println("delta y " + deltaY);
+ */
- return new Envelope(ll, ur);
- }
+ /* create the new extent */
+ Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0),
+ mapArea.getMinY() - (deltaY / 2.0));
+ Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0),
+ mapArea.getMaxY() + (deltaY / 2.0));
- public void doSelection(double x, double y, MapLayer layer) {
+ return new Envelope(ll, ur);
+ }
- Geometry geometry = gf.createPoint(new Coordinate(x, y));
+ public void doSelection(double x, double y, MapLayer layer) {
- // org.opengis.geometry.Geometry geometry = new Point();
+ Geometry geometry = gf.createPoint(new Coordinate(x, y));
- findFeature(geometry, layer);
+ // 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(Geometry geometry, MapLayer layer)
- throws IndexOutOfBoundsException {
- org.opengis.filter.spatial.BinarySpatialOperator f = null;
+ }
+ /**
+ * @param geometry
+ * - a geometry to construct the filter with
+ * @param i
+ * - the index of the layer to search
+ * @throws IndexOutOfBoundsException
+ */
+ private void findFeature(Geometry geometry, MapLayer layer)
+ throws IndexOutOfBoundsException {
+ org.opengis.filter.spatial.BinarySpatialOperator f = null;
- if ((context == null) || (layer==null)) {
- return ;
- }
+ if ((context == null) || (layer == null)) {
+ return;
+ }
+ try {
+ String name = layer.getFeatureSource().getSchema()
+ .getDefaultGeometry().getName();
+ if (name == "") {
+ name = "the_geom";
+ }
- try {
- String name = layer.getFeatureSource().getSchema()
- .getDefaultGeometry().getName();
+ try {
+ f = ff.contains(ff.property(name), ff.literal(geometry));
+ if (selectionManager != null) {
+ System.out.println("selection changed");
+ selectionManager.selectionChanged(this, f);
- if (name == "") {
- name = "the_geom";
- }
+ }
+ } catch (IllegalFilterException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
- try {
- f = ff.contains(ff.property(name), ff.literal(geometry));
- if(selectionManager!=null) {
- System.out.println("selection changed");
- selectionManager.selectionChanged(this, f);
+ /*
+ * // 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); }
+ */
- }
- } catch (IllegalFilterException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ /*
+ * GeometryAttributeType gat =
+ * layer.getFeatureSource().getSchema().getDefaultGeometry();
+ * fcol.setDefaultGeometry((Geometry)gat.createDefaultValue());
+ */
- /*// f.addLeftGeometry(ff.property(name));
- // System.out.println("looking with " + f);
- FeatureCollection fc = layer.getFeatureSource().getFeatures(f);
+ /*
+ * Iterator fi = fc.iterator(); while (fi.hasNext()) { Feature feat
+ * = (Feature) fi.next(); System.out.println("selected " +
+ * feat.getAttribute("STATE_NAME")); }
+ */
+ } catch (IllegalFilterException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return;
+ }
+ public void mouseClicked(MouseEvent e) {
+ // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"
+ // h:"+mapArea.getHeight());
+ Rectangle bounds = this.getBounds();
+ double x = (double) (e.getX());
+ double y = (double) (e.getY());
+ double width = mapArea.getWidth();
+ double height = mapArea.getHeight();
+ // xulu.sc
+ // double width2 = mapArea.getWidth() / 2.0;
+ // double height2 = mapArea.getHeight() / 2.0;
+ double width2 = width / 2.0;
+ double height2 = height / 2.0;
+ // xulu.ec
+ double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX();
+ double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)
+ + mapArea.getMinY();
+ /*
+ * System.out.println(""+x+"->"+mapX);
+ * System.out.println(""+y+"->"+mapY);
+ */
- if (fcol == null) {
- fcol = fc;
+ /*
+ * Coordinate ll = new Coordinate(mapArea.getMinX(), mapArea.getMinY());
+ * Coordinate ur = new Coordinate(mapArea.getMaxX(), mapArea.getMaxY());
+ */
+ double zlevel = 1.0;
- // here we should set the defaultgeom type
- } else {
- fcol.addAll(fc);
- }*/
+ switch (state) {
+ case Pan:
+ zlevel = 1.0;
+ // xulu.sc SK: return here.. a mouselistener is managing the PANNING
+ // break;
+ return;
+ // xulu.ec
+ case ZoomIn:
+ zlevel = zoomFactor;
- /*
- * GeometryAttributeType gat =
- * layer.getFeatureSource().getSchema().getDefaultGeometry();
- * fcol.setDefaultGeometry((Geometry)gat.createDefaultValue());
- */
+ break;
- /*
- * Iterator fi = fc.iterator(); while (fi.hasNext()) { Feature feat =
- * (Feature) fi.next(); System.out.println("selected " +
- * feat.getAttribute("STATE_NAME")); }
- */
- } catch (IllegalFilterException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return ;
- }
+ case ZoomOut:
+ zlevel = 1.0 / zoomFactor;
- public void mouseClicked(MouseEvent e) {
- // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"
- // h:"+mapArea.getHeight());
- Rectangle bounds = this.getBounds();
- double x = (double) (e.getX());
- double y = (double) (e.getY());
- double width = mapArea.getWidth();
- double height = mapArea.getHeight();
-//xulu.sc
-// double width2 = mapArea.getWidth() / 2.0;
-// double height2 = mapArea.getHeight() / 2.0;
- double width2 = width / 2.0;
- double height2 = height / 2.0;
-//xulu.ec
- double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX();
- double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)
- + mapArea.getMinY();
+ break;
- /*
- * System.out.println(""+x+"->"+mapX);
- * System.out.println(""+y+"->"+mapY);
- */
+ case Select:
+ doSelection(mapX, mapY, selectionLayer);
- /*
- * Coordinate ll = new Coordinate(mapArea.getMinX(), mapArea.getMinY());
- * Coordinate ur = new Coordinate(mapArea.getMaxX(), mapArea.getMaxY());
- */
- double zlevel = 1.0;
+ return;
- switch (state) {
- case Pan:
- zlevel = 1.0;
-//xulu.sc SK: return here.. a mouselistener is maanaging the PANNING
-// break;
- return;
-//xulu.ec
- case ZoomIn:
- zlevel = zoomFactor;
+ default:
+ return;
+ }
- break;
+ Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY
+ - (height2 / zlevel));
+ Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY
+ + (height2 / zlevel));
+ // xulu.sc SK: Check for min/max scale
+ // mapArea = new Envelope(ll, ur);
+ final Envelope newMapArea = new Envelope(ll, ur);
+ setMapArea(bestAllowedMapArea(newMapArea));
+ // xulu.ec
- case ZoomOut:
- zlevel = 1.0 / zoomFactor;
+ // sk.ec
- break;
+ // System.out.println("after area "+mapArea+"\nw:"+mapArea.getWidth()+"
+ // h:"+mapArea.getHeight());
+ repaint();
+ }
- case Select:
- doSelection(mapX, mapY, selectionLayer);
+ public void mouseEntered(MouseEvent e) {
+ }
+ public void mouseExited(MouseEvent e) {
+ }
- return;
+ public void mousePressed(MouseEvent e) {
+ startX = e.getX();
+ startY = e.getY();
+ lastX = 0;
+ lastY = 0;
+ }
- default:
- return;
- }
+ public void mouseReleased(MouseEvent e) {
+ int endX = e.getX();
+ int endY = e.getY();
- Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY
- - (height2 / zlevel));
- Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY
- + (height2 / zlevel));
-//xulu.sc SK: Check for min/max scale
-// mapArea = new Envelope(ll, ur);
- final Envelope newMapArea = new Envelope(ll, ur);
- setMapArea( bestAllowedMapArea( newMapArea ) );
-//xulu.ec
+ processDrag(startX, startY, endX, endY, e);
+ lastX = 0;
+ lastY = 0;
- // System.out.println("after area "+mapArea+"\nw:"+mapArea.getWidth()+"
- // h:"+mapArea.getHeight());
- repaint();
- }
+ /**
+ * Es wird nicht (mehr) gepannt!
+ */
+ panning_started = false;
+ }
- public void mouseEntered(MouseEvent e) {
- }
+ public void mouseDragged(MouseEvent e) {
+ Graphics graphics = this.getGraphics();
+ int x = e.getX();
+ int y = e.getY();
- public void mouseExited(MouseEvent e) {
- }
+ if ((state == JMapPane.Pan)
+ || ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {
+ /**
+ * SK: Der Cursor wird auf PANNING gesetzt.
+ */
+ if (panning_started == false) {
+ panning_started = true;
+ setCursor(SwingUtil.PANNING_CURSOR);
+ }
- public void mousePressed(MouseEvent e) {
- startX = e.getX();
- startY = e.getY();
- lastX = 0;
- lastY = 0;
- }
-
- public void mouseReleased(MouseEvent e) {
- int endX = e.getX();
- int endY = e.getY();
-
- processDrag(startX, startY, endX, endY, e);
- lastX = 0;
- lastY = 0;
-
- /**
- * Es wird nicht (mehr) gepannt!
- */
- panning_started = false;
- }
-
- public void mouseDragged(MouseEvent e) {
- Graphics graphics = this.getGraphics();
- int x = e.getX();
- int y = e.getY();
-
-
- if ( (state == JMapPane.Pan) || ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {
- /**
- * SK:
- * Der Cursor wird auf PANNING gesetzt.
- */
- if (panning_started == false){
- panning_started = true;
- setCursor( SwingUtil.PANNING_CURSOR );
- }
-
-
- // move the image with the mouse
- if ((lastX > 0) && (lastY > 0)) {
- int dx = lastX - startX;
- int dy = lastY - startY;
- // System.out.println("translate "+dx+","+dy);
- final Graphics2D g2 = panningImage.createGraphics();
- g2.setBackground( new Color(240,240,240) ); //TODO richtige farbe? am besten vom L&F die hintergrundfarbe auslesen...
+ // move the image with the mouse
+ if ((lastX > 0) && (lastY > 0)) {
+ int dx = lastX - startX;
+ int dy = lastY - startY;
+ // System.out.println("translate "+dx+","+dy);
+ final Graphics2D g2 = panningImage.createGraphics();
+ g2.setBackground(new Color(240, 240, 240)); // TODO richtige
+ // farbe? am besten
+ // vom L&F die
+ // hintergrundfarbe
+ // auslesen...
g2.clearRect(0, 0, this.getWidth(), this.getHeight());
g2.drawImage(baseImage, dx, dy, this);
- graphics.drawImage(panningImage, 0, 0, this);
- }
+ graphics.drawImage(panningImage, 0, 0, this);
+ }
- lastX = x;
- lastY = y;
- } else
-
- if ((state == JMapPane.ZoomIn) || (state == JMapPane.ZoomOut)) {
-
-
- graphics.setXORMode(Color.WHITE);
+ lastX = x;
+ lastY = y;
+ } else
- if ((lastX > 0) && (lastY > 0)) {
- drawRectangle(graphics);
- }
+ if ((state == JMapPane.ZoomIn) || (state == JMapPane.ZoomOut)) {
- // draw new box
- lastX = x;
- lastY = y;
- drawRectangle(graphics);
- } else if (state == JMapPane.Select && selectionLayer != null) {
+ graphics.setXORMode(Color.WHITE);
- // construct a new bbox filter
- Rectangle bounds = this.getBounds();
+ if ((lastX > 0) && (lastY > 0)) {
+ drawRectangle(graphics);
+ }
- double mapWidth = mapArea.getWidth();
- double mapHeight = mapArea.getHeight();
+ // draw new box
+ lastX = x;
+ lastY = y;
+ drawRectangle(graphics);
+ } else if (state == JMapPane.Select && selectionLayer != null) {
- double x1 = ((this.startX * mapWidth) / (double) bounds.width)
- + mapArea.getMinX();
- double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height)
- + mapArea.getMinY();
- double x2 = ((x * mapWidth) / (double) bounds.width)
- + mapArea.getMinX();
- double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height)
- + mapArea.getMinY();
- double left = Math.min(x1, x2);
- double right = Math.max(x1, x2);
- double bottom = Math.min(y1, y2);
- double top = Math.max(y1, y2);
+ // construct a new bbox filter
+ Rectangle bounds = this.getBounds();
+ double mapWidth = mapArea.getWidth();
+ double mapHeight = mapArea.getHeight();
- String name = selectionLayer.getFeatureSource().getSchema()
- .getDefaultGeometry().getName();
+ double x1 = ((this.startX * mapWidth) / (double) bounds.width)
+ + mapArea.getMinX();
+ double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height)
+ + mapArea.getMinY();
+ double x2 = ((x * mapWidth) / (double) bounds.width)
+ + mapArea.getMinX();
+ double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height)
+ + mapArea.getMinY();
+ double left = Math.min(x1, x2);
+ double right = Math.max(x1, x2);
+ double bottom = Math.min(y1, y2);
+ double top = Math.max(y1, y2);
- if (name == "") {
- name = "the_geom";
- }
- Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,
- getContext().getCoordinateReferenceSystem().toString());
- if(selectionManager!=null) {
- selectionManager.selectionChanged(this, bb);
- }
+ String name = selectionLayer.getFeatureSource().getSchema()
+ .getDefaultGeometry().getName();
- graphics.setXORMode(Color.green);
+ if (name == "") {
+ name = "the_geom";
+ }
+ Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,
+ getContext().getCoordinateReferenceSystem().toString());
+ if (selectionManager != null) {
+ selectionManager.selectionChanged(this, bb);
+ }
- /*
- * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); }
- */
+ graphics.setXORMode(Color.green);
- // draw new box
- lastX = x;
- lastY = y;
- drawRectangle(graphics);
- }
-
- }
+ /*
+ * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); }
+ */
- // sk.cs
-// private void processDrag(int x1, int y1, int x2, int y2) {
- // sk.ce
- protected void processDrag(int x1, int y1, int x2, int y2, MouseEvent e) {
-
- /****
- * If no layer is availabe we dont want a NullPointerException
- */
- if (mapArea == null) return;
-
- // System.out.println("processing drag from " + x1 + "," + y1 + " -> "
- // + x2 + "," + y2);
- if ((x1 == x2) && (y1 == y2)) {
- if (isClickable()) {
- mouseClicked(new MouseEvent(this, 0, new Date().getTime(), 0,
- x1, y1, y2, false));
- }
+ // draw new box
+ lastX = x;
+ lastY = y;
+ drawRectangle(graphics);
+ }
- return;
- }
-
- Rectangle bounds = this.getBounds();
+ }
- double mapWidth = mapArea.getWidth();
- double mapHeight = mapArea.getHeight();
+ // sk.cs
+ // private void processDrag(int x1, int y1, int x2, int y2) {
+ // sk.ce
+ protected void processDrag(final int x1, final int y1, final int x2,
+ final int y2, MouseEvent e) {
- double startX = ((x1 * mapWidth) / (double) bounds.width)
- + mapArea.getMinX();
- double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height)
- + mapArea.getMinY();
- double endX = ((x2 * mapWidth) / (double) bounds.width)
- + mapArea.getMinX();
- double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height)
- + mapArea.getMinY();
+ /****
+ * If no layer is availabe we dont want a NullPointerException
+ */
+ if (mapArea == null)
+ return;
- if ( (state == JMapPane.Pan) || (e.getButton()== MouseEvent.BUTTON3)) {
- // move the image with the mouse
- // calculate X offsets from start point to the end Point
- double deltaX1 = endX - startX;
+ // System.out.println("processing drag from " + x1 + "," + y1 + " -> "
+ // + x2 + "," + y2);
+ if ((x1 == x2) && (y1 == y2)) {
+ if (isClickable()) {
+ mouseClicked(new MouseEvent(this, 0, new Date().getTime(), 0,
+ x1, y1, y2, false));
+ }
- // System.out.println("deltaX " + deltaX1);
- // new edges
- double left = mapArea.getMinX() - deltaX1;
- double right = mapArea.getMaxX() - deltaX1;
+ return;
+ }
- // now for Y
- double deltaY1 = endY - startY;
+ Rectangle bounds = this.getBounds();
- // System.out.println("deltaY " + deltaY1);
- double bottom = mapArea.getMinY() - deltaY1;
- double top = mapArea.getMaxY() - deltaY1;
- Coordinate ll = new Coordinate(left, bottom);
- Coordinate ur = new Coordinate(right, top);
-//xulu.sc
-// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
- setMapArea( fixAspectRatio(this.getBounds(), new Envelope(ll, ur)) );
-//xulu.ec
- } else if (state == JMapPane.ZoomIn) {
-
+ double mapWidth = mapArea.getWidth();
+ double mapHeight = mapArea.getHeight();
- // Zu kleine Flächen sollen nicht gezoomt werden.
- //sk.bc
- if ( (Math.abs(x1-x2) * Math.abs(y2-y1) )<100 ) return;
- // sk.ec
-
- drawRectangle(this.getGraphics());
- // make the dragged rectangle (in map coords) the new BBOX
- double left = Math.min(startX, endX);
- double right = Math.max(startX, endX);
- double bottom = Math.min(startY, endY);
- double top = Math.max(startY, endY);
- Coordinate ll = new Coordinate(left, bottom);
- Coordinate ur = new Coordinate(right, top);
-//xulu.sc
-// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
- setMapArea( fixAspectRatio(this.getBounds(), new Envelope(ll, ur)) );
-//xulu.ec
- } else if (state == JMapPane.ZoomOut) {
- drawRectangle(this.getGraphics());
-
- // make the dragged rectangle in screen coords the new map size?
- double left = Math.min(startX, endX);
- double right = Math.max(startX, endX);
- double bottom = Math.min(startY, endY);
- double top = Math.max(startY, endY);
- double nWidth = (mapWidth * mapWidth) / (right - left);
- double nHeight = (mapHeight * mapHeight) / (top - bottom);
- double deltaX1 = left - mapArea.getMinX();
- double nDeltaX1 = (deltaX1 * nWidth) / mapWidth;
- double deltaY1 = bottom - mapArea.getMinY();
- double nDeltaY1 = (deltaY1 * nHeight) / mapHeight;
- Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1,
- mapArea.getMinY() - nDeltaY1);
- double deltaX2 = mapArea.getMaxX() - right;
- double nDeltaX2 = (deltaX2 * nWidth) / mapWidth;
- double deltaY2 = mapArea.getMaxY() - top;
- double nDeltaY2 = (deltaY2 * nHeight) / mapHeight;
- Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2,
- mapArea.getMaxY() + nDeltaY2);
-//xulu.sc
-// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
- setMapArea( fixAspectRatio(this.getBounds(), new Envelope(ll, ur)) );
-//xulu.ec
- } else if (state == JMapPane.Select && selectionLayer !=null) {
- double left = Math.min(startX, endX);
- double right = Math.max(startX, endX);
- double bottom = Math.min(startY, endY);
- double top = Math.max(startY, endY);
+ double startX = ((x1 * mapWidth) / (double) bounds.width)
+ + mapArea.getMinX();
+ double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height)
+ + mapArea.getMinY();
+ double endX = ((x2 * mapWidth) / (double) bounds.width)
+ + mapArea.getMinX();
+ double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height)
+ + mapArea.getMinY();
+ if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) {
+ // move the image with the mouse
+ // calculate X offsets from start point to the end Point
+ double deltaX1 = endX - startX;
- String name = selectionLayer.getFeatureSource().getSchema()
- .getDefaultGeometry().getLocalName();
+ // System.out.println("deltaX " + deltaX1);
+ // new edges
+ double left = mapArea.getMinX() - deltaX1;
+ double right = mapArea.getMaxX() - deltaX1;
- if (name == "") {
- name = "the_geom";
- }
- Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,
- getContext().getCoordinateReferenceSystem().toString());
- //System.out.println(bb.toString());
- if(selectionManager!=null) {
- selectionManager.selectionChanged(this, bb);
- }
- /*FeatureCollection fc;
- selection = null;
- try {
- fc = selectionLayer.getFeatureSource().getFeatures(bb);
- selection = fc;
- } catch (IOException e) {
- e.printStackTrace();
- }
-*/
- }
+ // now for Y
+ double deltaY1 = endY - startY;
-//xulu.so
-// setMapArea(mapArea);
-//xulu.eo
- repaint();
- }
+ // System.out.println("deltaY " + deltaY1);
+ double bottom = mapArea.getMinY() - deltaY1;
+ double top = mapArea.getMaxY() - deltaY1;
+ Coordinate ll = new Coordinate(left, bottom);
+ Coordinate ur = new Coordinate(right, top);
+ // xulu.sc
+ // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
+ setMapArea(fixAspectRatio(this.getBounds(), new Envelope(ll, ur)));
+ // xulu.ec
+ } else if (state == JMapPane.ZoomIn) {
- private boolean isClickable() {
- return clickable;
- }
+ // Zu kleine Flächen sollen nicht gezoomt werden.
+ // sk.bc
+ if ((Math.abs(x1 - x2) * Math.abs(y2 - y1)) < 150)
+ return;
+ // sk.ec
- private org.geotools.styling.Style setupStyle(int type, Color color) {
- StyleFactory sf = org.geotools.factory.CommonFactoryFinder
- .getStyleFactory(null);
- StyleBuilder sb = new StyleBuilder();
+ drawRectangle(this.getGraphics());
+ // make the dragged rectangle (in map coords) the new BBOX
+ double left = Math.min(startX, endX);
+ double right = Math.max(startX, endX);
+ double bottom = Math.min(startY, endY);
+ double top = Math.max(startY, endY);
+ Coordinate ll = new Coordinate(left, bottom);
+ Coordinate ur = new Coordinate(right, top);
+ // xulu.sc
- org.geotools.styling.Style s = sf.createStyle();
- s.setTitle("selection");
+ // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
+ setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
- // TODO parameterise the color
- PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);
- ps.setStroke(sb.createStroke(color));
+ // sk.sc
+// {
+// // SK tries to paint a preview of the zoom ;-9 aha.... well
+// Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();
+// graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+// RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
+// graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+// RenderingHints.VALUE_ANTIALIAS_OFF);
+// graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
+// RenderingHints.VALUE_RENDER_SPEED);
+// graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),
+// JMapPane.this.getHeight(), x1, y1, x2, y2, null);
+// }
+ // xulu.ec
+ } else if (state == JMapPane.ZoomOut) {
+ drawRectangle(this.getGraphics());
- LineSymbolizer ls = sb.createLineSymbolizer(color);
- Graphic h = sb.createGraphic();
- h.setMarks(new Mark[] { sb.createMark("square", color) });
+ // make the dragged rectangle in screen coords the new map size?
+ double left = Math.min(startX, endX);
+ double right = Math.max(startX, endX);
+ double bottom = Math.min(startY, endY);
+ double top = Math.max(startY, endY);
+ double nWidth = (mapWidth * mapWidth) / (right - left);
+ double nHeight = (mapHeight * mapHeight) / (top - bottom);
+ double deltaX1 = left - mapArea.getMinX();
+ double nDeltaX1 = (deltaX1 * nWidth) / mapWidth;
+ double deltaY1 = bottom - mapArea.getMinY();
+ double nDeltaY1 = (deltaY1 * nHeight) / mapHeight;
+ Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1,
+ mapArea.getMinY() - nDeltaY1);
+ double deltaX2 = mapArea.getMaxX() - right;
+ double nDeltaX2 = (deltaX2 * nWidth) / mapWidth;
+ double deltaY2 = mapArea.getMaxY() - top;
+ double nDeltaY2 = (deltaY2 * nHeight) / mapHeight;
+ Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2,
+ mapArea.getMaxY() + nDeltaY2);
+ // xulu.sc
+ // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
+ setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
- PointSymbolizer pts = sb.createPointSymbolizer(h);
+ // xulu.ec
+ } else if (state == JMapPane.Select && selectionLayer != null) {
+ double left = Math.min(startX, endX);
+ double right = Math.max(startX, endX);
+ double bottom = Math.min(startY, endY);
+ double top = Math.max(startY, endY);
- // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});
- switch (type) {
- case POLYGON:
- s = sb.createStyle(ps);
+ String name = selectionLayer.getFeatureSource().getSchema()
+ .getDefaultGeometry().getLocalName();
- break;
+ if (name == "") {
+ name = "the_geom";
+ }
+ Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,
+ getContext().getCoordinateReferenceSystem().toString());
+ // System.out.println(bb.toString());
+ if (selectionManager != null) {
+ selectionManager.selectionChanged(this, bb);
+ }
+ /*
+ * FeatureCollection fc; selection = null; try { fc =
+ * selectionLayer.getFeatureSource().getFeatures(bb); selection =
+ * fc; } catch (IOException e) { e.printStackTrace(); }
+ */
+ }
- case POINT:
- s = sb.createStyle(pts);
+ // xulu.so
+ // setMapArea(mapArea);
+ // xulu.eo
+ repaint();
+ }
- break;
+ private boolean isClickable() {
+ return clickable;
+ }
- case LINE:
- s = sb.createStyle(ls);
- }
+ private org.geotools.styling.Style setupStyle(int type, Color color) {
+ StyleFactory sf = org.geotools.factory.CommonFactoryFinder
+ .getStyleFactory(null);
+ StyleBuilder sb = new StyleBuilder();
- return s;
- }
+ org.geotools.styling.Style s = sf.createStyle();
+ s.setTitle("selection");
- public void highlightChanged(HighlightChangedEvent e) {
- org.opengis.filter.Filter f = e.getFilter();
+ // TODO parameterise the color
+ PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);
+ ps.setStroke(sb.createStroke(color));
- try {
- highlightFeature = highlightLayer.getFeatureSource().getFeatures(f);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
+ LineSymbolizer ls = sb.createLineSymbolizer(color);
+ Graphic h = sb.createGraphic();
+ h.setMarks(new Mark[] { sb.createMark("square", color) });
- repaint();
- }
+ PointSymbolizer pts = sb.createPointSymbolizer(h);
- public void propertyChange(PropertyChangeEvent evt) {
- String prop = evt.getPropertyName();
+ // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});
+ switch (type) {
+ case POLYGON:
+ s = sb.createStyle(ps);
- if (prop.equalsIgnoreCase("crs")) {
- context.setAreaOfInterest(context.getAreaOfInterest(),
- (CoordinateReferenceSystem) evt.getNewValue());
- }
- }
+ break;
- public boolean isReset() {
- return reset;
- }
+ case POINT:
+ s = sb.createStyle(pts);
- public void setReset(boolean reset) {
- this.reset = reset;
- }
+ break;
- public void layerAdded(MapLayerListEvent event) {
- changed = true;
+ case LINE:
+ s = sb.createStyle(ls);
+ }
- if (context.getLayers().length == 1) { // the first one
+ return s;
+ }
- try {
-//xulu.sc
-// mapArea = context.getLayerBounds();
- mapArea = context.getAreaOfInterest();
- if ( mapArea == null )
- mapArea = context.getLayerBounds();
-//xulu.ec
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ public void highlightChanged(HighlightChangedEvent e) {
+ org.opengis.filter.Filter f = e.getFilter();
- reset = true;
- }
+ try {
+ highlightFeature = highlightLayer.getFeatureSource().getFeatures(f);
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
- repaint();
- }
+ repaint();
+ }
- public void layerRemoved(MapLayerListEvent event) {
- changed = true;
- repaint();
- }
+ public void propertyChange(PropertyChangeEvent evt) {
+ String prop = evt.getPropertyName();
- public void layerChanged(MapLayerListEvent event) {
- changed = true;
- // System.out.println("layer changed - repaint");
- repaint();
- }
+ if (prop.equalsIgnoreCase("crs")) {
+ context.setAreaOfInterest(context.getAreaOfInterest(),
+ (CoordinateReferenceSystem) evt.getNewValue());
+ }
+ }
- public void layerMoved(MapLayerListEvent event) {
- changed = true;
- repaint();
- }
+ public boolean isReset() {
+ return reset;
+ }
- protected void drawRectangle(Graphics graphics) {
- // undraw last box/draw new box
- int left = Math.min(startX, lastX);
- int right = Math.max(startX, lastX);
- int top = Math.max(startY, lastY);
- int bottom = Math.min(startY, lastY);
- int width = right - left;
- int height = top - bottom;
- // System.out.println("drawing rect("+left+","+bottom+","+ width+","+
- // height+")");
- graphics.drawRect(left, bottom, width, height);
- }
+ public void setReset(boolean reset) {
+ this.reset = reset;
+ }
- /**
- * if clickable is set to true then a single click on the map pane will zoom
- * or pan the map.
- *
- * @param clickable
- */
- public void setClickable(boolean clickable) {
- this.clickable = clickable;
- }
+ public void layerAdded(MapLayerListEvent event) {
+ changed = true;
- public void mouseMoved(MouseEvent e) {
- }
+ if (context.getLayers().length == 1) { // the first one
- public FeatureCollection getSelection() {
- return selection;
- }
+ try {
+ // xulu.sc
+ // mapArea = context.getLayerBounds();
+ mapArea = context.getAreaOfInterest();
+ if (mapArea == null)
+ mapArea = context.getLayerBounds();
+ // xulu.ec
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
- public void setSelection(FeatureCollection selection) {
- this.selection = selection;
- repaint();
- }
+ reset = true;
+ }
- /* (non-Javadoc)
- * @see org.geotools.gui.swing.event.SelectionChangeListener#selectionChanged(org.geotools.gui.swing.event.SelectionChangedEvent)
- */
- public void selectionChanged(SelectionChangedEvent e) {
+ repaint();
+ }
- try {
- selection = selectionLayer.getFeatureSource().getFeatures(e.getFilter());
- repaint();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- }
+ public void layerRemoved(MapLayerListEvent event) {
+ changed = true;
+ repaint();
+ }
- public SelectionManager getSelectionManager() {
- return selectionManager;
- }
+ public void layerChanged(MapLayerListEvent event) {
+ changed = true;
+ // System.out.println("layer changed - repaint");
+ repaint();
+ }
- public void setSelectionManager(SelectionManager selectionManager) {
- this.selectionManager = selectionManager;
- this.selectionManager.addSelectionChangeListener(this);
+ public void layerMoved(MapLayerListEvent event) {
+ changed = true;
+ repaint();
+ }
- }
+ protected void drawRectangle(Graphics graphics) {
+ // undraw last box/draw new box
+ int left = Math.min(startX, lastX);
+ int right = Math.max(startX, lastX);
+ int top = Math.max(startY, lastY);
+ int bottom = Math.min(startY, lastY);
+ int width = right - left;
+ int height = top - bottom;
+ // System.out.println("drawing rect("+left+","+bottom+","+ width+","+
+ // height+")");
+ graphics.drawRect(left, bottom, width, height);
+ }
+ /**
+ * if clickable is set to true then a single click on the map pane will zoom
+ * or pan the map.
+ *
+ * @param clickable
+ */
+ public void setClickable(boolean clickable) {
+ this.clickable = clickable;
+ }
-//xulu.sn
+ public void mouseMoved(MouseEvent e) {
+ }
+
+ public FeatureCollection getSelection() {
+ return selection;
+ }
+
+ public void setSelection(FeatureCollection selection) {
+ this.selection = selection;
+ repaint();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.geotools.gui.swing.event.SelectionChangeListener#selectionChanged
+ * (org.geotools.gui.swing.event.SelectionChangedEvent)
+ */
+ public void selectionChanged(SelectionChangedEvent e) {
+
+ try {
+ selection = selectionLayer.getFeatureSource().getFeatures(
+ e.getFilter());
+ repaint();
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+ }
+
+ public SelectionManager getSelectionManager() {
+ return selectionManager;
+ }
+
+ public void setSelectionManager(SelectionManager selectionManager) {
+ this.selectionManager = selectionManager;
+ this.selectionManager.addSelectionChangeListener(this);
+
+ }
+
+ // xulu.sn
/**
* Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste
* erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten
@@ -1258,7 +1272,8 @@
return env;
/**
- * Correct the aspect Ratio before we check the rest. Otherwise we might easily fail.
+ * Correct the aspect Ratio before we check the rest. Otherwise we might
+ * easily fail.
*/
env = fixAspectRatio(this.getBounds(), env);
@@ -1294,45 +1309,50 @@
return new Envelope(ll, ur);
}
- /**
- * Retuns the minimum allowed zoom scale. This is the bigger number value of the two.
- * Defaults to {@link Double}.MAX_VALUE
- *
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
- */
- public Double getMinZoomScale() {
- return minZoomScale;
- }
+ /**
+ * Retuns the minimum allowed zoom scale. This is the bigger number value of
+ * the two. Defaults to {@link Double}.MAX_VALUE
+ *
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ * Krüger</a>
+ */
+ public Double getMinZoomScale() {
+ return minZoomScale;
+ }
- /**
- * Retuns the maximum allowed zoom scale. This is the smaller number value of the two.
- * Defaults to {@link Double}.MIN_VALUE
- *
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
- */
- public Double getMaxZoomScale() {
- return maxZoomScale;
- }
+ /**
+ * Retuns the maximum allowed zoom scale. This is the smaller number value
+ * of the two. Defaults to {@link Double}.MIN_VALUE
+ *
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ * Krüger</a>
+ */
+ public Double getMaxZoomScale() {
+ return maxZoomScale;
+ }
- /**
- * Set the maximum allowed zoom scale. This is the smaller number value of the two.
- *
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
- */
- public void setMaxZoomScale(Double maxZoomScale) {
- // System.out.println("setting max scale to "+maxZoomScale);
- this.maxZoomScale = maxZoomScale;
- }
+ /**
+ * Set the maximum allowed zoom scale. This is the smaller number value of
+ * the two.
+ *
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ * Krüger</a>
+ */
+ public void setMaxZoomScale(Double maxZoomScale) {
+ // System.out.println("setting max scale to "+maxZoomScale);
+ this.maxZoomScale = maxZoomScale;
+ }
- /**
- * Set the minimum (nearest) allowed zoom scale. This is the bigger number value of the two.
- *
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
- */
- public void setMinZoomScale(Double minZoomScale) {
- this.minZoomScale = minZoomScale;
- }
-//xulu.en
+ /**
+ * Set the minimum (nearest) allowed zoom scale. This is the bigger number
+ * value of the two.
+ *
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ * Krüger</a>
+ */
+ public void setMinZoomScale(Double minZoomScale) {
+ this.minZoomScale = minZoomScale;
+ }
+ // xulu.en
-
}
More information about the Schmitzm-commits
mailing list