13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
* Lesser General Public License for more details. |
* Lesser General Public License for more details. |
15 |
*/ |
*/ |
16 |
package org.geotools.gui.swing; |
package gtmig.org.geotools.swing; |
17 |
|
|
18 |
/** |
/** |
19 |
* <b>Xulu:<br> |
* <b>Xulu:<br> |
58 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
59 |
|
|
60 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
61 |
import org.geotools.feature.FeatureCollection; |
import org.geotools.geometry.jts.ReferencedEnvelope; |
|
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; |
|
62 |
import org.geotools.map.MapContext; |
import org.geotools.map.MapContext; |
|
import org.geotools.map.MapLayer; |
|
63 |
import org.geotools.map.event.MapLayerListEvent; |
import org.geotools.map.event.MapLayerListEvent; |
64 |
import org.geotools.map.event.MapLayerListListener; |
import org.geotools.map.event.MapLayerListListener; |
|
import org.geotools.referencing.crs.DefaultGeographicCRS; |
|
65 |
import org.geotools.renderer.GTRenderer; |
import org.geotools.renderer.GTRenderer; |
66 |
|
import org.geotools.renderer.label.LabelCacheImpl; |
67 |
import org.geotools.renderer.lite.LabelCache; |
import org.geotools.renderer.lite.LabelCache; |
|
import org.geotools.renderer.lite.LabelCacheDefault; |
|
68 |
import org.geotools.renderer.lite.StreamingRenderer; |
import org.geotools.renderer.lite.StreamingRenderer; |
69 |
import org.geotools.renderer.shape.TransitionShapefileRenderer; |
import org.geotools.renderer.shape.ShapefileRenderer; |
|
import org.geotools.styling.Graphic; |
|
|
import org.geotools.styling.LineSymbolizer; |
|
|
import org.geotools.styling.Mark; |
|
|
import org.geotools.styling.PointSymbolizer; |
|
|
import org.geotools.styling.PolygonSymbolizer; |
|
|
import org.geotools.styling.Style; |
|
|
import org.geotools.styling.StyleBuilder; |
|
|
import org.geotools.styling.StyleFactory; |
|
|
import org.opengis.filter.Filter; |
|
70 |
import org.opengis.filter.FilterFactory2; |
import org.opengis.filter.FilterFactory2; |
71 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
72 |
|
|
73 |
|
import schmitzm.geotools.JTSUtil; |
74 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
75 |
|
|
76 |
import com.vividsolutions.jts.geom.Coordinate; |
import com.vividsolutions.jts.geom.Coordinate; |
77 |
import com.vividsolutions.jts.geom.Envelope; |
import com.vividsolutions.jts.geom.Envelope; |
|
import com.vividsolutions.jts.geom.Geometry; |
|
78 |
import com.vividsolutions.jts.geom.GeometryFactory; |
import com.vividsolutions.jts.geom.GeometryFactory; |
79 |
|
|
80 |
public class JMapPane extends JPanel implements MouseListener, |
public class JMapPane extends JPanel implements MouseListener, |
81 |
MouseMotionListener, HighlightChangeListener, SelectionChangeListener, |
MouseMotionListener, PropertyChangeListener, MapLayerListListener { |
|
PropertyChangeListener, MapLayerListListener { |
|
82 |
private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName()); |
private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName()); |
83 |
|
|
84 |
private static final long serialVersionUID = -8647971481359690499L; |
private static final long serialVersionUID = -8647971481359690499L; |
93 |
|
|
94 |
public static final int Select = 4; |
public static final int Select = 4; |
95 |
|
|
|
private static final int POLYGON = 0; |
|
|
|
|
|
private static final int LINE = 1; |
|
|
|
|
|
private static final int POINT = 2; |
|
|
|
|
96 |
/** |
/** |
97 |
* what renders the map |
* what renders the map |
98 |
*/ |
*/ |
99 |
GTRenderer renderer; |
GTRenderer renderer; |
100 |
|
|
|
private GTRenderer highlightRenderer, selectionRenderer; |
|
|
|
|
101 |
/** |
/** |
102 |
* the map context to render |
* the map context to render |
103 |
*/ |
*/ |
104 |
MapContext context; |
MapContext context; |
105 |
|
|
|
private MapContext selectionContext; |
|
|
|
|
106 |
/** |
/** |
107 |
* the area of the map to draw |
* the area of the map to draw |
108 |
*/ |
*/ |
|
// xulu.sc |
|
|
// Envelope mapArea; |
|
109 |
protected Envelope mapArea; |
protected Envelope mapArea; |
|
// xulu.ec |
|
110 |
|
|
111 |
/** |
/** |
112 |
* the size of the pane last time we drew |
* the size of the pane last time we drew |
113 |
*/ |
*/ |
|
// xulu.sc |
|
|
// private Rectangle oldRect = null; |
|
114 |
protected Rectangle oldRect = null; |
protected Rectangle oldRect = null; |
|
// xulu.ec |
|
115 |
|
|
116 |
/** |
/** |
117 |
* the last map area drawn. |
* the last map area drawn. |
118 |
*/ |
*/ |
|
// xulu.sc |
|
|
// private Envelope oldMapArea = null; |
|
119 |
protected Envelope oldMapArea = null; |
protected Envelope oldMapArea = null; |
|
// xulu.ec |
|
120 |
|
|
121 |
/** |
/** |
122 |
* the base image of the map |
* the base image of the map |
123 |
*/ |
*/ |
124 |
protected BufferedImage baseImage, panningImage; |
protected BufferedImage baseImage, panningImage; |
|
// SK: private BufferedImage baseImage, panningImage; |
|
|
|
|
|
/** |
|
|
* 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; |
|
125 |
|
|
126 |
/** |
/** |
127 |
* a factory for filters |
* a factory for filters |
133 |
*/ |
*/ |
134 |
GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null); |
GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null); |
135 |
|
|
|
/** |
|
|
* the collections of features to be selected or highlighted |
|
|
*/ |
|
|
FeatureCollection selection; |
|
|
|
|
|
/** |
|
|
* the collections of features to be selected or highlighted |
|
|
*/ |
|
|
FeatureCollection highlightFeature; |
|
|
|
|
136 |
private int state = ZoomIn; |
private int state = ZoomIn; |
137 |
|
|
138 |
/** |
/** |
140 |
*/ |
*/ |
141 |
private double zoomFactor = 2.0; |
private double zoomFactor = 2.0; |
142 |
|
|
|
Style lineHighlightStyle; |
|
|
|
|
|
Style pointHighlightStyle; |
|
|
|
|
|
Style polygonHighlightStyle; |
|
|
|
|
|
Style polygonSelectionStyle; |
|
|
|
|
|
Style pointSelectionStyle; |
|
|
|
|
|
Style lineSelectionStyle; |
|
|
|
|
143 |
boolean changed = true; |
boolean changed = true; |
144 |
|
|
145 |
LabelCache labelCache = new LabelCacheDefault(); |
LabelCache labelCache = new LabelCacheImpl(); |
146 |
|
|
|
// xulu.sc |
|
|
// private boolean reset = false; |
|
147 |
protected boolean reset = false; |
protected boolean reset = false; |
|
// xulu.ec |
|
148 |
|
|
149 |
int startX; |
int startX; |
150 |
|
|
151 |
int startY; |
int startY; |
152 |
|
|
153 |
|
/** |
154 |
|
* If not <code>null</code>, the {@link JMapPane} will not allow to zoom/pan |
155 |
|
* out of that area |
156 |
|
**/ |
157 |
|
private Envelope maxExtend = null; |
158 |
|
|
159 |
|
// /** |
160 |
|
// * Is max. 1 or 0 of the 2 axised allowed to extend the maxExtend? If |
161 |
|
// * <code>true</code> the extends has to be fully inside maxExtend |
162 |
|
// **/ |
163 |
|
// boolean maxExtendForceMode = true; |
164 |
|
|
165 |
private boolean clickable; |
private boolean clickable; |
166 |
|
|
167 |
int lastX; |
int lastX; |
168 |
|
|
169 |
int lastY; |
int lastY; |
170 |
|
|
|
private SelectionManager selectionManager; |
|
|
// xulu.sn |
|
171 |
private Double maxZoomScale = Double.MIN_VALUE; |
private Double maxZoomScale = Double.MIN_VALUE; |
172 |
private Double minZoomScale = Double.MAX_VALUE; |
private Double minZoomScale = Double.MAX_VALUE; |
|
// xulu.en |
|
173 |
|
|
|
// sk.sn |
|
174 |
/** |
/** |
175 |
* Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses |
* Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses |
176 |
* Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu |
* Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu |
178 |
*/ |
*/ |
179 |
private boolean panning_started = false; |
private boolean panning_started = false; |
180 |
|
|
|
// sk.en |
|
|
|
|
181 |
public JMapPane() { |
public JMapPane() { |
182 |
this(null, true, null, null); |
this(null, true, null, null); |
183 |
} |
} |
218 |
|
|
219 |
this.addMouseListener(this); |
this.addMouseListener(this); |
220 |
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); |
|
221 |
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); |
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); |
222 |
} |
} |
223 |
|
|
229 |
} |
} |
230 |
|
|
231 |
public void setRenderer(final GTRenderer renderer) { |
public void setRenderer(final GTRenderer renderer) { |
232 |
Map hints = new HashMap(); |
Map<Object, Object> hints = new HashMap<Object, Object>(); |
233 |
|
|
234 |
this.renderer = renderer; |
this.renderer = renderer; |
235 |
|
|
236 |
if (renderer instanceof StreamingRenderer || renderer instanceof TransitionShapefileRenderer) { |
if (renderer instanceof StreamingRenderer |
237 |
|
|| renderer instanceof ShapefileRenderer) { |
238 |
hints = renderer.getRendererHints(); |
hints = renderer.getRendererHints(); |
239 |
if (hints == null) { |
if (hints == null) { |
240 |
hints = new HashMap(); |
hints = new HashMap<Object, Object>(); |
241 |
} |
} |
242 |
if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) { |
if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) { |
243 |
labelCache = (LabelCache) hints |
labelCache = (LabelCache) hints |
247 |
} |
} |
248 |
|
|
249 |
hints.put("memoryPreloadingEnabled", Boolean.TRUE); |
hints.put("memoryPreloadingEnabled", Boolean.TRUE); |
250 |
|
|
251 |
renderer.setRendererHints(hints); |
renderer.setRendererHints(hints); |
252 |
} |
} |
253 |
|
|
254 |
// this.highlightRenderer = new StreamingRenderer(); |
// this.highlightRenderer = new StreamingRenderer(); |
255 |
// this.selectionRenderer = new StreamingRenderer(); |
// this.selectionRenderer = new StreamingRenderer(); |
256 |
|
|
257 |
// highlightRenderer.setRendererHints(hints); |
// highlightRenderer.setRendererHints(hints); |
258 |
// selectionRenderer.setRendererHints(hints); |
// selectionRenderer.setRendererHints(hints); |
259 |
|
|
260 |
// renderer.setRendererHints(hints); |
// renderer.setRendererHints(hints); |
261 |
|
|
262 |
if (this.context != null) { |
if (this.context != null) { |
263 |
this.renderer.setContext(this.context); |
this.renderer.setContext(this.context); |
310 |
this.zoomFactor = zoomFactor; |
this.zoomFactor = zoomFactor; |
311 |
} |
} |
312 |
|
|
|
public MapLayer getSelectionLayer() { |
|
|
return selectionLayer; |
|
|
} |
|
|
|
|
|
public void setSelectionLayer(final MapLayer selectionLayer) { |
|
|
this.selectionLayer = selectionLayer; |
|
|
if (selectionManager != null) { |
|
|
selectionManager.setSelectionLayer(selectionLayer); |
|
|
} |
|
|
} |
|
|
|
|
|
public boolean isHighlight() { |
|
|
return highlight; |
|
|
} |
|
|
|
|
|
public void setHighlight(final boolean highlight) { |
|
|
this.highlight = highlight; |
|
|
} |
|
|
|
|
|
public MapLayer getHighlightLayer() { |
|
|
return highlightLayer; |
|
|
} |
|
|
|
|
|
public void setHighlightLayer(final MapLayer highlightLayer) { |
|
|
this.highlightLayer = highlightLayer; |
|
|
|
|
|
if (highlightManager != null) { |
|
|
highlightManager.setHighlightLayer(highlightLayer); |
|
|
} |
|
|
} |
|
|
|
|
|
public HighlightManager getHighlightManager() { |
|
|
return highlightManager; |
|
|
} |
|
|
|
|
|
public void setHighlightManager(final HighlightManager highlightManager) { |
|
|
this.highlightManager = highlightManager; |
|
|
this.highlightManager.addHighlightChangeListener(this); |
|
|
this.addMouseMotionListener(this.highlightManager); |
|
|
} |
|
|
|
|
|
public Style getLineHighlightStyle() { |
|
|
return lineHighlightStyle; |
|
|
} |
|
|
|
|
|
public void setLineHighlightStyle(final Style lineHighlightStyle) { |
|
|
this.lineHighlightStyle = lineHighlightStyle; |
|
|
} |
|
|
|
|
|
public Style getLineSelectionStyle() { |
|
|
return lineSelectionStyle; |
|
|
} |
|
|
|
|
|
public void setLineSelectionStyle(final Style lineSelectionStyle) { |
|
|
this.lineSelectionStyle = lineSelectionStyle; |
|
|
} |
|
|
|
|
|
public Style getPointHighlightStyle() { |
|
|
return pointHighlightStyle; |
|
|
} |
|
|
|
|
|
public void setPointHighlightStyle(final Style pointHighlightStyle) { |
|
|
this.pointHighlightStyle = pointHighlightStyle; |
|
|
} |
|
|
|
|
|
public Style getPointSelectionStyle() { |
|
|
return pointSelectionStyle; |
|
|
} |
|
|
|
|
|
public void setPointSelectionStyle(final Style pointSelectionStyle) { |
|
|
this.pointSelectionStyle = pointSelectionStyle; |
|
|
} |
|
|
|
|
|
public Style getPolygonHighlightStyle() { |
|
|
return polygonHighlightStyle; |
|
|
} |
|
|
|
|
|
public void setPolygonHighlightStyle(final Style polygonHighlightStyle) { |
|
|
this.polygonHighlightStyle = polygonHighlightStyle; |
|
|
} |
|
|
|
|
|
public Style getPolygonSelectionStyle() { |
|
|
return polygonSelectionStyle; |
|
|
} |
|
|
|
|
|
public void setPolygonSelectionStyle(final Style polygonSelectionStyle) { |
|
|
this.polygonSelectionStyle = polygonSelectionStyle; |
|
|
} |
|
|
|
|
313 |
protected void paintComponent(final Graphics g) { |
protected void paintComponent(final Graphics g) { |
314 |
super.paintComponent(g); |
super.paintComponent(g); |
315 |
|
|
325 |
try { |
try { |
326 |
mapArea = context.getLayerBounds(); |
mapArea = context.getLayerBounds(); |
327 |
} catch (final IOException e) { |
} catch (final IOException e) { |
328 |
// TODO Auto-generated catch block |
LOGGER.warn("context.getLayerBounds()", e); |
|
e.printStackTrace(); |
|
329 |
} |
} |
330 |
} |
} |
331 |
|
|
335 |
reset = false; /* forget about the reset */ |
reset = false; /* forget about the reset */ |
336 |
oldRect = r; /* store what the current size is */ |
oldRect = r; /* store what the current size is */ |
337 |
|
|
338 |
mapArea = fixAspectRatio(r, mapArea); |
mapArea = fixAspectRatio(r, mapArea, false); |
339 |
} |
} |
340 |
} |
} |
341 |
|
|
348 |
.getCoordinateReferenceSystem()); |
.getCoordinateReferenceSystem()); |
349 |
} |
} |
350 |
|
|
351 |
if (changed ) { /* if the map changed then redraw */ |
if (changed) { /* if the map changed then redraw */ |
352 |
changed = false; |
changed = false; |
353 |
baseImage = new BufferedImage(dr.width, dr.height, |
baseImage = new BufferedImage(dr.width, dr.height, |
354 |
BufferedImage.TYPE_INT_ARGB); |
BufferedImage.TYPE_INT_ARGB); |
355 |
|
|
356 |
final Graphics2D ig = baseImage.createGraphics(); |
final Graphics2D ig = baseImage.createGraphics(); |
357 |
/* System.out.println("rendering"); */ |
/* System.out.println("rendering"); */ |
358 |
if (renderer.getContext() != null) |
if (renderer.getContext() != null) |
359 |
renderer.setContext(context); |
renderer.setContext(context); |
360 |
labelCache.clear(); // work around anoying labelcache bug |
labelCache.clear(); // work around anoying labelcache bug |
361 |
|
|
369 |
} |
} |
370 |
|
|
371 |
((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); |
|
|
|
|
|
final 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; |
|
|
} |
|
|
|
|
|
final MapContext highlightContext = new DefaultMapContext( |
|
|
DefaultGeographicCRS.WGS84); |
|
|
|
|
|
highlightContext.addLayer(highlightFeature, highlightStyle); |
|
|
highlightRenderer.setContext(highlightContext); |
|
|
|
|
|
/* System.out.println("rendering highlight"); */ |
|
|
highlightRenderer.paint((Graphics2D) g, dr, mapArea); |
|
|
} |
|
372 |
} |
} |
373 |
|
|
374 |
private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea) { |
/** |
375 |
|
* Returns an {@link Envelope} that has the same aspect ratio as the given rectangle |
376 |
|
* @param grow |
377 |
|
* If <code>true</code>, than the area will be enlarged to match |
378 |
|
* the aspect ratio. If <code>false</code>, it will only shrink. |
379 |
|
*/ |
380 |
|
private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea, |
381 |
|
boolean grow) { |
382 |
|
|
383 |
|
if (mapArea == null) { |
384 |
|
LOGGER.warn("mapArea has been null in method fixAspectRatio, returning an unmodified "); |
385 |
|
} |
386 |
|
|
387 |
final double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
final double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
388 |
final double mapHeight = mapArea.getHeight(); |
final double mapHeight = mapArea.getHeight(); |
389 |
final double scaleX = r.getWidth() / mapArea.getWidth(); /* |
final double scaleX = r.getWidth() / mapArea.getWidth(); /* |
390 |
* calculate the new |
* calculate the |
391 |
* scale |
* new scale |
392 |
*/ |
*/ |
393 |
|
|
394 |
final double scaleY = r.getHeight() / mapArea.getHeight(); |
final double scaleY = r.getHeight() / mapArea.getHeight(); |
395 |
double scale = 1.0; // stupid compiler! |
double scale = 1.0; // stupid compiler! |
396 |
|
|
397 |
if (scaleX < scaleY) { /* pick the smaller scale */ |
if ((grow && scaleX < scaleY) || (!grow && scaleX > scaleY)) { |
398 |
scale = scaleX; |
scale = scaleX; |
399 |
} else { |
} else { |
400 |
scale = scaleY; |
scale = scaleY; |
410 |
*/ |
*/ |
411 |
|
|
412 |
/* create the new extent */ |
/* create the new extent */ |
413 |
final Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0), |
final Coordinate ll = new Coordinate( |
414 |
mapArea.getMinY() - (deltaY / 2.0)); |
mapArea.getMinX() - (deltaX / 2.0), mapArea.getMinY() |
415 |
final Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0), |
- (deltaY / 2.0)); |
416 |
mapArea.getMaxY() + (deltaY / 2.0)); |
final Coordinate ur = new Coordinate( |
417 |
|
mapArea.getMaxX() + (deltaX / 2.0), mapArea.getMaxY() |
418 |
|
+ (deltaY / 2.0)); |
419 |
|
|
420 |
return new Envelope(ll, ur); |
return new Envelope(ll, ur); |
421 |
} |
} |
422 |
|
|
|
public void doSelection(final double x, final double y, final MapLayer layer) { |
|
|
|
|
|
final Geometry geometry = gf.createPoint(new Coordinate(x, y)); |
|
|
|
|
|
// org.opengis.geometry.Geometry geometry = new Point(); |
|
|
|
|
|
findFeature(geometry, layer); |
|
|
|
|
|
} |
|
|
|
|
|
/** |
|
|
* @param geometry |
|
|
* - a geometry to construct the filter with |
|
|
* @param i |
|
|
* - the index of the layer to search |
|
|
* @throws IndexOutOfBoundsException |
|
|
*/ |
|
|
private void findFeature(final Geometry geometry, final MapLayer layer) |
|
|
throws IndexOutOfBoundsException { |
|
|
org.opengis.filter.spatial.BinarySpatialOperator f = null; |
|
|
|
|
|
if ((context == null) || (layer == null)) { |
|
|
return; |
|
|
} |
|
|
|
|
|
try { |
|
|
String name = layer.getFeatureSource().getSchema() |
|
|
.getDefaultGeometry().getLocalName(); |
|
|
|
|
|
if (name == "") { |
|
|
name = "the_geom"; |
|
|
} |
|
|
|
|
|
try { |
|
|
f = ff.contains(ff.property(name), ff.literal(geometry)); |
|
|
if (selectionManager != null) { |
|
|
// System.out.println("selection changed"); |
|
|
selectionManager.selectionChanged(this, f); |
|
|
|
|
|
} |
|
|
} catch (final IllegalFilterException e) { |
|
|
// TODO Auto-generated catch block |
|
|
e.printStackTrace(); |
|
|
} |
|
|
|
|
|
/* |
|
|
* // f.addLeftGeometry(ff.property(name)); // |
|
|
* System.out.println("looking with " + f); FeatureCollection fc = |
|
|
* layer.getFeatureSource().getFeatures(f); |
|
|
* |
|
|
* |
|
|
* |
|
|
* if (fcol == null) { fcol = fc; |
|
|
* |
|
|
* // here we should set the defaultgeom type } else { |
|
|
* fcol.addAll(fc); } |
|
|
*/ |
|
|
|
|
|
/* |
|
|
* GeometryAttributeType gat = |
|
|
* layer.getFeatureSource().getSchema().getDefaultGeometry(); |
|
|
* fcol.setDefaultGeometry((Geometry)gat.createDefaultValue()); |
|
|
*/ |
|
|
|
|
|
/* |
|
|
* Iterator fi = fc.iterator(); while (fi.hasNext()) { Feature feat |
|
|
* = (Feature) fi.next(); System.out.println("selected " + |
|
|
* feat.getAttribute("STATE_NAME")); } |
|
|
*/ |
|
|
} catch (final IllegalFilterException e) { |
|
|
// TODO Auto-generated catch block |
|
|
e.printStackTrace(); |
|
|
} |
|
|
return; |
|
|
} |
|
|
|
|
423 |
public void mouseClicked(final MouseEvent e) { |
public void mouseClicked(final MouseEvent e) { |
424 |
if (mapArea == null) return; |
if (mapArea == null) |
425 |
|
return; |
426 |
// System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+" |
// System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+" |
427 |
// h:"+mapArea.getHeight()); |
// h:"+mapArea.getHeight()); |
428 |
final Rectangle bounds = this.getBounds(); |
final Rectangle bounds = this.getBounds(); |
436 |
final double width2 = width / 2.0; |
final double width2 = width / 2.0; |
437 |
final double height2 = height / 2.0; |
final double height2 = height / 2.0; |
438 |
// xulu.ec |
// xulu.ec |
439 |
final double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX(); |
final double mapX = ((x * width) / (double) bounds.width) |
440 |
|
+ mapArea.getMinX(); |
441 |
final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height) |
final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height) |
442 |
+ mapArea.getMinY(); |
+ mapArea.getMinY(); |
443 |
|
|
468 |
zlevel = 1.0 / zoomFactor; |
zlevel = 1.0 / zoomFactor; |
469 |
|
|
470 |
break; |
break; |
471 |
|
// |
472 |
case Select: |
// case Select: |
473 |
doSelection(mapX, mapY, selectionLayer); |
// doSelection(mapX, mapY, selectionLayer); |
474 |
|
// |
475 |
return; |
// return; |
476 |
|
|
477 |
default: |
default: |
478 |
return; |
return; |
544 |
// System.out.println("translate "+dx+","+dy); |
// System.out.println("translate "+dx+","+dy); |
545 |
final Graphics2D g2 = panningImage.createGraphics(); |
final Graphics2D g2 = panningImage.createGraphics(); |
546 |
g2.setBackground(new Color(240, 240, 240)); // TODO richtige |
g2.setBackground(new Color(240, 240, 240)); // TODO richtige |
547 |
// farbe? am besten |
// farbe? am besten |
548 |
// vom L&F die |
// vom L&F die |
549 |
// hintergrundfarbe |
// hintergrundfarbe |
550 |
// auslesen... |
// auslesen... |
551 |
|
|
552 |
g2.clearRect(0, 0, this.getWidth(), this.getHeight()); |
g2.clearRect(0, 0, this.getWidth(), this.getHeight()); |
553 |
g2.drawImage(baseImage, dx, dy, this); |
g2.drawImage(baseImage, dx, dy, this); |
554 |
graphics.drawImage(panningImage, 0, 0, this); |
graphics.drawImage(panningImage, 0, 0, this); |
570 |
lastX = x; |
lastX = x; |
571 |
lastY = y; |
lastY = y; |
572 |
drawRectangle(graphics); |
drawRectangle(graphics); |
|
} else if (state == JMapPane.Select && selectionLayer != null) { |
|
|
|
|
|
// construct a new bbox filter |
|
|
final Rectangle bounds = this.getBounds(); |
|
|
|
|
|
final double mapWidth = mapArea.getWidth(); |
|
|
final double mapHeight = mapArea.getHeight(); |
|
|
|
|
|
final double x1 = ((this.startX * mapWidth) / (double) bounds.width) |
|
|
+ mapArea.getMinX(); |
|
|
final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height) |
|
|
+ mapArea.getMinY(); |
|
|
final double x2 = ((x * mapWidth) / (double) bounds.width) |
|
|
+ mapArea.getMinX(); |
|
|
final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height) |
|
|
+ mapArea.getMinY(); |
|
|
final double left = Math.min(x1, x2); |
|
|
final double right = Math.max(x1, x2); |
|
|
final double bottom = Math.min(y1, y2); |
|
|
final double top = Math.max(y1, y2); |
|
|
|
|
|
String name = selectionLayer.getFeatureSource().getSchema() |
|
|
.getDefaultGeometry().getName(); |
|
|
|
|
|
if (name == "") { |
|
|
name = "the_geom"; |
|
|
} |
|
|
final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top, |
|
|
getContext().getCoordinateReferenceSystem().toString()); |
|
|
if (selectionManager != null) { |
|
|
selectionManager.selectionChanged(this, bb); |
|
|
} |
|
|
|
|
|
graphics.setXORMode(Color.green); |
|
|
|
|
|
/* |
|
|
* if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); } |
|
|
*/ |
|
|
|
|
|
// draw new box |
|
|
lastX = x; |
|
|
lastY = y; |
|
|
drawRectangle(graphics); |
|
573 |
} |
} |
574 |
|
// else if (state == JMapPane.Select && selectionLayer != null) { |
575 |
|
// |
576 |
|
// // construct a new bbox filter |
577 |
|
// final Rectangle bounds = this.getBounds(); |
578 |
|
// |
579 |
|
// final double mapWidth = mapArea.getWidth(); |
580 |
|
// final double mapHeight = mapArea.getHeight(); |
581 |
|
// |
582 |
|
// final double x1 = ((this.startX * mapWidth) / (double) bounds.width) |
583 |
|
// + mapArea.getMinX(); |
584 |
|
// final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / |
585 |
|
// (double) bounds.height) |
586 |
|
// + mapArea.getMinY(); |
587 |
|
// final double x2 = ((x * mapWidth) / (double) bounds.width) |
588 |
|
// + mapArea.getMinX(); |
589 |
|
// final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) |
590 |
|
// bounds.height) |
591 |
|
// + mapArea.getMinY(); |
592 |
|
// final double left = Math.min(x1, x2); |
593 |
|
// final double right = Math.max(x1, x2); |
594 |
|
// final double bottom = Math.min(y1, y2); |
595 |
|
// final double top = Math.max(y1, y2); |
596 |
|
// |
597 |
|
// String name = selectionLayer.getFeatureSource().getSchema() |
598 |
|
// .getDefaultGeometry().getName(); |
599 |
|
// |
600 |
|
// if (name == "") { |
601 |
|
// name = "the_geom"; |
602 |
|
// } |
603 |
|
// final Filter bb = ff.bbox(ff.property(name), left, bottom, right, |
604 |
|
// top, |
605 |
|
// getContext().getCoordinateReferenceSystem().toString()); |
606 |
|
// if (selectionManager != null) { |
607 |
|
// selectionManager.selectionChanged(this, bb); |
608 |
|
// } |
609 |
|
// |
610 |
|
// graphics.setXORMode(Color.green); |
611 |
|
// |
612 |
|
// /* |
613 |
|
// * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); } |
614 |
|
// */ |
615 |
|
// |
616 |
|
// // draw new box |
617 |
|
// lastX = x; |
618 |
|
// lastY = y; |
619 |
|
// drawRectangle(graphics); |
620 |
|
// } |
621 |
|
|
622 |
} |
} |
623 |
|
|
627 |
protected void processDrag(final int x1, final int y1, final int x2, |
protected void processDrag(final int x1, final int y1, final int x2, |
628 |
final int y2, final MouseEvent e) { |
final int y2, final MouseEvent e) { |
629 |
|
|
630 |
|
|
631 |
/**** |
/**** |
632 |
* If no layer is availabe we dont want a NullPointerException |
* If no layers exist, we ignore the drag. |
633 |
*/ |
*/ |
634 |
if (mapArea == null) |
if (context.getLayerCount() <= 0) { |
635 |
return; |
return; |
636 |
|
} |
637 |
|
|
638 |
// System.out.println("processing drag from " + x1 + "," + y1 + " -> " |
// System.out.println("processing drag from " + x1 + "," + y1 + " -> " |
639 |
// + x2 + "," + y2); |
// + x2 + "," + y2); |
640 |
if ((x1 == x2) && (y1 == y2)) { |
if ((x1 == x2) && (y1 == y2)) { |
680 |
final Coordinate ur = new Coordinate(right, top); |
final Coordinate ur = new Coordinate(right, top); |
681 |
// xulu.sc |
// xulu.sc |
682 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
683 |
setMapArea(fixAspectRatio(this.getBounds(), new Envelope(ll, ur))); |
|
684 |
|
|
685 |
|
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
686 |
// xulu.ec |
// xulu.ec |
687 |
} else if (state == JMapPane.ZoomIn) { |
} else if (state == JMapPane.ZoomIn) { |
688 |
|
|
706 |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
707 |
|
|
708 |
// sk.sc |
// sk.sc |
709 |
// { |
// { |
710 |
// // SK tries to paint a preview of the zoom ;-9 aha.... well |
// // SK tries to paint a preview of the zoom ;-9 aha.... well |
711 |
// Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics(); |
// Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics(); |
712 |
// graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
// graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
713 |
// RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
// RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
714 |
// graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
// graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
715 |
// RenderingHints.VALUE_ANTIALIAS_OFF); |
// RenderingHints.VALUE_ANTIALIAS_OFF); |
716 |
// graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
// graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
717 |
// RenderingHints.VALUE_RENDER_SPEED); |
// RenderingHints.VALUE_RENDER_SPEED); |
718 |
// graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(), |
// graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(), |
719 |
// JMapPane.this.getHeight(), x1, y1, x2, y2, null); |
// JMapPane.this.getHeight(), x1, y1, x2, y2, null); |
720 |
// } |
// } |
721 |
// xulu.ec |
// xulu.ec |
722 |
} else if (state == JMapPane.ZoomOut) { |
} else if (state == JMapPane.ZoomOut) { |
723 |
drawRectangle(this.getGraphics()); |
drawRectangle(this.getGraphics()); |
746 |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
747 |
|
|
748 |
// xulu.ec |
// xulu.ec |
|
} else if (state == JMapPane.Select && selectionLayer != null) { |
|
|
final double left = Math.min(startX, endX); |
|
|
final double right = Math.max(startX, endX); |
|
|
final double bottom = Math.min(startY, endY); |
|
|
final double top = Math.max(startY, endY); |
|
|
|
|
|
String name = selectionLayer.getFeatureSource().getSchema() |
|
|
.getDefaultGeometry().getLocalName(); |
|
|
|
|
|
if (name == "") { |
|
|
name = "the_geom"; |
|
|
} |
|
|
final 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(); } |
|
|
*/ |
|
749 |
} |
} |
750 |
|
// else if (state == JMapPane.Select && selectionLayer != null) { |
751 |
|
// final double left = Math.min(startX, endX); |
752 |
|
// final double right = Math.max(startX, endX); |
753 |
|
// final double bottom = Math.min(startY, endY); |
754 |
|
// final double top = Math.max(startY, endY); |
755 |
|
// |
756 |
|
// String name = selectionLayer.getFeatureSource().getSchema() |
757 |
|
// .getDefaultGeometry().getLocalName(); |
758 |
|
// |
759 |
|
// if (name == "") { |
760 |
|
// name = "the_geom"; |
761 |
|
// } |
762 |
|
// final Filter bb = ff.bbox(ff.property(name), left, bottom, right, |
763 |
|
// top, |
764 |
|
// getContext().getCoordinateReferenceSystem().toString()); |
765 |
|
// // System.out.println(bb.toString()); |
766 |
|
// if (selectionManager != null) { |
767 |
|
// selectionManager.selectionChanged(this, bb); |
768 |
|
// } |
769 |
|
// /* |
770 |
|
// * FeatureCollection fc; selection = null; try { fc = |
771 |
|
// * selectionLayer.getFeatureSource().getFeatures(bb); selection = |
772 |
|
// * fc; } catch (IOException e) { e.printStackTrace(); } |
773 |
|
// */ |
774 |
|
// } |
775 |
|
|
776 |
// xulu.so |
// xulu.so |
777 |
// setMapArea(mapArea); |
// setMapArea(mapArea); |
783 |
return clickable; |
return clickable; |
784 |
} |
} |
785 |
|
|
786 |
private org.geotools.styling.Style setupStyle(final int type, final Color color) { |
// |
787 |
final StyleFactory sf = org.geotools.factory.CommonFactoryFinder |
// private org.geotools.styling.Style setupStyle(final int type, final Color |
788 |
.getStyleFactory(null); |
// color) { |
789 |
final StyleBuilder sb = new StyleBuilder(); |
// final StyleFactory sf = org.geotools.factory.CommonFactoryFinder |
790 |
|
// .getStyleFactory(null); |
791 |
org.geotools.styling.Style s = sf.createStyle(); |
// final StyleBuilder sb = new StyleBuilder(); |
792 |
s.setTitle("selection"); |
// |
793 |
|
// org.geotools.styling.Style s = sf.createStyle(); |
794 |
// TODO parameterise the color |
// s.setTitle("selection"); |
795 |
final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color); |
// |
796 |
ps.setStroke(sb.createStroke(color)); |
// // TODO parameterise the color |
797 |
|
// final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color); |
798 |
final LineSymbolizer ls = sb.createLineSymbolizer(color); |
// ps.setStroke(sb.createStroke(color)); |
799 |
final Graphic h = sb.createGraphic(); |
// |
800 |
h.setMarks(new Mark[] { sb.createMark("square", color) }); |
// final LineSymbolizer ls = sb.createLineSymbolizer(color); |
801 |
|
// final Graphic h = sb.createGraphic(); |
802 |
final PointSymbolizer pts = sb.createPointSymbolizer(h); |
// h.setMarks(new Mark[] { sb.createMark("square", color) }); |
803 |
|
// |
804 |
// Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts}); |
// final PointSymbolizer pts = sb.createPointSymbolizer(h); |
805 |
switch (type) { |
// |
806 |
case POLYGON: |
// // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts}); |
807 |
s = sb.createStyle(ps); |
// switch (type) { |
808 |
|
// case POLYGON: |
809 |
break; |
// s = sb.createStyle(ps); |
810 |
|
// |
811 |
case POINT: |
// break; |
812 |
s = sb.createStyle(pts); |
// |
813 |
|
// case POINT: |
814 |
break; |
// s = sb.createStyle(pts); |
815 |
|
// |
816 |
case LINE: |
// break; |
817 |
s = sb.createStyle(ls); |
// |
818 |
} |
// case LINE: |
819 |
|
// s = sb.createStyle(ls); |
820 |
return s; |
// } |
821 |
} |
// |
822 |
|
// return s; |
823 |
public void highlightChanged(final HighlightChangedEvent e) { |
// } |
|
final org.opengis.filter.Filter f = e.getFilter(); |
|
|
|
|
|
try { |
|
|
highlightFeature = highlightLayer.getFeatureSource().getFeatures(f); |
|
|
} catch (final IOException e1) { |
|
|
// TODO Auto-generated catch block |
|
|
e1.printStackTrace(); |
|
|
} |
|
|
|
|
|
repaint(); |
|
|
} |
|
824 |
|
|
825 |
public void propertyChange(final PropertyChangeEvent evt) { |
public void propertyChange(final PropertyChangeEvent evt) { |
826 |
final String prop = evt.getPropertyName(); |
final String prop = evt.getPropertyName(); |
904 |
public void mouseMoved(final MouseEvent e) { |
public void mouseMoved(final MouseEvent e) { |
905 |
} |
} |
906 |
|
|
|
public FeatureCollection getSelection() { |
|
|
return selection; |
|
|
} |
|
|
|
|
|
public void setSelection(final 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(final SelectionChangedEvent e) { |
|
|
|
|
|
try { |
|
|
selection = selectionLayer.getFeatureSource().getFeatures( |
|
|
e.getFilter()); |
|
|
repaint(); |
|
|
} catch (final IOException e1) { |
|
|
e1.printStackTrace(); |
|
|
} |
|
|
} |
|
|
|
|
|
public SelectionManager getSelectionManager() { |
|
|
return selectionManager; |
|
|
} |
|
|
|
|
|
public void setSelectionManager(final SelectionManager selectionManager) { |
|
|
this.selectionManager = selectionManager; |
|
|
this.selectionManager.addSelectionChangeListener(this); |
|
|
|
|
|
} |
|
|
|
|
907 |
// xulu.sn |
// xulu.sn |
908 |
/** |
/** |
909 |
* Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste |
* Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste |
922 |
if (env == null) |
if (env == null) |
923 |
return env; |
return env; |
924 |
|
|
925 |
|
Envelope newArea = null; |
926 |
|
|
927 |
/** |
/** |
928 |
* Correct the aspect Ratio before we check the rest. Otherwise we might |
* Correct the aspect Ratio before we check the rest. Otherwise we might |
929 |
* easily fail. |
* easily fail. |
930 |
*/ |
*/ |
931 |
env = fixAspectRatio(this.getBounds(), env); |
env = fixAspectRatio(this.getBounds(), env, false); |
932 |
|
|
933 |
final double scale = env.getWidth() / getWidth(); |
final double scale = env.getWidth() / getWidth(); |
934 |
final double centerX = env.getMinX() + env.getWidth() / 2.; |
final double centerX = env.getMinX() + env.getWidth() / 2.; |
935 |
final double centerY = env.getMinY() + env.getHeight() / 2.; |
final double centerY = env.getMinY() + env.getHeight() / 2.; |
936 |
double newWidth2; |
double newWidth2 = 0; |
937 |
double newHeight2; |
double newHeight2 = 0; |
938 |
if (scale < getMaxZoomScale()) { |
if (scale < getMaxZoomScale()) { |
939 |
// **************************************************************************** |
// **************************************************************************** |
940 |
// Wir zoomen weiter rein als erlaubt => Anpassen des envelope |
// Wir zoomen weiter rein als erlaubt => Anpassen des envelope |
951 |
// **************************************************************************** |
// **************************************************************************** |
952 |
// Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen |
// Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen |
953 |
// **************************************************************************** |
// **************************************************************************** |
954 |
return env; |
newArea = env; |
955 |
} |
} |
956 |
|
|
957 |
final Coordinate ll = new Coordinate(centerX - newWidth2, centerY |
if (newArea == null) { |
|
- newHeight2); |
|
|
final Coordinate ur = new Coordinate(centerX + newWidth2, centerY |
|
|
+ newHeight2); |
|
958 |
|
|
959 |
return new Envelope(ll, ur); |
final Coordinate ll = new Coordinate(centerX - newWidth2, centerY |
960 |
|
- newHeight2); |
961 |
|
final Coordinate ur = new Coordinate(centerX + newWidth2, centerY |
962 |
|
+ newHeight2); |
963 |
|
|
964 |
|
newArea = new Envelope(ll, ur); |
965 |
|
} |
966 |
|
|
967 |
|
Envelope maxAllowedExtend = getMaxExtend(); |
968 |
|
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)) { |
969 |
|
/* |
970 |
|
* If a maxExtend is set, we have to honour that... |
971 |
|
*/ |
972 |
|
|
973 |
|
// Exceeds top? Move down and maybe cut |
974 |
|
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
975 |
|
double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY(); |
976 |
|
// LOGGER.debug("Moving area down by " + divY); |
977 |
|
|
978 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
979 |
|
newArea.getMinY() - divY), new Coordinate(newArea |
980 |
|
.getMaxX(), newArea.getMaxY() - divY)); |
981 |
|
|
982 |
|
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
983 |
|
// LOGGER.debug("Now it exeeds the bottom border.. cut!"); |
984 |
|
// And cut the bottom if it moved out of the area |
985 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
986 |
|
maxAllowedExtend.getMinY()), new Coordinate(newArea |
987 |
|
.getMaxX(), newArea.getMaxY())); |
988 |
|
|
989 |
|
// LOGGER.debug("and fix aspect ratio"); |
990 |
|
|
991 |
|
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
992 |
|
} |
993 |
|
} |
994 |
|
|
995 |
|
// Exceeds bottom? Move up and maybe cut |
996 |
|
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
997 |
|
double divY = newArea.getMinY() - maxAllowedExtend.getMinY(); |
998 |
|
// LOGGER.debug("Moving area up by " + divY); |
999 |
|
|
1000 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
1001 |
|
newArea.getMinY() - divY), new Coordinate(newArea |
1002 |
|
.getMaxX(), newArea.getMaxY() - divY)); |
1003 |
|
|
1004 |
|
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
1005 |
|
LOGGER.debug("Now it exeeds the top border.. cut!"); |
1006 |
|
// And cut the bottom if it moved out of the area |
1007 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
1008 |
|
newArea.getMinY()), new Coordinate(newArea |
1009 |
|
.getMaxX(), maxAllowedExtend.getMaxY())); |
1010 |
|
|
1011 |
|
LOGGER.debug("and fix aspect ratio"); |
1012 |
|
|
1013 |
|
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
1014 |
|
} |
1015 |
|
} |
1016 |
|
|
1017 |
|
// Exceeds to the right? move and maybe cut |
1018 |
|
if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) { |
1019 |
|
|
1020 |
|
// Move left.. |
1021 |
|
double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX(); |
1022 |
|
// LOGGER.debug("Moving area left by " + divX); |
1023 |
|
|
1024 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX() - divX, |
1025 |
|
newArea.getMinY()), new Coordinate(newArea.getMaxX() |
1026 |
|
- divX, newArea.getMaxY())); |
1027 |
|
|
1028 |
|
if (newArea.getMinX() < maxAllowedExtend.getMinX()) { |
1029 |
|
LOGGER.debug("Now it exeeds the left border.. cut!"); |
1030 |
|
// And cut the left if it moved out of the area |
1031 |
|
newArea = new Envelope(new Coordinate(maxAllowedExtend.getMinX(), |
1032 |
|
newArea.getMinY()), new Coordinate(newArea |
1033 |
|
.getMaxX(), newArea.getMaxY())); |
1034 |
|
|
1035 |
|
LOGGER.debug("and fix aspect ratio"); |
1036 |
|
|
1037 |
|
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
1038 |
|
} |
1039 |
|
} |
1040 |
|
|
1041 |
|
// Exceeds to the left? move and maybe cut |
1042 |
|
if (newArea.getMinX() < maxAllowedExtend.getMinX()) { |
1043 |
|
|
1044 |
|
// Move right.. |
1045 |
|
double divX = newArea.getMinX() - maxAllowedExtend.getMinX(); |
1046 |
|
// LOGGER.debug("Moving area right by " + divX); |
1047 |
|
|
1048 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX() - divX, |
1049 |
|
newArea.getMinY()), new Coordinate(newArea.getMaxX() |
1050 |
|
- divX, newArea.getMaxY())); |
1051 |
|
|
1052 |
|
if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) { |
1053 |
|
LOGGER.debug("Now it exeeds the right border.. cut!"); |
1054 |
|
// And cut the left if it moved out of the area |
1055 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
1056 |
|
newArea.getMinY()), new Coordinate(maxAllowedExtend |
1057 |
|
.getMaxX(), newArea.getMaxY())); |
1058 |
|
|
1059 |
|
LOGGER.debug("and fix aspect ratio"); |
1060 |
|
|
1061 |
|
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
1062 |
|
} |
1063 |
|
} |
1064 |
|
|
1065 |
|
} |
1066 |
|
|
1067 |
|
return newArea; |
1068 |
} |
} |
1069 |
|
|
1070 |
/** |
/** |
1097 |
* Krüger</a> |
* Krüger</a> |
1098 |
*/ |
*/ |
1099 |
public void setMaxZoomScale(final Double maxZoomScale) { |
public void setMaxZoomScale(final Double maxZoomScale) { |
|
// System.out.println("setting max scale to "+maxZoomScale); |
|
1100 |
this.maxZoomScale = maxZoomScale; |
this.maxZoomScale = maxZoomScale; |
1101 |
} |
} |
1102 |
|
|
1110 |
public void setMinZoomScale(final Double minZoomScale) { |
public void setMinZoomScale(final Double minZoomScale) { |
1111 |
this.minZoomScale = minZoomScale; |
this.minZoomScale = minZoomScale; |
1112 |
} |
} |
1113 |
// xulu.en |
|
1114 |
|
/** |
1115 |
|
* Defines an evelope of the viwable area. The JMapPane will never show |
1116 |
|
* anything outside of this extend. |
1117 |
|
* |
1118 |
|
* @param maxExtend |
1119 |
|
* <code>null</code> to not have this restriction. |
1120 |
|
*/ |
1121 |
|
public void setMaxExtend(Envelope maxExtend) { |
1122 |
|
this.maxExtend = maxExtend; |
1123 |
|
} |
1124 |
|
|
1125 |
|
/** |
1126 |
|
* Returns the evelope of the viewable area. The JMapPane will never show |
1127 |
|
* anything outside of this extend. If this has been set to |
1128 |
|
* <code>null</code> via {@link #setMaxExtend(Envelope)}, it tries to return |
1129 |
|
* quickly the context's bounds. It it takes to long to determine the |
1130 |
|
* context bounds, <code>null</code> is returned. |
1131 |
|
* |
1132 |
|
* @param maxExtend |
1133 |
|
* <code>null</code> to not have this restriction. |
1134 |
|
*/ |
1135 |
|
|
1136 |
|
public Envelope getMaxExtend() { |
1137 |
|
if (maxExtend == null) { |
1138 |
|
try { |
1139 |
|
return fixAspectRatio( |
1140 |
|
this.getBounds(), |
1141 |
|
// Kartenbereich um 10% vergroessern |
1142 |
|
JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1), |
1143 |
|
true |
1144 |
|
); |
1145 |
|
} catch (IOException e) { |
1146 |
|
LOGGER.warn( |
1147 |
|
"maxExtend == null; faild to getLayerBounds of context", |
1148 |
|
e); |
1149 |
|
} |
1150 |
|
} |
1151 |
|
return maxExtend; |
1152 |
|
} |
1153 |
|
|
1154 |
} |
} |