13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
* Lesser General Public License for more details. |
* Lesser General Public License for more details. |
15 |
*/ |
*/ |
16 |
package org.geotools.gui.swing; |
package gtmig.org.geotools.swing; |
17 |
|
|
18 |
/** |
/** |
19 |
* <b>Xulu:<br> |
* <b>Xulu:<br> |
43 |
import java.awt.Graphics2D; |
import java.awt.Graphics2D; |
44 |
import java.awt.LayoutManager; |
import java.awt.LayoutManager; |
45 |
import java.awt.Rectangle; |
import java.awt.Rectangle; |
46 |
|
import java.awt.RenderingHints; |
47 |
import java.awt.event.InputEvent; |
import java.awt.event.InputEvent; |
48 |
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
49 |
import java.awt.event.MouseListener; |
import java.awt.event.MouseListener; |
50 |
import java.awt.event.MouseMotionListener; |
import java.awt.event.MouseMotionListener; |
51 |
|
import java.awt.geom.AffineTransform; |
52 |
import java.awt.image.BufferedImage; |
import java.awt.image.BufferedImage; |
53 |
import java.beans.PropertyChangeEvent; |
import java.beans.PropertyChangeEvent; |
54 |
import java.beans.PropertyChangeListener; |
import java.beans.PropertyChangeListener; |
60 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
61 |
|
|
62 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
|
import org.geotools.feature.FeatureCollection; |
|
|
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; |
|
|
import org.geotools.map.DefaultMapContext; |
|
63 |
import org.geotools.map.MapContext; |
import org.geotools.map.MapContext; |
|
import org.geotools.map.MapLayer; |
|
64 |
import org.geotools.map.event.MapLayerListEvent; |
import org.geotools.map.event.MapLayerListEvent; |
65 |
import org.geotools.map.event.MapLayerListListener; |
import org.geotools.map.event.MapLayerListListener; |
|
import org.geotools.referencing.crs.DefaultGeographicCRS; |
|
66 |
import org.geotools.renderer.GTRenderer; |
import org.geotools.renderer.GTRenderer; |
67 |
|
import org.geotools.renderer.label.LabelCacheImpl; |
68 |
import org.geotools.renderer.lite.LabelCache; |
import org.geotools.renderer.lite.LabelCache; |
|
import org.geotools.renderer.lite.LabelCacheDefault; |
|
69 |
import org.geotools.renderer.lite.StreamingRenderer; |
import org.geotools.renderer.lite.StreamingRenderer; |
|
import org.geotools.styling.Graphic; |
|
|
import org.geotools.styling.LineSymbolizer; |
|
|
import org.geotools.styling.Mark; |
|
|
import org.geotools.styling.PointSymbolizer; |
|
|
import org.geotools.styling.PolygonSymbolizer; |
|
|
import org.geotools.styling.Style; |
|
|
import org.geotools.styling.StyleBuilder; |
|
|
import org.geotools.styling.StyleFactory; |
|
|
import org.opengis.filter.Filter; |
|
70 |
import org.opengis.filter.FilterFactory2; |
import org.opengis.filter.FilterFactory2; |
71 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
72 |
|
|
73 |
|
import schmitzm.geotools.JTSUtil; |
74 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
75 |
|
|
76 |
import com.vividsolutions.jts.geom.Coordinate; |
import com.vividsolutions.jts.geom.Coordinate; |
77 |
import com.vividsolutions.jts.geom.Envelope; |
import com.vividsolutions.jts.geom.Envelope; |
|
import com.vividsolutions.jts.geom.Geometry; |
|
78 |
import com.vividsolutions.jts.geom.GeometryFactory; |
import com.vividsolutions.jts.geom.GeometryFactory; |
79 |
|
|
80 |
public class JMapPane extends JPanel implements MouseListener, |
public class JMapPane extends JPanel implements MouseListener, |
81 |
MouseMotionListener, HighlightChangeListener, SelectionChangeListener, |
MouseMotionListener, PropertyChangeListener, MapLayerListListener { |
82 |
PropertyChangeListener, MapLayerListListener { |
private static Logger LOGGER = Logger.getLogger(JMapPane.class); |
|
private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName()); |
|
83 |
|
|
84 |
private static final long serialVersionUID = -8647971481359690499L; |
private static final long serialVersionUID = -8647971481359690499L; |
85 |
|
|
93 |
|
|
94 |
public static final int Select = 4; |
public static final int Select = 4; |
95 |
|
|
|
private static final int POLYGON = 0; |
|
|
|
|
|
private static final int LINE = 1; |
|
|
|
|
|
private static final int POINT = 2; |
|
|
|
|
96 |
/** |
/** |
97 |
* what renders the map |
* what renders the map |
98 |
*/ |
*/ |
99 |
GTRenderer renderer; |
GTRenderer renderer; |
100 |
|
|
|
private GTRenderer highlightRenderer, selectionRenderer; |
|
|
|
|
101 |
/** |
/** |
102 |
* the map context to render |
* the map context to render |
103 |
*/ |
*/ |
104 |
MapContext context; |
MapContext context; |
105 |
|
|
|
private MapContext selectionContext; |
|
|
|
|
106 |
/** |
/** |
107 |
* the area of the map to draw |
* the area of the map to draw |
108 |
*/ |
*/ |
|
// xulu.sc |
|
|
// Envelope mapArea; |
|
109 |
protected Envelope mapArea; |
protected Envelope mapArea; |
|
// xulu.ec |
|
110 |
|
|
111 |
/** |
/** |
112 |
* the size of the pane last time we drew |
* the size of the pane last time we drew |
113 |
*/ |
*/ |
|
// xulu.sc |
|
|
// private Rectangle oldRect = null; |
|
114 |
protected Rectangle oldRect = null; |
protected Rectangle oldRect = null; |
|
// xulu.ec |
|
115 |
|
|
116 |
/** |
/** |
117 |
* the last map area drawn. |
* the last map area drawn. |
118 |
*/ |
*/ |
|
// xulu.sc |
|
|
// private Envelope oldMapArea = null; |
|
119 |
protected Envelope oldMapArea = null; |
protected Envelope oldMapArea = null; |
|
// xulu.ec |
|
120 |
|
|
121 |
/** |
/** |
122 |
* the base image of the map |
* the base image of the map |
123 |
*/ |
*/ |
124 |
protected BufferedImage baseImage, panningImage; |
protected BufferedImage baseImage, panningImage; |
|
// SK: private BufferedImage baseImage, panningImage; |
|
|
|
|
|
/** |
|
|
* image of selection |
|
|
*/ |
|
|
private BufferedImage selectImage; |
|
|
|
|
|
/** |
|
|
* style for selected items |
|
|
*/ |
|
|
private Style selectionStyle; |
|
|
|
|
|
/** |
|
|
* layer that selection works on |
|
|
*/ |
|
|
private MapLayer selectionLayer; |
|
|
|
|
|
/** |
|
|
* layer that highlight works on |
|
|
*/ |
|
|
private MapLayer highlightLayer; |
|
|
|
|
|
/** |
|
|
* the object which manages highlighting |
|
|
*/ |
|
|
private HighlightManager highlightManager; |
|
|
|
|
|
/** |
|
|
* is highlighting on or off |
|
|
*/ |
|
|
private boolean highlight = true; |
|
125 |
|
|
126 |
/** |
/** |
127 |
* a factory for filters |
* a factory for filters |
133 |
*/ |
*/ |
134 |
GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null); |
GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null); |
135 |
|
|
|
/** |
|
|
* the collections of features to be selected or highlighted |
|
|
*/ |
|
|
FeatureCollection selection; |
|
|
|
|
|
/** |
|
|
* the collections of features to be selected or highlighted |
|
|
*/ |
|
|
FeatureCollection highlightFeature; |
|
|
|
|
136 |
private int state = ZoomIn; |
private int state = ZoomIn; |
137 |
|
|
138 |
/** |
/** |
140 |
*/ |
*/ |
141 |
private double zoomFactor = 2.0; |
private double zoomFactor = 2.0; |
142 |
|
|
|
Style lineHighlightStyle; |
|
|
|
|
|
Style pointHighlightStyle; |
|
|
|
|
|
Style polygonHighlightStyle; |
|
|
|
|
|
Style polygonSelectionStyle; |
|
|
|
|
|
Style pointSelectionStyle; |
|
|
|
|
|
Style lineSelectionStyle; |
|
|
|
|
143 |
boolean changed = true; |
boolean changed = true; |
144 |
|
|
145 |
LabelCache labelCache = new LabelCacheDefault(); |
LabelCache labelCache = new LabelCacheImpl(); |
146 |
|
|
|
// xulu.sc |
|
|
// private boolean reset = false; |
|
147 |
protected boolean reset = false; |
protected boolean reset = false; |
|
// xulu.ec |
|
148 |
|
|
149 |
int startX; |
int startX; |
150 |
|
|
151 |
int startY; |
int startY; |
152 |
|
|
153 |
|
/** |
154 |
|
* If not <code>null</code>, the {@link JMapPane} will not allow to zoom/pan |
155 |
|
* out of that area |
156 |
|
**/ |
157 |
|
private Envelope maxExtend = null; |
158 |
|
|
159 |
|
// /** |
160 |
|
// * Is max. 1 or 0 of the 2 axised allowed to extend the maxExtend? If |
161 |
|
// * <code>true</code> the extends has to be fully inside maxExtend |
162 |
|
// **/ |
163 |
|
// boolean maxExtendForceMode = true; |
164 |
|
|
165 |
private boolean clickable; |
private boolean clickable; |
166 |
|
|
167 |
int lastX; |
int lastX; |
168 |
|
|
169 |
int lastY; |
int lastY; |
170 |
|
|
|
private SelectionManager selectionManager; |
|
|
// xulu.sn |
|
171 |
private Double maxZoomScale = Double.MIN_VALUE; |
private Double maxZoomScale = Double.MIN_VALUE; |
172 |
private Double minZoomScale = Double.MAX_VALUE; |
private Double minZoomScale = Double.MAX_VALUE; |
|
// xulu.en |
|
173 |
|
|
|
// sk.sn |
|
174 |
/** |
/** |
175 |
* Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses |
* Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses |
176 |
* Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu |
* Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu |
178 |
*/ |
*/ |
179 |
private boolean panning_started = false; |
private boolean panning_started = false; |
180 |
|
|
181 |
// sk.en |
/** |
182 |
|
* This color is used as the default background color when painting a map. |
183 |
|
*/ |
184 |
|
private Color mapBackgroundColor = Color.WHITE; |
185 |
|
|
186 |
public JMapPane() { |
public JMapPane() { |
187 |
this(null, true, null, null); |
this(null, true, null, null); |
195 |
* @param context |
* @param context |
196 |
* - the map context to display |
* - the map context to display |
197 |
*/ |
*/ |
198 |
public JMapPane(GTRenderer render, MapContext context) { |
public JMapPane(final GTRenderer render, final MapContext context) { |
199 |
this(null, true, render, context); |
this(null, true, render, context); |
200 |
} |
} |
201 |
|
|
211 |
* @param context |
* @param context |
212 |
* - what to draw |
* - what to draw |
213 |
*/ |
*/ |
214 |
public JMapPane(LayoutManager layout, boolean isDoubleBuffered, |
public JMapPane(final LayoutManager layout, final boolean isDoubleBuffered, |
215 |
GTRenderer render, MapContext context) { |
final GTRenderer render, final MapContext context) { |
216 |
super(layout, isDoubleBuffered); |
super(layout, isDoubleBuffered); |
217 |
|
|
218 |
ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder |
ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder |
223 |
|
|
224 |
this.addMouseListener(this); |
this.addMouseListener(this); |
225 |
this.addMouseMotionListener(this); |
this.addMouseMotionListener(this); |
|
setHighlightManager(new HighlightManager(highlightLayer)); |
|
|
setSelectionManager(new SelectionManager(selectionLayer)); |
|
|
lineHighlightStyle = setupStyle(LINE, Color.red); |
|
|
|
|
|
pointHighlightStyle = setupStyle(POINT, Color.red); |
|
|
|
|
|
polygonHighlightStyle = setupStyle(POLYGON, Color.red); |
|
|
|
|
|
polygonSelectionStyle = setupStyle(POLYGON, Color.cyan); |
|
|
|
|
|
pointSelectionStyle = setupStyle(POINT, Color.cyan); |
|
|
|
|
|
lineSelectionStyle = setupStyle(LINE, Color.cyan); |
|
226 |
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); |
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); |
227 |
} |
} |
228 |
|
|
233 |
return renderer; |
return renderer; |
234 |
} |
} |
235 |
|
|
236 |
public void setRenderer(GTRenderer renderer) { |
public void setRenderer(final GTRenderer renderer) { |
237 |
Map hints = new HashMap(); |
Map<Object, Object> hints = new HashMap<Object, Object>(); |
|
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); |
|
|
} |
|
238 |
|
|
239 |
this.renderer = renderer; |
this.renderer = renderer; |
240 |
// this.highlightRenderer = new StreamingRenderer(); |
// MS: Apply hint also for ShapeFileRenderer |
241 |
// this.selectionRenderer = new StreamingRenderer(); |
// if (renderer instanceof StreamingRenderer) { |
242 |
|
hints = renderer.getRendererHints(); |
243 |
|
if (hints == null) { |
244 |
|
hints = new HashMap<Object, Object>(); |
245 |
|
} |
246 |
|
if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) { |
247 |
|
labelCache = (LabelCache) hints |
248 |
|
.get(StreamingRenderer.LABEL_CACHE_KEY); |
249 |
|
} else { |
250 |
|
hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache); |
251 |
|
} |
252 |
|
|
253 |
hints.put("memoryPreloadingEnabled", Boolean.FALSE); |
hints.put("memoryPreloadingEnabled", Boolean.TRUE); |
254 |
// highlightRenderer.setRendererHints(hints); |
|
255 |
// selectionRenderer.setRendererHints(hints); |
renderer.setRendererHints(hints); |
256 |
|
// } |
257 |
|
|
258 |
if (this.context != null) { |
if (this.context != null) { |
259 |
this.renderer.setContext(this.context); |
this.renderer.setContext(this.context); |
264 |
return context; |
return context; |
265 |
} |
} |
266 |
|
|
267 |
public void setContext(MapContext context) { |
public void setContext(final MapContext context) { |
268 |
if (this.context != null) { |
if (this.context != null) { |
269 |
this.context.removeMapLayerListListener(this); |
this.context.removeMapLayerListListener(this); |
270 |
} |
} |
284 |
return mapArea; |
return mapArea; |
285 |
} |
} |
286 |
|
|
287 |
public void setMapArea(Envelope mapArea) { |
public void setMapArea(final Envelope mapArea) { |
288 |
this.mapArea = mapArea; |
this.mapArea = mapArea; |
289 |
} |
} |
290 |
|
|
292 |
return state; |
return state; |
293 |
} |
} |
294 |
|
|
295 |
public void setState(int state) { |
public void setState(final int state) { |
296 |
this.state = state; |
this.state = state; |
297 |
|
|
298 |
// System.out.println("State: " + state); |
// System.out.println("State: " + state); |
302 |
return zoomFactor; |
return zoomFactor; |
303 |
} |
} |
304 |
|
|
305 |
public void setZoomFactor(double zoomFactor) { |
public void setZoomFactor(final double zoomFactor) { |
306 |
this.zoomFactor = zoomFactor; |
this.zoomFactor = zoomFactor; |
307 |
} |
} |
308 |
|
|
309 |
public MapLayer getSelectionLayer() { |
protected void paintComponent(final Graphics g) { |
|
return selectionLayer; |
|
|
} |
|
|
|
|
|
public void setSelectionLayer(MapLayer selectionLayer) { |
|
|
this.selectionLayer = selectionLayer; |
|
|
if (selectionManager != null) { |
|
|
selectionManager.setSelectionLayer(selectionLayer); |
|
|
} |
|
|
} |
|
|
|
|
|
public boolean isHighlight() { |
|
|
return highlight; |
|
|
} |
|
|
|
|
|
public void setHighlight(boolean highlight) { |
|
|
this.highlight = highlight; |
|
|
} |
|
|
|
|
|
public MapLayer getHighlightLayer() { |
|
|
return highlightLayer; |
|
|
} |
|
|
|
|
|
public void setHighlightLayer(MapLayer highlightLayer) { |
|
|
this.highlightLayer = highlightLayer; |
|
|
|
|
|
if (highlightManager != null) { |
|
|
highlightManager.setHighlightLayer(highlightLayer); |
|
|
} |
|
|
} |
|
|
|
|
|
public HighlightManager getHighlightManager() { |
|
|
return highlightManager; |
|
|
} |
|
|
|
|
|
public void setHighlightManager(HighlightManager highlightManager) { |
|
|
this.highlightManager = highlightManager; |
|
|
this.highlightManager.addHighlightChangeListener(this); |
|
|
this.addMouseMotionListener(this.highlightManager); |
|
|
} |
|
|
|
|
|
public Style getLineHighlightStyle() { |
|
|
return lineHighlightStyle; |
|
|
} |
|
|
|
|
|
public void setLineHighlightStyle(Style lineHighlightStyle) { |
|
|
this.lineHighlightStyle = lineHighlightStyle; |
|
|
} |
|
|
|
|
|
public Style getLineSelectionStyle() { |
|
|
return lineSelectionStyle; |
|
|
} |
|
|
|
|
|
public void setLineSelectionStyle(Style lineSelectionStyle) { |
|
|
this.lineSelectionStyle = lineSelectionStyle; |
|
|
} |
|
|
|
|
|
public Style getPointHighlightStyle() { |
|
|
return pointHighlightStyle; |
|
|
} |
|
|
|
|
|
public void setPointHighlightStyle(Style pointHighlightStyle) { |
|
|
this.pointHighlightStyle = pointHighlightStyle; |
|
|
} |
|
|
|
|
|
public Style getPointSelectionStyle() { |
|
|
return pointSelectionStyle; |
|
|
} |
|
|
|
|
|
public void setPointSelectionStyle(Style pointSelectionStyle) { |
|
|
this.pointSelectionStyle = pointSelectionStyle; |
|
|
} |
|
|
|
|
|
public Style getPolygonHighlightStyle() { |
|
|
return polygonHighlightStyle; |
|
|
} |
|
|
|
|
|
public void setPolygonHighlightStyle(Style polygonHighlightStyle) { |
|
|
this.polygonHighlightStyle = polygonHighlightStyle; |
|
|
} |
|
|
|
|
|
public Style getPolygonSelectionStyle() { |
|
|
return polygonSelectionStyle; |
|
|
} |
|
|
|
|
|
public void setPolygonSelectionStyle(Style polygonSelectionStyle) { |
|
|
this.polygonSelectionStyle = polygonSelectionStyle; |
|
|
} |
|
|
|
|
|
protected void paintComponent(Graphics g) { |
|
310 |
super.paintComponent(g); |
super.paintComponent(g); |
311 |
|
|
312 |
if ((renderer == null) || (mapArea == null)) { |
if ((renderer == null) || (mapArea == null)) { |
313 |
return; |
return; |
314 |
} |
} |
315 |
|
|
316 |
Rectangle r = getBounds(); |
final Rectangle r = getBounds(); |
317 |
Rectangle dr = new Rectangle(r.width, r.height); |
final Rectangle dr = new Rectangle(r.width, r.height); |
318 |
|
|
319 |
if (!r.equals(oldRect) || reset) { |
if (!r.equals(oldRect) || reset) { |
320 |
if (!r.equals(oldRect) && (mapArea == null)) { |
if (!r.equals(oldRect) && (mapArea == null)) { |
321 |
try { |
try { |
322 |
mapArea = context.getLayerBounds(); |
mapArea = context.getLayerBounds(); |
323 |
} catch (IOException e) { |
} catch (final IOException e) { |
324 |
// TODO Auto-generated catch block |
LOGGER.warn("context.getLayerBounds()", e); |
|
e.printStackTrace(); |
|
325 |
} |
} |
326 |
} |
} |
327 |
|
|
331 |
reset = false; /* forget about the reset */ |
reset = false; /* forget about the reset */ |
332 |
oldRect = r; /* store what the current size is */ |
oldRect = r; /* store what the current size is */ |
333 |
|
|
334 |
mapArea = fixAspectRatio(r, mapArea); |
mapArea = JTSUtil.fixAspectRatio(r, mapArea, false); |
335 |
} |
} |
336 |
} |
} |
337 |
|
|
344 |
.getCoordinateReferenceSystem()); |
.getCoordinateReferenceSystem()); |
345 |
} |
} |
346 |
|
|
347 |
if (changed ) { /* if the map changed then redraw */ |
if (changed) { /* if the map changed then redraw */ |
348 |
changed = false; |
changed = false; |
349 |
|
|
350 |
|
// The baseImage should not have alpha |
351 |
baseImage = new BufferedImage(dr.width, dr.height, |
baseImage = new BufferedImage(dr.width, dr.height, |
352 |
BufferedImage.TYPE_INT_ARGB); |
BufferedImage.TYPE_INT_RGB); |
353 |
|
|
354 |
Graphics2D ig = baseImage.createGraphics(); |
final Graphics2D ig = baseImage.createGraphics(); |
355 |
/* System.out.println("rendering"); */ |
ig.setBackground(getMapBackgroundColor()); |
356 |
renderer.setContext(context); |
ig.fillRect(0, 0, dr.width, dr.height); |
357 |
labelCache.clear(); // work around anoying labelcache bug |
|
358 |
|
// /* System.out.println("rendering"); */ |
359 |
|
if (renderer.getContext() != null) |
360 |
|
renderer.setContext(context); |
361 |
|
|
362 |
|
// TODO is this clearing still needed? We already replace all that stuff whenever we change the style. Deactivated 31.10.09.. let's see |
363 |
|
// labelCache.clear(); // work around anoying labelcache bug |
364 |
|
|
365 |
// draw the map |
// draw the map |
366 |
renderer.paint((Graphics2D) ig, dr, mapArea); |
renderer.paint(ig, dr, mapArea); |
367 |
|
|
368 |
// TODO nur machen, wenn panning beginnt |
// TODO nur machen, wenn panning beginnt |
369 |
panningImage = new BufferedImage(dr.width, dr.height, |
panningImage = new BufferedImage(dr.width, dr.height, |
372 |
} |
} |
373 |
|
|
374 |
((Graphics2D) g).drawImage(baseImage, 0, 0, this); |
((Graphics2D) g).drawImage(baseImage, 0, 0, this); |
|
|
|
|
if ((selection != null) && (selection.size() > 0)) { |
|
|
// paint selection |
|
|
|
|
|
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"; */ |
|
|
|
|
|
if (type.toLowerCase().endsWith("polygon")) { |
|
|
selectionStyle = polygonSelectionStyle; |
|
|
} else if (type.toLowerCase().endsWith("point")) { |
|
|
selectionStyle = pointSelectionStyle; |
|
|
} else if (type.toLowerCase().endsWith("line")) { |
|
|
selectionStyle = lineSelectionStyle; |
|
|
} |
|
|
|
|
|
selectionContext = new DefaultMapContext(DefaultGeographicCRS.WGS84); |
|
|
|
|
|
selectionContext.addLayer(selection, selectionStyle); |
|
|
selectionRenderer.setContext(selectionContext); |
|
|
|
|
|
selectImage = new BufferedImage(dr.width, dr.height, |
|
|
BufferedImage.TYPE_INT_ARGB); |
|
|
|
|
|
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); |
|
|
|
|
|
highlightContext.addLayer(highlightFeature, highlightStyle); |
|
|
highlightRenderer.setContext(highlightContext); |
|
|
|
|
|
/* 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 |
|
|
*/ |
|
|
|
|
|
double scaleY = r.getHeight() / mapArea.getHeight(); |
|
|
double scale = 1.0; // stupid compiler! |
|
|
|
|
|
if (scaleX < scaleY) { /* pick the smaller scale */ |
|
|
scale = scaleX; |
|
|
} else { |
|
|
scale = scaleY; |
|
|
} |
|
|
|
|
|
/* calculate the difference in width and height of the new extent */ |
|
|
double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth); |
|
|
double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight); |
|
|
|
|
|
/* |
|
|
* System.out.println("delta x " + deltaX); |
|
|
* System.out.println("delta y " + deltaY); |
|
|
*/ |
|
|
|
|
|
/* 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)); |
|
|
|
|
|
return new Envelope(ll, ur); |
|
375 |
} |
} |
376 |
|
|
377 |
public void doSelection(double x, double y, MapLayer layer) { |
public void mouseClicked(final MouseEvent e) { |
378 |
|
if (mapArea == null) |
|
Geometry geometry = gf.createPoint(new Coordinate(x, y)); |
|
|
|
|
|
// org.opengis.geometry.Geometry geometry = new Point(); |
|
|
|
|
|
findFeature(geometry, layer); |
|
|
|
|
|
} |
|
|
|
|
|
/** |
|
|
* @param geometry |
|
|
* - a geometry to construct the filter with |
|
|
* @param i |
|
|
* - the index of the layer to search |
|
|
* @throws IndexOutOfBoundsException |
|
|
*/ |
|
|
private void findFeature(Geometry geometry, MapLayer layer) |
|
|
throws IndexOutOfBoundsException { |
|
|
org.opengis.filter.spatial.BinarySpatialOperator f = null; |
|
|
|
|
|
if ((context == null) || (layer == null)) { |
|
379 |
return; |
return; |
|
} |
|
|
|
|
|
try { |
|
|
String name = layer.getFeatureSource().getSchema() |
|
|
.getDefaultGeometry().getLocalName(); |
|
|
|
|
|
if (name == "") { |
|
|
name = "the_geom"; |
|
|
} |
|
|
|
|
|
try { |
|
|
f = ff.contains(ff.property(name), ff.literal(geometry)); |
|
|
if (selectionManager != null) { |
|
|
// System.out.println("selection changed"); |
|
|
selectionManager.selectionChanged(this, f); |
|
|
|
|
|
} |
|
|
} catch (IllegalFilterException e) { |
|
|
// TODO Auto-generated catch block |
|
|
e.printStackTrace(); |
|
|
} |
|
|
|
|
|
/* |
|
|
* // f.addLeftGeometry(ff.property(name)); // |
|
|
* System.out.println("looking with " + f); FeatureCollection fc = |
|
|
* layer.getFeatureSource().getFeatures(f); |
|
|
* |
|
|
* |
|
|
* |
|
|
* if (fcol == null) { fcol = fc; |
|
|
* |
|
|
* // here we should set the defaultgeom type } else { |
|
|
* fcol.addAll(fc); } |
|
|
*/ |
|
|
|
|
|
/* |
|
|
* GeometryAttributeType gat = |
|
|
* layer.getFeatureSource().getSchema().getDefaultGeometry(); |
|
|
* fcol.setDefaultGeometry((Geometry)gat.createDefaultValue()); |
|
|
*/ |
|
|
|
|
|
/* |
|
|
* Iterator fi = fc.iterator(); while (fi.hasNext()) { 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) { |
|
|
if (mapArea == null) return; |
|
380 |
// System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+" |
// System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+" |
381 |
// h:"+mapArea.getHeight()); |
// h:"+mapArea.getHeight()); |
382 |
Rectangle bounds = this.getBounds(); |
final Rectangle bounds = this.getBounds(); |
383 |
double x = (double) (e.getX()); |
final double x = (double) (e.getX()); |
384 |
double y = (double) (e.getY()); |
final double y = (double) (e.getY()); |
385 |
double width = mapArea.getWidth(); |
final double width = mapArea.getWidth(); |
386 |
double height = mapArea.getHeight(); |
final double height = mapArea.getHeight(); |
387 |
// xulu.sc |
// xulu.sc |
388 |
// double width2 = mapArea.getWidth() / 2.0; |
// double width2 = mapArea.getWidth() / 2.0; |
389 |
// double height2 = mapArea.getHeight() / 2.0; |
// double height2 = mapArea.getHeight() / 2.0; |
390 |
double width2 = width / 2.0; |
final double width2 = width / 2.0; |
391 |
double height2 = height / 2.0; |
final double height2 = height / 2.0; |
392 |
// xulu.ec |
// xulu.ec |
393 |
double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX(); |
final double mapX = ((x * width) / (double) bounds.width) |
394 |
double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height) |
+ mapArea.getMinX(); |
395 |
|
final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height) |
396 |
+ mapArea.getMinY(); |
+ mapArea.getMinY(); |
397 |
|
|
398 |
/* |
/* |
422 |
zlevel = 1.0 / zoomFactor; |
zlevel = 1.0 / zoomFactor; |
423 |
|
|
424 |
break; |
break; |
425 |
|
// |
426 |
case Select: |
// case Select: |
427 |
doSelection(mapX, mapY, selectionLayer); |
// doSelection(mapX, mapY, selectionLayer); |
428 |
|
// |
429 |
return; |
// return; |
430 |
|
|
431 |
default: |
default: |
432 |
return; |
return; |
433 |
} |
} |
434 |
|
|
435 |
Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY |
final Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY |
436 |
- (height2 / zlevel)); |
- (height2 / zlevel)); |
437 |
Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY |
final Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY |
438 |
+ (height2 / zlevel)); |
+ (height2 / zlevel)); |
439 |
// xulu.sc SK: Check for min/max scale |
// xulu.sc SK: Check for min/max scale |
440 |
// mapArea = new Envelope(ll, ur); |
// mapArea = new Envelope(ll, ur); |
449 |
repaint(); |
repaint(); |
450 |
} |
} |
451 |
|
|
452 |
public void mouseEntered(MouseEvent e) { |
public void mouseEntered(final MouseEvent e) { |
453 |
} |
} |
454 |
|
|
455 |
public void mouseExited(MouseEvent e) { |
public void mouseExited(final MouseEvent e) { |
456 |
} |
} |
457 |
|
|
458 |
public void mousePressed(MouseEvent e) { |
public void mousePressed(final MouseEvent e) { |
459 |
startX = e.getX(); |
startX = e.getX(); |
460 |
startY = e.getY(); |
startY = e.getY(); |
461 |
lastX = 0; |
lastX = 0; |
462 |
lastY = 0; |
lastY = 0; |
463 |
} |
} |
464 |
|
|
465 |
public void mouseReleased(MouseEvent e) { |
public void mouseReleased(final MouseEvent e) { |
466 |
int endX = e.getX(); |
final int endX = e.getX(); |
467 |
int endY = e.getY(); |
final int endY = e.getY(); |
468 |
|
|
469 |
processDrag(startX, startY, endX, endY, e); |
processDrag(startX, startY, endX, endY, e); |
470 |
lastX = 0; |
lastX = 0; |
476 |
panning_started = false; |
panning_started = false; |
477 |
} |
} |
478 |
|
|
479 |
public void mouseDragged(MouseEvent e) { |
public void mouseDragged(final MouseEvent e) { |
480 |
Graphics graphics = this.getGraphics(); |
final Graphics graphics = this.getGraphics(); |
481 |
int x = e.getX(); |
final int x = e.getX(); |
482 |
int y = e.getY(); |
final int y = e.getY(); |
483 |
|
|
484 |
if ((state == JMapPane.Pan) |
if ((state == JMapPane.Pan) |
485 |
|| ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
|| ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
493 |
|
|
494 |
// move the image with the mouse |
// move the image with the mouse |
495 |
if ((lastX > 0) && (lastY > 0)) { |
if ((lastX > 0) && (lastY > 0)) { |
496 |
int dx = lastX - startX; |
final int dx = lastX - startX; |
497 |
int dy = lastY - startY; |
final int dy = lastY - startY; |
498 |
// System.out.println("translate "+dx+","+dy); |
// System.out.println("translate "+dx+","+dy); |
499 |
final Graphics2D g2 = panningImage.createGraphics(); |
final Graphics2D g2 = panningImage.createGraphics(); |
500 |
g2.setBackground(new Color(240, 240, 240)); // TODO richtige |
g2.setBackground(getMapBackgroundColor()); |
501 |
// farbe? am besten |
|
|
// vom L&F die |
|
|
// hintergrundfarbe |
|
|
// auslesen... |
|
|
|
|
502 |
g2.clearRect(0, 0, this.getWidth(), this.getHeight()); |
g2.clearRect(0, 0, this.getWidth(), this.getHeight()); |
503 |
g2.drawImage(baseImage, dx, dy, this); |
g2.drawImage(baseImage, dx, dy, this); |
504 |
graphics.drawImage(panningImage, 0, 0, this); |
graphics.drawImage(panningImage, 0, 0, this); |
520 |
lastX = x; |
lastX = x; |
521 |
lastY = y; |
lastY = y; |
522 |
drawRectangle(graphics); |
drawRectangle(graphics); |
|
} else if (state == JMapPane.Select && selectionLayer != null) { |
|
|
|
|
|
// construct a new bbox filter |
|
|
Rectangle bounds = this.getBounds(); |
|
|
|
|
|
double mapWidth = mapArea.getWidth(); |
|
|
double mapHeight = mapArea.getHeight(); |
|
|
|
|
|
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); |
|
|
|
|
|
String name = selectionLayer.getFeatureSource().getSchema() |
|
|
.getDefaultGeometry().getName(); |
|
|
|
|
|
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); |
|
|
} |
|
|
|
|
|
graphics.setXORMode(Color.green); |
|
|
|
|
|
/* |
|
|
* if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); } |
|
|
*/ |
|
|
|
|
|
// draw new box |
|
|
lastX = x; |
|
|
lastY = y; |
|
|
drawRectangle(graphics); |
|
523 |
} |
} |
524 |
|
// else if (state == JMapPane.Select && selectionLayer != null) { |
525 |
|
// |
526 |
|
// // construct a new bbox filter |
527 |
|
// final Rectangle bounds = this.getBounds(); |
528 |
|
// |
529 |
|
// final double mapWidth = mapArea.getWidth(); |
530 |
|
// final double mapHeight = mapArea.getHeight(); |
531 |
|
// |
532 |
|
// final double x1 = ((this.startX * mapWidth) / (double) bounds.width) |
533 |
|
// + mapArea.getMinX(); |
534 |
|
// final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / |
535 |
|
// (double) bounds.height) |
536 |
|
// + mapArea.getMinY(); |
537 |
|
// final double x2 = ((x * mapWidth) / (double) bounds.width) |
538 |
|
// + mapArea.getMinX(); |
539 |
|
// final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) |
540 |
|
// bounds.height) |
541 |
|
// + mapArea.getMinY(); |
542 |
|
// final double left = Math.min(x1, x2); |
543 |
|
// final double right = Math.max(x1, x2); |
544 |
|
// final double bottom = Math.min(y1, y2); |
545 |
|
// final double top = Math.max(y1, y2); |
546 |
|
// |
547 |
|
// String name = selectionLayer.getFeatureSource().getSchema() |
548 |
|
// .getDefaultGeometry().getName(); |
549 |
|
// |
550 |
|
// if (name == "") { |
551 |
|
// name = "the_geom"; |
552 |
|
// } |
553 |
|
// final Filter bb = ff.bbox(ff.property(name), left, bottom, right, |
554 |
|
// top, |
555 |
|
// getContext().getCoordinateReferenceSystem().toString()); |
556 |
|
// if (selectionManager != null) { |
557 |
|
// selectionManager.selectionChanged(this, bb); |
558 |
|
// } |
559 |
|
// |
560 |
|
// graphics.setXORMode(Color.green); |
561 |
|
// |
562 |
|
// /* |
563 |
|
// * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); } |
564 |
|
// */ |
565 |
|
// |
566 |
|
// // draw new box |
567 |
|
// lastX = x; |
568 |
|
// lastY = y; |
569 |
|
// drawRectangle(graphics); |
570 |
|
// } |
571 |
|
|
572 |
} |
} |
573 |
|
|
575 |
// private void processDrag(int x1, int y1, int x2, int y2) { |
// private void processDrag(int x1, int y1, int x2, int y2) { |
576 |
// sk.ce |
// sk.ce |
577 |
protected void processDrag(final int x1, final int y1, final int x2, |
protected void processDrag(final int x1, final int y1, final int x2, |
578 |
final int y2, MouseEvent e) { |
final int y2, final MouseEvent e) { |
579 |
|
|
580 |
/**** |
/**** |
581 |
* If no layer is availabe we dont want a NullPointerException |
* If no layers exist, we ignore the drag. |
582 |
*/ |
*/ |
583 |
if (mapArea == null) |
if (context.getLayerCount() <= 0) { |
584 |
return; |
return; |
585 |
|
} |
586 |
|
|
587 |
// System.out.println("processing drag from " + x1 + "," + y1 + " -> " |
// System.out.println("processing drag from " + x1 + "," + y1 + " -> " |
588 |
// + x2 + "," + y2); |
// + x2 + "," + y2); |
595 |
return; |
return; |
596 |
} |
} |
597 |
|
|
598 |
Rectangle bounds = this.getBounds(); |
final Rectangle bounds = this.getBounds(); |
599 |
|
|
600 |
double mapWidth = mapArea.getWidth(); |
final double mapWidth = mapArea.getWidth(); |
601 |
double mapHeight = mapArea.getHeight(); |
final double mapHeight = mapArea.getHeight(); |
602 |
|
|
603 |
double startX = ((x1 * mapWidth) / (double) bounds.width) |
final double startX = ((x1 * mapWidth) / (double) bounds.width) |
604 |
+ mapArea.getMinX(); |
+ mapArea.getMinX(); |
605 |
double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height) |
final double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height) |
606 |
+ mapArea.getMinY(); |
+ mapArea.getMinY(); |
607 |
double endX = ((x2 * mapWidth) / (double) bounds.width) |
final double endX = ((x2 * mapWidth) / (double) bounds.width) |
608 |
+ mapArea.getMinX(); |
+ mapArea.getMinX(); |
609 |
double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height) |
final double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height) |
610 |
+ mapArea.getMinY(); |
+ mapArea.getMinY(); |
611 |
|
|
612 |
if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) { |
if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) { |
613 |
// move the image with the mouse |
// move the image with the mouse |
614 |
// calculate X offsets from start point to the end Point |
// calculate X offsets from start point to the end Point |
615 |
double deltaX1 = endX - startX; |
final double deltaX1 = endX - startX; |
616 |
|
|
617 |
// System.out.println("deltaX " + deltaX1); |
// System.out.println("deltaX " + deltaX1); |
618 |
// new edges |
// new edges |
619 |
double left = mapArea.getMinX() - deltaX1; |
final double left = mapArea.getMinX() - deltaX1; |
620 |
double right = mapArea.getMaxX() - deltaX1; |
final double right = mapArea.getMaxX() - deltaX1; |
621 |
|
|
622 |
// now for Y |
// now for Y |
623 |
double deltaY1 = endY - startY; |
final double deltaY1 = endY - startY; |
624 |
|
|
625 |
// System.out.println("deltaY " + deltaY1); |
// System.out.println("deltaY " + deltaY1); |
626 |
double bottom = mapArea.getMinY() - deltaY1; |
final double bottom = mapArea.getMinY() - deltaY1; |
627 |
double top = mapArea.getMaxY() - deltaY1; |
final double top = mapArea.getMaxY() - deltaY1; |
628 |
Coordinate ll = new Coordinate(left, bottom); |
final Coordinate ll = new Coordinate(left, bottom); |
629 |
Coordinate ur = new Coordinate(right, top); |
final Coordinate ur = new Coordinate(right, top); |
630 |
// xulu.sc |
// xulu.sc |
631 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
632 |
setMapArea(fixAspectRatio(this.getBounds(), new Envelope(ll, ur))); |
|
633 |
|
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
634 |
// xulu.ec |
// xulu.ec |
635 |
} else if (state == JMapPane.ZoomIn) { |
} else if (state == JMapPane.ZoomIn) { |
636 |
|
|
642 |
|
|
643 |
drawRectangle(this.getGraphics()); |
drawRectangle(this.getGraphics()); |
644 |
// make the dragged rectangle (in map coords) the new BBOX |
// make the dragged rectangle (in map coords) the new BBOX |
645 |
double left = Math.min(startX, endX); |
final double left = Math.min(startX, endX); |
646 |
double right = Math.max(startX, endX); |
final double right = Math.max(startX, endX); |
647 |
double bottom = Math.min(startY, endY); |
final double bottom = Math.min(startY, endY); |
648 |
double top = Math.max(startY, endY); |
final double top = Math.max(startY, endY); |
649 |
Coordinate ll = new Coordinate(left, bottom); |
final Coordinate ll = new Coordinate(left, bottom); |
650 |
Coordinate ur = new Coordinate(right, top); |
final Coordinate ur = new Coordinate(right, top); |
651 |
// xulu.sc |
// xulu.sc |
652 |
|
|
653 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
654 |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
655 |
|
|
656 |
// sk.sc |
// sk.sc |
657 |
// { |
{ |
658 |
// // SK tries to paint a preview of the zoom ;-9 aha.... well |
// // SK tries to paint a preview of the zoom ;-9 aha.... well |
659 |
// Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics(); |
// |
660 |
// graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
// double reductionFactor = 1/8.; |
661 |
// RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
//// |
662 |
// graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
//// BufferedImage reducedBaseImage = new BufferedImage((int)(baseImage.getWidth()*reductionFactor), (int)(baseImage.getHeight()*reductionFactor), BufferedImage.TYPE_INT_RGB); |
663 |
// RenderingHints.VALUE_ANTIALIAS_OFF); |
//// Graphics2D reducedG = (Graphics2D) reducedBaseImage.getGraphics(); |
664 |
// graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
// AffineTransform reductionTransform =new AffineTransform(); |
665 |
// RenderingHints.VALUE_RENDER_SPEED); |
// reductionTransform.scale(reductionFactor, reductionFactor); |
666 |
// graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(), |
//// reducedG.drawImage(baseImage, reductionTransform, null); |
667 |
// JMapPane.this.getHeight(), x1, y1, x2, y2, null); |
// |
668 |
// } |
// Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics(); |
669 |
|
//// graphics.getTransform().scale(reductionFactor, reductionFactor); |
670 |
|
// |
671 |
|
// graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
672 |
|
// RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
673 |
|
// graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
674 |
|
// RenderingHints.VALUE_ANTIALIAS_OFF); |
675 |
|
// graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
676 |
|
// RenderingHints.VALUE_RENDER_SPEED); |
677 |
|
// graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(), |
678 |
|
// JMapPane.this.getHeight(), x1, y1, x2, y2, null); |
679 |
|
} |
680 |
// xulu.ec |
// xulu.ec |
681 |
} else if (state == JMapPane.ZoomOut) { |
} else if (state == JMapPane.ZoomOut) { |
682 |
drawRectangle(this.getGraphics()); |
drawRectangle(this.getGraphics()); |
683 |
|
|
684 |
// make the dragged rectangle in screen coords the new map size? |
// make the dragged rectangle in screen coords the new map size? |
685 |
double left = Math.min(startX, endX); |
final double left = Math.min(startX, endX); |
686 |
double right = Math.max(startX, endX); |
final double right = Math.max(startX, endX); |
687 |
double bottom = Math.min(startY, endY); |
final double bottom = Math.min(startY, endY); |
688 |
double top = Math.max(startY, endY); |
final double top = Math.max(startY, endY); |
689 |
double nWidth = (mapWidth * mapWidth) / (right - left); |
final double nWidth = (mapWidth * mapWidth) / (right - left); |
690 |
double nHeight = (mapHeight * mapHeight) / (top - bottom); |
final double nHeight = (mapHeight * mapHeight) / (top - bottom); |
691 |
double deltaX1 = left - mapArea.getMinX(); |
final double deltaX1 = left - mapArea.getMinX(); |
692 |
double nDeltaX1 = (deltaX1 * nWidth) / mapWidth; |
final double nDeltaX1 = (deltaX1 * nWidth) / mapWidth; |
693 |
double deltaY1 = bottom - mapArea.getMinY(); |
final double deltaY1 = bottom - mapArea.getMinY(); |
694 |
double nDeltaY1 = (deltaY1 * nHeight) / mapHeight; |
final double nDeltaY1 = (deltaY1 * nHeight) / mapHeight; |
695 |
Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1, |
final Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1, |
696 |
mapArea.getMinY() - nDeltaY1); |
mapArea.getMinY() - nDeltaY1); |
697 |
double deltaX2 = mapArea.getMaxX() - right; |
final double deltaX2 = mapArea.getMaxX() - right; |
698 |
double nDeltaX2 = (deltaX2 * nWidth) / mapWidth; |
final double nDeltaX2 = (deltaX2 * nWidth) / mapWidth; |
699 |
double deltaY2 = mapArea.getMaxY() - top; |
final double deltaY2 = mapArea.getMaxY() - top; |
700 |
double nDeltaY2 = (deltaY2 * nHeight) / mapHeight; |
final double nDeltaY2 = (deltaY2 * nHeight) / mapHeight; |
701 |
Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2, |
final Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2, |
702 |
mapArea.getMaxY() + nDeltaY2); |
mapArea.getMaxY() + nDeltaY2); |
703 |
// xulu.sc |
// xulu.sc |
704 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
705 |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
706 |
|
|
707 |
// xulu.ec |
// 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); |
|
|
|
|
|
String name = selectionLayer.getFeatureSource().getSchema() |
|
|
.getDefaultGeometry().getLocalName(); |
|
|
|
|
|
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(); } |
|
|
*/ |
|
708 |
} |
} |
709 |
|
// else if (state == JMapPane.Select && selectionLayer != null) { |
710 |
|
// final double left = Math.min(startX, endX); |
711 |
|
// final double right = Math.max(startX, endX); |
712 |
|
// final double bottom = Math.min(startY, endY); |
713 |
|
// final double top = Math.max(startY, endY); |
714 |
|
// |
715 |
|
// String name = selectionLayer.getFeatureSource().getSchema() |
716 |
|
// .getDefaultGeometry().getLocalName(); |
717 |
|
// |
718 |
|
// if (name == "") { |
719 |
|
// name = "the_geom"; |
720 |
|
// } |
721 |
|
// final Filter bb = ff.bbox(ff.property(name), left, bottom, right, |
722 |
|
// top, |
723 |
|
// getContext().getCoordinateReferenceSystem().toString()); |
724 |
|
// // System.out.println(bb.toString()); |
725 |
|
// if (selectionManager != null) { |
726 |
|
// selectionManager.selectionChanged(this, bb); |
727 |
|
// } |
728 |
|
// /* |
729 |
|
// * FeatureCollection fc; selection = null; try { fc = |
730 |
|
// * selectionLayer.getFeatureSource().getFeatures(bb); selection = |
731 |
|
// * fc; } catch (IOException e) { e.printStackTrace(); } |
732 |
|
// */ |
733 |
|
// } |
734 |
|
|
735 |
// xulu.so |
// xulu.so |
736 |
// setMapArea(mapArea); |
// setMapArea(mapArea); |
742 |
return clickable; |
return clickable; |
743 |
} |
} |
744 |
|
|
745 |
private org.geotools.styling.Style setupStyle(int type, Color color) { |
// |
746 |
StyleFactory sf = org.geotools.factory.CommonFactoryFinder |
// private org.geotools.styling.Style setupStyle(final int type, final Color |
747 |
.getStyleFactory(null); |
// color) { |
748 |
StyleBuilder sb = new StyleBuilder(); |
// final StyleFactory sf = org.geotools.factory.CommonFactoryFinder |
749 |
|
// .getStyleFactory(null); |
750 |
org.geotools.styling.Style s = sf.createStyle(); |
// final StyleBuilder sb = new StyleBuilder(); |
751 |
s.setTitle("selection"); |
// |
752 |
|
// org.geotools.styling.Style s = sf.createStyle(); |
753 |
// TODO parameterise the color |
// s.setTitle("selection"); |
754 |
PolygonSymbolizer ps = sb.createPolygonSymbolizer(color); |
// |
755 |
ps.setStroke(sb.createStroke(color)); |
// // TODO parameterise the color |
756 |
|
// final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color); |
757 |
LineSymbolizer ls = sb.createLineSymbolizer(color); |
// ps.setStroke(sb.createStroke(color)); |
758 |
Graphic h = sb.createGraphic(); |
// |
759 |
h.setMarks(new Mark[] { sb.createMark("square", color) }); |
// final LineSymbolizer ls = sb.createLineSymbolizer(color); |
760 |
|
// final Graphic h = sb.createGraphic(); |
761 |
PointSymbolizer pts = sb.createPointSymbolizer(h); |
// h.setMarks(new Mark[] { sb.createMark("square", color) }); |
762 |
|
// |
763 |
// Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts}); |
// final PointSymbolizer pts = sb.createPointSymbolizer(h); |
764 |
switch (type) { |
// |
765 |
case POLYGON: |
// // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts}); |
766 |
s = sb.createStyle(ps); |
// switch (type) { |
767 |
|
// case POLYGON: |
768 |
break; |
// s = sb.createStyle(ps); |
769 |
|
// |
770 |
case POINT: |
// break; |
771 |
s = sb.createStyle(pts); |
// |
772 |
|
// case POINT: |
773 |
break; |
// s = sb.createStyle(pts); |
774 |
|
// |
775 |
case LINE: |
// break; |
776 |
s = sb.createStyle(ls); |
// |
777 |
} |
// case LINE: |
778 |
|
// s = sb.createStyle(ls); |
779 |
return s; |
// } |
780 |
} |
// |
781 |
|
// return s; |
782 |
public void highlightChanged(HighlightChangedEvent e) { |
// } |
|
org.opengis.filter.Filter f = e.getFilter(); |
|
783 |
|
|
784 |
try { |
public void propertyChange(final PropertyChangeEvent evt) { |
785 |
highlightFeature = highlightLayer.getFeatureSource().getFeatures(f); |
final String prop = evt.getPropertyName(); |
|
} catch (IOException e1) { |
|
|
// TODO Auto-generated catch block |
|
|
e1.printStackTrace(); |
|
|
} |
|
|
|
|
|
repaint(); |
|
|
} |
|
|
|
|
|
public void propertyChange(PropertyChangeEvent evt) { |
|
|
String prop = evt.getPropertyName(); |
|
786 |
|
|
787 |
if (prop.equalsIgnoreCase("crs")) { |
if (prop.equalsIgnoreCase("crs")) { |
788 |
context.setAreaOfInterest(context.getAreaOfInterest(), |
context.setAreaOfInterest(context.getAreaOfInterest(), |
794 |
return reset; |
return reset; |
795 |
} |
} |
796 |
|
|
797 |
public void setReset(boolean reset) { |
public void setReset(final boolean reset) { |
798 |
this.reset = reset; |
this.reset = reset; |
799 |
} |
} |
800 |
|
|
801 |
public void layerAdded(MapLayerListEvent event) { |
public void layerAdded(final MapLayerListEvent event) { |
802 |
changed = true; |
changed = true; |
803 |
|
|
804 |
if (context.getLayers().length == 1) { // the first one |
if (context.getLayers().length == 1) { // the first one |
810 |
if (mapArea == null) |
if (mapArea == null) |
811 |
mapArea = context.getLayerBounds(); |
mapArea = context.getLayerBounds(); |
812 |
// xulu.ec |
// xulu.ec |
813 |
} catch (IOException e) { |
} catch (final IOException e) { |
814 |
// TODO Auto-generated catch block |
// TODO Auto-generated catch block |
815 |
e.printStackTrace(); |
e.printStackTrace(); |
816 |
} |
} |
821 |
repaint(); |
repaint(); |
822 |
} |
} |
823 |
|
|
824 |
public void layerRemoved(MapLayerListEvent event) { |
public void layerRemoved(final MapLayerListEvent event) { |
825 |
changed = true; |
changed = true; |
826 |
repaint(); |
repaint(); |
827 |
} |
} |
828 |
|
|
829 |
public void layerChanged(MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
830 |
changed = true; |
changed = true; |
831 |
// System.out.println("layer changed - repaint"); |
// System.out.println("layer changed - repaint"); |
832 |
repaint(); |
repaint(); |
833 |
} |
} |
834 |
|
|
835 |
public void layerMoved(MapLayerListEvent event) { |
public void layerMoved(final MapLayerListEvent event) { |
836 |
changed = true; |
changed = true; |
837 |
repaint(); |
repaint(); |
838 |
} |
} |
839 |
|
|
840 |
protected void drawRectangle(Graphics graphics) { |
protected void drawRectangle(final Graphics graphics) { |
841 |
// undraw last box/draw new box |
// undraw last box/draw new box |
842 |
int left = Math.min(startX, lastX); |
final int left = Math.min(startX, lastX); |
843 |
int right = Math.max(startX, lastX); |
final int right = Math.max(startX, lastX); |
844 |
int top = Math.max(startY, lastY); |
final int top = Math.max(startY, lastY); |
845 |
int bottom = Math.min(startY, lastY); |
final int bottom = Math.min(startY, lastY); |
846 |
int width = right - left; |
final int width = right - left; |
847 |
int height = top - bottom; |
final int height = top - bottom; |
848 |
// System.out.println("drawing rect("+left+","+bottom+","+ width+","+ |
// System.out.println("drawing rect("+left+","+bottom+","+ width+","+ |
849 |
// height+")"); |
// height+")"); |
850 |
graphics.drawRect(left, bottom, width, height); |
graphics.drawRect(left, bottom, width, height); |
856 |
* |
* |
857 |
* @param clickable |
* @param clickable |
858 |
*/ |
*/ |
859 |
public void setClickable(boolean clickable) { |
public void setClickable(final boolean clickable) { |
860 |
this.clickable = clickable; |
this.clickable = clickable; |
861 |
} |
} |
862 |
|
|
863 |
public void mouseMoved(MouseEvent e) { |
public void mouseMoved(final 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); |
|
|
|
|
864 |
} |
} |
865 |
|
|
866 |
// xulu.sn |
// xulu.sn |
881 |
if (env == null) |
if (env == null) |
882 |
return env; |
return env; |
883 |
|
|
884 |
|
Envelope newArea = null; |
885 |
|
|
886 |
/** |
/** |
887 |
* Correct the aspect Ratio before we check the rest. Otherwise we might |
* Correct the aspect Ratio before we check the rest. Otherwise we might |
888 |
* easily fail. |
* easily fail. We allow to grow here, because we don't check against |
889 |
|
* the maxExtend |
890 |
*/ |
*/ |
891 |
env = fixAspectRatio(this.getBounds(), env); |
env = JTSUtil.fixAspectRatio(this.getBounds(), env, true); |
892 |
|
|
893 |
double scale = env.getWidth() / getWidth(); |
final double scale = env.getWidth() / getWidth(); |
894 |
double centerX = env.getMinX() + env.getWidth() / 2.; |
final double centerX = env.getMinX() + env.getWidth() / 2.; |
895 |
double centerY = env.getMinY() + env.getHeight() / 2.; |
final double centerY = env.getMinY() + env.getHeight() / 2.; |
896 |
double newWidth2; |
double newWidth2 = 0; |
897 |
double newHeight2; |
double newHeight2 = 0; |
898 |
if (scale < getMaxZoomScale()) { |
if (scale < getMaxZoomScale()) { |
899 |
// **************************************************************************** |
// **************************************************************************** |
900 |
// Wir zoomen weiter rein als erlaubt => Anpassen des envelope |
// Wir zoomen weiter rein als erlaubt => Anpassen des envelope |
911 |
// **************************************************************************** |
// **************************************************************************** |
912 |
// Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen |
// Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen |
913 |
// **************************************************************************** |
// **************************************************************************** |
914 |
return env; |
newArea = env; |
915 |
} |
} |
916 |
|
|
917 |
Coordinate ll = new Coordinate(centerX - newWidth2, centerY |
if (newArea == null) { |
918 |
- newHeight2); |
|
919 |
Coordinate ur = new Coordinate(centerX + newWidth2, centerY |
final Coordinate ll = new Coordinate(centerX - newWidth2, centerY |
920 |
+ newHeight2); |
- newHeight2); |
921 |
|
final Coordinate ur = new Coordinate(centerX + newWidth2, centerY |
922 |
|
+ newHeight2); |
923 |
|
|
924 |
|
newArea = new Envelope(ll, ur); |
925 |
|
} |
926 |
|
|
927 |
|
Envelope maxAllowedExtend = getMaxExtend(); |
928 |
|
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
929 |
|
&& newArea != null && !newArea.isNull() |
930 |
|
&& !Double.isNaN(newArea.getMinX()) |
931 |
|
&& !Double.isNaN(newArea.getMaxX()) |
932 |
|
&& !Double.isNaN(newArea.getMinY()) |
933 |
|
&& !Double.isNaN(newArea.getMaxY())) { |
934 |
|
/* |
935 |
|
* If a maxExtend is set, we have to honour that... |
936 |
|
*/ |
937 |
|
|
938 |
|
// Exceeds top? Move down and maybe cut |
939 |
|
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
940 |
|
double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY(); |
941 |
|
// LOGGER.debug("Moving area down by " + divY); |
942 |
|
|
943 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
944 |
|
newArea.getMinY() - divY), new Coordinate(newArea |
945 |
|
.getMaxX(), newArea.getMaxY() - divY)); |
946 |
|
|
947 |
|
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
948 |
|
// LOGGER.debug("Now it exeeds the bottom border.. cut!"); |
949 |
|
// And cut the bottom if it moved out of the area |
950 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
951 |
|
maxAllowedExtend.getMinY()), new Coordinate(newArea |
952 |
|
.getMaxX(), newArea.getMaxY())); |
953 |
|
|
954 |
|
// LOGGER.debug("and fix aspect ratio"); |
955 |
|
|
956 |
|
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
957 |
|
false); |
958 |
|
} |
959 |
|
} |
960 |
|
|
961 |
|
// Exceeds bottom? Move up and maybe cut |
962 |
|
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
963 |
|
double divY = newArea.getMinY() - maxAllowedExtend.getMinY(); |
964 |
|
// LOGGER.debug("Moving area up by " + divY); |
965 |
|
|
966 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
967 |
|
newArea.getMinY() - divY), new Coordinate(newArea |
968 |
|
.getMaxX(), newArea.getMaxY() - divY)); |
969 |
|
|
970 |
|
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
971 |
|
// LOGGER.debug("Now it exeeds the top border.. cut!"); |
972 |
|
// And cut the bottom if it moved out of the area |
973 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
974 |
|
newArea.getMinY()), new Coordinate(newArea |
975 |
|
.getMaxX(), maxAllowedExtend.getMaxY())); |
976 |
|
|
977 |
|
// LOGGER.debug("and fix aspect ratio"); |
978 |
|
|
979 |
|
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
980 |
|
false); |
981 |
|
} |
982 |
|
} |
983 |
|
|
984 |
|
// Exceeds to the right? move and maybe cut |
985 |
|
if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) { |
986 |
|
|
987 |
|
// Move left.. |
988 |
|
double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX(); |
989 |
|
// LOGGER.debug("Moving area left by " + divX); |
990 |
|
|
991 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX() - divX, |
992 |
|
newArea.getMinY()), new Coordinate(newArea.getMaxX() |
993 |
|
- divX, newArea.getMaxY())); |
994 |
|
|
995 |
|
if (newArea.getMinX() < maxAllowedExtend.getMinX()) { |
996 |
|
// LOGGER.debug("Now it exeeds the left border.. cut!"); |
997 |
|
// And cut the left if it moved out of the area |
998 |
|
newArea = new Envelope(new Coordinate(maxAllowedExtend |
999 |
|
.getMinX(), newArea.getMinY()), new Coordinate( |
1000 |
|
newArea.getMaxX(), newArea.getMaxY())); |
1001 |
|
|
1002 |
|
// LOGGER.debug("and fix aspect ratio"); |
1003 |
|
|
1004 |
return new Envelope(ll, ur); |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
1005 |
|
false); |
1006 |
|
} |
1007 |
|
} |
1008 |
|
|
1009 |
|
// Exceeds to the left? move and maybe cut |
1010 |
|
if (newArea.getMinX() < maxAllowedExtend.getMinX()) { |
1011 |
|
|
1012 |
|
// Move right.. |
1013 |
|
double divX = newArea.getMinX() - maxAllowedExtend.getMinX(); |
1014 |
|
// LOGGER.debug("Moving area right by " + divX); |
1015 |
|
|
1016 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX() - divX, |
1017 |
|
newArea.getMinY()), new Coordinate(newArea.getMaxX() |
1018 |
|
- divX, newArea.getMaxY())); |
1019 |
|
|
1020 |
|
if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) { |
1021 |
|
// LOGGER.debug("Now it exeeds the right border.. cut!"); |
1022 |
|
// And cut the left if it moved out of the area |
1023 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
1024 |
|
newArea.getMinY()), new Coordinate(maxAllowedExtend |
1025 |
|
.getMaxX(), newArea.getMaxY())); |
1026 |
|
|
1027 |
|
// LOGGER.debug("and fix aspect ratio"); |
1028 |
|
|
1029 |
|
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
1030 |
|
false); |
1031 |
|
} |
1032 |
|
} |
1033 |
|
|
1034 |
|
} |
1035 |
|
|
1036 |
|
return newArea; |
1037 |
} |
} |
1038 |
|
|
1039 |
/** |
/** |
1060 |
|
|
1061 |
/** |
/** |
1062 |
* Set the maximum allowed zoom scale. This is the smaller number value of |
* Set the maximum allowed zoom scale. This is the smaller number value of |
1063 |
* the two. |
* the two. If <code>null</code> is passed, Double.MINVALUE are used which |
1064 |
|
* mean there is no restriction. |
1065 |
* |
* |
1066 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
1067 |
* Krüger</a> |
* Krüger</a> |
1068 |
*/ |
*/ |
1069 |
public void setMaxZoomScale(Double maxZoomScale) { |
public void setMaxZoomScale(final Double maxZoomScale) { |
1070 |
// System.out.println("setting max scale to "+maxZoomScale); |
this.maxZoomScale = maxZoomScale == null ? Double.MIN_VALUE |
1071 |
this.maxZoomScale = maxZoomScale; |
: maxZoomScale; |
1072 |
} |
} |
1073 |
|
|
1074 |
/** |
/** |
1075 |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
1076 |
* value of the two. |
* value of the two. If <code>null</code> is passed, Double.MAXVALUE are |
1077 |
|
* used which mean there is no restriction. |
1078 |
|
* |
1079 |
* |
* |
1080 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
1081 |
* Krüger</a> |
* Krüger</a> |
1082 |
*/ |
*/ |
1083 |
public void setMinZoomScale(Double minZoomScale) { |
public void setMinZoomScale(final Double minZoomScale) { |
1084 |
this.minZoomScale = minZoomScale; |
this.minZoomScale = minZoomScale == null ? Double.MAX_VALUE |
1085 |
|
: minZoomScale; |
1086 |
|
} |
1087 |
|
|
1088 |
|
/** |
1089 |
|
* Defines an evelope of the viwable area. The JMapPane will never show |
1090 |
|
* anything outside of this extend. |
1091 |
|
* |
1092 |
|
* @param maxExtend |
1093 |
|
* <code>null</code> to not have this restriction. |
1094 |
|
*/ |
1095 |
|
public void setMaxExtend(Envelope maxExtend) { |
1096 |
|
this.maxExtend = maxExtend; |
1097 |
|
} |
1098 |
|
|
1099 |
|
/** |
1100 |
|
* Returns the evelope of the viewable area. The JMapPane will never show |
1101 |
|
* anything outside of this extend. If this has been set to |
1102 |
|
* <code>null</code> via {@link #setMaxExtend(Envelope)}, it tries to return |
1103 |
|
* quickly the context's bounds. It it takes to long to determine the |
1104 |
|
* context bounds, <code>null</code> is returned. |
1105 |
|
* |
1106 |
|
* @param maxExtend |
1107 |
|
* <code>null</code> to not have this restriction. |
1108 |
|
*/ |
1109 |
|
|
1110 |
|
public Envelope getMaxExtend() { |
1111 |
|
if (maxExtend == null) { |
1112 |
|
try { |
1113 |
|
return JTSUtil.fixAspectRatio(this.getBounds(), |
1114 |
|
// Kartenbereich um 10% vergroessern |
1115 |
|
JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1), |
1116 |
|
true); |
1117 |
|
} catch (IOException e) { |
1118 |
|
LOGGER |
1119 |
|
.warn( |
1120 |
|
"maxExtend == null; failed to getLayerBounds of context", |
1121 |
|
e); |
1122 |
|
} |
1123 |
|
} |
1124 |
|
return maxExtend; |
1125 |
|
} |
1126 |
|
|
1127 |
|
/** |
1128 |
|
* Set the background color of the map. |
1129 |
|
* @param if <code>null</code>, white is used. |
1130 |
|
*/ |
1131 |
|
public void setMapBackgroundColor(Color bgColor) { |
1132 |
|
if (bgColor == null) bgColor = Color.WHITE; |
1133 |
|
this.mapBackgroundColor = bgColor; |
1134 |
|
} |
1135 |
|
|
1136 |
|
/** |
1137 |
|
* Returns the background {@link Color} of the map pane. Default is white. |
1138 |
|
**/ |
1139 |
|
public Color getMapBackgroundColor() { |
1140 |
|
return mapBackgroundColor; |
1141 |
} |
} |
|
// xulu.en |
|
1142 |
|
|
1143 |
} |
} |