1 |
mojays |
2 |
/* |
2 |
|
|
* GeoTools - OpenSource mapping toolkit |
3 |
|
|
* http://geotools.org |
4 |
|
|
* (C) 2002-2006, GeoTools Project Managment Committee (PMC) |
5 |
|
|
* |
6 |
|
|
* This library is free software; you can redistribute it and/or |
7 |
|
|
* modify it under the terms of the GNU Lesser General Public |
8 |
|
|
* License as published by the Free Software Foundation; |
9 |
|
|
* version 2.1 of the License. |
10 |
|
|
* |
11 |
|
|
* This library is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
|
|
* Lesser General Public License for more details. |
15 |
|
|
*/ |
16 |
|
|
package org.geotools.gui.swing; |
17 |
|
|
|
18 |
|
|
/** |
19 |
|
|
* <b>Xulu:<br> |
20 |
mojays |
114 |
* Code taken from gt-2.4.5 to make some changes (marked with {@code xulu}), |
21 |
mojays |
2 |
* which can not be realized in a subclass:</b> |
22 |
|
|
* <ul> |
23 |
|
|
* <li>{@link #getMapArea()} declared as {@code final}<li> |
24 |
|
|
* <li>some variables declared as {@code protected}</li> |
25 |
|
|
* <li>minimal/maximal zoom scale</li> |
26 |
|
|
* <li>zoom in and zoom out via mouse click realized by setMapArea(..)</li> |
27 |
|
|
* </ul> |
28 |
|
|
* <br><br> |
29 |
|
|
* A simple map container that is a JPanel with a map in. provides simple |
30 |
|
|
* pan,zoom, highlight and selection The mappane stores an image of the map |
31 |
|
|
* (drawn from the context) and an image of the slected feature(s) to speed up |
32 |
|
|
* rendering of the highlights. Thus the whole map is only redrawn when the bbox |
33 |
|
|
* changes, selection is only redrawn when the selected feature changes. |
34 |
|
|
* |
35 |
|
|
* |
36 |
|
|
* @author Ian Turton |
37 |
|
|
* |
38 |
|
|
*/ |
39 |
|
|
|
40 |
|
|
import java.awt.Color; |
41 |
|
|
import java.awt.Cursor; |
42 |
|
|
import java.awt.Graphics; |
43 |
|
|
import java.awt.Graphics2D; |
44 |
|
|
import java.awt.LayoutManager; |
45 |
|
|
import java.awt.Rectangle; |
46 |
|
|
import java.awt.event.InputEvent; |
47 |
|
|
import java.awt.event.MouseEvent; |
48 |
|
|
import java.awt.event.MouseListener; |
49 |
|
|
import java.awt.event.MouseMotionListener; |
50 |
|
|
import java.awt.image.BufferedImage; |
51 |
|
|
import java.beans.PropertyChangeEvent; |
52 |
|
|
import java.beans.PropertyChangeListener; |
53 |
|
|
import java.io.IOException; |
54 |
|
|
import java.util.Date; |
55 |
|
|
import java.util.HashMap; |
56 |
|
|
import java.util.Map; |
57 |
|
|
|
58 |
|
|
import javax.swing.JPanel; |
59 |
|
|
|
60 |
|
|
import org.apache.log4j.Logger; |
61 |
|
|
import org.geotools.feature.FeatureCollection; |
62 |
|
|
import org.geotools.filter.IllegalFilterException; |
63 |
|
|
import org.geotools.map.DefaultMapContext; |
64 |
|
|
import org.geotools.map.MapContext; |
65 |
|
|
import org.geotools.map.MapLayer; |
66 |
|
|
import org.geotools.map.event.MapLayerListEvent; |
67 |
|
|
import org.geotools.map.event.MapLayerListListener; |
68 |
|
|
import org.geotools.referencing.crs.DefaultGeographicCRS; |
69 |
|
|
import org.geotools.renderer.GTRenderer; |
70 |
|
|
import org.geotools.renderer.lite.LabelCache; |
71 |
|
|
import org.geotools.renderer.lite.LabelCacheDefault; |
72 |
|
|
import org.geotools.renderer.lite.StreamingRenderer; |
73 |
alfonx |
226 |
import org.geotools.renderer.shape.TransitionShapefileRenderer; |
74 |
mojays |
2 |
import org.geotools.styling.Graphic; |
75 |
|
|
import org.geotools.styling.LineSymbolizer; |
76 |
|
|
import org.geotools.styling.Mark; |
77 |
|
|
import org.geotools.styling.PointSymbolizer; |
78 |
|
|
import org.geotools.styling.PolygonSymbolizer; |
79 |
|
|
import org.geotools.styling.Style; |
80 |
|
|
import org.geotools.styling.StyleBuilder; |
81 |
|
|
import org.geotools.styling.StyleFactory; |
82 |
|
|
import org.opengis.filter.Filter; |
83 |
|
|
import org.opengis.filter.FilterFactory2; |
84 |
|
|
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
85 |
|
|
|
86 |
|
|
import schmitzm.swing.SwingUtil; |
87 |
|
|
|
88 |
mojays |
320 |
import com.sun.jini.jeri.internal.runtime.SelectionManager; |
89 |
mojays |
2 |
import com.vividsolutions.jts.geom.Coordinate; |
90 |
|
|
import com.vividsolutions.jts.geom.Envelope; |
91 |
|
|
import com.vividsolutions.jts.geom.Geometry; |
92 |
|
|
import com.vividsolutions.jts.geom.GeometryFactory; |
93 |
|
|
|
94 |
|
|
public class JMapPane extends JPanel implements MouseListener, |
95 |
alfonx |
144 |
MouseMotionListener, HighlightChangeListener, SelectionChangeListener, |
96 |
|
|
PropertyChangeListener, MapLayerListListener { |
97 |
|
|
private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName()); |
98 |
alfonx |
153 |
|
99 |
alfonx |
144 |
private static final long serialVersionUID = -8647971481359690499L; |
100 |
mojays |
2 |
|
101 |
alfonx |
144 |
public static final int Reset = 0; |
102 |
mojays |
2 |
|
103 |
alfonx |
144 |
public static final int ZoomIn = 1; |
104 |
mojays |
2 |
|
105 |
alfonx |
144 |
public static final int ZoomOut = 2; |
106 |
mojays |
2 |
|
107 |
alfonx |
144 |
public static final int Pan = 3; |
108 |
mojays |
2 |
|
109 |
alfonx |
144 |
public static final int Select = 4; |
110 |
mojays |
2 |
|
111 |
alfonx |
144 |
private static final int POLYGON = 0; |
112 |
mojays |
2 |
|
113 |
alfonx |
144 |
private static final int LINE = 1; |
114 |
mojays |
2 |
|
115 |
alfonx |
144 |
private static final int POINT = 2; |
116 |
mojays |
2 |
|
117 |
alfonx |
144 |
/** |
118 |
|
|
* what renders the map |
119 |
|
|
*/ |
120 |
|
|
GTRenderer renderer; |
121 |
mojays |
2 |
|
122 |
alfonx |
144 |
private GTRenderer highlightRenderer, selectionRenderer; |
123 |
mojays |
2 |
|
124 |
alfonx |
144 |
/** |
125 |
|
|
* the map context to render |
126 |
|
|
*/ |
127 |
|
|
MapContext context; |
128 |
mojays |
2 |
|
129 |
alfonx |
144 |
private MapContext selectionContext; |
130 |
mojays |
2 |
|
131 |
alfonx |
144 |
/** |
132 |
|
|
* the area of the map to draw |
133 |
|
|
*/ |
134 |
|
|
// xulu.sc |
135 |
|
|
// Envelope mapArea; |
136 |
|
|
protected Envelope mapArea; |
137 |
|
|
// xulu.ec |
138 |
mojays |
2 |
|
139 |
alfonx |
144 |
/** |
140 |
|
|
* the size of the pane last time we drew |
141 |
|
|
*/ |
142 |
|
|
// xulu.sc |
143 |
|
|
// private Rectangle oldRect = null; |
144 |
|
|
protected Rectangle oldRect = null; |
145 |
|
|
// xulu.ec |
146 |
mojays |
2 |
|
147 |
alfonx |
144 |
/** |
148 |
|
|
* the last map area drawn. |
149 |
|
|
*/ |
150 |
|
|
// xulu.sc |
151 |
|
|
// private Envelope oldMapArea = null; |
152 |
|
|
protected Envelope oldMapArea = null; |
153 |
|
|
// xulu.ec |
154 |
mojays |
2 |
|
155 |
alfonx |
144 |
/** |
156 |
|
|
* the base image of the map |
157 |
|
|
*/ |
158 |
|
|
protected BufferedImage baseImage, panningImage; |
159 |
|
|
// SK: private BufferedImage baseImage, panningImage; |
160 |
mojays |
2 |
|
161 |
alfonx |
144 |
/** |
162 |
|
|
* image of selection |
163 |
|
|
*/ |
164 |
|
|
private BufferedImage selectImage; |
165 |
mojays |
2 |
|
166 |
alfonx |
144 |
/** |
167 |
|
|
* style for selected items |
168 |
|
|
*/ |
169 |
|
|
private Style selectionStyle; |
170 |
mojays |
2 |
|
171 |
alfonx |
144 |
/** |
172 |
|
|
* layer that selection works on |
173 |
|
|
*/ |
174 |
|
|
private MapLayer selectionLayer; |
175 |
mojays |
2 |
|
176 |
alfonx |
144 |
/** |
177 |
|
|
* layer that highlight works on |
178 |
|
|
*/ |
179 |
|
|
private MapLayer highlightLayer; |
180 |
mojays |
2 |
|
181 |
alfonx |
144 |
/** |
182 |
|
|
* the object which manages highlighting |
183 |
|
|
*/ |
184 |
|
|
private HighlightManager highlightManager; |
185 |
mojays |
2 |
|
186 |
alfonx |
144 |
/** |
187 |
|
|
* is highlighting on or off |
188 |
|
|
*/ |
189 |
|
|
private boolean highlight = true; |
190 |
mojays |
2 |
|
191 |
alfonx |
144 |
/** |
192 |
|
|
* a factory for filters |
193 |
|
|
*/ |
194 |
|
|
FilterFactory2 ff; |
195 |
mojays |
2 |
|
196 |
alfonx |
144 |
/** |
197 |
|
|
* a factory for geometries |
198 |
|
|
*/ |
199 |
|
|
GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null); |
200 |
mojays |
2 |
|
201 |
alfonx |
144 |
/** |
202 |
|
|
* the collections of features to be selected or highlighted |
203 |
|
|
*/ |
204 |
|
|
FeatureCollection selection; |
205 |
mojays |
2 |
|
206 |
alfonx |
144 |
/** |
207 |
|
|
* the collections of features to be selected or highlighted |
208 |
|
|
*/ |
209 |
|
|
FeatureCollection highlightFeature; |
210 |
mojays |
2 |
|
211 |
alfonx |
144 |
private int state = ZoomIn; |
212 |
mojays |
2 |
|
213 |
alfonx |
144 |
/** |
214 |
|
|
* how far to zoom in or out |
215 |
|
|
*/ |
216 |
|
|
private double zoomFactor = 2.0; |
217 |
mojays |
2 |
|
218 |
alfonx |
144 |
Style lineHighlightStyle; |
219 |
mojays |
2 |
|
220 |
alfonx |
144 |
Style pointHighlightStyle; |
221 |
mojays |
2 |
|
222 |
alfonx |
144 |
Style polygonHighlightStyle; |
223 |
mojays |
2 |
|
224 |
alfonx |
144 |
Style polygonSelectionStyle; |
225 |
mojays |
2 |
|
226 |
alfonx |
144 |
Style pointSelectionStyle; |
227 |
mojays |
2 |
|
228 |
alfonx |
144 |
Style lineSelectionStyle; |
229 |
mojays |
2 |
|
230 |
alfonx |
144 |
boolean changed = true; |
231 |
mojays |
2 |
|
232 |
alfonx |
144 |
LabelCache labelCache = new LabelCacheDefault(); |
233 |
mojays |
2 |
|
234 |
alfonx |
144 |
// xulu.sc |
235 |
|
|
// private boolean reset = false; |
236 |
|
|
protected boolean reset = false; |
237 |
|
|
// xulu.ec |
238 |
mojays |
2 |
|
239 |
alfonx |
144 |
int startX; |
240 |
mojays |
2 |
|
241 |
alfonx |
144 |
int startY; |
242 |
mojays |
2 |
|
243 |
alfonx |
144 |
private boolean clickable; |
244 |
mojays |
2 |
|
245 |
alfonx |
144 |
int lastX; |
246 |
mojays |
2 |
|
247 |
alfonx |
144 |
int lastY; |
248 |
mojays |
2 |
|
249 |
alfonx |
144 |
private SelectionManager selectionManager; |
250 |
|
|
// xulu.sn |
251 |
|
|
private Double maxZoomScale = Double.MIN_VALUE; |
252 |
|
|
private Double minZoomScale = Double.MAX_VALUE; |
253 |
|
|
// xulu.en |
254 |
mojays |
2 |
|
255 |
alfonx |
144 |
// sk.sn |
256 |
|
|
/** |
257 |
|
|
* Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses |
258 |
|
|
* Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu |
259 |
|
|
* setzen. |
260 |
|
|
*/ |
261 |
mojays |
2 |
private boolean panning_started = false; |
262 |
|
|
|
263 |
alfonx |
144 |
// sk.en |
264 |
mojays |
2 |
|
265 |
alfonx |
144 |
public JMapPane() { |
266 |
|
|
this(null, true, null, null); |
267 |
|
|
} |
268 |
mojays |
2 |
|
269 |
alfonx |
144 |
/** |
270 |
|
|
* create a basic JMapPane |
271 |
|
|
* |
272 |
|
|
* @param render |
273 |
|
|
* - how to draw the map |
274 |
|
|
* @param context |
275 |
|
|
* - the map context to display |
276 |
|
|
*/ |
277 |
alfonx |
307 |
public JMapPane(final GTRenderer render, final MapContext context) { |
278 |
alfonx |
144 |
this(null, true, render, context); |
279 |
|
|
} |
280 |
mojays |
2 |
|
281 |
alfonx |
144 |
/** |
282 |
|
|
* full constructor extending JPanel |
283 |
|
|
* |
284 |
|
|
* @param layout |
285 |
|
|
* - layout (probably shouldn't be set) |
286 |
|
|
* @param isDoubleBuffered |
287 |
|
|
* - a Swing thing I don't really understand |
288 |
|
|
* @param render |
289 |
|
|
* - what to draw the map with |
290 |
|
|
* @param context |
291 |
|
|
* - what to draw |
292 |
|
|
*/ |
293 |
alfonx |
307 |
public JMapPane(final LayoutManager layout, final boolean isDoubleBuffered, |
294 |
|
|
final GTRenderer render, final MapContext context) { |
295 |
alfonx |
144 |
super(layout, isDoubleBuffered); |
296 |
mojays |
2 |
|
297 |
alfonx |
144 |
ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder |
298 |
|
|
.getFilterFactory(null); |
299 |
|
|
setRenderer(render); |
300 |
mojays |
2 |
|
301 |
alfonx |
144 |
setContext(context); |
302 |
mojays |
2 |
|
303 |
alfonx |
144 |
this.addMouseListener(this); |
304 |
|
|
this.addMouseMotionListener(this); |
305 |
|
|
setHighlightManager(new HighlightManager(highlightLayer)); |
306 |
|
|
setSelectionManager(new SelectionManager(selectionLayer)); |
307 |
|
|
lineHighlightStyle = setupStyle(LINE, Color.red); |
308 |
mojays |
2 |
|
309 |
alfonx |
144 |
pointHighlightStyle = setupStyle(POINT, Color.red); |
310 |
mojays |
2 |
|
311 |
alfonx |
144 |
polygonHighlightStyle = setupStyle(POLYGON, Color.red); |
312 |
mojays |
2 |
|
313 |
alfonx |
144 |
polygonSelectionStyle = setupStyle(POLYGON, Color.cyan); |
314 |
mojays |
2 |
|
315 |
alfonx |
144 |
pointSelectionStyle = setupStyle(POINT, Color.cyan); |
316 |
mojays |
2 |
|
317 |
alfonx |
144 |
lineSelectionStyle = setupStyle(LINE, Color.cyan); |
318 |
|
|
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); |
319 |
|
|
} |
320 |
mojays |
2 |
|
321 |
alfonx |
144 |
/** |
322 |
|
|
* get the renderer |
323 |
|
|
*/ |
324 |
|
|
public GTRenderer getRenderer() { |
325 |
|
|
return renderer; |
326 |
|
|
} |
327 |
mojays |
2 |
|
328 |
alfonx |
307 |
public void setRenderer(final GTRenderer renderer) { |
329 |
alfonx |
144 |
Map hints = new HashMap(); |
330 |
alfonx |
307 |
|
331 |
|
|
this.renderer = renderer; |
332 |
|
|
|
333 |
alfonx |
226 |
if (renderer instanceof StreamingRenderer || renderer instanceof TransitionShapefileRenderer) { |
334 |
alfonx |
144 |
hints = renderer.getRendererHints(); |
335 |
|
|
if (hints == null) { |
336 |
|
|
hints = new HashMap(); |
337 |
|
|
} |
338 |
|
|
if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) { |
339 |
|
|
labelCache = (LabelCache) hints |
340 |
|
|
.get(StreamingRenderer.LABEL_CACHE_KEY); |
341 |
|
|
} else { |
342 |
|
|
hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache); |
343 |
|
|
} |
344 |
alfonx |
307 |
|
345 |
|
|
hints.put("memoryPreloadingEnabled", Boolean.TRUE); |
346 |
|
|
|
347 |
alfonx |
144 |
renderer.setRendererHints(hints); |
348 |
|
|
} |
349 |
mojays |
2 |
|
350 |
alfonx |
207 |
// this.highlightRenderer = new StreamingRenderer(); |
351 |
|
|
// this.selectionRenderer = new StreamingRenderer(); |
352 |
mojays |
2 |
|
353 |
alfonx |
207 |
// highlightRenderer.setRendererHints(hints); |
354 |
|
|
// selectionRenderer.setRendererHints(hints); |
355 |
alfonx |
307 |
|
356 |
|
|
// renderer.setRendererHints(hints); |
357 |
mojays |
2 |
|
358 |
alfonx |
144 |
if (this.context != null) { |
359 |
|
|
this.renderer.setContext(this.context); |
360 |
|
|
} |
361 |
|
|
} |
362 |
mojays |
2 |
|
363 |
alfonx |
144 |
public MapContext getContext() { |
364 |
|
|
return context; |
365 |
|
|
} |
366 |
mojays |
2 |
|
367 |
alfonx |
307 |
public void setContext(final MapContext context) { |
368 |
alfonx |
144 |
if (this.context != null) { |
369 |
|
|
this.context.removeMapLayerListListener(this); |
370 |
|
|
} |
371 |
mojays |
2 |
|
372 |
alfonx |
144 |
this.context = context; |
373 |
mojays |
2 |
|
374 |
alfonx |
144 |
if (context != null) { |
375 |
|
|
this.context.addMapLayerListListener(this); |
376 |
|
|
} |
377 |
mojays |
2 |
|
378 |
alfonx |
144 |
if (renderer != null) { |
379 |
|
|
renderer.setContext(this.context); |
380 |
|
|
} |
381 |
|
|
} |
382 |
mojays |
2 |
|
383 |
alfonx |
144 |
public Envelope getMapArea() { |
384 |
|
|
return mapArea; |
385 |
|
|
} |
386 |
mojays |
2 |
|
387 |
alfonx |
307 |
public void setMapArea(final Envelope mapArea) { |
388 |
alfonx |
144 |
this.mapArea = mapArea; |
389 |
|
|
} |
390 |
mojays |
2 |
|
391 |
alfonx |
144 |
public int getState() { |
392 |
|
|
return state; |
393 |
|
|
} |
394 |
mojays |
2 |
|
395 |
alfonx |
307 |
public void setState(final int state) { |
396 |
alfonx |
144 |
this.state = state; |
397 |
mojays |
2 |
|
398 |
alfonx |
144 |
// System.out.println("State: " + state); |
399 |
|
|
} |
400 |
mojays |
2 |
|
401 |
alfonx |
144 |
public double getZoomFactor() { |
402 |
|
|
return zoomFactor; |
403 |
|
|
} |
404 |
mojays |
2 |
|
405 |
alfonx |
307 |
public void setZoomFactor(final double zoomFactor) { |
406 |
alfonx |
144 |
this.zoomFactor = zoomFactor; |
407 |
|
|
} |
408 |
mojays |
2 |
|
409 |
alfonx |
144 |
public MapLayer getSelectionLayer() { |
410 |
|
|
return selectionLayer; |
411 |
|
|
} |
412 |
mojays |
2 |
|
413 |
alfonx |
307 |
public void setSelectionLayer(final MapLayer selectionLayer) { |
414 |
alfonx |
144 |
this.selectionLayer = selectionLayer; |
415 |
|
|
if (selectionManager != null) { |
416 |
|
|
selectionManager.setSelectionLayer(selectionLayer); |
417 |
|
|
} |
418 |
|
|
} |
419 |
mojays |
2 |
|
420 |
alfonx |
144 |
public boolean isHighlight() { |
421 |
|
|
return highlight; |
422 |
|
|
} |
423 |
mojays |
2 |
|
424 |
alfonx |
307 |
public void setHighlight(final boolean highlight) { |
425 |
alfonx |
144 |
this.highlight = highlight; |
426 |
|
|
} |
427 |
mojays |
2 |
|
428 |
alfonx |
144 |
public MapLayer getHighlightLayer() { |
429 |
|
|
return highlightLayer; |
430 |
|
|
} |
431 |
mojays |
2 |
|
432 |
alfonx |
307 |
public void setHighlightLayer(final MapLayer highlightLayer) { |
433 |
alfonx |
144 |
this.highlightLayer = highlightLayer; |
434 |
mojays |
2 |
|
435 |
alfonx |
144 |
if (highlightManager != null) { |
436 |
|
|
highlightManager.setHighlightLayer(highlightLayer); |
437 |
|
|
} |
438 |
|
|
} |
439 |
mojays |
2 |
|
440 |
alfonx |
144 |
public HighlightManager getHighlightManager() { |
441 |
|
|
return highlightManager; |
442 |
|
|
} |
443 |
mojays |
2 |
|
444 |
alfonx |
307 |
public void setHighlightManager(final HighlightManager highlightManager) { |
445 |
alfonx |
144 |
this.highlightManager = highlightManager; |
446 |
|
|
this.highlightManager.addHighlightChangeListener(this); |
447 |
|
|
this.addMouseMotionListener(this.highlightManager); |
448 |
|
|
} |
449 |
mojays |
2 |
|
450 |
alfonx |
144 |
public Style getLineHighlightStyle() { |
451 |
|
|
return lineHighlightStyle; |
452 |
|
|
} |
453 |
mojays |
2 |
|
454 |
alfonx |
307 |
public void setLineHighlightStyle(final Style lineHighlightStyle) { |
455 |
alfonx |
144 |
this.lineHighlightStyle = lineHighlightStyle; |
456 |
|
|
} |
457 |
mojays |
2 |
|
458 |
alfonx |
144 |
public Style getLineSelectionStyle() { |
459 |
|
|
return lineSelectionStyle; |
460 |
|
|
} |
461 |
mojays |
2 |
|
462 |
alfonx |
307 |
public void setLineSelectionStyle(final Style lineSelectionStyle) { |
463 |
alfonx |
144 |
this.lineSelectionStyle = lineSelectionStyle; |
464 |
|
|
} |
465 |
mojays |
2 |
|
466 |
alfonx |
144 |
public Style getPointHighlightStyle() { |
467 |
|
|
return pointHighlightStyle; |
468 |
|
|
} |
469 |
mojays |
2 |
|
470 |
alfonx |
307 |
public void setPointHighlightStyle(final Style pointHighlightStyle) { |
471 |
alfonx |
144 |
this.pointHighlightStyle = pointHighlightStyle; |
472 |
|
|
} |
473 |
mojays |
2 |
|
474 |
alfonx |
144 |
public Style getPointSelectionStyle() { |
475 |
|
|
return pointSelectionStyle; |
476 |
|
|
} |
477 |
mojays |
2 |
|
478 |
alfonx |
307 |
public void setPointSelectionStyle(final Style pointSelectionStyle) { |
479 |
alfonx |
144 |
this.pointSelectionStyle = pointSelectionStyle; |
480 |
|
|
} |
481 |
mojays |
2 |
|
482 |
alfonx |
144 |
public Style getPolygonHighlightStyle() { |
483 |
|
|
return polygonHighlightStyle; |
484 |
|
|
} |
485 |
mojays |
2 |
|
486 |
alfonx |
307 |
public void setPolygonHighlightStyle(final Style polygonHighlightStyle) { |
487 |
alfonx |
144 |
this.polygonHighlightStyle = polygonHighlightStyle; |
488 |
|
|
} |
489 |
mojays |
2 |
|
490 |
alfonx |
144 |
public Style getPolygonSelectionStyle() { |
491 |
|
|
return polygonSelectionStyle; |
492 |
|
|
} |
493 |
mojays |
2 |
|
494 |
alfonx |
307 |
public void setPolygonSelectionStyle(final Style polygonSelectionStyle) { |
495 |
alfonx |
144 |
this.polygonSelectionStyle = polygonSelectionStyle; |
496 |
|
|
} |
497 |
mojays |
2 |
|
498 |
alfonx |
307 |
protected void paintComponent(final Graphics g) { |
499 |
alfonx |
144 |
super.paintComponent(g); |
500 |
mojays |
2 |
|
501 |
alfonx |
144 |
if ((renderer == null) || (mapArea == null)) { |
502 |
|
|
return; |
503 |
|
|
} |
504 |
mojays |
2 |
|
505 |
alfonx |
307 |
final Rectangle r = getBounds(); |
506 |
|
|
final Rectangle dr = new Rectangle(r.width, r.height); |
507 |
mojays |
2 |
|
508 |
alfonx |
144 |
if (!r.equals(oldRect) || reset) { |
509 |
|
|
if (!r.equals(oldRect) && (mapArea == null)) { |
510 |
|
|
try { |
511 |
|
|
mapArea = context.getLayerBounds(); |
512 |
alfonx |
307 |
} catch (final IOException e) { |
513 |
alfonx |
144 |
// TODO Auto-generated catch block |
514 |
|
|
e.printStackTrace(); |
515 |
|
|
} |
516 |
|
|
} |
517 |
mojays |
2 |
|
518 |
alfonx |
144 |
if (mapArea != null) { |
519 |
|
|
/* either the viewer size has changed or we've done a reset */ |
520 |
|
|
changed = true; /* note we need to redraw */ |
521 |
|
|
reset = false; /* forget about the reset */ |
522 |
|
|
oldRect = r; /* store what the current size is */ |
523 |
mojays |
2 |
|
524 |
alfonx |
144 |
mapArea = fixAspectRatio(r, mapArea); |
525 |
|
|
} |
526 |
|
|
} |
527 |
mojays |
2 |
|
528 |
alfonx |
144 |
if (!mapArea.equals(oldMapArea)) { /* did the map extent change? */ |
529 |
|
|
changed = true; |
530 |
|
|
oldMapArea = mapArea; |
531 |
|
|
// when we tell the context that the bounds have changed WMSLayers |
532 |
|
|
// can refresh them selves |
533 |
|
|
context.setAreaOfInterest(mapArea, context |
534 |
|
|
.getCoordinateReferenceSystem()); |
535 |
|
|
} |
536 |
mojays |
2 |
|
537 |
alfonx |
167 |
if (changed ) { /* if the map changed then redraw */ |
538 |
alfonx |
144 |
changed = false; |
539 |
|
|
baseImage = new BufferedImage(dr.width, dr.height, |
540 |
|
|
BufferedImage.TYPE_INT_ARGB); |
541 |
mojays |
2 |
|
542 |
alfonx |
307 |
final Graphics2D ig = baseImage.createGraphics(); |
543 |
alfonx |
144 |
/* System.out.println("rendering"); */ |
544 |
alfonx |
307 |
if (renderer.getContext() != null) |
545 |
|
|
renderer.setContext(context); |
546 |
alfonx |
144 |
labelCache.clear(); // work around anoying labelcache bug |
547 |
mojays |
2 |
|
548 |
alfonx |
144 |
// draw the map |
549 |
|
|
renderer.paint((Graphics2D) ig, dr, mapArea); |
550 |
mojays |
2 |
|
551 |
alfonx |
167 |
// TODO nur machen, wenn panning beginnt |
552 |
alfonx |
144 |
panningImage = new BufferedImage(dr.width, dr.height, |
553 |
|
|
BufferedImage.TYPE_INT_RGB); |
554 |
mojays |
2 |
|
555 |
alfonx |
144 |
} |
556 |
mojays |
2 |
|
557 |
alfonx |
144 |
((Graphics2D) g).drawImage(baseImage, 0, 0, this); |
558 |
mojays |
2 |
|
559 |
alfonx |
144 |
if ((selection != null) && (selection.size() > 0)) { |
560 |
|
|
// paint selection |
561 |
mojays |
2 |
|
562 |
alfonx |
144 |
String type = selectionLayer.getFeatureSource().getSchema() |
563 |
|
|
.getDefaultGeometry().getType().getName(); |
564 |
|
|
/* String type = selection.getDefaultGeometry().getGeometryType(); */ |
565 |
|
|
/* System.out.println(type); */ |
566 |
|
|
if (type == null) |
567 |
|
|
type = "polygon"; |
568 |
mojays |
2 |
|
569 |
alfonx |
144 |
/* String type = "point"; */ |
570 |
mojays |
2 |
|
571 |
alfonx |
144 |
if (type.toLowerCase().endsWith("polygon")) { |
572 |
|
|
selectionStyle = polygonSelectionStyle; |
573 |
|
|
} else if (type.toLowerCase().endsWith("point")) { |
574 |
|
|
selectionStyle = pointSelectionStyle; |
575 |
|
|
} else if (type.toLowerCase().endsWith("line")) { |
576 |
|
|
selectionStyle = lineSelectionStyle; |
577 |
|
|
} |
578 |
mojays |
2 |
|
579 |
alfonx |
144 |
selectionContext = new DefaultMapContext(DefaultGeographicCRS.WGS84); |
580 |
mojays |
2 |
|
581 |
alfonx |
144 |
selectionContext.addLayer(selection, selectionStyle); |
582 |
|
|
selectionRenderer.setContext(selectionContext); |
583 |
mojays |
2 |
|
584 |
alfonx |
144 |
selectImage = new BufferedImage(dr.width, dr.height, |
585 |
|
|
BufferedImage.TYPE_INT_ARGB); |
586 |
mojays |
2 |
|
587 |
alfonx |
307 |
final Graphics2D ig = selectImage.createGraphics(); |
588 |
alfonx |
144 |
/* System.out.println("rendering selection"); */ |
589 |
|
|
selectionRenderer.paint((Graphics2D) ig, dr, mapArea); |
590 |
mojays |
2 |
|
591 |
alfonx |
144 |
((Graphics2D) g).drawImage(selectImage, 0, 0, this); |
592 |
|
|
} |
593 |
mojays |
2 |
|
594 |
alfonx |
144 |
if (highlight && (highlightFeature != null) |
595 |
|
|
&& (highlightFeature.size() > 0)) { |
596 |
|
|
/* |
597 |
|
|
* String type = selection.getDefaultGeometry().getGeometryType(); |
598 |
|
|
* System.out.println(type); if(type==null) type="polygon"; |
599 |
|
|
*/ |
600 |
|
|
String type = highlightLayer.getFeatureSource().getSchema() |
601 |
|
|
.getDefaultGeometry().getType().getName(); |
602 |
|
|
/* String type = selection.getDefaultGeometry().getGeometryType(); */ |
603 |
|
|
// System.out.println(type); |
604 |
|
|
if (type == null) |
605 |
|
|
type = "polygon"; |
606 |
mojays |
2 |
|
607 |
alfonx |
144 |
/* String type = "point"; */ |
608 |
|
|
Style highlightStyle = null; |
609 |
|
|
if (type.toLowerCase().endsWith("polygon")) { |
610 |
|
|
highlightStyle = polygonHighlightStyle; |
611 |
|
|
} else if (type.toLowerCase().endsWith("point")) { |
612 |
|
|
highlightStyle = pointHighlightStyle; |
613 |
|
|
} else if (type.toLowerCase().endsWith("line")) { |
614 |
|
|
highlightStyle = lineHighlightStyle; |
615 |
|
|
} |
616 |
mojays |
2 |
|
617 |
alfonx |
307 |
final MapContext highlightContext = new DefaultMapContext( |
618 |
alfonx |
144 |
DefaultGeographicCRS.WGS84); |
619 |
mojays |
2 |
|
620 |
alfonx |
144 |
highlightContext.addLayer(highlightFeature, highlightStyle); |
621 |
|
|
highlightRenderer.setContext(highlightContext); |
622 |
mojays |
2 |
|
623 |
alfonx |
144 |
/* System.out.println("rendering highlight"); */ |
624 |
|
|
highlightRenderer.paint((Graphics2D) g, dr, mapArea); |
625 |
|
|
} |
626 |
|
|
} |
627 |
mojays |
2 |
|
628 |
alfonx |
307 |
private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea) { |
629 |
mojays |
2 |
|
630 |
alfonx |
307 |
final double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
631 |
|
|
final double mapHeight = mapArea.getHeight(); |
632 |
|
|
final double scaleX = r.getWidth() / mapArea.getWidth(); /* |
633 |
alfonx |
144 |
* calculate the new |
634 |
|
|
* scale |
635 |
|
|
*/ |
636 |
mojays |
2 |
|
637 |
alfonx |
307 |
final double scaleY = r.getHeight() / mapArea.getHeight(); |
638 |
alfonx |
144 |
double scale = 1.0; // stupid compiler! |
639 |
mojays |
2 |
|
640 |
alfonx |
144 |
if (scaleX < scaleY) { /* pick the smaller scale */ |
641 |
|
|
scale = scaleX; |
642 |
|
|
} else { |
643 |
|
|
scale = scaleY; |
644 |
|
|
} |
645 |
mojays |
2 |
|
646 |
alfonx |
144 |
/* calculate the difference in width and height of the new extent */ |
647 |
alfonx |
307 |
final double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth); |
648 |
|
|
final double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight); |
649 |
mojays |
2 |
|
650 |
alfonx |
144 |
/* |
651 |
|
|
* System.out.println("delta x " + deltaX); |
652 |
|
|
* System.out.println("delta y " + deltaY); |
653 |
|
|
*/ |
654 |
mojays |
2 |
|
655 |
alfonx |
144 |
/* create the new extent */ |
656 |
alfonx |
307 |
final Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0), |
657 |
alfonx |
144 |
mapArea.getMinY() - (deltaY / 2.0)); |
658 |
alfonx |
307 |
final Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0), |
659 |
alfonx |
144 |
mapArea.getMaxY() + (deltaY / 2.0)); |
660 |
mojays |
2 |
|
661 |
alfonx |
144 |
return new Envelope(ll, ur); |
662 |
|
|
} |
663 |
mojays |
2 |
|
664 |
alfonx |
307 |
public void doSelection(final double x, final double y, final MapLayer layer) { |
665 |
mojays |
2 |
|
666 |
alfonx |
307 |
final Geometry geometry = gf.createPoint(new Coordinate(x, y)); |
667 |
mojays |
2 |
|
668 |
alfonx |
144 |
// org.opengis.geometry.Geometry geometry = new Point(); |
669 |
mojays |
2 |
|
670 |
alfonx |
144 |
findFeature(geometry, layer); |
671 |
mojays |
2 |
|
672 |
alfonx |
144 |
} |
673 |
mojays |
2 |
|
674 |
alfonx |
144 |
/** |
675 |
|
|
* @param geometry |
676 |
|
|
* - a geometry to construct the filter with |
677 |
|
|
* @param i |
678 |
|
|
* - the index of the layer to search |
679 |
|
|
* @throws IndexOutOfBoundsException |
680 |
|
|
*/ |
681 |
alfonx |
307 |
private void findFeature(final Geometry geometry, final MapLayer layer) |
682 |
alfonx |
144 |
throws IndexOutOfBoundsException { |
683 |
|
|
org.opengis.filter.spatial.BinarySpatialOperator f = null; |
684 |
mojays |
2 |
|
685 |
alfonx |
144 |
if ((context == null) || (layer == null)) { |
686 |
|
|
return; |
687 |
|
|
} |
688 |
mojays |
2 |
|
689 |
alfonx |
144 |
try { |
690 |
|
|
String name = layer.getFeatureSource().getSchema() |
691 |
alfonx |
153 |
.getDefaultGeometry().getLocalName(); |
692 |
mojays |
2 |
|
693 |
alfonx |
144 |
if (name == "") { |
694 |
|
|
name = "the_geom"; |
695 |
|
|
} |
696 |
mojays |
2 |
|
697 |
alfonx |
144 |
try { |
698 |
|
|
f = ff.contains(ff.property(name), ff.literal(geometry)); |
699 |
|
|
if (selectionManager != null) { |
700 |
alfonx |
153 |
// System.out.println("selection changed"); |
701 |
alfonx |
144 |
selectionManager.selectionChanged(this, f); |
702 |
mojays |
2 |
|
703 |
alfonx |
144 |
} |
704 |
alfonx |
307 |
} catch (final IllegalFilterException e) { |
705 |
alfonx |
144 |
// TODO Auto-generated catch block |
706 |
|
|
e.printStackTrace(); |
707 |
|
|
} |
708 |
mojays |
2 |
|
709 |
alfonx |
144 |
/* |
710 |
|
|
* // f.addLeftGeometry(ff.property(name)); // |
711 |
|
|
* System.out.println("looking with " + f); FeatureCollection fc = |
712 |
|
|
* layer.getFeatureSource().getFeatures(f); |
713 |
|
|
* |
714 |
|
|
* |
715 |
|
|
* |
716 |
|
|
* if (fcol == null) { fcol = fc; |
717 |
|
|
* |
718 |
|
|
* // here we should set the defaultgeom type } else { |
719 |
|
|
* fcol.addAll(fc); } |
720 |
|
|
*/ |
721 |
mojays |
2 |
|
722 |
alfonx |
144 |
/* |
723 |
|
|
* GeometryAttributeType gat = |
724 |
|
|
* layer.getFeatureSource().getSchema().getDefaultGeometry(); |
725 |
|
|
* fcol.setDefaultGeometry((Geometry)gat.createDefaultValue()); |
726 |
|
|
*/ |
727 |
mojays |
2 |
|
728 |
alfonx |
144 |
/* |
729 |
alfonx |
318 |
* Iterator fi = fc.iterator(); while (fi.hasNext()) { SimpleFeature feat |
730 |
|
|
* = (SimpleFeature) fi.next(); System.out.println("selected " + |
731 |
alfonx |
144 |
* feat.getAttribute("STATE_NAME")); } |
732 |
|
|
*/ |
733 |
alfonx |
307 |
} catch (final IllegalFilterException e) { |
734 |
alfonx |
144 |
// TODO Auto-generated catch block |
735 |
|
|
e.printStackTrace(); |
736 |
|
|
} |
737 |
|
|
return; |
738 |
|
|
} |
739 |
mojays |
2 |
|
740 |
alfonx |
307 |
public void mouseClicked(final MouseEvent e) { |
741 |
alfonx |
172 |
if (mapArea == null) return; |
742 |
alfonx |
144 |
// System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+" |
743 |
|
|
// h:"+mapArea.getHeight()); |
744 |
alfonx |
307 |
final Rectangle bounds = this.getBounds(); |
745 |
|
|
final double x = (double) (e.getX()); |
746 |
|
|
final double y = (double) (e.getY()); |
747 |
|
|
final double width = mapArea.getWidth(); |
748 |
|
|
final double height = mapArea.getHeight(); |
749 |
alfonx |
144 |
// xulu.sc |
750 |
|
|
// double width2 = mapArea.getWidth() / 2.0; |
751 |
|
|
// double height2 = mapArea.getHeight() / 2.0; |
752 |
alfonx |
307 |
final double width2 = width / 2.0; |
753 |
|
|
final double height2 = height / 2.0; |
754 |
alfonx |
144 |
// xulu.ec |
755 |
alfonx |
307 |
final double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX(); |
756 |
|
|
final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height) |
757 |
alfonx |
144 |
+ mapArea.getMinY(); |
758 |
mojays |
2 |
|
759 |
alfonx |
144 |
/* |
760 |
|
|
* System.out.println(""+x+"->"+mapX); |
761 |
|
|
* System.out.println(""+y+"->"+mapY); |
762 |
|
|
*/ |
763 |
mojays |
2 |
|
764 |
alfonx |
144 |
/* |
765 |
|
|
* Coordinate ll = new Coordinate(mapArea.getMinX(), mapArea.getMinY()); |
766 |
|
|
* Coordinate ur = new Coordinate(mapArea.getMaxX(), mapArea.getMaxY()); |
767 |
|
|
*/ |
768 |
|
|
double zlevel = 1.0; |
769 |
mojays |
2 |
|
770 |
alfonx |
144 |
switch (state) { |
771 |
|
|
case Pan: |
772 |
|
|
zlevel = 1.0; |
773 |
|
|
// xulu.sc SK: return here.. a mouselistener is managing the PANNING |
774 |
|
|
// break; |
775 |
|
|
return; |
776 |
|
|
// xulu.ec |
777 |
|
|
case ZoomIn: |
778 |
|
|
zlevel = zoomFactor; |
779 |
mojays |
2 |
|
780 |
alfonx |
144 |
break; |
781 |
mojays |
2 |
|
782 |
alfonx |
144 |
case ZoomOut: |
783 |
|
|
zlevel = 1.0 / zoomFactor; |
784 |
mojays |
2 |
|
785 |
alfonx |
144 |
break; |
786 |
mojays |
2 |
|
787 |
alfonx |
144 |
case Select: |
788 |
|
|
doSelection(mapX, mapY, selectionLayer); |
789 |
mojays |
2 |
|
790 |
alfonx |
144 |
return; |
791 |
mojays |
2 |
|
792 |
alfonx |
144 |
default: |
793 |
|
|
return; |
794 |
|
|
} |
795 |
mojays |
2 |
|
796 |
alfonx |
307 |
final Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY |
797 |
alfonx |
144 |
- (height2 / zlevel)); |
798 |
alfonx |
307 |
final Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY |
799 |
alfonx |
144 |
+ (height2 / zlevel)); |
800 |
|
|
// xulu.sc SK: Check for min/max scale |
801 |
|
|
// mapArea = new Envelope(ll, ur); |
802 |
|
|
final Envelope newMapArea = new Envelope(ll, ur); |
803 |
|
|
setMapArea(bestAllowedMapArea(newMapArea)); |
804 |
|
|
// xulu.ec |
805 |
mojays |
2 |
|
806 |
alfonx |
144 |
// sk.ec |
807 |
mojays |
2 |
|
808 |
alfonx |
144 |
// System.out.println("after area "+mapArea+"\nw:"+mapArea.getWidth()+" |
809 |
|
|
// h:"+mapArea.getHeight()); |
810 |
|
|
repaint(); |
811 |
|
|
} |
812 |
mojays |
2 |
|
813 |
alfonx |
307 |
public void mouseEntered(final MouseEvent e) { |
814 |
alfonx |
144 |
} |
815 |
mojays |
2 |
|
816 |
alfonx |
307 |
public void mouseExited(final MouseEvent e) { |
817 |
alfonx |
144 |
} |
818 |
mojays |
2 |
|
819 |
alfonx |
307 |
public void mousePressed(final MouseEvent e) { |
820 |
alfonx |
144 |
startX = e.getX(); |
821 |
|
|
startY = e.getY(); |
822 |
|
|
lastX = 0; |
823 |
|
|
lastY = 0; |
824 |
|
|
} |
825 |
mojays |
2 |
|
826 |
alfonx |
307 |
public void mouseReleased(final MouseEvent e) { |
827 |
|
|
final int endX = e.getX(); |
828 |
|
|
final int endY = e.getY(); |
829 |
mojays |
2 |
|
830 |
alfonx |
144 |
processDrag(startX, startY, endX, endY, e); |
831 |
|
|
lastX = 0; |
832 |
|
|
lastY = 0; |
833 |
mojays |
2 |
|
834 |
alfonx |
144 |
/** |
835 |
|
|
* Es wird nicht (mehr) gepannt! |
836 |
|
|
*/ |
837 |
|
|
panning_started = false; |
838 |
|
|
} |
839 |
mojays |
2 |
|
840 |
alfonx |
307 |
public void mouseDragged(final MouseEvent e) { |
841 |
|
|
final Graphics graphics = this.getGraphics(); |
842 |
|
|
final int x = e.getX(); |
843 |
|
|
final int y = e.getY(); |
844 |
mojays |
2 |
|
845 |
alfonx |
144 |
if ((state == JMapPane.Pan) |
846 |
|
|
|| ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
847 |
|
|
/** |
848 |
|
|
* SK: Der Cursor wird auf PANNING gesetzt. |
849 |
|
|
*/ |
850 |
|
|
if (panning_started == false) { |
851 |
|
|
panning_started = true; |
852 |
|
|
setCursor(SwingUtil.PANNING_CURSOR); |
853 |
|
|
} |
854 |
mojays |
2 |
|
855 |
alfonx |
144 |
// move the image with the mouse |
856 |
|
|
if ((lastX > 0) && (lastY > 0)) { |
857 |
alfonx |
307 |
final int dx = lastX - startX; |
858 |
|
|
final int dy = lastY - startY; |
859 |
alfonx |
144 |
// System.out.println("translate "+dx+","+dy); |
860 |
|
|
final Graphics2D g2 = panningImage.createGraphics(); |
861 |
|
|
g2.setBackground(new Color(240, 240, 240)); // TODO richtige |
862 |
|
|
// farbe? am besten |
863 |
|
|
// vom L&F die |
864 |
|
|
// hintergrundfarbe |
865 |
|
|
// auslesen... |
866 |
alfonx |
148 |
|
867 |
mojays |
2 |
g2.clearRect(0, 0, this.getWidth(), this.getHeight()); |
868 |
|
|
g2.drawImage(baseImage, dx, dy, this); |
869 |
alfonx |
144 |
graphics.drawImage(panningImage, 0, 0, this); |
870 |
|
|
} |
871 |
mojays |
2 |
|
872 |
alfonx |
144 |
lastX = x; |
873 |
|
|
lastY = y; |
874 |
|
|
} else |
875 |
mojays |
2 |
|
876 |
alfonx |
144 |
if ((state == JMapPane.ZoomIn) || (state == JMapPane.ZoomOut)) { |
877 |
mojays |
2 |
|
878 |
alfonx |
144 |
graphics.setXORMode(Color.WHITE); |
879 |
mojays |
2 |
|
880 |
alfonx |
144 |
if ((lastX > 0) && (lastY > 0)) { |
881 |
|
|
drawRectangle(graphics); |
882 |
|
|
} |
883 |
mojays |
2 |
|
884 |
alfonx |
144 |
// draw new box |
885 |
|
|
lastX = x; |
886 |
|
|
lastY = y; |
887 |
|
|
drawRectangle(graphics); |
888 |
|
|
} else if (state == JMapPane.Select && selectionLayer != null) { |
889 |
mojays |
2 |
|
890 |
alfonx |
144 |
// construct a new bbox filter |
891 |
alfonx |
307 |
final Rectangle bounds = this.getBounds(); |
892 |
mojays |
2 |
|
893 |
alfonx |
307 |
final double mapWidth = mapArea.getWidth(); |
894 |
|
|
final double mapHeight = mapArea.getHeight(); |
895 |
mojays |
2 |
|
896 |
alfonx |
307 |
final double x1 = ((this.startX * mapWidth) / (double) bounds.width) |
897 |
alfonx |
144 |
+ mapArea.getMinX(); |
898 |
alfonx |
307 |
final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height) |
899 |
alfonx |
144 |
+ mapArea.getMinY(); |
900 |
alfonx |
307 |
final double x2 = ((x * mapWidth) / (double) bounds.width) |
901 |
alfonx |
144 |
+ mapArea.getMinX(); |
902 |
alfonx |
307 |
final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height) |
903 |
alfonx |
144 |
+ mapArea.getMinY(); |
904 |
alfonx |
307 |
final double left = Math.min(x1, x2); |
905 |
|
|
final double right = Math.max(x1, x2); |
906 |
|
|
final double bottom = Math.min(y1, y2); |
907 |
|
|
final double top = Math.max(y1, y2); |
908 |
mojays |
2 |
|
909 |
alfonx |
144 |
String name = selectionLayer.getFeatureSource().getSchema() |
910 |
|
|
.getDefaultGeometry().getName(); |
911 |
mojays |
2 |
|
912 |
alfonx |
144 |
if (name == "") { |
913 |
|
|
name = "the_geom"; |
914 |
|
|
} |
915 |
alfonx |
307 |
final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top, |
916 |
alfonx |
144 |
getContext().getCoordinateReferenceSystem().toString()); |
917 |
|
|
if (selectionManager != null) { |
918 |
|
|
selectionManager.selectionChanged(this, bb); |
919 |
|
|
} |
920 |
mojays |
2 |
|
921 |
alfonx |
144 |
graphics.setXORMode(Color.green); |
922 |
mojays |
2 |
|
923 |
alfonx |
144 |
/* |
924 |
|
|
* if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); } |
925 |
|
|
*/ |
926 |
mojays |
2 |
|
927 |
alfonx |
144 |
// draw new box |
928 |
|
|
lastX = x; |
929 |
|
|
lastY = y; |
930 |
|
|
drawRectangle(graphics); |
931 |
|
|
} |
932 |
mojays |
2 |
|
933 |
alfonx |
144 |
} |
934 |
mojays |
2 |
|
935 |
alfonx |
144 |
// sk.cs |
936 |
|
|
// private void processDrag(int x1, int y1, int x2, int y2) { |
937 |
|
|
// sk.ce |
938 |
|
|
protected void processDrag(final int x1, final int y1, final int x2, |
939 |
alfonx |
307 |
final int y2, final MouseEvent e) { |
940 |
mojays |
2 |
|
941 |
alfonx |
144 |
/**** |
942 |
|
|
* If no layer is availabe we dont want a NullPointerException |
943 |
|
|
*/ |
944 |
|
|
if (mapArea == null) |
945 |
|
|
return; |
946 |
mojays |
2 |
|
947 |
alfonx |
144 |
// System.out.println("processing drag from " + x1 + "," + y1 + " -> " |
948 |
|
|
// + x2 + "," + y2); |
949 |
|
|
if ((x1 == x2) && (y1 == y2)) { |
950 |
|
|
if (isClickable()) { |
951 |
|
|
mouseClicked(new MouseEvent(this, 0, new Date().getTime(), 0, |
952 |
|
|
x1, y1, y2, false)); |
953 |
|
|
} |
954 |
mojays |
2 |
|
955 |
alfonx |
144 |
return; |
956 |
|
|
} |
957 |
mojays |
2 |
|
958 |
alfonx |
307 |
final Rectangle bounds = this.getBounds(); |
959 |
mojays |
2 |
|
960 |
alfonx |
307 |
final double mapWidth = mapArea.getWidth(); |
961 |
|
|
final double mapHeight = mapArea.getHeight(); |
962 |
mojays |
2 |
|
963 |
alfonx |
307 |
final double startX = ((x1 * mapWidth) / (double) bounds.width) |
964 |
alfonx |
144 |
+ mapArea.getMinX(); |
965 |
alfonx |
307 |
final double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height) |
966 |
alfonx |
144 |
+ mapArea.getMinY(); |
967 |
alfonx |
307 |
final double endX = ((x2 * mapWidth) / (double) bounds.width) |
968 |
alfonx |
144 |
+ mapArea.getMinX(); |
969 |
alfonx |
307 |
final double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height) |
970 |
alfonx |
144 |
+ mapArea.getMinY(); |
971 |
mojays |
2 |
|
972 |
alfonx |
144 |
if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) { |
973 |
|
|
// move the image with the mouse |
974 |
|
|
// calculate X offsets from start point to the end Point |
975 |
alfonx |
307 |
final double deltaX1 = endX - startX; |
976 |
mojays |
2 |
|
977 |
alfonx |
144 |
// System.out.println("deltaX " + deltaX1); |
978 |
|
|
// new edges |
979 |
alfonx |
307 |
final double left = mapArea.getMinX() - deltaX1; |
980 |
|
|
final double right = mapArea.getMaxX() - deltaX1; |
981 |
mojays |
2 |
|
982 |
alfonx |
144 |
// now for Y |
983 |
alfonx |
307 |
final double deltaY1 = endY - startY; |
984 |
mojays |
2 |
|
985 |
alfonx |
144 |
// System.out.println("deltaY " + deltaY1); |
986 |
alfonx |
307 |
final double bottom = mapArea.getMinY() - deltaY1; |
987 |
|
|
final double top = mapArea.getMaxY() - deltaY1; |
988 |
|
|
final Coordinate ll = new Coordinate(left, bottom); |
989 |
|
|
final Coordinate ur = new Coordinate(right, top); |
990 |
alfonx |
144 |
// xulu.sc |
991 |
|
|
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
992 |
|
|
setMapArea(fixAspectRatio(this.getBounds(), new Envelope(ll, ur))); |
993 |
|
|
// xulu.ec |
994 |
|
|
} else if (state == JMapPane.ZoomIn) { |
995 |
mojays |
2 |
|
996 |
alfonx |
144 |
// Zu kleine Flächen sollen nicht gezoomt werden. |
997 |
|
|
// sk.bc |
998 |
|
|
if ((Math.abs(x1 - x2) * Math.abs(y2 - y1)) < 150) |
999 |
|
|
return; |
1000 |
|
|
// sk.ec |
1001 |
mojays |
2 |
|
1002 |
alfonx |
144 |
drawRectangle(this.getGraphics()); |
1003 |
|
|
// make the dragged rectangle (in map coords) the new BBOX |
1004 |
alfonx |
307 |
final double left = Math.min(startX, endX); |
1005 |
|
|
final double right = Math.max(startX, endX); |
1006 |
|
|
final double bottom = Math.min(startY, endY); |
1007 |
|
|
final double top = Math.max(startY, endY); |
1008 |
|
|
final Coordinate ll = new Coordinate(left, bottom); |
1009 |
|
|
final Coordinate ur = new Coordinate(right, top); |
1010 |
alfonx |
144 |
// xulu.sc |
1011 |
mojays |
2 |
|
1012 |
alfonx |
144 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
1013 |
|
|
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
1014 |
mojays |
2 |
|
1015 |
alfonx |
144 |
// sk.sc |
1016 |
|
|
// { |
1017 |
|
|
// // SK tries to paint a preview of the zoom ;-9 aha.... well |
1018 |
|
|
// Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics(); |
1019 |
|
|
// graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
1020 |
|
|
// RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
1021 |
|
|
// graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
1022 |
|
|
// RenderingHints.VALUE_ANTIALIAS_OFF); |
1023 |
|
|
// graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
1024 |
|
|
// RenderingHints.VALUE_RENDER_SPEED); |
1025 |
|
|
// graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(), |
1026 |
|
|
// JMapPane.this.getHeight(), x1, y1, x2, y2, null); |
1027 |
|
|
// } |
1028 |
|
|
// xulu.ec |
1029 |
|
|
} else if (state == JMapPane.ZoomOut) { |
1030 |
|
|
drawRectangle(this.getGraphics()); |
1031 |
mojays |
2 |
|
1032 |
alfonx |
144 |
// make the dragged rectangle in screen coords the new map size? |
1033 |
alfonx |
307 |
final double left = Math.min(startX, endX); |
1034 |
|
|
final double right = Math.max(startX, endX); |
1035 |
|
|
final double bottom = Math.min(startY, endY); |
1036 |
|
|
final double top = Math.max(startY, endY); |
1037 |
|
|
final double nWidth = (mapWidth * mapWidth) / (right - left); |
1038 |
|
|
final double nHeight = (mapHeight * mapHeight) / (top - bottom); |
1039 |
|
|
final double deltaX1 = left - mapArea.getMinX(); |
1040 |
|
|
final double nDeltaX1 = (deltaX1 * nWidth) / mapWidth; |
1041 |
|
|
final double deltaY1 = bottom - mapArea.getMinY(); |
1042 |
|
|
final double nDeltaY1 = (deltaY1 * nHeight) / mapHeight; |
1043 |
|
|
final Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1, |
1044 |
alfonx |
144 |
mapArea.getMinY() - nDeltaY1); |
1045 |
alfonx |
307 |
final double deltaX2 = mapArea.getMaxX() - right; |
1046 |
|
|
final double nDeltaX2 = (deltaX2 * nWidth) / mapWidth; |
1047 |
|
|
final double deltaY2 = mapArea.getMaxY() - top; |
1048 |
|
|
final double nDeltaY2 = (deltaY2 * nHeight) / mapHeight; |
1049 |
|
|
final Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2, |
1050 |
alfonx |
144 |
mapArea.getMaxY() + nDeltaY2); |
1051 |
|
|
// xulu.sc |
1052 |
|
|
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
1053 |
|
|
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
1054 |
mojays |
2 |
|
1055 |
alfonx |
144 |
// xulu.ec |
1056 |
|
|
} else if (state == JMapPane.Select && selectionLayer != null) { |
1057 |
alfonx |
307 |
final double left = Math.min(startX, endX); |
1058 |
|
|
final double right = Math.max(startX, endX); |
1059 |
|
|
final double bottom = Math.min(startY, endY); |
1060 |
|
|
final double top = Math.max(startY, endY); |
1061 |
mojays |
2 |
|
1062 |
alfonx |
144 |
String name = selectionLayer.getFeatureSource().getSchema() |
1063 |
|
|
.getDefaultGeometry().getLocalName(); |
1064 |
mojays |
2 |
|
1065 |
alfonx |
144 |
if (name == "") { |
1066 |
|
|
name = "the_geom"; |
1067 |
|
|
} |
1068 |
alfonx |
307 |
final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top, |
1069 |
alfonx |
144 |
getContext().getCoordinateReferenceSystem().toString()); |
1070 |
|
|
// System.out.println(bb.toString()); |
1071 |
|
|
if (selectionManager != null) { |
1072 |
|
|
selectionManager.selectionChanged(this, bb); |
1073 |
|
|
} |
1074 |
|
|
/* |
1075 |
|
|
* FeatureCollection fc; selection = null; try { fc = |
1076 |
|
|
* selectionLayer.getFeatureSource().getFeatures(bb); selection = |
1077 |
|
|
* fc; } catch (IOException e) { e.printStackTrace(); } |
1078 |
|
|
*/ |
1079 |
|
|
} |
1080 |
mojays |
2 |
|
1081 |
alfonx |
144 |
// xulu.so |
1082 |
|
|
// setMapArea(mapArea); |
1083 |
|
|
// xulu.eo |
1084 |
|
|
repaint(); |
1085 |
|
|
} |
1086 |
mojays |
2 |
|
1087 |
alfonx |
144 |
private boolean isClickable() { |
1088 |
|
|
return clickable; |
1089 |
|
|
} |
1090 |
mojays |
2 |
|
1091 |
alfonx |
307 |
private org.geotools.styling.Style setupStyle(final int type, final Color color) { |
1092 |
|
|
final StyleFactory sf = org.geotools.factory.CommonFactoryFinder |
1093 |
alfonx |
144 |
.getStyleFactory(null); |
1094 |
alfonx |
307 |
final StyleBuilder sb = new StyleBuilder(); |
1095 |
mojays |
2 |
|
1096 |
alfonx |
144 |
org.geotools.styling.Style s = sf.createStyle(); |
1097 |
|
|
s.setTitle("selection"); |
1098 |
mojays |
2 |
|
1099 |
alfonx |
144 |
// TODO parameterise the color |
1100 |
alfonx |
307 |
final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color); |
1101 |
alfonx |
144 |
ps.setStroke(sb.createStroke(color)); |
1102 |
mojays |
2 |
|
1103 |
alfonx |
307 |
final LineSymbolizer ls = sb.createLineSymbolizer(color); |
1104 |
|
|
final Graphic h = sb.createGraphic(); |
1105 |
alfonx |
144 |
h.setMarks(new Mark[] { sb.createMark("square", color) }); |
1106 |
mojays |
2 |
|
1107 |
alfonx |
307 |
final PointSymbolizer pts = sb.createPointSymbolizer(h); |
1108 |
mojays |
2 |
|
1109 |
alfonx |
144 |
// Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts}); |
1110 |
|
|
switch (type) { |
1111 |
|
|
case POLYGON: |
1112 |
|
|
s = sb.createStyle(ps); |
1113 |
mojays |
2 |
|
1114 |
alfonx |
144 |
break; |
1115 |
mojays |
2 |
|
1116 |
alfonx |
144 |
case POINT: |
1117 |
|
|
s = sb.createStyle(pts); |
1118 |
mojays |
2 |
|
1119 |
alfonx |
144 |
break; |
1120 |
mojays |
2 |
|
1121 |
alfonx |
144 |
case LINE: |
1122 |
|
|
s = sb.createStyle(ls); |
1123 |
|
|
} |
1124 |
mojays |
2 |
|
1125 |
alfonx |
144 |
return s; |
1126 |
|
|
} |
1127 |
mojays |
2 |
|
1128 |
alfonx |
307 |
public void highlightChanged(final HighlightChangedEvent e) { |
1129 |
|
|
final org.opengis.filter.Filter f = e.getFilter(); |
1130 |
mojays |
2 |
|
1131 |
alfonx |
144 |
try { |
1132 |
|
|
highlightFeature = highlightLayer.getFeatureSource().getFeatures(f); |
1133 |
alfonx |
307 |
} catch (final IOException e1) { |
1134 |
alfonx |
144 |
// TODO Auto-generated catch block |
1135 |
|
|
e1.printStackTrace(); |
1136 |
|
|
} |
1137 |
mojays |
2 |
|
1138 |
alfonx |
144 |
repaint(); |
1139 |
|
|
} |
1140 |
mojays |
2 |
|
1141 |
alfonx |
307 |
public void propertyChange(final PropertyChangeEvent evt) { |
1142 |
|
|
final String prop = evt.getPropertyName(); |
1143 |
mojays |
2 |
|
1144 |
alfonx |
144 |
if (prop.equalsIgnoreCase("crs")) { |
1145 |
|
|
context.setAreaOfInterest(context.getAreaOfInterest(), |
1146 |
|
|
(CoordinateReferenceSystem) evt.getNewValue()); |
1147 |
|
|
} |
1148 |
|
|
} |
1149 |
mojays |
2 |
|
1150 |
alfonx |
144 |
public boolean isReset() { |
1151 |
|
|
return reset; |
1152 |
|
|
} |
1153 |
mojays |
2 |
|
1154 |
alfonx |
307 |
public void setReset(final boolean reset) { |
1155 |
alfonx |
144 |
this.reset = reset; |
1156 |
|
|
} |
1157 |
mojays |
2 |
|
1158 |
alfonx |
307 |
public void layerAdded(final MapLayerListEvent event) { |
1159 |
alfonx |
144 |
changed = true; |
1160 |
mojays |
2 |
|
1161 |
alfonx |
144 |
if (context.getLayers().length == 1) { // the first one |
1162 |
mojays |
2 |
|
1163 |
alfonx |
144 |
try { |
1164 |
|
|
// xulu.sc |
1165 |
|
|
// mapArea = context.getLayerBounds(); |
1166 |
|
|
mapArea = context.getAreaOfInterest(); |
1167 |
|
|
if (mapArea == null) |
1168 |
|
|
mapArea = context.getLayerBounds(); |
1169 |
|
|
// xulu.ec |
1170 |
alfonx |
307 |
} catch (final IOException e) { |
1171 |
alfonx |
144 |
// TODO Auto-generated catch block |
1172 |
|
|
e.printStackTrace(); |
1173 |
|
|
} |
1174 |
mojays |
2 |
|
1175 |
alfonx |
144 |
reset = true; |
1176 |
|
|
} |
1177 |
mojays |
2 |
|
1178 |
alfonx |
144 |
repaint(); |
1179 |
|
|
} |
1180 |
mojays |
2 |
|
1181 |
alfonx |
307 |
public void layerRemoved(final MapLayerListEvent event) { |
1182 |
alfonx |
144 |
changed = true; |
1183 |
|
|
repaint(); |
1184 |
|
|
} |
1185 |
mojays |
2 |
|
1186 |
alfonx |
307 |
public void layerChanged(final MapLayerListEvent event) { |
1187 |
alfonx |
144 |
changed = true; |
1188 |
|
|
// System.out.println("layer changed - repaint"); |
1189 |
|
|
repaint(); |
1190 |
|
|
} |
1191 |
mojays |
2 |
|
1192 |
alfonx |
307 |
public void layerMoved(final MapLayerListEvent event) { |
1193 |
alfonx |
144 |
changed = true; |
1194 |
|
|
repaint(); |
1195 |
|
|
} |
1196 |
mojays |
2 |
|
1197 |
alfonx |
307 |
protected void drawRectangle(final Graphics graphics) { |
1198 |
alfonx |
144 |
// undraw last box/draw new box |
1199 |
alfonx |
307 |
final int left = Math.min(startX, lastX); |
1200 |
|
|
final int right = Math.max(startX, lastX); |
1201 |
|
|
final int top = Math.max(startY, lastY); |
1202 |
|
|
final int bottom = Math.min(startY, lastY); |
1203 |
|
|
final int width = right - left; |
1204 |
|
|
final int height = top - bottom; |
1205 |
alfonx |
144 |
// System.out.println("drawing rect("+left+","+bottom+","+ width+","+ |
1206 |
|
|
// height+")"); |
1207 |
|
|
graphics.drawRect(left, bottom, width, height); |
1208 |
|
|
} |
1209 |
mojays |
2 |
|
1210 |
alfonx |
144 |
/** |
1211 |
|
|
* if clickable is set to true then a single click on the map pane will zoom |
1212 |
|
|
* or pan the map. |
1213 |
|
|
* |
1214 |
|
|
* @param clickable |
1215 |
|
|
*/ |
1216 |
alfonx |
307 |
public void setClickable(final boolean clickable) { |
1217 |
alfonx |
144 |
this.clickable = clickable; |
1218 |
|
|
} |
1219 |
mojays |
2 |
|
1220 |
alfonx |
307 |
public void mouseMoved(final MouseEvent e) { |
1221 |
alfonx |
144 |
} |
1222 |
|
|
|
1223 |
|
|
public FeatureCollection getSelection() { |
1224 |
|
|
return selection; |
1225 |
|
|
} |
1226 |
|
|
|
1227 |
alfonx |
307 |
public void setSelection(final FeatureCollection selection) { |
1228 |
alfonx |
144 |
this.selection = selection; |
1229 |
|
|
repaint(); |
1230 |
|
|
} |
1231 |
|
|
|
1232 |
|
|
/* |
1233 |
|
|
* (non-Javadoc) |
1234 |
|
|
* |
1235 |
|
|
* @see |
1236 |
|
|
* org.geotools.gui.swing.event.SelectionChangeListener#selectionChanged |
1237 |
|
|
* (org.geotools.gui.swing.event.SelectionChangedEvent) |
1238 |
|
|
*/ |
1239 |
alfonx |
307 |
public void selectionChanged(final SelectionChangedEvent e) { |
1240 |
alfonx |
144 |
|
1241 |
|
|
try { |
1242 |
|
|
selection = selectionLayer.getFeatureSource().getFeatures( |
1243 |
|
|
e.getFilter()); |
1244 |
|
|
repaint(); |
1245 |
alfonx |
307 |
} catch (final IOException e1) { |
1246 |
alfonx |
144 |
e1.printStackTrace(); |
1247 |
|
|
} |
1248 |
|
|
} |
1249 |
|
|
|
1250 |
|
|
public SelectionManager getSelectionManager() { |
1251 |
|
|
return selectionManager; |
1252 |
|
|
} |
1253 |
|
|
|
1254 |
alfonx |
307 |
public void setSelectionManager(final SelectionManager selectionManager) { |
1255 |
alfonx |
144 |
this.selectionManager = selectionManager; |
1256 |
|
|
this.selectionManager.addSelectionChangeListener(this); |
1257 |
|
|
|
1258 |
|
|
} |
1259 |
|
|
|
1260 |
|
|
// xulu.sn |
1261 |
alfonx |
76 |
/** |
1262 |
|
|
* Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste |
1263 |
|
|
* erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten |
1264 |
|
|
* werden, FALLS der uebergeben Envelope nicht schon gueltig sein sollte.<br/> |
1265 |
|
|
* Since 21. April 09: Before thecalculation starts, the aspect ratio is |
1266 |
|
|
* corrected. This change implies, that setMapArea() will most of the time |
1267 |
|
|
* not allow setting to a wrong aspectRatio. |
1268 |
|
|
* |
1269 |
|
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
1270 |
|
|
* Krüger</a> |
1271 |
|
|
*/ |
1272 |
|
|
public Envelope bestAllowedMapArea(Envelope env) { |
1273 |
|
|
if (getWidth() == 0) |
1274 |
|
|
return env; |
1275 |
|
|
if (env == null) |
1276 |
|
|
return env; |
1277 |
mojays |
2 |
|
1278 |
alfonx |
76 |
/** |
1279 |
alfonx |
144 |
* Correct the aspect Ratio before we check the rest. Otherwise we might |
1280 |
|
|
* easily fail. |
1281 |
alfonx |
76 |
*/ |
1282 |
|
|
env = fixAspectRatio(this.getBounds(), env); |
1283 |
mojays |
2 |
|
1284 |
alfonx |
307 |
final double scale = env.getWidth() / getWidth(); |
1285 |
|
|
final double centerX = env.getMinX() + env.getWidth() / 2.; |
1286 |
|
|
final double centerY = env.getMinY() + env.getHeight() / 2.; |
1287 |
alfonx |
76 |
double newWidth2; |
1288 |
|
|
double newHeight2; |
1289 |
|
|
if (scale < getMaxZoomScale()) { |
1290 |
|
|
// **************************************************************************** |
1291 |
|
|
// Wir zoomen weiter rein als erlaubt => Anpassen des envelope |
1292 |
|
|
// **************************************************************************** |
1293 |
|
|
newWidth2 = getMaxZoomScale() * getWidth() / 2.; |
1294 |
|
|
newHeight2 = getMaxZoomScale() * getHeight() / 2.; |
1295 |
|
|
} else if (scale > getMinZoomScale()) { |
1296 |
|
|
// **************************************************************************** |
1297 |
|
|
// Wir zoomen weiter raus als erlaubt => Anpassen des envelope |
1298 |
|
|
// **************************************************************************** |
1299 |
|
|
newWidth2 = getMinZoomScale() * getWidth() / 2.; |
1300 |
|
|
newHeight2 = getMinZoomScale() * getHeight() / 2.; |
1301 |
|
|
} else { |
1302 |
|
|
// **************************************************************************** |
1303 |
|
|
// Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen |
1304 |
|
|
// **************************************************************************** |
1305 |
|
|
return env; |
1306 |
|
|
} |
1307 |
mojays |
2 |
|
1308 |
alfonx |
307 |
final Coordinate ll = new Coordinate(centerX - newWidth2, centerY |
1309 |
alfonx |
76 |
- newHeight2); |
1310 |
alfonx |
307 |
final Coordinate ur = new Coordinate(centerX + newWidth2, centerY |
1311 |
alfonx |
76 |
+ newHeight2); |
1312 |
mojays |
2 |
|
1313 |
alfonx |
76 |
return new Envelope(ll, ur); |
1314 |
|
|
} |
1315 |
|
|
|
1316 |
alfonx |
144 |
/** |
1317 |
|
|
* Retuns the minimum allowed zoom scale. This is the bigger number value of |
1318 |
|
|
* the two. Defaults to {@link Double}.MAX_VALUE |
1319 |
|
|
* |
1320 |
|
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
1321 |
|
|
* Krüger</a> |
1322 |
|
|
*/ |
1323 |
|
|
public Double getMinZoomScale() { |
1324 |
|
|
return minZoomScale; |
1325 |
|
|
} |
1326 |
mojays |
2 |
|
1327 |
alfonx |
144 |
/** |
1328 |
|
|
* Retuns the maximum allowed zoom scale. This is the smaller number value |
1329 |
|
|
* of the two. Defaults to {@link Double}.MIN_VALUE |
1330 |
|
|
* |
1331 |
|
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
1332 |
|
|
* Krüger</a> |
1333 |
|
|
*/ |
1334 |
|
|
public Double getMaxZoomScale() { |
1335 |
|
|
return maxZoomScale; |
1336 |
|
|
} |
1337 |
mojays |
2 |
|
1338 |
alfonx |
144 |
/** |
1339 |
|
|
* Set the maximum allowed zoom scale. This is the smaller number value of |
1340 |
|
|
* the two. |
1341 |
|
|
* |
1342 |
|
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
1343 |
|
|
* Krüger</a> |
1344 |
|
|
*/ |
1345 |
alfonx |
307 |
public void setMaxZoomScale(final Double maxZoomScale) { |
1346 |
alfonx |
144 |
// System.out.println("setting max scale to "+maxZoomScale); |
1347 |
|
|
this.maxZoomScale = maxZoomScale; |
1348 |
|
|
} |
1349 |
mojays |
2 |
|
1350 |
alfonx |
144 |
/** |
1351 |
|
|
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
1352 |
|
|
* value of the two. |
1353 |
|
|
* |
1354 |
|
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
1355 |
|
|
* Krüger</a> |
1356 |
|
|
*/ |
1357 |
alfonx |
307 |
public void setMinZoomScale(final Double minZoomScale) { |
1358 |
alfonx |
144 |
this.minZoomScale = minZoomScale; |
1359 |
|
|
} |
1360 |
|
|
// xulu.en |
1361 |
mojays |
2 |
|
1362 |
|
|
} |