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