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