58 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
59 |
|
|
60 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
|
import org.geotools.feature.FeatureCollection; |
|
|
import org.geotools.filter.IllegalFilterException; |
|
|
import org.geotools.gui.swing.event.HighlightChangeListener; |
|
|
import org.geotools.gui.swing.event.HighlightChangedEvent; |
|
|
import org.geotools.gui.swing.event.SelectionChangeListener; |
|
|
import org.geotools.gui.swing.event.SelectionChangedEvent; |
|
|
import org.geotools.map.DefaultMapContext; |
|
61 |
import org.geotools.map.MapContext; |
import org.geotools.map.MapContext; |
|
import org.geotools.map.MapLayer; |
|
62 |
import org.geotools.map.event.MapLayerListEvent; |
import org.geotools.map.event.MapLayerListEvent; |
63 |
import org.geotools.map.event.MapLayerListListener; |
import org.geotools.map.event.MapLayerListListener; |
|
import org.geotools.referencing.crs.DefaultGeographicCRS; |
|
64 |
import org.geotools.renderer.GTRenderer; |
import org.geotools.renderer.GTRenderer; |
65 |
|
import org.geotools.renderer.label.LabelCacheImpl; |
66 |
import org.geotools.renderer.lite.LabelCache; |
import org.geotools.renderer.lite.LabelCache; |
|
import org.geotools.renderer.lite.LabelCacheDefault; |
|
67 |
import org.geotools.renderer.lite.StreamingRenderer; |
import org.geotools.renderer.lite.StreamingRenderer; |
68 |
|
import org.geotools.renderer.shape.TransitionShapefileRenderer; |
69 |
import org.geotools.styling.Graphic; |
import org.geotools.styling.Graphic; |
70 |
import org.geotools.styling.LineSymbolizer; |
import org.geotools.styling.LineSymbolizer; |
71 |
import org.geotools.styling.Mark; |
import org.geotools.styling.Mark; |
72 |
import org.geotools.styling.PointSymbolizer; |
import org.geotools.styling.PointSymbolizer; |
73 |
import org.geotools.styling.PolygonSymbolizer; |
import org.geotools.styling.PolygonSymbolizer; |
|
import org.geotools.styling.Style; |
|
74 |
import org.geotools.styling.StyleBuilder; |
import org.geotools.styling.StyleBuilder; |
75 |
import org.geotools.styling.StyleFactory; |
import org.geotools.styling.StyleFactory; |
|
import org.opengis.filter.Filter; |
|
76 |
import org.opengis.filter.FilterFactory2; |
import org.opengis.filter.FilterFactory2; |
77 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
78 |
|
|
80 |
|
|
81 |
import com.vividsolutions.jts.geom.Coordinate; |
import com.vividsolutions.jts.geom.Coordinate; |
82 |
import com.vividsolutions.jts.geom.Envelope; |
import com.vividsolutions.jts.geom.Envelope; |
|
import com.vividsolutions.jts.geom.Geometry; |
|
83 |
import com.vividsolutions.jts.geom.GeometryFactory; |
import com.vividsolutions.jts.geom.GeometryFactory; |
84 |
|
|
85 |
public class JMapPane extends JPanel implements MouseListener, |
public class JMapPane extends JPanel implements MouseListener, |
86 |
MouseMotionListener, HighlightChangeListener, SelectionChangeListener, |
MouseMotionListener, PropertyChangeListener, MapLayerListListener { |
|
PropertyChangeListener, MapLayerListListener { |
|
87 |
private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName()); |
private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName()); |
88 |
|
|
89 |
private static final long serialVersionUID = -8647971481359690499L; |
private static final long serialVersionUID = -8647971481359690499L; |
149 |
// SK: private BufferedImage baseImage, panningImage; |
// SK: private BufferedImage baseImage, panningImage; |
150 |
|
|
151 |
/** |
/** |
|
* image of selection |
|
|
*/ |
|
|
private BufferedImage selectImage; |
|
|
|
|
|
/** |
|
|
* style for selected items |
|
|
*/ |
|
|
private Style selectionStyle; |
|
|
|
|
|
/** |
|
|
* layer that selection works on |
|
|
*/ |
|
|
private MapLayer selectionLayer; |
|
|
|
|
|
/** |
|
|
* layer that highlight works on |
|
|
*/ |
|
|
private MapLayer highlightLayer; |
|
|
|
|
|
/** |
|
|
* the object which manages highlighting |
|
|
*/ |
|
|
private HighlightManager highlightManager; |
|
|
|
|
|
/** |
|
|
* is highlighting on or off |
|
|
*/ |
|
|
private boolean highlight = true; |
|
|
|
|
|
/** |
|
152 |
* a factory for filters |
* a factory for filters |
153 |
*/ |
*/ |
154 |
FilterFactory2 ff; |
FilterFactory2 ff; |
158 |
*/ |
*/ |
159 |
GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null); |
GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null); |
160 |
|
|
|
/** |
|
|
* the collections of features to be selected or highlighted |
|
|
*/ |
|
|
FeatureCollection selection; |
|
|
|
|
|
/** |
|
|
* the collections of features to be selected or highlighted |
|
|
*/ |
|
|
FeatureCollection highlightFeature; |
|
|
|
|
161 |
private int state = ZoomIn; |
private int state = ZoomIn; |
162 |
|
|
163 |
/** |
/** |
165 |
*/ |
*/ |
166 |
private double zoomFactor = 2.0; |
private double zoomFactor = 2.0; |
167 |
|
|
|
Style lineHighlightStyle; |
|
|
|
|
|
Style pointHighlightStyle; |
|
|
|
|
|
Style polygonHighlightStyle; |
|
|
|
|
|
Style polygonSelectionStyle; |
|
|
|
|
|
Style pointSelectionStyle; |
|
|
|
|
|
Style lineSelectionStyle; |
|
|
|
|
168 |
boolean changed = true; |
boolean changed = true; |
169 |
|
|
170 |
LabelCache labelCache = new LabelCacheDefault(); |
LabelCache labelCache = new LabelCacheImpl(); |
171 |
|
|
172 |
// xulu.sc |
// xulu.sc |
173 |
// private boolean reset = false; |
// private boolean reset = false; |
184 |
|
|
185 |
int lastY; |
int lastY; |
186 |
|
|
|
private SelectionManager selectionManager; |
|
187 |
// xulu.sn |
// xulu.sn |
188 |
private Double maxZoomScale = Double.MIN_VALUE; |
private Double maxZoomScale = Double.MIN_VALUE; |
189 |
private Double minZoomScale = Double.MAX_VALUE; |
private Double minZoomScale = Double.MAX_VALUE; |
211 |
* @param context |
* @param context |
212 |
* - the map context to display |
* - the map context to display |
213 |
*/ |
*/ |
214 |
public JMapPane(GTRenderer render, MapContext context) { |
public JMapPane(final GTRenderer render, final MapContext context) { |
215 |
this(null, true, render, context); |
this(null, true, render, context); |
216 |
} |
} |
217 |
|
|
227 |
* @param context |
* @param context |
228 |
* - what to draw |
* - what to draw |
229 |
*/ |
*/ |
230 |
public JMapPane(LayoutManager layout, boolean isDoubleBuffered, |
public JMapPane(final LayoutManager layout, final boolean isDoubleBuffered, |
231 |
GTRenderer render, MapContext context) { |
final GTRenderer render, final MapContext context) { |
232 |
super(layout, isDoubleBuffered); |
super(layout, isDoubleBuffered); |
233 |
|
|
234 |
ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder |
ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder |
239 |
|
|
240 |
this.addMouseListener(this); |
this.addMouseListener(this); |
241 |
this.addMouseMotionListener(this); |
this.addMouseMotionListener(this); |
|
setHighlightManager(new HighlightManager(highlightLayer)); |
|
|
setSelectionManager(new SelectionManager(selectionLayer)); |
|
|
lineHighlightStyle = setupStyle(LINE, Color.red); |
|
|
|
|
|
pointHighlightStyle = setupStyle(POINT, Color.red); |
|
|
|
|
|
polygonHighlightStyle = setupStyle(POLYGON, Color.red); |
|
|
|
|
|
polygonSelectionStyle = setupStyle(POLYGON, Color.cyan); |
|
|
|
|
|
pointSelectionStyle = setupStyle(POINT, Color.cyan); |
|
|
|
|
|
lineSelectionStyle = setupStyle(LINE, Color.cyan); |
|
242 |
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); |
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); |
243 |
} |
} |
244 |
|
|
249 |
return renderer; |
return renderer; |
250 |
} |
} |
251 |
|
|
252 |
public void setRenderer(GTRenderer renderer) { |
public void setRenderer(final GTRenderer renderer) { |
253 |
Map hints = new HashMap(); |
Map hints = new HashMap(); |
254 |
if (renderer instanceof StreamingRenderer) { |
|
255 |
|
this.renderer = renderer; |
256 |
|
|
257 |
|
if (renderer instanceof StreamingRenderer || renderer instanceof TransitionShapefileRenderer) { |
258 |
hints = renderer.getRendererHints(); |
hints = renderer.getRendererHints(); |
259 |
if (hints == null) { |
if (hints == null) { |
260 |
hints = new HashMap(); |
hints = new HashMap(); |
265 |
} else { |
} else { |
266 |
hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache); |
hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache); |
267 |
} |
} |
268 |
|
|
269 |
|
hints.put("memoryPreloadingEnabled", Boolean.TRUE); |
270 |
|
|
271 |
renderer.setRendererHints(hints); |
renderer.setRendererHints(hints); |
272 |
} |
} |
273 |
|
|
|
this.renderer = renderer; |
|
274 |
// this.highlightRenderer = new StreamingRenderer(); |
// this.highlightRenderer = new StreamingRenderer(); |
275 |
// this.selectionRenderer = new StreamingRenderer(); |
// this.selectionRenderer = new StreamingRenderer(); |
276 |
|
|
|
hints.put("memoryPreloadingEnabled", Boolean.FALSE); |
|
277 |
// highlightRenderer.setRendererHints(hints); |
// highlightRenderer.setRendererHints(hints); |
278 |
// selectionRenderer.setRendererHints(hints); |
// selectionRenderer.setRendererHints(hints); |
279 |
|
|
280 |
|
// renderer.setRendererHints(hints); |
281 |
|
|
282 |
if (this.context != null) { |
if (this.context != null) { |
283 |
this.renderer.setContext(this.context); |
this.renderer.setContext(this.context); |
288 |
return context; |
return context; |
289 |
} |
} |
290 |
|
|
291 |
public void setContext(MapContext context) { |
public void setContext(final MapContext context) { |
292 |
if (this.context != null) { |
if (this.context != null) { |
293 |
this.context.removeMapLayerListListener(this); |
this.context.removeMapLayerListListener(this); |
294 |
} |
} |
308 |
return mapArea; |
return mapArea; |
309 |
} |
} |
310 |
|
|
311 |
public void setMapArea(Envelope mapArea) { |
public void setMapArea(final Envelope mapArea) { |
312 |
this.mapArea = mapArea; |
this.mapArea = mapArea; |
313 |
} |
} |
314 |
|
|
316 |
return state; |
return state; |
317 |
} |
} |
318 |
|
|
319 |
public void setState(int state) { |
public void setState(final int state) { |
320 |
this.state = state; |
this.state = state; |
321 |
|
|
322 |
// System.out.println("State: " + state); |
// System.out.println("State: " + state); |
326 |
return zoomFactor; |
return zoomFactor; |
327 |
} |
} |
328 |
|
|
329 |
public void setZoomFactor(double zoomFactor) { |
public void setZoomFactor(final double zoomFactor) { |
330 |
this.zoomFactor = zoomFactor; |
this.zoomFactor = zoomFactor; |
331 |
} |
} |
332 |
|
|
|
public MapLayer getSelectionLayer() { |
|
|
return selectionLayer; |
|
|
} |
|
|
|
|
|
public void setSelectionLayer(MapLayer selectionLayer) { |
|
|
this.selectionLayer = selectionLayer; |
|
|
if (selectionManager != null) { |
|
|
selectionManager.setSelectionLayer(selectionLayer); |
|
|
} |
|
|
} |
|
|
|
|
|
public boolean isHighlight() { |
|
|
return highlight; |
|
|
} |
|
|
|
|
|
public void setHighlight(boolean highlight) { |
|
|
this.highlight = highlight; |
|
|
} |
|
|
|
|
|
public MapLayer getHighlightLayer() { |
|
|
return highlightLayer; |
|
|
} |
|
|
|
|
|
public void setHighlightLayer(MapLayer highlightLayer) { |
|
|
this.highlightLayer = highlightLayer; |
|
|
|
|
|
if (highlightManager != null) { |
|
|
highlightManager.setHighlightLayer(highlightLayer); |
|
|
} |
|
|
} |
|
|
|
|
|
public HighlightManager getHighlightManager() { |
|
|
return highlightManager; |
|
|
} |
|
|
|
|
|
public void setHighlightManager(HighlightManager highlightManager) { |
|
|
this.highlightManager = highlightManager; |
|
|
this.highlightManager.addHighlightChangeListener(this); |
|
|
this.addMouseMotionListener(this.highlightManager); |
|
|
} |
|
|
|
|
|
public Style getLineHighlightStyle() { |
|
|
return lineHighlightStyle; |
|
|
} |
|
|
|
|
|
public void setLineHighlightStyle(Style lineHighlightStyle) { |
|
|
this.lineHighlightStyle = lineHighlightStyle; |
|
|
} |
|
|
|
|
|
public Style getLineSelectionStyle() { |
|
|
return lineSelectionStyle; |
|
|
} |
|
|
|
|
|
public void setLineSelectionStyle(Style lineSelectionStyle) { |
|
|
this.lineSelectionStyle = lineSelectionStyle; |
|
|
} |
|
|
|
|
|
public Style getPointHighlightStyle() { |
|
|
return pointHighlightStyle; |
|
|
} |
|
|
|
|
|
public void setPointHighlightStyle(Style pointHighlightStyle) { |
|
|
this.pointHighlightStyle = pointHighlightStyle; |
|
|
} |
|
|
|
|
|
public Style getPointSelectionStyle() { |
|
|
return pointSelectionStyle; |
|
|
} |
|
|
|
|
|
public void setPointSelectionStyle(Style pointSelectionStyle) { |
|
|
this.pointSelectionStyle = pointSelectionStyle; |
|
|
} |
|
|
|
|
|
public Style getPolygonHighlightStyle() { |
|
|
return polygonHighlightStyle; |
|
|
} |
|
|
|
|
|
public void setPolygonHighlightStyle(Style polygonHighlightStyle) { |
|
|
this.polygonHighlightStyle = polygonHighlightStyle; |
|
|
} |
|
|
|
|
|
public Style getPolygonSelectionStyle() { |
|
|
return polygonSelectionStyle; |
|
|
} |
|
|
|
|
|
public void setPolygonSelectionStyle(Style polygonSelectionStyle) { |
|
|
this.polygonSelectionStyle = polygonSelectionStyle; |
|
|
} |
|
333 |
|
|
334 |
protected void paintComponent(Graphics g) { |
protected void paintComponent(final Graphics g) { |
335 |
super.paintComponent(g); |
super.paintComponent(g); |
336 |
|
|
337 |
if ((renderer == null) || (mapArea == null)) { |
if ((renderer == null) || (mapArea == null)) { |
338 |
return; |
return; |
339 |
} |
} |
340 |
|
|
341 |
Rectangle r = getBounds(); |
final Rectangle r = getBounds(); |
342 |
Rectangle dr = new Rectangle(r.width, r.height); |
final Rectangle dr = new Rectangle(r.width, r.height); |
343 |
|
|
344 |
if (!r.equals(oldRect) || reset) { |
if (!r.equals(oldRect) || reset) { |
345 |
if (!r.equals(oldRect) && (mapArea == null)) { |
if (!r.equals(oldRect) && (mapArea == null)) { |
346 |
try { |
try { |
347 |
mapArea = context.getLayerBounds(); |
mapArea = context.getLayerBounds(); |
348 |
} catch (IOException e) { |
} catch (final IOException e) { |
349 |
// TODO Auto-generated catch block |
LOGGER.warn("context.getLayerBounds()", e); |
|
e.printStackTrace(); |
|
350 |
} |
} |
351 |
} |
} |
352 |
|
|
374 |
baseImage = new BufferedImage(dr.width, dr.height, |
baseImage = new BufferedImage(dr.width, dr.height, |
375 |
BufferedImage.TYPE_INT_ARGB); |
BufferedImage.TYPE_INT_ARGB); |
376 |
|
|
377 |
Graphics2D ig = baseImage.createGraphics(); |
final Graphics2D ig = baseImage.createGraphics(); |
378 |
/* System.out.println("rendering"); */ |
/* System.out.println("rendering"); */ |
379 |
renderer.setContext(context); |
if (renderer.getContext() != null) |
380 |
|
renderer.setContext(context); |
381 |
labelCache.clear(); // work around anoying labelcache bug |
labelCache.clear(); // work around anoying labelcache bug |
382 |
|
|
383 |
// draw the map |
// draw the map |
390 |
} |
} |
391 |
|
|
392 |
((Graphics2D) g).drawImage(baseImage, 0, 0, this); |
((Graphics2D) g).drawImage(baseImage, 0, 0, this); |
|
|
|
|
if ((selection != null) && (selection.size() > 0)) { |
|
|
// paint selection |
|
|
|
|
|
String type = selectionLayer.getFeatureSource().getSchema() |
|
|
.getDefaultGeometry().getType().getName(); |
|
|
/* String type = selection.getDefaultGeometry().getGeometryType(); */ |
|
|
/* System.out.println(type); */ |
|
|
if (type == null) |
|
|
type = "polygon"; |
|
|
|
|
|
/* String type = "point"; */ |
|
|
|
|
|
if (type.toLowerCase().endsWith("polygon")) { |
|
|
selectionStyle = polygonSelectionStyle; |
|
|
} else if (type.toLowerCase().endsWith("point")) { |
|
|
selectionStyle = pointSelectionStyle; |
|
|
} else if (type.toLowerCase().endsWith("line")) { |
|
|
selectionStyle = lineSelectionStyle; |
|
|
} |
|
|
|
|
|
selectionContext = new DefaultMapContext(DefaultGeographicCRS.WGS84); |
|
|
|
|
|
selectionContext.addLayer(selection, selectionStyle); |
|
|
selectionRenderer.setContext(selectionContext); |
|
|
|
|
|
selectImage = new BufferedImage(dr.width, dr.height, |
|
|
BufferedImage.TYPE_INT_ARGB); |
|
|
|
|
|
Graphics2D ig = selectImage.createGraphics(); |
|
|
/* System.out.println("rendering selection"); */ |
|
|
selectionRenderer.paint((Graphics2D) ig, dr, mapArea); |
|
|
|
|
|
((Graphics2D) g).drawImage(selectImage, 0, 0, this); |
|
|
} |
|
|
|
|
|
if (highlight && (highlightFeature != null) |
|
|
&& (highlightFeature.size() > 0)) { |
|
|
/* |
|
|
* String type = selection.getDefaultGeometry().getGeometryType(); |
|
|
* System.out.println(type); if(type==null) type="polygon"; |
|
|
*/ |
|
|
String type = highlightLayer.getFeatureSource().getSchema() |
|
|
.getDefaultGeometry().getType().getName(); |
|
|
/* String type = selection.getDefaultGeometry().getGeometryType(); */ |
|
|
// System.out.println(type); |
|
|
if (type == null) |
|
|
type = "polygon"; |
|
|
|
|
|
/* String type = "point"; */ |
|
|
Style highlightStyle = null; |
|
|
if (type.toLowerCase().endsWith("polygon")) { |
|
|
highlightStyle = polygonHighlightStyle; |
|
|
} else if (type.toLowerCase().endsWith("point")) { |
|
|
highlightStyle = pointHighlightStyle; |
|
|
} else if (type.toLowerCase().endsWith("line")) { |
|
|
highlightStyle = lineHighlightStyle; |
|
|
} |
|
|
|
|
|
MapContext highlightContext = new DefaultMapContext( |
|
|
DefaultGeographicCRS.WGS84); |
|
|
|
|
|
highlightContext.addLayer(highlightFeature, highlightStyle); |
|
|
highlightRenderer.setContext(highlightContext); |
|
|
|
|
|
/* System.out.println("rendering highlight"); */ |
|
|
highlightRenderer.paint((Graphics2D) g, dr, mapArea); |
|
|
} |
|
393 |
} |
} |
394 |
|
|
395 |
private Envelope fixAspectRatio(Rectangle r, Envelope mapArea) { |
private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea) { |
396 |
|
|
397 |
double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
final double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
398 |
double mapHeight = mapArea.getHeight(); |
final double mapHeight = mapArea.getHeight(); |
399 |
double scaleX = r.getWidth() / mapArea.getWidth(); /* |
final double scaleX = r.getWidth() / mapArea.getWidth(); /* |
400 |
* calculate the new |
* calculate the new |
401 |
* scale |
* scale |
402 |
*/ |
*/ |
403 |
|
|
404 |
double scaleY = r.getHeight() / mapArea.getHeight(); |
final double scaleY = r.getHeight() / mapArea.getHeight(); |
405 |
double scale = 1.0; // stupid compiler! |
double scale = 1.0; // stupid compiler! |
406 |
|
|
407 |
if (scaleX < scaleY) { /* pick the smaller scale */ |
if (scaleX < scaleY) { /* pick the smaller scale */ |
411 |
} |
} |
412 |
|
|
413 |
/* calculate the difference in width and height of the new extent */ |
/* calculate the difference in width and height of the new extent */ |
414 |
double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth); |
final double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth); |
415 |
double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight); |
final double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight); |
416 |
|
|
417 |
/* |
/* |
418 |
* System.out.println("delta x " + deltaX); |
* System.out.println("delta x " + deltaX); |
420 |
*/ |
*/ |
421 |
|
|
422 |
/* create the new extent */ |
/* create the new extent */ |
423 |
Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0), |
final Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0), |
424 |
mapArea.getMinY() - (deltaY / 2.0)); |
mapArea.getMinY() - (deltaY / 2.0)); |
425 |
Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0), |
final Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0), |
426 |
mapArea.getMaxY() + (deltaY / 2.0)); |
mapArea.getMaxY() + (deltaY / 2.0)); |
427 |
|
|
428 |
return new Envelope(ll, ur); |
return new Envelope(ll, ur); |
429 |
} |
} |
430 |
|
|
431 |
public void doSelection(double x, double y, MapLayer layer) { |
// public void doSelection(final double x, final double y, final MapLayer layer) { |
432 |
|
// |
433 |
Geometry geometry = gf.createPoint(new Coordinate(x, y)); |
// final Geometry geometry = gf.createPoint(new Coordinate(x, y)); |
434 |
|
// |
435 |
// org.opengis.geometry.Geometry geometry = new Point(); |
// // org.opengis.geometry.Geometry geometry = new Point(); |
436 |
|
// |
437 |
findFeature(geometry, layer); |
// findFeature(geometry, layer); |
438 |
|
// |
439 |
} |
// } |
440 |
|
// |
441 |
/** |
// /** |
442 |
* @param geometry |
// * @param geometry |
443 |
* - a geometry to construct the filter with |
// * - a geometry to construct the filter with |
444 |
* @param i |
// * @param i |
445 |
* - the index of the layer to search |
// * - the index of the layer to search |
446 |
* @throws IndexOutOfBoundsException |
// * @throws IndexOutOfBoundsException |
447 |
*/ |
// */ |
448 |
private void findFeature(Geometry geometry, MapLayer layer) |
// private void findFeature(final Geometry geometry, final MapLayer layer) |
449 |
throws IndexOutOfBoundsException { |
// throws IndexOutOfBoundsException { |
450 |
org.opengis.filter.spatial.BinarySpatialOperator f = null; |
// org.opengis.filter.spatial.BinarySpatialOperator f = null; |
451 |
|
// |
452 |
if ((context == null) || (layer == null)) { |
// if ((context == null) || (layer == null)) { |
453 |
return; |
// return; |
454 |
} |
// } |
455 |
|
// |
456 |
try { |
// try { |
457 |
String name = layer.getFeatureSource().getSchema() |
// String name = layer.getFeatureSource().getSchema() |
458 |
.getDefaultGeometry().getLocalName(); |
// .getDefaultGeometry().getLocalName(); |
459 |
|
// |
460 |
if (name == "") { |
// if (name == "") { |
461 |
name = "the_geom"; |
// name = "the_geom"; |
462 |
} |
// } |
463 |
|
// |
464 |
try { |
// try { |
465 |
f = ff.contains(ff.property(name), ff.literal(geometry)); |
// f = ff.contains(ff.property(name), ff.literal(geometry)); |
466 |
if (selectionManager != null) { |
// if (selectionManager != null) { |
467 |
// System.out.println("selection changed"); |
//// System.out.println("selection changed"); |
468 |
selectionManager.selectionChanged(this, f); |
// selectionManager.selectionChanged(this, f); |
469 |
|
// |
470 |
} |
// } |
471 |
} catch (IllegalFilterException e) { |
// } catch (final IllegalFilterException e) { |
472 |
// TODO Auto-generated catch block |
// // TODO Auto-generated catch block |
473 |
e.printStackTrace(); |
// e.printStackTrace(); |
474 |
} |
// } |
475 |
|
// |
476 |
/* |
// /* |
477 |
* // f.addLeftGeometry(ff.property(name)); // |
// * // f.addLeftGeometry(ff.property(name)); // |
478 |
* System.out.println("looking with " + f); FeatureCollection fc = |
// * System.out.println("looking with " + f); FeatureCollection fc = |
479 |
* layer.getFeatureSource().getFeatures(f); |
// * layer.getFeatureSource().getFeatures(f); |
480 |
* |
// * |
481 |
* |
// * |
482 |
* |
// * |
483 |
* if (fcol == null) { fcol = fc; |
// * if (fcol == null) { fcol = fc; |
484 |
* |
// * |
485 |
* // here we should set the defaultgeom type } else { |
// * // here we should set the defaultgeom type } else { |
486 |
* fcol.addAll(fc); } |
// * fcol.addAll(fc); } |
487 |
*/ |
// */ |
488 |
|
// |
489 |
/* |
// /* |
490 |
* GeometryAttributeType gat = |
// * GeometryAttributeType gat = |
491 |
* layer.getFeatureSource().getSchema().getDefaultGeometry(); |
// * layer.getFeatureSource().getSchema().getDefaultGeometry(); |
492 |
* fcol.setDefaultGeometry((Geometry)gat.createDefaultValue()); |
// * fcol.setDefaultGeometry((Geometry)gat.createDefaultValue()); |
493 |
*/ |
// */ |
494 |
|
// |
495 |
/* |
// /* |
496 |
* Iterator fi = fc.iterator(); while (fi.hasNext()) { Feature feat |
// * Iterator fi = fc.iterator(); while (fi.hasNext()) { SimpleFeature feat |
497 |
* = (Feature) fi.next(); System.out.println("selected " + |
// * = (SimpleFeature) fi.next(); System.out.println("selected " + |
498 |
* feat.getAttribute("STATE_NAME")); } |
// * feat.getAttribute("STATE_NAME")); } |
499 |
*/ |
// */ |
500 |
} catch (IllegalFilterException e) { |
// } catch (final IllegalFilterException e) { |
501 |
// TODO Auto-generated catch block |
// // TODO Auto-generated catch block |
502 |
e.printStackTrace(); |
// e.printStackTrace(); |
503 |
} |
// } |
504 |
return; |
// return; |
505 |
} |
// } |
506 |
|
|
507 |
public void mouseClicked(MouseEvent e) { |
public void mouseClicked(final MouseEvent e) { |
508 |
if (mapArea == null) return; |
if (mapArea == null) return; |
509 |
// System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+" |
// System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+" |
510 |
// h:"+mapArea.getHeight()); |
// h:"+mapArea.getHeight()); |
511 |
Rectangle bounds = this.getBounds(); |
final Rectangle bounds = this.getBounds(); |
512 |
double x = (double) (e.getX()); |
final double x = (double) (e.getX()); |
513 |
double y = (double) (e.getY()); |
final double y = (double) (e.getY()); |
514 |
double width = mapArea.getWidth(); |
final double width = mapArea.getWidth(); |
515 |
double height = mapArea.getHeight(); |
final double height = mapArea.getHeight(); |
516 |
// xulu.sc |
// xulu.sc |
517 |
// double width2 = mapArea.getWidth() / 2.0; |
// double width2 = mapArea.getWidth() / 2.0; |
518 |
// double height2 = mapArea.getHeight() / 2.0; |
// double height2 = mapArea.getHeight() / 2.0; |
519 |
double width2 = width / 2.0; |
final double width2 = width / 2.0; |
520 |
double height2 = height / 2.0; |
final double height2 = height / 2.0; |
521 |
// xulu.ec |
// xulu.ec |
522 |
double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX(); |
final double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX(); |
523 |
double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height) |
final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height) |
524 |
+ mapArea.getMinY(); |
+ mapArea.getMinY(); |
525 |
|
|
526 |
/* |
/* |
550 |
zlevel = 1.0 / zoomFactor; |
zlevel = 1.0 / zoomFactor; |
551 |
|
|
552 |
break; |
break; |
553 |
|
// |
554 |
case Select: |
// case Select: |
555 |
doSelection(mapX, mapY, selectionLayer); |
// doSelection(mapX, mapY, selectionLayer); |
556 |
|
// |
557 |
return; |
// return; |
558 |
|
|
559 |
default: |
default: |
560 |
return; |
return; |
561 |
} |
} |
562 |
|
|
563 |
Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY |
final Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY |
564 |
- (height2 / zlevel)); |
- (height2 / zlevel)); |
565 |
Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY |
final Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY |
566 |
+ (height2 / zlevel)); |
+ (height2 / zlevel)); |
567 |
// xulu.sc SK: Check for min/max scale |
// xulu.sc SK: Check for min/max scale |
568 |
// mapArea = new Envelope(ll, ur); |
// mapArea = new Envelope(ll, ur); |
577 |
repaint(); |
repaint(); |
578 |
} |
} |
579 |
|
|
580 |
public void mouseEntered(MouseEvent e) { |
public void mouseEntered(final MouseEvent e) { |
581 |
} |
} |
582 |
|
|
583 |
public void mouseExited(MouseEvent e) { |
public void mouseExited(final MouseEvent e) { |
584 |
} |
} |
585 |
|
|
586 |
public void mousePressed(MouseEvent e) { |
public void mousePressed(final MouseEvent e) { |
587 |
startX = e.getX(); |
startX = e.getX(); |
588 |
startY = e.getY(); |
startY = e.getY(); |
589 |
lastX = 0; |
lastX = 0; |
590 |
lastY = 0; |
lastY = 0; |
591 |
} |
} |
592 |
|
|
593 |
public void mouseReleased(MouseEvent e) { |
public void mouseReleased(final MouseEvent e) { |
594 |
int endX = e.getX(); |
final int endX = e.getX(); |
595 |
int endY = e.getY(); |
final int endY = e.getY(); |
596 |
|
|
597 |
processDrag(startX, startY, endX, endY, e); |
processDrag(startX, startY, endX, endY, e); |
598 |
lastX = 0; |
lastX = 0; |
604 |
panning_started = false; |
panning_started = false; |
605 |
} |
} |
606 |
|
|
607 |
public void mouseDragged(MouseEvent e) { |
public void mouseDragged(final MouseEvent e) { |
608 |
Graphics graphics = this.getGraphics(); |
final Graphics graphics = this.getGraphics(); |
609 |
int x = e.getX(); |
final int x = e.getX(); |
610 |
int y = e.getY(); |
final int y = e.getY(); |
611 |
|
|
612 |
if ((state == JMapPane.Pan) |
if ((state == JMapPane.Pan) |
613 |
|| ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
|| ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
621 |
|
|
622 |
// move the image with the mouse |
// move the image with the mouse |
623 |
if ((lastX > 0) && (lastY > 0)) { |
if ((lastX > 0) && (lastY > 0)) { |
624 |
int dx = lastX - startX; |
final int dx = lastX - startX; |
625 |
int dy = lastY - startY; |
final int dy = lastY - startY; |
626 |
// System.out.println("translate "+dx+","+dy); |
// System.out.println("translate "+dx+","+dy); |
627 |
final Graphics2D g2 = panningImage.createGraphics(); |
final Graphics2D g2 = panningImage.createGraphics(); |
628 |
g2.setBackground(new Color(240, 240, 240)); // TODO richtige |
g2.setBackground(new Color(240, 240, 240)); // TODO richtige |
652 |
lastX = x; |
lastX = x; |
653 |
lastY = y; |
lastY = y; |
654 |
drawRectangle(graphics); |
drawRectangle(graphics); |
655 |
} else if (state == JMapPane.Select && selectionLayer != null) { |
} |
656 |
|
// else if (state == JMapPane.Select && selectionLayer != null) { |
657 |
// construct a new bbox filter |
// |
658 |
Rectangle bounds = this.getBounds(); |
// // construct a new bbox filter |
659 |
|
// final Rectangle bounds = this.getBounds(); |
660 |
double mapWidth = mapArea.getWidth(); |
// |
661 |
double mapHeight = mapArea.getHeight(); |
// final double mapWidth = mapArea.getWidth(); |
662 |
|
// final double mapHeight = mapArea.getHeight(); |
663 |
double x1 = ((this.startX * mapWidth) / (double) bounds.width) |
// |
664 |
+ mapArea.getMinX(); |
// final double x1 = ((this.startX * mapWidth) / (double) bounds.width) |
665 |
double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height) |
// + mapArea.getMinX(); |
666 |
+ mapArea.getMinY(); |
// final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height) |
667 |
double x2 = ((x * mapWidth) / (double) bounds.width) |
// + mapArea.getMinY(); |
668 |
+ mapArea.getMinX(); |
// final double x2 = ((x * mapWidth) / (double) bounds.width) |
669 |
double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height) |
// + mapArea.getMinX(); |
670 |
+ mapArea.getMinY(); |
// final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height) |
671 |
double left = Math.min(x1, x2); |
// + mapArea.getMinY(); |
672 |
double right = Math.max(x1, x2); |
// final double left = Math.min(x1, x2); |
673 |
double bottom = Math.min(y1, y2); |
// final double right = Math.max(x1, x2); |
674 |
double top = Math.max(y1, y2); |
// final double bottom = Math.min(y1, y2); |
675 |
|
// final double top = Math.max(y1, y2); |
676 |
String name = selectionLayer.getFeatureSource().getSchema() |
// |
677 |
.getDefaultGeometry().getName(); |
// String name = selectionLayer.getFeatureSource().getSchema() |
678 |
|
// .getDefaultGeometry().getName(); |
679 |
if (name == "") { |
// |
680 |
name = "the_geom"; |
// if (name == "") { |
681 |
} |
// name = "the_geom"; |
682 |
Filter bb = ff.bbox(ff.property(name), left, bottom, right, top, |
// } |
683 |
getContext().getCoordinateReferenceSystem().toString()); |
// final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top, |
684 |
if (selectionManager != null) { |
// getContext().getCoordinateReferenceSystem().toString()); |
685 |
selectionManager.selectionChanged(this, bb); |
// if (selectionManager != null) { |
686 |
} |
// selectionManager.selectionChanged(this, bb); |
687 |
|
// } |
688 |
graphics.setXORMode(Color.green); |
// |
689 |
|
// graphics.setXORMode(Color.green); |
690 |
/* |
// |
691 |
* if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); } |
// /* |
692 |
*/ |
// * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); } |
693 |
|
// */ |
694 |
// draw new box |
// |
695 |
lastX = x; |
// // draw new box |
696 |
lastY = y; |
// lastX = x; |
697 |
drawRectangle(graphics); |
// lastY = y; |
698 |
} |
// drawRectangle(graphics); |
699 |
|
// } |
700 |
|
|
701 |
} |
} |
702 |
|
|
704 |
// private void processDrag(int x1, int y1, int x2, int y2) { |
// private void processDrag(int x1, int y1, int x2, int y2) { |
705 |
// sk.ce |
// sk.ce |
706 |
protected void processDrag(final int x1, final int y1, final int x2, |
protected void processDrag(final int x1, final int y1, final int x2, |
707 |
final int y2, MouseEvent e) { |
final int y2, final MouseEvent e) { |
708 |
|
|
709 |
/**** |
/**** |
710 |
* If no layer is availabe we dont want a NullPointerException |
* If no layer is availabe we dont want a NullPointerException |
723 |
return; |
return; |
724 |
} |
} |
725 |
|
|
726 |
Rectangle bounds = this.getBounds(); |
final Rectangle bounds = this.getBounds(); |
727 |
|
|
728 |
double mapWidth = mapArea.getWidth(); |
final double mapWidth = mapArea.getWidth(); |
729 |
double mapHeight = mapArea.getHeight(); |
final double mapHeight = mapArea.getHeight(); |
730 |
|
|
731 |
double startX = ((x1 * mapWidth) / (double) bounds.width) |
final double startX = ((x1 * mapWidth) / (double) bounds.width) |
732 |
+ mapArea.getMinX(); |
+ mapArea.getMinX(); |
733 |
double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height) |
final double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height) |
734 |
+ mapArea.getMinY(); |
+ mapArea.getMinY(); |
735 |
double endX = ((x2 * mapWidth) / (double) bounds.width) |
final double endX = ((x2 * mapWidth) / (double) bounds.width) |
736 |
+ mapArea.getMinX(); |
+ mapArea.getMinX(); |
737 |
double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height) |
final double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height) |
738 |
+ mapArea.getMinY(); |
+ mapArea.getMinY(); |
739 |
|
|
740 |
if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) { |
if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) { |
741 |
// move the image with the mouse |
// move the image with the mouse |
742 |
// calculate X offsets from start point to the end Point |
// calculate X offsets from start point to the end Point |
743 |
double deltaX1 = endX - startX; |
final double deltaX1 = endX - startX; |
744 |
|
|
745 |
// System.out.println("deltaX " + deltaX1); |
// System.out.println("deltaX " + deltaX1); |
746 |
// new edges |
// new edges |
747 |
double left = mapArea.getMinX() - deltaX1; |
final double left = mapArea.getMinX() - deltaX1; |
748 |
double right = mapArea.getMaxX() - deltaX1; |
final double right = mapArea.getMaxX() - deltaX1; |
749 |
|
|
750 |
// now for Y |
// now for Y |
751 |
double deltaY1 = endY - startY; |
final double deltaY1 = endY - startY; |
752 |
|
|
753 |
// System.out.println("deltaY " + deltaY1); |
// System.out.println("deltaY " + deltaY1); |
754 |
double bottom = mapArea.getMinY() - deltaY1; |
final double bottom = mapArea.getMinY() - deltaY1; |
755 |
double top = mapArea.getMaxY() - deltaY1; |
final double top = mapArea.getMaxY() - deltaY1; |
756 |
Coordinate ll = new Coordinate(left, bottom); |
final Coordinate ll = new Coordinate(left, bottom); |
757 |
Coordinate ur = new Coordinate(right, top); |
final Coordinate ur = new Coordinate(right, top); |
758 |
// xulu.sc |
// xulu.sc |
759 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
760 |
setMapArea(fixAspectRatio(this.getBounds(), new Envelope(ll, ur))); |
setMapArea(fixAspectRatio(this.getBounds(), new Envelope(ll, ur))); |
769 |
|
|
770 |
drawRectangle(this.getGraphics()); |
drawRectangle(this.getGraphics()); |
771 |
// make the dragged rectangle (in map coords) the new BBOX |
// make the dragged rectangle (in map coords) the new BBOX |
772 |
double left = Math.min(startX, endX); |
final double left = Math.min(startX, endX); |
773 |
double right = Math.max(startX, endX); |
final double right = Math.max(startX, endX); |
774 |
double bottom = Math.min(startY, endY); |
final double bottom = Math.min(startY, endY); |
775 |
double top = Math.max(startY, endY); |
final double top = Math.max(startY, endY); |
776 |
Coordinate ll = new Coordinate(left, bottom); |
final Coordinate ll = new Coordinate(left, bottom); |
777 |
Coordinate ur = new Coordinate(right, top); |
final Coordinate ur = new Coordinate(right, top); |
778 |
// xulu.sc |
// xulu.sc |
779 |
|
|
780 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
798 |
drawRectangle(this.getGraphics()); |
drawRectangle(this.getGraphics()); |
799 |
|
|
800 |
// make the dragged rectangle in screen coords the new map size? |
// make the dragged rectangle in screen coords the new map size? |
801 |
double left = Math.min(startX, endX); |
final double left = Math.min(startX, endX); |
802 |
double right = Math.max(startX, endX); |
final double right = Math.max(startX, endX); |
803 |
double bottom = Math.min(startY, endY); |
final double bottom = Math.min(startY, endY); |
804 |
double top = Math.max(startY, endY); |
final double top = Math.max(startY, endY); |
805 |
double nWidth = (mapWidth * mapWidth) / (right - left); |
final double nWidth = (mapWidth * mapWidth) / (right - left); |
806 |
double nHeight = (mapHeight * mapHeight) / (top - bottom); |
final double nHeight = (mapHeight * mapHeight) / (top - bottom); |
807 |
double deltaX1 = left - mapArea.getMinX(); |
final double deltaX1 = left - mapArea.getMinX(); |
808 |
double nDeltaX1 = (deltaX1 * nWidth) / mapWidth; |
final double nDeltaX1 = (deltaX1 * nWidth) / mapWidth; |
809 |
double deltaY1 = bottom - mapArea.getMinY(); |
final double deltaY1 = bottom - mapArea.getMinY(); |
810 |
double nDeltaY1 = (deltaY1 * nHeight) / mapHeight; |
final double nDeltaY1 = (deltaY1 * nHeight) / mapHeight; |
811 |
Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1, |
final Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1, |
812 |
mapArea.getMinY() - nDeltaY1); |
mapArea.getMinY() - nDeltaY1); |
813 |
double deltaX2 = mapArea.getMaxX() - right; |
final double deltaX2 = mapArea.getMaxX() - right; |
814 |
double nDeltaX2 = (deltaX2 * nWidth) / mapWidth; |
final double nDeltaX2 = (deltaX2 * nWidth) / mapWidth; |
815 |
double deltaY2 = mapArea.getMaxY() - top; |
final double deltaY2 = mapArea.getMaxY() - top; |
816 |
double nDeltaY2 = (deltaY2 * nHeight) / mapHeight; |
final double nDeltaY2 = (deltaY2 * nHeight) / mapHeight; |
817 |
Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2, |
final Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2, |
818 |
mapArea.getMaxY() + nDeltaY2); |
mapArea.getMaxY() + nDeltaY2); |
819 |
// xulu.sc |
// xulu.sc |
820 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
821 |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
822 |
|
|
823 |
// xulu.ec |
// xulu.ec |
824 |
} else if (state == JMapPane.Select && selectionLayer != null) { |
} |
825 |
double left = Math.min(startX, endX); |
// else if (state == JMapPane.Select && selectionLayer != null) { |
826 |
double right = Math.max(startX, endX); |
// final double left = Math.min(startX, endX); |
827 |
double bottom = Math.min(startY, endY); |
// final double right = Math.max(startX, endX); |
828 |
double top = Math.max(startY, endY); |
// final double bottom = Math.min(startY, endY); |
829 |
|
// final double top = Math.max(startY, endY); |
830 |
String name = selectionLayer.getFeatureSource().getSchema() |
// |
831 |
.getDefaultGeometry().getLocalName(); |
// String name = selectionLayer.getFeatureSource().getSchema() |
832 |
|
// .getDefaultGeometry().getLocalName(); |
833 |
if (name == "") { |
// |
834 |
name = "the_geom"; |
// if (name == "") { |
835 |
} |
// name = "the_geom"; |
836 |
Filter bb = ff.bbox(ff.property(name), left, bottom, right, top, |
// } |
837 |
getContext().getCoordinateReferenceSystem().toString()); |
// final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top, |
838 |
// System.out.println(bb.toString()); |
// getContext().getCoordinateReferenceSystem().toString()); |
839 |
if (selectionManager != null) { |
// // System.out.println(bb.toString()); |
840 |
selectionManager.selectionChanged(this, bb); |
// if (selectionManager != null) { |
841 |
} |
// selectionManager.selectionChanged(this, bb); |
842 |
/* |
// } |
843 |
* FeatureCollection fc; selection = null; try { fc = |
// /* |
844 |
* selectionLayer.getFeatureSource().getFeatures(bb); selection = |
// * FeatureCollection fc; selection = null; try { fc = |
845 |
* fc; } catch (IOException e) { e.printStackTrace(); } |
// * selectionLayer.getFeatureSource().getFeatures(bb); selection = |
846 |
*/ |
// * fc; } catch (IOException e) { e.printStackTrace(); } |
847 |
} |
// */ |
848 |
|
// } |
849 |
|
|
850 |
// xulu.so |
// xulu.so |
851 |
// setMapArea(mapArea); |
// setMapArea(mapArea); |
857 |
return clickable; |
return clickable; |
858 |
} |
} |
859 |
|
|
860 |
private org.geotools.styling.Style setupStyle(int type, Color color) { |
private org.geotools.styling.Style setupStyle(final int type, final Color color) { |
861 |
StyleFactory sf = org.geotools.factory.CommonFactoryFinder |
final StyleFactory sf = org.geotools.factory.CommonFactoryFinder |
862 |
.getStyleFactory(null); |
.getStyleFactory(null); |
863 |
StyleBuilder sb = new StyleBuilder(); |
final StyleBuilder sb = new StyleBuilder(); |
864 |
|
|
865 |
org.geotools.styling.Style s = sf.createStyle(); |
org.geotools.styling.Style s = sf.createStyle(); |
866 |
s.setTitle("selection"); |
s.setTitle("selection"); |
867 |
|
|
868 |
// TODO parameterise the color |
// TODO parameterise the color |
869 |
PolygonSymbolizer ps = sb.createPolygonSymbolizer(color); |
final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color); |
870 |
ps.setStroke(sb.createStroke(color)); |
ps.setStroke(sb.createStroke(color)); |
871 |
|
|
872 |
LineSymbolizer ls = sb.createLineSymbolizer(color); |
final LineSymbolizer ls = sb.createLineSymbolizer(color); |
873 |
Graphic h = sb.createGraphic(); |
final Graphic h = sb.createGraphic(); |
874 |
h.setMarks(new Mark[] { sb.createMark("square", color) }); |
h.setMarks(new Mark[] { sb.createMark("square", color) }); |
875 |
|
|
876 |
PointSymbolizer pts = sb.createPointSymbolizer(h); |
final PointSymbolizer pts = sb.createPointSymbolizer(h); |
877 |
|
|
878 |
// Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts}); |
// Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts}); |
879 |
switch (type) { |
switch (type) { |
894 |
return s; |
return s; |
895 |
} |
} |
896 |
|
|
|
public void highlightChanged(HighlightChangedEvent e) { |
|
|
org.opengis.filter.Filter f = e.getFilter(); |
|
897 |
|
|
898 |
try { |
public void propertyChange(final PropertyChangeEvent evt) { |
899 |
highlightFeature = highlightLayer.getFeatureSource().getFeatures(f); |
final String prop = evt.getPropertyName(); |
|
} catch (IOException e1) { |
|
|
// TODO Auto-generated catch block |
|
|
e1.printStackTrace(); |
|
|
} |
|
|
|
|
|
repaint(); |
|
|
} |
|
|
|
|
|
public void propertyChange(PropertyChangeEvent evt) { |
|
|
String prop = evt.getPropertyName(); |
|
900 |
|
|
901 |
if (prop.equalsIgnoreCase("crs")) { |
if (prop.equalsIgnoreCase("crs")) { |
902 |
context.setAreaOfInterest(context.getAreaOfInterest(), |
context.setAreaOfInterest(context.getAreaOfInterest(), |
908 |
return reset; |
return reset; |
909 |
} |
} |
910 |
|
|
911 |
public void setReset(boolean reset) { |
public void setReset(final boolean reset) { |
912 |
this.reset = reset; |
this.reset = reset; |
913 |
} |
} |
914 |
|
|
915 |
public void layerAdded(MapLayerListEvent event) { |
public void layerAdded(final MapLayerListEvent event) { |
916 |
changed = true; |
changed = true; |
917 |
|
|
918 |
if (context.getLayers().length == 1) { // the first one |
if (context.getLayers().length == 1) { // the first one |
924 |
if (mapArea == null) |
if (mapArea == null) |
925 |
mapArea = context.getLayerBounds(); |
mapArea = context.getLayerBounds(); |
926 |
// xulu.ec |
// xulu.ec |
927 |
} catch (IOException e) { |
} catch (final IOException e) { |
928 |
// TODO Auto-generated catch block |
// TODO Auto-generated catch block |
929 |
e.printStackTrace(); |
e.printStackTrace(); |
930 |
} |
} |
935 |
repaint(); |
repaint(); |
936 |
} |
} |
937 |
|
|
938 |
public void layerRemoved(MapLayerListEvent event) { |
public void layerRemoved(final MapLayerListEvent event) { |
939 |
changed = true; |
changed = true; |
940 |
repaint(); |
repaint(); |
941 |
} |
} |
942 |
|
|
943 |
public void layerChanged(MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
944 |
changed = true; |
changed = true; |
945 |
// System.out.println("layer changed - repaint"); |
// System.out.println("layer changed - repaint"); |
946 |
repaint(); |
repaint(); |
947 |
} |
} |
948 |
|
|
949 |
public void layerMoved(MapLayerListEvent event) { |
public void layerMoved(final MapLayerListEvent event) { |
950 |
changed = true; |
changed = true; |
951 |
repaint(); |
repaint(); |
952 |
} |
} |
953 |
|
|
954 |
protected void drawRectangle(Graphics graphics) { |
protected void drawRectangle(final Graphics graphics) { |
955 |
// undraw last box/draw new box |
// undraw last box/draw new box |
956 |
int left = Math.min(startX, lastX); |
final int left = Math.min(startX, lastX); |
957 |
int right = Math.max(startX, lastX); |
final int right = Math.max(startX, lastX); |
958 |
int top = Math.max(startY, lastY); |
final int top = Math.max(startY, lastY); |
959 |
int bottom = Math.min(startY, lastY); |
final int bottom = Math.min(startY, lastY); |
960 |
int width = right - left; |
final int width = right - left; |
961 |
int height = top - bottom; |
final int height = top - bottom; |
962 |
// System.out.println("drawing rect("+left+","+bottom+","+ width+","+ |
// System.out.println("drawing rect("+left+","+bottom+","+ width+","+ |
963 |
// height+")"); |
// height+")"); |
964 |
graphics.drawRect(left, bottom, width, height); |
graphics.drawRect(left, bottom, width, height); |
970 |
* |
* |
971 |
* @param clickable |
* @param clickable |
972 |
*/ |
*/ |
973 |
public void setClickable(boolean clickable) { |
public void setClickable(final boolean clickable) { |
974 |
this.clickable = clickable; |
this.clickable = clickable; |
975 |
} |
} |
976 |
|
|
977 |
public void mouseMoved(MouseEvent e) { |
public void mouseMoved(final MouseEvent e) { |
|
} |
|
|
|
|
|
public FeatureCollection getSelection() { |
|
|
return selection; |
|
|
} |
|
|
|
|
|
public void setSelection(FeatureCollection selection) { |
|
|
this.selection = selection; |
|
|
repaint(); |
|
978 |
} |
} |
979 |
|
|
|
/* |
|
|
* (non-Javadoc) |
|
|
* |
|
|
* @see |
|
|
* org.geotools.gui.swing.event.SelectionChangeListener#selectionChanged |
|
|
* (org.geotools.gui.swing.event.SelectionChangedEvent) |
|
|
*/ |
|
|
public void selectionChanged(SelectionChangedEvent e) { |
|
980 |
|
|
|
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); |
|
|
|
|
|
} |
|
981 |
|
|
982 |
// xulu.sn |
// xulu.sn |
983 |
/** |
/** |
1003 |
*/ |
*/ |
1004 |
env = fixAspectRatio(this.getBounds(), env); |
env = fixAspectRatio(this.getBounds(), env); |
1005 |
|
|
1006 |
double scale = env.getWidth() / getWidth(); |
final double scale = env.getWidth() / getWidth(); |
1007 |
double centerX = env.getMinX() + env.getWidth() / 2.; |
final double centerX = env.getMinX() + env.getWidth() / 2.; |
1008 |
double centerY = env.getMinY() + env.getHeight() / 2.; |
final double centerY = env.getMinY() + env.getHeight() / 2.; |
1009 |
double newWidth2; |
double newWidth2; |
1010 |
double newHeight2; |
double newHeight2; |
1011 |
if (scale < getMaxZoomScale()) { |
if (scale < getMaxZoomScale()) { |
1027 |
return env; |
return env; |
1028 |
} |
} |
1029 |
|
|
1030 |
Coordinate ll = new Coordinate(centerX - newWidth2, centerY |
final Coordinate ll = new Coordinate(centerX - newWidth2, centerY |
1031 |
- newHeight2); |
- newHeight2); |
1032 |
Coordinate ur = new Coordinate(centerX + newWidth2, centerY |
final Coordinate ur = new Coordinate(centerX + newWidth2, centerY |
1033 |
+ newHeight2); |
+ newHeight2); |
1034 |
|
|
1035 |
return new Envelope(ll, ur); |
return new Envelope(ll, ur); |
1064 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
1065 |
* Krüger</a> |
* Krüger</a> |
1066 |
*/ |
*/ |
1067 |
public void setMaxZoomScale(Double maxZoomScale) { |
public void setMaxZoomScale(final Double maxZoomScale) { |
1068 |
// System.out.println("setting max scale to "+maxZoomScale); |
// System.out.println("setting max scale to "+maxZoomScale); |
1069 |
this.maxZoomScale = maxZoomScale; |
this.maxZoomScale = maxZoomScale; |
1070 |
} |
} |
1076 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
1077 |
* Krüger</a> |
* Krüger</a> |
1078 |
*/ |
*/ |
1079 |
public void setMinZoomScale(Double minZoomScale) { |
public void setMinZoomScale(final Double minZoomScale) { |
1080 |
this.minZoomScale = minZoomScale; |
this.minZoomScale = minZoomScale; |
1081 |
} |
} |
1082 |
// xulu.en |
// xulu.en |