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> |
20 |
* Code taken from gt-2.4.2 to make some changes (marked with {@code xulu}), |
* Code taken from gt-2.4.5 to make some changes (marked with {@code xulu}), |
21 |
* which can not be realized in a subclass:</b> |
* which can not be realized in a subclass:</b> |
22 |
* <ul> |
* <ul> |
23 |
* <li>{@link #getMapArea()} declared as {@code final}<li> |
* <li>{@link #getMapArea()} declared as {@code final}<li> |
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, PropertyChangeListener, |
MouseMotionListener, PropertyChangeListener, MapLayerListListener { |
82 |
MapLayerListListener { |
private static Logger LOGGER = Logger.getLogger(JMapPane.class); |
|
private static Logger LOGGER = Logger.getLogger( JMapPane.class.getName() ); |
|
|
/** |
|
|
* |
|
|
*/ |
|
|
private static final long serialVersionUID = -8647971481359690499L; |
|
83 |
|
|
84 |
public static final int Reset = 0; |
private static final long serialVersionUID = -8647971481359690499L; |
85 |
|
|
86 |
public static final int ZoomIn = 1; |
public static final int Reset = 0; |
87 |
|
|
88 |
public static final int ZoomOut = 2; |
public static final int ZoomIn = 1; |
89 |
|
|
90 |
public static final int Pan = 3; |
public static final int ZoomOut = 2; |
91 |
|
|
92 |
public static final int Select = 4; |
public static final int Pan = 3; |
93 |
|
|
94 |
private static final int POLYGON = 0; |
public static final int Select = 4; |
95 |
|
|
96 |
private static final int LINE = 1; |
/** |
97 |
|
* what renders the map |
98 |
|
*/ |
99 |
|
GTRenderer renderer; |
100 |
|
|
101 |
private static final int POINT = 2; |
/** |
102 |
|
* the map context to render |
103 |
|
*/ |
104 |
|
MapContext context; |
105 |
|
|
106 |
/** |
/** |
107 |
* what renders the map |
* the area of the map to draw |
108 |
*/ |
*/ |
109 |
GTRenderer renderer; |
protected Envelope mapArea; |
110 |
|
|
111 |
private GTRenderer highlightRenderer, selectionRenderer; |
/** |
112 |
|
* the size of the pane last time we drew |
113 |
|
*/ |
114 |
|
protected Rectangle oldRect = null; |
115 |
|
|
116 |
/** |
/** |
117 |
* the map context to render |
* the last map area drawn. |
118 |
*/ |
*/ |
119 |
MapContext context; |
protected Envelope oldMapArea = null; |
120 |
|
|
121 |
private MapContext selectionContext; |
/** |
122 |
|
* the base image of the map |
123 |
|
*/ |
124 |
|
protected BufferedImage baseImage, panningImage; |
125 |
|
|
126 |
/** |
/** |
127 |
* the area of the map to draw |
* a factory for filters |
128 |
*/ |
*/ |
129 |
//xulu.sc |
FilterFactory2 ff; |
|
// Envelope mapArea; |
|
|
protected Envelope mapArea; |
|
|
//xulu.ec |
|
130 |
|
|
131 |
/** |
/** |
132 |
* the size of the pane last time we drew |
* a factory for geometries |
133 |
*/ |
*/ |
134 |
//xulu.sc |
GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null); |
|
// private Rectangle oldRect = null; |
|
|
protected Rectangle oldRect = null; |
|
|
//xulu.ec |
|
135 |
|
|
136 |
/** |
private int state = ZoomIn; |
|
* the last map area drawn. |
|
|
*/ |
|
|
//xulu.sc |
|
|
// private Envelope oldMapArea = null; |
|
|
protected Envelope oldMapArea = null; |
|
|
//xulu.ec |
|
137 |
|
|
138 |
/** |
/** |
139 |
* the base image of the map |
* how far to zoom in or out |
140 |
*/ |
*/ |
141 |
protected BufferedImage baseImage, panningImage; |
private double zoomFactor = 2.0; |
|
// SK: private BufferedImage baseImage, panningImage; |
|
142 |
|
|
143 |
/** |
boolean changed = true; |
|
* image of selection |
|
|
*/ |
|
|
private BufferedImage selectImage; |
|
144 |
|
|
145 |
/** |
LabelCache labelCache = new LabelCacheImpl(); |
|
* style for selected items |
|
|
*/ |
|
|
private Style selectionStyle; |
|
146 |
|
|
147 |
/** |
protected boolean reset = false; |
|
* layer that selection works on |
|
|
*/ |
|
|
private MapLayer selectionLayer; |
|
148 |
|
|
149 |
/** |
int startX; |
|
* layer that highlight works on |
|
|
*/ |
|
|
private MapLayer highlightLayer; |
|
150 |
|
|
151 |
/** |
int startY; |
|
* the object which manages highlighting |
|
|
*/ |
|
|
private HighlightManager highlightManager; |
|
152 |
|
|
153 |
/** |
/** |
154 |
* is highlighting on or off |
* If not <code>null</code>, the {@link JMapPane} will not allow to zoom/pan |
155 |
*/ |
* out of that area |
156 |
private boolean highlight = true; |
**/ |
157 |
|
private Envelope maxExtend = null; |
158 |
|
|
159 |
/** |
// /** |
160 |
* a factory for filters |
// * 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 |
FilterFactory2 ff; |
// **/ |
163 |
|
// boolean maxExtendForceMode = true; |
164 |
|
|
165 |
/** |
private boolean clickable; |
|
* a factory for geometries |
|
|
*/ |
|
|
GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null); |
|
166 |
|
|
167 |
/** |
int lastX; |
|
* the collections of features to be selected or highlighted |
|
|
*/ |
|
|
FeatureCollection selection; |
|
168 |
|
|
169 |
/** |
int lastY; |
|
* the collections of features to be selected or highlighted |
|
|
*/ |
|
|
FeatureCollection highlightFeature; |
|
170 |
|
|
171 |
private int state = ZoomIn; |
private Double maxZoomScale = Double.MIN_VALUE; |
172 |
|
private Double minZoomScale = Double.MAX_VALUE; |
173 |
|
|
174 |
/** |
/** |
175 |
* how far to zoom in or out |
* Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses |
176 |
*/ |
* Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu |
177 |
private double zoomFactor = 2.0; |
* setzen. |
178 |
|
*/ |
|
Style lineHighlightStyle; |
|
|
|
|
|
Style pointHighlightStyle; |
|
|
|
|
|
Style polygonHighlightStyle; |
|
|
|
|
|
Style polygonSelectionStyle; |
|
|
|
|
|
Style pointSelectionStyle; |
|
|
|
|
|
Style lineSelectionStyle; |
|
|
|
|
|
boolean changed = true; |
|
|
|
|
|
LabelCache labelCache = new LabelCacheDefault(); |
|
|
|
|
|
//xulu.sc |
|
|
// private boolean reset = false; |
|
|
protected boolean reset = false; |
|
|
//xulu.ec |
|
|
|
|
|
int startX; |
|
|
|
|
|
int startY; |
|
|
|
|
|
private boolean clickable; |
|
|
|
|
|
int lastX; |
|
|
|
|
|
int lastY; |
|
|
|
|
|
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. |
|
|
*/ |
|
179 |
private boolean panning_started = false; |
private boolean panning_started = false; |
|
// sk.en |
|
180 |
|
|
181 |
public JMapPane() { |
/** |
182 |
this(null, true, null, null); |
* This color is used as the default background color when painting a map. |
183 |
} |
*/ |
184 |
|
private Color mapBackgroundColor = Color.WHITE; |
185 |
/** |
|
186 |
* create a basic JMapPane |
public JMapPane() { |
187 |
* |
this(null, true, null, null); |
188 |
* @param render - |
} |
189 |
* how to draw the map |
|
190 |
* @param context - |
/** |
191 |
* the map context to display |
* create a basic JMapPane |
192 |
*/ |
* |
193 |
public JMapPane(GTRenderer render, MapContext context) { |
* @param render |
194 |
this(null, true, render, context); |
* - how to draw the map |
195 |
} |
* @param context |
196 |
|
* - the map context to display |
197 |
/** |
*/ |
198 |
* full constructor extending JPanel |
public JMapPane(final GTRenderer render, final MapContext context) { |
199 |
* |
this(null, true, render, context); |
200 |
* @param layout - |
} |
201 |
* layout (probably shouldn't be set) |
|
202 |
* @param isDoubleBuffered - |
/** |
203 |
* a Swing thing I don't really understand |
* full constructor extending JPanel |
204 |
* @param render - |
* |
205 |
* what to draw the map with |
* @param layout |
206 |
* @param context - |
* - layout (probably shouldn't be set) |
207 |
* what to draw |
* @param isDoubleBuffered |
208 |
*/ |
* - a Swing thing I don't really understand |
209 |
public JMapPane(LayoutManager layout, boolean isDoubleBuffered, |
* @param render |
210 |
GTRenderer render, MapContext context) { |
* - what to draw the map with |
211 |
super(layout, isDoubleBuffered); |
* @param context |
212 |
|
* - what to draw |
213 |
ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder |
*/ |
214 |
.getFilterFactory(null); |
public JMapPane(final LayoutManager layout, final boolean isDoubleBuffered, |
215 |
setRenderer(render); |
final GTRenderer render, final MapContext context) { |
216 |
|
super(layout, isDoubleBuffered); |
217 |
setContext(context); |
|
218 |
|
ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder |
219 |
this.addMouseListener(this); |
.getFilterFactory(null); |
220 |
this.addMouseMotionListener(this); |
setRenderer(render); |
221 |
setHighlightManager(new HighlightManager(highlightLayer)); |
|
222 |
setSelectionManager(new SelectionManager(selectionLayer)); |
setContext(context); |
223 |
lineHighlightStyle = setupStyle(LINE, Color.red); |
|
224 |
|
this.addMouseListener(this); |
225 |
pointHighlightStyle = setupStyle(POINT, Color.red); |
this.addMouseMotionListener(this); |
226 |
|
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); |
227 |
polygonHighlightStyle = setupStyle(POLYGON, Color.red); |
} |
228 |
|
|
229 |
polygonSelectionStyle = setupStyle(POLYGON, Color.cyan); |
/** |
230 |
|
* get the renderer |
231 |
pointSelectionStyle = setupStyle(POINT, Color.cyan); |
*/ |
232 |
|
public GTRenderer getRenderer() { |
233 |
lineSelectionStyle = setupStyle(LINE, Color.cyan); |
return renderer; |
234 |
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); |
} |
235 |
} |
|
236 |
|
public void setRenderer(final GTRenderer renderer) { |
237 |
/** |
Map<Object, Object> hints = new HashMap<Object, Object>(); |
238 |
* get the renderer |
|
239 |
*/ |
this.renderer = renderer; |
240 |
public GTRenderer getRenderer() { |
// MS: Apply hint also for ShapeFileRenderer |
241 |
return renderer; |
// if (renderer instanceof StreamingRenderer) { |
242 |
} |
hints = renderer.getRendererHints(); |
243 |
|
if (hints == null) { |
244 |
public void setRenderer(GTRenderer renderer) { |
hints = new HashMap<Object, Object>(); |
245 |
Map hints = new HashMap(); |
} |
246 |
if (renderer instanceof StreamingRenderer) { |
if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) { |
247 |
hints = renderer.getRendererHints(); |
labelCache = (LabelCache) hints |
248 |
if (hints == null) { |
.get(StreamingRenderer.LABEL_CACHE_KEY); |
249 |
hints = new HashMap(); |
} else { |
250 |
} |
hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache); |
251 |
if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) { |
} |
252 |
labelCache = (LabelCache) hints |
|
253 |
.get(StreamingRenderer.LABEL_CACHE_KEY); |
hints.put("memoryPreloadingEnabled", Boolean.TRUE); |
254 |
} else { |
|
255 |
hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache); |
renderer.setRendererHints(hints); |
256 |
} |
// } |
257 |
renderer.setRendererHints(hints); |
|
258 |
} |
if (this.context != null) { |
259 |
|
this.renderer.setContext(this.context); |
260 |
this.renderer = renderer; |
} |
261 |
this.highlightRenderer = new StreamingRenderer(); |
} |
262 |
this.selectionRenderer = new StreamingRenderer(); |
|
263 |
|
public MapContext getContext() { |
264 |
hints.put("memoryPreloadingEnabled", Boolean.FALSE); |
return context; |
265 |
highlightRenderer.setRendererHints(hints); |
} |
266 |
selectionRenderer.setRendererHints(hints); |
|
267 |
|
public void setContext(final MapContext context) { |
268 |
if (this.context != null) { |
if (this.context != null) { |
269 |
this.renderer.setContext(this.context); |
this.context.removeMapLayerListListener(this); |
270 |
} |
} |
271 |
} |
|
272 |
|
this.context = context; |
273 |
public MapContext getContext() { |
|
274 |
return context; |
if (context != null) { |
275 |
} |
this.context.addMapLayerListListener(this); |
276 |
|
} |
277 |
public void setContext(MapContext context) { |
|
278 |
if (this.context != null) { |
if (renderer != null) { |
279 |
this.context.removeMapLayerListListener(this); |
renderer.setContext(this.context); |
280 |
} |
} |
281 |
|
} |
282 |
this.context = context; |
|
283 |
|
public Envelope getMapArea() { |
284 |
if (context != null) { |
return mapArea; |
285 |
this.context.addMapLayerListListener(this); |
} |
286 |
} |
|
287 |
|
public void setMapArea(final Envelope mapArea) { |
288 |
if (renderer != null) { |
this.mapArea = mapArea; |
289 |
renderer.setContext(this.context); |
} |
290 |
} |
|
291 |
} |
public int getState() { |
292 |
|
return state; |
293 |
public Envelope getMapArea() { |
} |
294 |
return mapArea; |
|
295 |
} |
public void setState(final int state) { |
296 |
|
this.state = state; |
297 |
public void setMapArea(Envelope mapArea) { |
|
298 |
this.mapArea = mapArea; |
// System.out.println("State: " + state); |
299 |
} |
} |
300 |
|
|
301 |
public int getState() { |
public double getZoomFactor() { |
302 |
return state; |
return zoomFactor; |
303 |
} |
} |
304 |
|
|
305 |
public void setState(int state) { |
public void setZoomFactor(final double zoomFactor) { |
306 |
this.state = state; |
this.zoomFactor = zoomFactor; |
307 |
|
} |
308 |
// System.out.println("State: " + state); |
|
309 |
} |
protected void paintComponent(final Graphics g) { |
310 |
|
super.paintComponent(g); |
311 |
public double getZoomFactor() { |
|
312 |
return zoomFactor; |
if ((renderer == null) || (mapArea == null)) { |
313 |
} |
return; |
314 |
|
} |
315 |
public void setZoomFactor(double zoomFactor) { |
|
316 |
this.zoomFactor = zoomFactor; |
final Rectangle r = getBounds(); |
317 |
} |
final Rectangle dr = new Rectangle(r.width, r.height); |
318 |
|
|
319 |
public MapLayer getSelectionLayer() { |
if (!r.equals(oldRect) || reset) { |
320 |
return selectionLayer; |
if (!r.equals(oldRect) && (mapArea == null)) { |
321 |
} |
try { |
322 |
|
mapArea = context.getLayerBounds(); |
323 |
public void setSelectionLayer(MapLayer selectionLayer) { |
} catch (final IOException e) { |
324 |
this.selectionLayer = selectionLayer; |
LOGGER.warn("context.getLayerBounds()", e); |
325 |
if(selectionManager!=null) { |
} |
326 |
selectionManager.setSelectionLayer(selectionLayer); |
} |
327 |
} |
|
328 |
} |
if (mapArea != null) { |
329 |
|
/* either the viewer size has changed or we've done a reset */ |
330 |
public boolean isHighlight() { |
changed = true; /* note we need to redraw */ |
331 |
return highlight; |
reset = false; /* forget about the reset */ |
332 |
} |
oldRect = r; /* store what the current size is */ |
333 |
|
|
334 |
public void setHighlight(boolean highlight) { |
mapArea = JTSUtil.fixAspectRatio(r, mapArea, false); |
335 |
this.highlight = highlight; |
} |
336 |
} |
} |
337 |
|
|
338 |
public MapLayer getHighlightLayer() { |
if (!mapArea.equals(oldMapArea)) { /* did the map extent change? */ |
339 |
return highlightLayer; |
changed = true; |
340 |
} |
oldMapArea = mapArea; |
341 |
|
// when we tell the context that the bounds have changed WMSLayers |
342 |
public void setHighlightLayer(MapLayer highlightLayer) { |
// can refresh them selves |
343 |
this.highlightLayer = highlightLayer; |
context.setAreaOfInterest(mapArea, context |
344 |
|
.getCoordinateReferenceSystem()); |
345 |
if (highlightManager != null) { |
} |
346 |
highlightManager.setHighlightLayer(highlightLayer); |
|
347 |
} |
if (changed) { /* if the map changed then redraw */ |
348 |
} |
changed = false; |
349 |
|
|
350 |
public HighlightManager getHighlightManager() { |
// The baseImage should not have alpha |
351 |
return highlightManager; |
baseImage = new BufferedImage(dr.width, dr.height, |
352 |
} |
BufferedImage.TYPE_INT_RGB); |
353 |
|
|
354 |
public void setHighlightManager(HighlightManager highlightManager) { |
final Graphics2D ig = baseImage.createGraphics(); |
355 |
this.highlightManager = highlightManager; |
ig.setBackground(getMapBackgroundColor()); |
356 |
this.highlightManager.addHighlightChangeListener(this); |
ig.fillRect(0, 0, dr.width, dr.height); |
357 |
this.addMouseMotionListener(this.highlightManager); |
|
358 |
} |
// /* System.out.println("rendering"); */ |
359 |
|
if (renderer.getContext() != null) |
360 |
public Style getLineHighlightStyle() { |
renderer.setContext(context); |
361 |
return lineHighlightStyle; |
|
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 |
public void setLineHighlightStyle(Style lineHighlightStyle) { |
|
365 |
this.lineHighlightStyle = lineHighlightStyle; |
// draw the map |
366 |
} |
renderer.paint(ig, dr, mapArea); |
367 |
|
|
368 |
public Style getLineSelectionStyle() { |
// TODO nur machen, wenn panning beginnt |
369 |
return lineSelectionStyle; |
panningImage = new BufferedImage(dr.width, dr.height, |
370 |
} |
BufferedImage.TYPE_INT_RGB); |
371 |
|
|
372 |
public void setLineSelectionStyle(Style lineSelectionStyle) { |
} |
373 |
this.lineSelectionStyle = lineSelectionStyle; |
|
374 |
} |
((Graphics2D) g).drawImage(baseImage, 0, 0, this); |
375 |
|
} |
376 |
public Style getPointHighlightStyle() { |
|
377 |
return pointHighlightStyle; |
public void mouseClicked(final MouseEvent e) { |
378 |
} |
if (mapArea == null) |
379 |
|
return; |
380 |
public void setPointHighlightStyle(Style pointHighlightStyle) { |
// System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+" |
381 |
this.pointHighlightStyle = pointHighlightStyle; |
// h:"+mapArea.getHeight()); |
382 |
} |
final Rectangle bounds = this.getBounds(); |
383 |
|
final double x = (double) (e.getX()); |
384 |
public Style getPointSelectionStyle() { |
final double y = (double) (e.getY()); |
385 |
return pointSelectionStyle; |
final double width = mapArea.getWidth(); |
386 |
} |
final double height = mapArea.getHeight(); |
387 |
|
// xulu.sc |
388 |
public void setPointSelectionStyle(Style pointSelectionStyle) { |
// double width2 = mapArea.getWidth() / 2.0; |
389 |
this.pointSelectionStyle = pointSelectionStyle; |
// double height2 = mapArea.getHeight() / 2.0; |
390 |
} |
final double width2 = width / 2.0; |
391 |
|
final double height2 = height / 2.0; |
392 |
public Style getPolygonHighlightStyle() { |
// xulu.ec |
393 |
return polygonHighlightStyle; |
final double mapX = ((x * width) / (double) bounds.width) |
394 |
} |
+ mapArea.getMinX(); |
395 |
|
final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height) |
396 |
public void setPolygonHighlightStyle(Style polygonHighlightStyle) { |
+ mapArea.getMinY(); |
397 |
this.polygonHighlightStyle = polygonHighlightStyle; |
|
398 |
} |
/* |
399 |
|
* System.out.println(""+x+"->"+mapX); |
400 |
public Style getPolygonSelectionStyle() { |
* System.out.println(""+y+"->"+mapY); |
401 |
return polygonSelectionStyle; |
*/ |
402 |
} |
|
403 |
|
/* |
404 |
public void setPolygonSelectionStyle(Style polygonSelectionStyle) { |
* Coordinate ll = new Coordinate(mapArea.getMinX(), mapArea.getMinY()); |
405 |
this.polygonSelectionStyle = polygonSelectionStyle; |
* Coordinate ur = new Coordinate(mapArea.getMaxX(), mapArea.getMaxY()); |
406 |
} |
*/ |
407 |
|
double zlevel = 1.0; |
408 |
protected void paintComponent(Graphics g) { |
|
409 |
super.paintComponent(g); |
switch (state) { |
410 |
|
case Pan: |
411 |
if ((renderer == null) || (mapArea == null) ) { |
zlevel = 1.0; |
412 |
return; |
// xulu.sc SK: return here.. a mouselistener is managing the PANNING |
413 |
} |
// break; |
414 |
|
return; |
415 |
Rectangle r = getBounds(); |
// xulu.ec |
416 |
Rectangle dr = new Rectangle(r.width, r.height); |
case ZoomIn: |
417 |
|
zlevel = zoomFactor; |
418 |
if (!r.equals(oldRect) || reset) { |
|
419 |
if(!r.equals(oldRect) && (mapArea == null)) { |
break; |
420 |
try { |
|
421 |
mapArea=context.getLayerBounds(); |
case ZoomOut: |
422 |
} catch (IOException e) { |
zlevel = 1.0 / zoomFactor; |
423 |
// TODO Auto-generated catch block |
|
424 |
e.printStackTrace(); |
break; |
425 |
} |
// |
426 |
} |
// case Select: |
427 |
|
// doSelection(mapX, mapY, selectionLayer); |
428 |
if (mapArea != null){ |
// |
429 |
/* either the viewer size has changed or we've done a reset */ |
// return; |
430 |
changed = true; /* note we need to redraw */ |
|
431 |
reset = false; /* forget about the reset */ |
default: |
432 |
oldRect = r; /* store what the current size is */ |
return; |
433 |
|
} |
434 |
mapArea = fixAspectRatio(r, mapArea); |
|
435 |
} |
final Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY |
436 |
} |
- (height2 / zlevel)); |
437 |
|
final Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY |
438 |
if (!mapArea.equals(oldMapArea)) { /* did the map extent change? */ |
+ (height2 / zlevel)); |
439 |
changed = true; |
// xulu.sc SK: Check for min/max scale |
440 |
oldMapArea = mapArea; |
// mapArea = new Envelope(ll, ur); |
441 |
// when we tell the context that the bounds have changed WMSLayers |
final Envelope newMapArea = new Envelope(ll, ur); |
442 |
// can refresh them selves |
setMapArea(bestAllowedMapArea(newMapArea)); |
443 |
context.setAreaOfInterest(mapArea, context |
// xulu.ec |
444 |
.getCoordinateReferenceSystem()); |
|
445 |
} |
// sk.ec |
446 |
|
|
447 |
if (changed) { /* if the map changed then redraw */ |
// System.out.println("after area "+mapArea+"\nw:"+mapArea.getWidth()+" |
448 |
changed = false; |
// h:"+mapArea.getHeight()); |
449 |
baseImage = new BufferedImage(dr.width, dr.height, |
repaint(); |
450 |
BufferedImage.TYPE_INT_ARGB); |
} |
451 |
|
|
452 |
Graphics2D ig = baseImage.createGraphics(); |
public void mouseEntered(final MouseEvent e) { |
453 |
/* System.out.println("rendering"); */ |
} |
454 |
renderer.setContext(context); |
|
455 |
labelCache.clear(); // work around anoying labelcache bug |
public void mouseExited(final MouseEvent e) { |
456 |
|
} |
457 |
|
|
458 |
// draw the map |
public void mousePressed(final MouseEvent e) { |
459 |
renderer.paint((Graphics2D) ig, dr, mapArea); |
startX = e.getX(); |
460 |
|
startY = e.getY(); |
461 |
// TODO , nur machen, wenn panning beginnt |
lastX = 0; |
462 |
panningImage = new BufferedImage(dr.width, dr.height, |
lastY = 0; |
463 |
BufferedImage.TYPE_INT_RGB); |
} |
464 |
|
|
465 |
} |
public void mouseReleased(final MouseEvent e) { |
466 |
|
final int endX = e.getX(); |
467 |
((Graphics2D) g).drawImage(baseImage, 0, 0, this); |
final int endY = e.getY(); |
468 |
|
|
469 |
if ((selection != null) && (selection.size() > 0)) { |
processDrag(startX, startY, endX, endY, e); |
470 |
// paint selection |
lastX = 0; |
471 |
|
lastY = 0; |
472 |
String type = selectionLayer.getFeatureSource().getSchema() |
|
473 |
.getDefaultGeometry().getType().getName(); |
/** |
474 |
/*String type = selection.getDefaultGeometry().getGeometryType();*/ |
* Es wird nicht (mehr) gepannt! |
475 |
/*System.out.println(type);*/ |
*/ |
476 |
if (type == null) |
panning_started = false; |
477 |
type = "polygon"; |
} |
478 |
|
|
479 |
/* String type = "point"; */ |
public void mouseDragged(final MouseEvent e) { |
480 |
|
final Graphics graphics = this.getGraphics(); |
481 |
if (type.toLowerCase().endsWith("polygon")) { |
final int x = e.getX(); |
482 |
selectionStyle = polygonSelectionStyle; |
final int y = e.getY(); |
483 |
} else if (type.toLowerCase().endsWith("point")) { |
|
484 |
selectionStyle = pointSelectionStyle; |
if ((state == JMapPane.Pan) |
485 |
} else if (type.toLowerCase().endsWith("line")) { |
|| ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
486 |
selectionStyle = lineSelectionStyle; |
/** |
487 |
} |
* SK: Der Cursor wird auf PANNING gesetzt. |
488 |
|
*/ |
489 |
selectionContext = new DefaultMapContext(DefaultGeographicCRS.WGS84); |
if (panning_started == false) { |
490 |
|
panning_started = true; |
491 |
selectionContext.addLayer(selection, selectionStyle); |
setCursor(SwingUtil.PANNING_CURSOR); |
492 |
selectionRenderer.setContext(selectionContext); |
} |
493 |
|
|
494 |
selectImage = new BufferedImage(dr.width, dr.height, |
// move the image with the mouse |
495 |
BufferedImage.TYPE_INT_ARGB); |
if ((lastX > 0) && (lastY > 0)) { |
496 |
|
final int dx = lastX - startX; |
497 |
Graphics2D ig = selectImage.createGraphics(); |
final int dy = lastY - startY; |
498 |
/* System.out.println("rendering selection"); */ |
// System.out.println("translate "+dx+","+dy); |
499 |
selectionRenderer.paint((Graphics2D) ig, dr, mapArea); |
final Graphics2D g2 = panningImage.createGraphics(); |
500 |
|
g2.setBackground(getMapBackgroundColor()); |
501 |
((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); |
|
|
} |
|
|
|
|
|
public void doSelection(double x, double y, MapLayer layer) { |
|
|
|
|
|
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)) { |
|
|
return ; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
String name = layer.getFeatureSource().getSchema() |
|
|
.getDefaultGeometry().getName(); |
|
|
|
|
|
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) { |
|
|
// 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); |
|
|
*/ |
|
|
|
|
|
/* |
|
|
* Coordinate ll = new Coordinate(mapArea.getMinX(), mapArea.getMinY()); |
|
|
* Coordinate ur = new Coordinate(mapArea.getMaxX(), mapArea.getMaxY()); |
|
|
*/ |
|
|
double zlevel = 1.0; |
|
|
|
|
|
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; |
|
|
|
|
|
break; |
|
|
|
|
|
case ZoomOut: |
|
|
zlevel = 1.0 / zoomFactor; |
|
|
|
|
|
break; |
|
|
|
|
|
case Select: |
|
|
doSelection(mapX, mapY, selectionLayer); |
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
default: |
|
|
return; |
|
|
} |
|
|
|
|
|
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 |
|
|
|
|
|
// System.out.println("after area "+mapArea+"\nw:"+mapArea.getWidth()+" |
|
|
// h:"+mapArea.getHeight()); |
|
|
repaint(); |
|
|
} |
|
|
|
|
|
public void mouseEntered(MouseEvent e) { |
|
|
} |
|
|
|
|
|
public void mouseExited(MouseEvent e) { |
|
|
} |
|
|
|
|
|
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... |
|
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); |
505 |
} |
} |
506 |
|
|
507 |
lastX = x; |
lastX = x; |
508 |
lastY = y; |
lastY = y; |
509 |
} else |
} else |
510 |
|
|
511 |
if ((state == JMapPane.ZoomIn) || (state == JMapPane.ZoomOut)) { |
if ((state == JMapPane.ZoomIn) || (state == JMapPane.ZoomOut)) { |
512 |
|
|
513 |
|
graphics.setXORMode(Color.WHITE); |
514 |
graphics.setXORMode(Color.WHITE); |
|
515 |
|
if ((lastX > 0) && (lastY > 0)) { |
516 |
if ((lastX > 0) && (lastY > 0)) { |
drawRectangle(graphics); |
517 |
drawRectangle(graphics); |
} |
518 |
} |
|
519 |
|
// draw new box |
520 |
// draw new box |
lastX = x; |
521 |
lastX = x; |
lastY = y; |
522 |
lastY = y; |
drawRectangle(graphics); |
523 |
drawRectangle(graphics); |
} |
524 |
} else if (state == JMapPane.Select && selectionLayer != null) { |
// else if (state == JMapPane.Select && selectionLayer != null) { |
525 |
|
// |
526 |
// construct a new bbox filter |
// // construct a new bbox filter |
527 |
Rectangle bounds = this.getBounds(); |
// final Rectangle bounds = this.getBounds(); |
528 |
|
// |
529 |
double mapWidth = mapArea.getWidth(); |
// final double mapWidth = mapArea.getWidth(); |
530 |
double mapHeight = mapArea.getHeight(); |
// final double mapHeight = mapArea.getHeight(); |
531 |
|
// |
532 |
double x1 = ((this.startX * mapWidth) / (double) bounds.width) |
// final double x1 = ((this.startX * mapWidth) / (double) bounds.width) |
533 |
+ mapArea.getMinX(); |
// + mapArea.getMinX(); |
534 |
double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height) |
// final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / |
535 |
+ mapArea.getMinY(); |
// (double) bounds.height) |
536 |
double x2 = ((x * mapWidth) / (double) bounds.width) |
// + mapArea.getMinY(); |
537 |
+ mapArea.getMinX(); |
// final double x2 = ((x * mapWidth) / (double) bounds.width) |
538 |
double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height) |
// + mapArea.getMinX(); |
539 |
+ mapArea.getMinY(); |
// final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) |
540 |
double left = Math.min(x1, x2); |
// bounds.height) |
541 |
double right = Math.max(x1, x2); |
// + mapArea.getMinY(); |
542 |
double bottom = Math.min(y1, y2); |
// final double left = Math.min(x1, x2); |
543 |
double top = Math.max(y1, y2); |
// final double right = Math.max(x1, x2); |
544 |
|
// final double bottom = Math.min(y1, y2); |
545 |
|
// final double top = Math.max(y1, y2); |
546 |
String name = selectionLayer.getFeatureSource().getSchema() |
// |
547 |
.getDefaultGeometry().getName(); |
// String name = selectionLayer.getFeatureSource().getSchema() |
548 |
|
// .getDefaultGeometry().getName(); |
549 |
if (name == "") { |
// |
550 |
name = "the_geom"; |
// if (name == "") { |
551 |
} |
// name = "the_geom"; |
552 |
Filter bb = ff.bbox(ff.property(name), left, bottom, right, top, |
// } |
553 |
getContext().getCoordinateReferenceSystem().toString()); |
// final Filter bb = ff.bbox(ff.property(name), left, bottom, right, |
554 |
if(selectionManager!=null) { |
// top, |
555 |
selectionManager.selectionChanged(this, bb); |
// getContext().getCoordinateReferenceSystem().toString()); |
556 |
} |
// if (selectionManager != null) { |
557 |
|
// selectionManager.selectionChanged(this, bb); |
558 |
graphics.setXORMode(Color.green); |
// } |
559 |
|
// |
560 |
/* |
// graphics.setXORMode(Color.green); |
561 |
* if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); } |
// |
562 |
*/ |
// /* |
563 |
|
// * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); } |
564 |
// draw new box |
// */ |
565 |
lastX = x; |
// |
566 |
lastY = y; |
// // draw new box |
567 |
drawRectangle(graphics); |
// lastX = x; |
568 |
} |
// lastY = y; |
569 |
|
// drawRectangle(graphics); |
570 |
} |
// } |
571 |
|
|
572 |
// sk.cs |
} |
573 |
// private void processDrag(int x1, int y1, int x2, int y2) { |
|
574 |
// sk.ce |
// sk.cs |
575 |
protected void processDrag(int x1, int y1, int x2, int y2, MouseEvent e) { |
// private void processDrag(int x1, int y1, int x2, int y2) { |
576 |
|
// sk.ce |
577 |
/**** |
protected void processDrag(final int x1, final int y1, final int x2, |
578 |
* If no layer is availabe we dont want a NullPointerException |
final int y2, final MouseEvent e) { |
579 |
*/ |
|
580 |
if (mapArea == null) return; |
/**** |
581 |
|
* If no layers exist, we ignore the drag. |
582 |
// System.out.println("processing drag from " + x1 + "," + y1 + " -> " |
*/ |
583 |
// + x2 + "," + y2); |
if (context.getLayerCount() <= 0) { |
584 |
if ((x1 == x2) && (y1 == y2)) { |
return; |
585 |
if (isClickable()) { |
} |
586 |
mouseClicked(new MouseEvent(this, 0, new Date().getTime(), 0, |
|
587 |
x1, y1, y2, false)); |
// System.out.println("processing drag from " + x1 + "," + y1 + " -> " |
588 |
} |
// + x2 + "," + y2); |
589 |
|
if ((x1 == x2) && (y1 == y2)) { |
590 |
return; |
if (isClickable()) { |
591 |
} |
mouseClicked(new MouseEvent(this, 0, new Date().getTime(), 0, |
592 |
|
x1, y1, y2, false)); |
593 |
Rectangle bounds = this.getBounds(); |
} |
594 |
|
|
595 |
double mapWidth = mapArea.getWidth(); |
return; |
596 |
double mapHeight = mapArea.getHeight(); |
} |
597 |
|
|
598 |
double startX = ((x1 * mapWidth) / (double) bounds.width) |
final Rectangle bounds = this.getBounds(); |
599 |
+ mapArea.getMinX(); |
|
600 |
double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height) |
final double mapWidth = mapArea.getWidth(); |
601 |
+ mapArea.getMinY(); |
final double mapHeight = mapArea.getHeight(); |
602 |
double endX = ((x2 * mapWidth) / (double) bounds.width) |
|
603 |
+ mapArea.getMinX(); |
final double startX = ((x1 * mapWidth) / (double) bounds.width) |
604 |
double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height) |
+ mapArea.getMinX(); |
605 |
+ mapArea.getMinY(); |
final double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height) |
606 |
|
+ mapArea.getMinY(); |
607 |
if ( (state == JMapPane.Pan) || (e.getButton()== MouseEvent.BUTTON3)) { |
final double endX = ((x2 * mapWidth) / (double) bounds.width) |
608 |
// move the image with the mouse |
+ mapArea.getMinX(); |
609 |
// calculate X offsets from start point to the end Point |
final double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height) |
610 |
double deltaX1 = endX - startX; |
+ mapArea.getMinY(); |
611 |
|
|
612 |
// System.out.println("deltaX " + deltaX1); |
if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) { |
613 |
// new edges |
// move the image with the mouse |
614 |
double left = mapArea.getMinX() - deltaX1; |
// calculate X offsets from start point to the end Point |
615 |
double right = mapArea.getMaxX() - deltaX1; |
final double deltaX1 = endX - startX; |
616 |
|
|
617 |
// now for Y |
// System.out.println("deltaX " + deltaX1); |
618 |
double deltaY1 = endY - startY; |
// new edges |
619 |
|
final double left = mapArea.getMinX() - deltaX1; |
620 |
// System.out.println("deltaY " + deltaY1); |
final double right = mapArea.getMaxX() - deltaX1; |
621 |
double bottom = mapArea.getMinY() - deltaY1; |
|
622 |
double top = mapArea.getMaxY() - deltaY1; |
// now for Y |
623 |
Coordinate ll = new Coordinate(left, bottom); |
final double deltaY1 = endY - startY; |
624 |
Coordinate ur = new Coordinate(right, top); |
|
625 |
//xulu.sc |
// System.out.println("deltaY " + deltaY1); |
626 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
final double bottom = mapArea.getMinY() - deltaY1; |
627 |
setMapArea( fixAspectRatio(this.getBounds(), new Envelope(ll, ur)) ); |
final double top = mapArea.getMaxY() - deltaY1; |
628 |
//xulu.ec |
final Coordinate ll = new Coordinate(left, bottom); |
629 |
} else if (state == JMapPane.ZoomIn) { |
final Coordinate ur = new Coordinate(right, top); |
630 |
|
// xulu.sc |
631 |
|
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
632 |
// Zu kleine Flächen sollen nicht gezoomt werden. |
|
633 |
//sk.bc |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
634 |
if ( (Math.abs(x1-x2) * Math.abs(y2-y1) )<100 ) return; |
// xulu.ec |
635 |
// sk.ec |
} else if (state == JMapPane.ZoomIn) { |
636 |
|
|
637 |
drawRectangle(this.getGraphics()); |
// Zu kleine Flächen sollen nicht gezoomt werden. |
638 |
// make the dragged rectangle (in map coords) the new BBOX |
// sk.bc |
639 |
double left = Math.min(startX, endX); |
if ((Math.abs(x1 - x2) * Math.abs(y2 - y1)) < 150) |
640 |
double right = Math.max(startX, endX); |
return; |
641 |
double bottom = Math.min(startY, endY); |
// sk.ec |
642 |
double top = Math.max(startY, endY); |
|
643 |
Coordinate ll = new Coordinate(left, bottom); |
drawRectangle(this.getGraphics()); |
644 |
Coordinate ur = new Coordinate(right, top); |
// make the dragged rectangle (in map coords) the new BBOX |
645 |
//xulu.sc |
final double left = Math.min(startX, endX); |
646 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
final double right = Math.max(startX, endX); |
647 |
setMapArea( fixAspectRatio(this.getBounds(), new Envelope(ll, ur)) ); |
final double bottom = Math.min(startY, endY); |
648 |
//xulu.ec |
final double top = Math.max(startY, endY); |
649 |
} else if (state == JMapPane.ZoomOut) { |
final Coordinate ll = new Coordinate(left, bottom); |
650 |
drawRectangle(this.getGraphics()); |
final Coordinate ur = new Coordinate(right, top); |
651 |
|
// xulu.sc |
652 |
// make the dragged rectangle in screen coords the new map size? |
|
653 |
double left = Math.min(startX, endX); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
654 |
double right = Math.max(startX, endX); |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
655 |
double bottom = Math.min(startY, endY); |
|
656 |
double top = Math.max(startY, endY); |
// sk.sc |
657 |
double nWidth = (mapWidth * mapWidth) / (right - left); |
{ |
658 |
double nHeight = (mapHeight * mapHeight) / (top - bottom); |
// // SK tries to paint a preview of the zoom ;-9 aha.... well |
659 |
double deltaX1 = left - mapArea.getMinX(); |
// |
660 |
double nDeltaX1 = (deltaX1 * nWidth) / mapWidth; |
// double reductionFactor = 1/8.; |
661 |
double deltaY1 = bottom - mapArea.getMinY(); |
//// |
662 |
double nDeltaY1 = (deltaY1 * nHeight) / mapHeight; |
//// BufferedImage reducedBaseImage = new BufferedImage((int)(baseImage.getWidth()*reductionFactor), (int)(baseImage.getHeight()*reductionFactor), BufferedImage.TYPE_INT_RGB); |
663 |
Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1, |
//// Graphics2D reducedG = (Graphics2D) reducedBaseImage.getGraphics(); |
664 |
mapArea.getMinY() - nDeltaY1); |
// AffineTransform reductionTransform =new AffineTransform(); |
665 |
double deltaX2 = mapArea.getMaxX() - right; |
// reductionTransform.scale(reductionFactor, reductionFactor); |
666 |
double nDeltaX2 = (deltaX2 * nWidth) / mapWidth; |
//// reducedG.drawImage(baseImage, reductionTransform, null); |
667 |
double deltaY2 = mapArea.getMaxY() - top; |
// |
668 |
double nDeltaY2 = (deltaY2 * nHeight) / mapHeight; |
// Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics(); |
669 |
Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2, |
//// graphics.getTransform().scale(reductionFactor, reductionFactor); |
670 |
mapArea.getMaxY() + nDeltaY2); |
// |
671 |
//xulu.sc |
// graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
672 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
673 |
setMapArea( fixAspectRatio(this.getBounds(), new Envelope(ll, ur)) ); |
// graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
674 |
//xulu.ec |
// RenderingHints.VALUE_ANTIALIAS_OFF); |
675 |
} else if (state == JMapPane.Select && selectionLayer !=null) { |
// graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
676 |
double left = Math.min(startX, endX); |
// RenderingHints.VALUE_RENDER_SPEED); |
677 |
double right = Math.max(startX, endX); |
// graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(), |
678 |
double bottom = Math.min(startY, endY); |
// JMapPane.this.getHeight(), x1, y1, x2, y2, null); |
679 |
double top = Math.max(startY, endY); |
} |
680 |
|
// xulu.ec |
681 |
|
} else if (state == JMapPane.ZoomOut) { |
682 |
String name = selectionLayer.getFeatureSource().getSchema() |
drawRectangle(this.getGraphics()); |
683 |
.getDefaultGeometry().getLocalName(); |
|
684 |
|
// make the dragged rectangle in screen coords the new map size? |
685 |
if (name == "") { |
final double left = Math.min(startX, endX); |
686 |
name = "the_geom"; |
final double right = Math.max(startX, endX); |
687 |
} |
final double bottom = Math.min(startY, endY); |
688 |
Filter bb = ff.bbox(ff.property(name), left, bottom, right, top, |
final double top = Math.max(startY, endY); |
689 |
getContext().getCoordinateReferenceSystem().toString()); |
final double nWidth = (mapWidth * mapWidth) / (right - left); |
690 |
//System.out.println(bb.toString()); |
final double nHeight = (mapHeight * mapHeight) / (top - bottom); |
691 |
if(selectionManager!=null) { |
final double deltaX1 = left - mapArea.getMinX(); |
692 |
selectionManager.selectionChanged(this, bb); |
final double nDeltaX1 = (deltaX1 * nWidth) / mapWidth; |
693 |
} |
final double deltaY1 = bottom - mapArea.getMinY(); |
694 |
/*FeatureCollection fc; |
final double nDeltaY1 = (deltaY1 * nHeight) / mapHeight; |
695 |
selection = null; |
final Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1, |
696 |
try { |
mapArea.getMinY() - nDeltaY1); |
697 |
fc = selectionLayer.getFeatureSource().getFeatures(bb); |
final double deltaX2 = mapArea.getMaxX() - right; |
698 |
selection = fc; |
final double nDeltaX2 = (deltaX2 * nWidth) / mapWidth; |
699 |
} catch (IOException e) { |
final double deltaY2 = mapArea.getMaxY() - top; |
700 |
e.printStackTrace(); |
final double nDeltaY2 = (deltaY2 * nHeight) / mapHeight; |
701 |
} |
final Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2, |
702 |
*/ |
mapArea.getMaxY() + nDeltaY2); |
703 |
} |
// xulu.sc |
704 |
|
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
705 |
//xulu.so |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
706 |
// setMapArea(mapArea); |
|
707 |
//xulu.eo |
// xulu.ec |
708 |
repaint(); |
} |
709 |
} |
// else if (state == JMapPane.Select && selectionLayer != null) { |
710 |
|
// final double left = Math.min(startX, endX); |
711 |
private boolean isClickable() { |
// final double right = Math.max(startX, endX); |
712 |
return clickable; |
// final double bottom = Math.min(startY, endY); |
713 |
} |
// final double top = Math.max(startY, endY); |
714 |
|
// |
715 |
private org.geotools.styling.Style setupStyle(int type, Color color) { |
// String name = selectionLayer.getFeatureSource().getSchema() |
716 |
StyleFactory sf = org.geotools.factory.CommonFactoryFinder |
// .getDefaultGeometry().getLocalName(); |
717 |
.getStyleFactory(null); |
// |
718 |
StyleBuilder sb = new StyleBuilder(); |
// if (name == "") { |
719 |
|
// name = "the_geom"; |
720 |
org.geotools.styling.Style s = sf.createStyle(); |
// } |
721 |
s.setTitle("selection"); |
// final Filter bb = ff.bbox(ff.property(name), left, bottom, right, |
722 |
|
// top, |
723 |
// TODO parameterise the color |
// getContext().getCoordinateReferenceSystem().toString()); |
724 |
PolygonSymbolizer ps = sb.createPolygonSymbolizer(color); |
// // System.out.println(bb.toString()); |
725 |
ps.setStroke(sb.createStroke(color)); |
// if (selectionManager != null) { |
726 |
|
// selectionManager.selectionChanged(this, bb); |
727 |
LineSymbolizer ls = sb.createLineSymbolizer(color); |
// } |
728 |
Graphic h = sb.createGraphic(); |
// /* |
729 |
h.setMarks(new Mark[] { sb.createMark("square", color) }); |
// * FeatureCollection fc; selection = null; try { fc = |
730 |
|
// * selectionLayer.getFeatureSource().getFeatures(bb); selection = |
731 |
PointSymbolizer pts = sb.createPointSymbolizer(h); |
// * fc; } catch (IOException e) { e.printStackTrace(); } |
732 |
|
// */ |
733 |
// Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts}); |
// } |
734 |
switch (type) { |
|
735 |
case POLYGON: |
// xulu.so |
736 |
s = sb.createStyle(ps); |
// setMapArea(mapArea); |
737 |
|
// xulu.eo |
738 |
break; |
repaint(); |
739 |
|
} |
740 |
case POINT: |
|
741 |
s = sb.createStyle(pts); |
private boolean isClickable() { |
742 |
|
return clickable; |
743 |
break; |
} |
744 |
|
|
745 |
case LINE: |
// |
746 |
s = sb.createStyle(ls); |
// private org.geotools.styling.Style setupStyle(final int type, final Color |
747 |
} |
// color) { |
748 |
|
// final StyleFactory sf = org.geotools.factory.CommonFactoryFinder |
749 |
return s; |
// .getStyleFactory(null); |
750 |
} |
// final StyleBuilder sb = new StyleBuilder(); |
751 |
|
// |
752 |
public void highlightChanged(HighlightChangedEvent e) { |
// org.geotools.styling.Style s = sf.createStyle(); |
753 |
org.opengis.filter.Filter f = e.getFilter(); |
// s.setTitle("selection"); |
754 |
|
// |
755 |
try { |
// // TODO parameterise the color |
756 |
highlightFeature = highlightLayer.getFeatureSource().getFeatures(f); |
// final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color); |
757 |
} catch (IOException e1) { |
// ps.setStroke(sb.createStroke(color)); |
758 |
// TODO Auto-generated catch block |
// |
759 |
e1.printStackTrace(); |
// final LineSymbolizer ls = sb.createLineSymbolizer(color); |
760 |
} |
// final Graphic h = sb.createGraphic(); |
761 |
|
// h.setMarks(new Mark[] { sb.createMark("square", color) }); |
762 |
repaint(); |
// |
763 |
} |
// final PointSymbolizer pts = sb.createPointSymbolizer(h); |
764 |
|
// |
765 |
public void propertyChange(PropertyChangeEvent evt) { |
// // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts}); |
766 |
String prop = evt.getPropertyName(); |
// switch (type) { |
767 |
|
// case POLYGON: |
768 |
if (prop.equalsIgnoreCase("crs")) { |
// s = sb.createStyle(ps); |
769 |
context.setAreaOfInterest(context.getAreaOfInterest(), |
// |
770 |
(CoordinateReferenceSystem) evt.getNewValue()); |
// break; |
771 |
} |
// |
772 |
} |
// case POINT: |
773 |
|
// s = sb.createStyle(pts); |
774 |
public boolean isReset() { |
// |
775 |
return reset; |
// break; |
776 |
} |
// |
777 |
|
// case LINE: |
778 |
public void setReset(boolean reset) { |
// s = sb.createStyle(ls); |
779 |
this.reset = reset; |
// } |
780 |
} |
// |
781 |
|
// return s; |
782 |
public void layerAdded(MapLayerListEvent event) { |
// } |
783 |
changed = true; |
|
784 |
|
public void propertyChange(final PropertyChangeEvent evt) { |
785 |
if (context.getLayers().length == 1) { // the first one |
final String prop = evt.getPropertyName(); |
786 |
|
|
787 |
try { |
if (prop.equalsIgnoreCase("crs")) { |
788 |
//xulu.sc |
context.setAreaOfInterest(context.getAreaOfInterest(), |
789 |
// mapArea = context.getLayerBounds(); |
(CoordinateReferenceSystem) evt.getNewValue()); |
790 |
mapArea = context.getAreaOfInterest(); |
} |
791 |
if ( mapArea == null ) |
} |
792 |
mapArea = context.getLayerBounds(); |
|
793 |
//xulu.ec |
public boolean isReset() { |
794 |
} catch (IOException e) { |
return reset; |
795 |
// TODO Auto-generated catch block |
} |
796 |
e.printStackTrace(); |
|
797 |
} |
public void setReset(final boolean reset) { |
798 |
|
this.reset = reset; |
799 |
reset = true; |
} |
800 |
} |
|
801 |
|
public void layerAdded(final MapLayerListEvent event) { |
802 |
repaint(); |
changed = true; |
803 |
} |
|
804 |
|
if (context.getLayers().length == 1) { // the first one |
805 |
public void layerRemoved(MapLayerListEvent event) { |
|
806 |
changed = true; |
try { |
807 |
repaint(); |
// xulu.sc |
808 |
} |
// mapArea = context.getLayerBounds(); |
809 |
|
mapArea = context.getAreaOfInterest(); |
810 |
public void layerChanged(MapLayerListEvent event) { |
if (mapArea == null) |
811 |
changed = true; |
mapArea = context.getLayerBounds(); |
812 |
// System.out.println("layer changed - repaint"); |
// xulu.ec |
813 |
repaint(); |
} catch (final IOException e) { |
814 |
} |
// TODO Auto-generated catch block |
815 |
|
e.printStackTrace(); |
816 |
public void layerMoved(MapLayerListEvent event) { |
} |
817 |
changed = true; |
|
818 |
repaint(); |
reset = true; |
819 |
} |
} |
820 |
|
|
821 |
protected void drawRectangle(Graphics graphics) { |
repaint(); |
822 |
// undraw last box/draw new box |
} |
823 |
int left = Math.min(startX, lastX); |
|
824 |
int right = Math.max(startX, lastX); |
public void layerRemoved(final MapLayerListEvent event) { |
825 |
int top = Math.max(startY, lastY); |
changed = true; |
826 |
int bottom = Math.min(startY, lastY); |
repaint(); |
827 |
int width = right - left; |
} |
828 |
int height = top - bottom; |
|
829 |
// System.out.println("drawing rect("+left+","+bottom+","+ width+","+ |
public void layerChanged(final MapLayerListEvent event) { |
830 |
// height+")"); |
changed = true; |
831 |
graphics.drawRect(left, bottom, width, height); |
// System.out.println("layer changed - repaint"); |
832 |
} |
repaint(); |
833 |
|
} |
834 |
/** |
|
835 |
* if clickable is set to true then a single click on the map pane will zoom |
public void layerMoved(final MapLayerListEvent event) { |
836 |
* or pan the map. |
changed = true; |
837 |
* |
repaint(); |
838 |
* @param clickable |
} |
839 |
*/ |
|
840 |
public void setClickable(boolean clickable) { |
protected void drawRectangle(final Graphics graphics) { |
841 |
this.clickable = clickable; |
// undraw last box/draw new box |
842 |
} |
final int left = Math.min(startX, lastX); |
843 |
|
final int right = Math.max(startX, lastX); |
844 |
public void mouseMoved(MouseEvent e) { |
final int top = Math.max(startY, lastY); |
845 |
} |
final int bottom = Math.min(startY, lastY); |
846 |
|
final int width = right - left; |
847 |
public FeatureCollection getSelection() { |
final int height = top - bottom; |
848 |
return selection; |
// System.out.println("drawing rect("+left+","+bottom+","+ width+","+ |
849 |
} |
// height+")"); |
850 |
|
graphics.drawRect(left, bottom, width, height); |
851 |
public void setSelection(FeatureCollection selection) { |
} |
852 |
this.selection = selection; |
|
853 |
repaint(); |
/** |
854 |
} |
* if clickable is set to true then a single click on the map pane will zoom |
855 |
|
* or pan the map. |
856 |
/* (non-Javadoc) |
* |
857 |
* @see org.geotools.gui.swing.event.SelectionChangeListener#selectionChanged(org.geotools.gui.swing.event.SelectionChangedEvent) |
* @param clickable |
858 |
*/ |
*/ |
859 |
public void selectionChanged(SelectionChangedEvent e) { |
public void setClickable(final boolean clickable) { |
860 |
|
this.clickable = clickable; |
861 |
try { |
} |
862 |
selection = selectionLayer.getFeatureSource().getFeatures(e.getFilter()); |
|
863 |
repaint(); |
public void mouseMoved(final MouseEvent e) { |
864 |
} catch (IOException e1) { |
} |
865 |
e1.printStackTrace(); |
|
866 |
} |
// xulu.sn |
867 |
} |
/** |
868 |
|
* Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste |
869 |
public SelectionManager getSelectionManager() { |
* erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten |
870 |
return selectionManager; |
* werden, FALLS der uebergeben Envelope nicht schon gueltig sein sollte.<br/> |
871 |
} |
* Since 21. April 09: Before thecalculation starts, the aspect ratio is |
872 |
|
* corrected. This change implies, that setMapArea() will most of the time |
873 |
public void setSelectionManager(SelectionManager selectionManager) { |
* not allow setting to a wrong aspectRatio. |
874 |
this.selectionManager = selectionManager; |
* |
875 |
this.selectionManager.addSelectionChangeListener(this); |
* @author <a href="mailto:[email protected]">Stefan Alfons |
876 |
|
* Krüger</a> |
877 |
} |
*/ |
878 |
|
public Envelope bestAllowedMapArea(Envelope env) { |
879 |
|
if (getWidth() == 0) |
880 |
//xulu.sn |
return env; |
881 |
/** |
if (env == null) |
882 |
* Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste erlaubte Flaeche damit |
return env; |
883 |
* die Massstabsbeschaenkungen noch eingehalten werden, FALLS der uebergeben Envelope |
|
884 |
* nicht schon gueltig sein sollte. |
Envelope newArea = null; |
885 |
* |
|
886 |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
/** |
887 |
*/ |
* Correct the aspect Ratio before we check the rest. Otherwise we might |
888 |
public Envelope bestAllowedMapArea(Envelope env) { |
* easily fail. We allow to grow here, because we don't check against |
889 |
if (getWidth() == 0) return env; |
* the maxExtend |
890 |
if (env == null) return env; |
*/ |
891 |
|
env = JTSUtil.fixAspectRatio(this.getBounds(), env, true); |
892 |
double scale = env.getWidth() / getWidth(); |
|
893 |
double centerX = env.getMinX() + env.getWidth() / 2.; |
final double scale = env.getWidth() / getWidth(); |
894 |
double centerY = env.getMinY() + env.getHeight() / 2.; |
final double centerX = env.getMinX() + env.getWidth() / 2.; |
895 |
double newWidth2; |
final double centerY = env.getMinY() + env.getHeight() / 2.; |
896 |
double newHeight2; |
double newWidth2 = 0; |
897 |
if (scale < getMaxZoomScale()) { |
double newHeight2 = 0; |
898 |
//**************************************************************************** |
if (scale < getMaxZoomScale()) { |
899 |
// Wir zoomen weiter rein als erlaubt => Anpassen des envelope |
// **************************************************************************** |
900 |
//**************************************************************************** |
// Wir zoomen weiter rein als erlaubt => Anpassen des envelope |
901 |
newWidth2 = getMaxZoomScale() * getWidth() / 2.; |
// **************************************************************************** |
902 |
newHeight2 = getMaxZoomScale() * getHeight() / 2.; |
newWidth2 = getMaxZoomScale() * getWidth() / 2.; |
903 |
} else if (scale > getMinZoomScale()) { |
newHeight2 = getMaxZoomScale() * getHeight() / 2.; |
904 |
//**************************************************************************** |
} else if (scale > getMinZoomScale()) { |
905 |
// Wir zoomen weiter raus als erlaubt => Anpassen des envelope |
// **************************************************************************** |
906 |
//**************************************************************************** |
// Wir zoomen weiter raus als erlaubt => Anpassen des envelope |
907 |
newWidth2 = getMinZoomScale() * getWidth() / 2.; |
// **************************************************************************** |
908 |
newHeight2 = getMinZoomScale() * getHeight() / 2.; |
newWidth2 = getMinZoomScale() * getWidth() / 2.; |
909 |
} else { |
newHeight2 = getMinZoomScale() * getHeight() / 2.; |
910 |
//**************************************************************************** |
} else { |
911 |
// Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen |
// **************************************************************************** |
912 |
//**************************************************************************** |
// Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen |
913 |
return env; |
// **************************************************************************** |
914 |
} |
newArea = env; |
915 |
|
} |
916 |
Coordinate ll = new Coordinate(centerX - newWidth2, centerY |
|
917 |
- newHeight2); |
if (newArea == null) { |
918 |
Coordinate ur = new Coordinate(centerX + newWidth2, centerY |
|
919 |
+ newHeight2); |
final Coordinate ll = new Coordinate(centerX - newWidth2, centerY |
920 |
|
- newHeight2); |
921 |
return new Envelope(ll, ur); |
final Coordinate ur = new Coordinate(centerX + newWidth2, centerY |
922 |
} |
+ newHeight2); |
923 |
|
|
924 |
/** |
newArea = new Envelope(ll, ur); |
925 |
* Retuns the minimum allowed zoom scale. This is the bigger number value of the two. |
} |
926 |
* Defaults to {@link Double}.MAX_VALUE |
|
927 |
* |
Envelope maxAllowedExtend = getMaxExtend(); |
928 |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
929 |
*/ |
&& newArea != null && !newArea.isNull() |
930 |
public Double getMinZoomScale() { |
&& !Double.isNaN(newArea.getMinX()) |
931 |
return minZoomScale; |
&& !Double.isNaN(newArea.getMaxX()) |
932 |
} |
&& !Double.isNaN(newArea.getMinY()) |
933 |
|
&& !Double.isNaN(newArea.getMaxY())) { |
934 |
/** |
/* |
935 |
* Retuns the maximum allowed zoom scale. This is the smaller number value of the two. |
* If a maxExtend is set, we have to honour that... |
936 |
* Defaults to {@link Double}.MIN_VALUE |
*/ |
937 |
* |
|
938 |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
// Exceeds top? Move down and maybe cut |
939 |
*/ |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
940 |
public Double getMaxZoomScale() { |
double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY(); |
941 |
return maxZoomScale; |
// LOGGER.debug("Moving area down by " + divY); |
942 |
} |
|
943 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
944 |
/** |
newArea.getMinY() - divY), new Coordinate(newArea |
945 |
* Set the maximum allowed zoom scale. This is the smaller number value of the two. |
.getMaxX(), newArea.getMaxY() - divY)); |
946 |
* |
|
947 |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
948 |
*/ |
// LOGGER.debug("Now it exeeds the bottom border.. cut!"); |
949 |
public void setMaxZoomScale(Double maxZoomScale) { |
// And cut the bottom if it moved out of the area |
950 |
// System.out.println("setting max scale to "+maxZoomScale); |
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
951 |
this.maxZoomScale = maxZoomScale; |
maxAllowedExtend.getMinY()), new Coordinate(newArea |
952 |
} |
.getMaxX(), newArea.getMaxY())); |
953 |
|
|
954 |
/** |
// LOGGER.debug("and fix aspect ratio"); |
955 |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number value of the two. |
|
956 |
* |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
957 |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
false); |
958 |
*/ |
} |
959 |
public void setMinZoomScale(Double minZoomScale) { |
} |
960 |
this.minZoomScale = minZoomScale; |
|
961 |
} |
// Exceeds bottom? Move up and maybe cut |
962 |
//xulu.en |
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 |
|
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 |
|
/** |
1040 |
|
* Retuns the minimum allowed zoom scale. This is the bigger number value of |
1041 |
|
* the two. Defaults to {@link Double}.MAX_VALUE |
1042 |
|
* |
1043 |
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
1044 |
|
* Krüger</a> |
1045 |
|
*/ |
1046 |
|
public Double getMinZoomScale() { |
1047 |
|
return minZoomScale; |
1048 |
|
} |
1049 |
|
|
1050 |
|
/** |
1051 |
|
* Retuns the maximum allowed zoom scale. This is the smaller number value |
1052 |
|
* of the two. Defaults to {@link Double}.MIN_VALUE |
1053 |
|
* |
1054 |
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
1055 |
|
* Krüger</a> |
1056 |
|
*/ |
1057 |
|
public Double getMaxZoomScale() { |
1058 |
|
return maxZoomScale; |
1059 |
|
} |
1060 |
|
|
1061 |
|
/** |
1062 |
|
* Set the maximum allowed zoom scale. This is the smaller number value of |
1063 |
|
* 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 |
1067 |
|
* Krüger</a> |
1068 |
|
*/ |
1069 |
|
public void setMaxZoomScale(final Double maxZoomScale) { |
1070 |
|
this.maxZoomScale = maxZoomScale == null ? Double.MIN_VALUE |
1071 |
|
: maxZoomScale; |
1072 |
|
} |
1073 |
|
|
1074 |
|
/** |
1075 |
|
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
1076 |
|
* 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 |
1081 |
|
* Krüger</a> |
1082 |
|
*/ |
1083 |
|
public void setMinZoomScale(final Double minZoomScale) { |
1084 |
|
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 |
|
} |
1142 |
|
|
1143 |
} |
} |