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; |
|
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.styling.Graphic; |
import org.geotools.renderer.shape.ShapefileRenderer; |
|
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; |
|
69 |
import org.opengis.filter.FilterFactory2; |
import org.opengis.filter.FilterFactory2; |
70 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
71 |
|
|
73 |
|
|
74 |
import com.vividsolutions.jts.geom.Coordinate; |
import com.vividsolutions.jts.geom.Coordinate; |
75 |
import com.vividsolutions.jts.geom.Envelope; |
import com.vividsolutions.jts.geom.Envelope; |
|
import com.vividsolutions.jts.geom.Geometry; |
|
76 |
import com.vividsolutions.jts.geom.GeometryFactory; |
import com.vividsolutions.jts.geom.GeometryFactory; |
77 |
|
|
78 |
public class JMapPane extends JPanel implements MouseListener, |
public class JMapPane extends JPanel implements MouseListener, |
79 |
MouseMotionListener, HighlightChangeListener, SelectionChangeListener, |
MouseMotionListener, PropertyChangeListener, MapLayerListListener { |
|
PropertyChangeListener, MapLayerListListener { |
|
80 |
private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName()); |
private static Logger LOGGER = Logger.getLogger(JMapPane.class.getName()); |
81 |
|
|
82 |
private static final long serialVersionUID = -8647971481359690499L; |
private static final long serialVersionUID = -8647971481359690499L; |
91 |
|
|
92 |
public static final int Select = 4; |
public static final int Select = 4; |
93 |
|
|
|
private static final int POLYGON = 0; |
|
|
|
|
|
private static final int LINE = 1; |
|
|
|
|
|
private static final int POINT = 2; |
|
|
|
|
94 |
/** |
/** |
95 |
* what renders the map |
* what renders the map |
96 |
*/ |
*/ |
97 |
GTRenderer renderer; |
GTRenderer renderer; |
98 |
|
|
|
private GTRenderer highlightRenderer, selectionRenderer; |
|
|
|
|
99 |
/** |
/** |
100 |
* the map context to render |
* the map context to render |
101 |
*/ |
*/ |
102 |
MapContext context; |
MapContext context; |
103 |
|
|
|
private MapContext selectionContext; |
|
|
|
|
104 |
/** |
/** |
105 |
* the area of the map to draw |
* the area of the map to draw |
106 |
*/ |
*/ |
|
// xulu.sc |
|
|
// Envelope mapArea; |
|
107 |
protected Envelope mapArea; |
protected Envelope mapArea; |
|
// xulu.ec |
|
108 |
|
|
109 |
/** |
/** |
110 |
* the size of the pane last time we drew |
* the size of the pane last time we drew |
111 |
*/ |
*/ |
|
// xulu.sc |
|
|
// private Rectangle oldRect = null; |
|
112 |
protected Rectangle oldRect = null; |
protected Rectangle oldRect = null; |
|
// xulu.ec |
|
113 |
|
|
114 |
/** |
/** |
115 |
* the last map area drawn. |
* the last map area drawn. |
116 |
*/ |
*/ |
|
// xulu.sc |
|
|
// private Envelope oldMapArea = null; |
|
117 |
protected Envelope oldMapArea = null; |
protected Envelope oldMapArea = null; |
|
// xulu.ec |
|
118 |
|
|
119 |
/** |
/** |
120 |
* the base image of the map |
* the base image of the map |
121 |
*/ |
*/ |
122 |
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; |
|
123 |
|
|
124 |
/** |
/** |
125 |
* a factory for filters |
* a factory for filters |
131 |
*/ |
*/ |
132 |
GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null); |
GeometryFactory gf = new GeometryFactory(); // FactoryFinder.getGeometryFactory(null); |
133 |
|
|
|
/** |
|
|
* the collections of features to be selected or highlighted |
|
|
*/ |
|
|
FeatureCollection selection; |
|
|
|
|
|
/** |
|
|
* the collections of features to be selected or highlighted |
|
|
*/ |
|
|
FeatureCollection highlightFeature; |
|
|
|
|
134 |
private int state = ZoomIn; |
private int state = ZoomIn; |
135 |
|
|
136 |
/** |
/** |
138 |
*/ |
*/ |
139 |
private double zoomFactor = 2.0; |
private double zoomFactor = 2.0; |
140 |
|
|
|
Style lineHighlightStyle; |
|
|
|
|
|
Style pointHighlightStyle; |
|
|
|
|
|
Style polygonHighlightStyle; |
|
|
|
|
|
Style polygonSelectionStyle; |
|
|
|
|
|
Style pointSelectionStyle; |
|
|
|
|
|
Style lineSelectionStyle; |
|
|
|
|
141 |
boolean changed = true; |
boolean changed = true; |
142 |
|
|
143 |
LabelCache labelCache = new LabelCacheDefault(); |
LabelCache labelCache = new LabelCacheImpl(); |
144 |
|
|
|
// xulu.sc |
|
|
// private boolean reset = false; |
|
145 |
protected boolean reset = false; |
protected boolean reset = false; |
|
// xulu.ec |
|
146 |
|
|
147 |
int startX; |
int startX; |
148 |
|
|
149 |
int startY; |
int startY; |
150 |
|
|
151 |
|
/** |
152 |
|
* If not <code>null</code>, the {@link JMapPane} will not allow to zoom/pan |
153 |
|
* out of that area |
154 |
|
**/ |
155 |
|
private Envelope maxExtend = null; |
156 |
|
|
157 |
|
// /** |
158 |
|
// * Is max. 1 or 0 of the 2 axised allowed to extend the maxExtend? If |
159 |
|
// * <code>true</code> the extends has to be fully inside maxExtend |
160 |
|
// **/ |
161 |
|
// boolean maxExtendForceMode = true; |
162 |
|
|
163 |
private boolean clickable; |
private boolean clickable; |
164 |
|
|
165 |
int lastX; |
int lastX; |
166 |
|
|
167 |
int lastY; |
int lastY; |
168 |
|
|
|
private SelectionManager selectionManager; |
|
|
// xulu.sn |
|
169 |
private Double maxZoomScale = Double.MIN_VALUE; |
private Double maxZoomScale = Double.MIN_VALUE; |
170 |
private Double minZoomScale = Double.MAX_VALUE; |
private Double minZoomScale = Double.MAX_VALUE; |
|
// xulu.en |
|
171 |
|
|
|
// sk.sn |
|
172 |
/** |
/** |
173 |
* Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses |
* Wenn true, dann wurde PANNING via mouseDraged-Events begonnen. Dieses |
174 |
* Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu |
* Flag wird benutzt um nur einmal den passenden Cursor nur einmal zu |
176 |
*/ |
*/ |
177 |
private boolean panning_started = false; |
private boolean panning_started = false; |
178 |
|
|
|
// sk.en |
|
|
|
|
179 |
public JMapPane() { |
public JMapPane() { |
180 |
this(null, true, null, null); |
this(null, true, null, null); |
181 |
} |
} |
188 |
* @param context |
* @param context |
189 |
* - the map context to display |
* - the map context to display |
190 |
*/ |
*/ |
191 |
public JMapPane(GTRenderer render, MapContext context) { |
public JMapPane(final GTRenderer render, final MapContext context) { |
192 |
this(null, true, render, context); |
this(null, true, render, context); |
193 |
} |
} |
194 |
|
|
204 |
* @param context |
* @param context |
205 |
* - what to draw |
* - what to draw |
206 |
*/ |
*/ |
207 |
public JMapPane(LayoutManager layout, boolean isDoubleBuffered, |
public JMapPane(final LayoutManager layout, final boolean isDoubleBuffered, |
208 |
GTRenderer render, MapContext context) { |
final GTRenderer render, final MapContext context) { |
209 |
super(layout, isDoubleBuffered); |
super(layout, isDoubleBuffered); |
210 |
|
|
211 |
ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder |
ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder |
216 |
|
|
217 |
this.addMouseListener(this); |
this.addMouseListener(this); |
218 |
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); |
|
219 |
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); |
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); |
220 |
} |
} |
221 |
|
|
226 |
return renderer; |
return renderer; |
227 |
} |
} |
228 |
|
|
229 |
public void setRenderer(GTRenderer renderer) { |
public void setRenderer(final GTRenderer renderer) { |
230 |
Map hints = new HashMap(); |
Map<Object, Object> hints = new HashMap<Object, Object>(); |
231 |
if (renderer instanceof StreamingRenderer) { |
|
232 |
|
this.renderer = renderer; |
233 |
|
|
234 |
|
if (renderer instanceof StreamingRenderer |
235 |
|
|| renderer instanceof ShapefileRenderer) { |
236 |
hints = renderer.getRendererHints(); |
hints = renderer.getRendererHints(); |
237 |
if (hints == null) { |
if (hints == null) { |
238 |
hints = new HashMap(); |
hints = new HashMap<Object, Object>(); |
239 |
} |
} |
240 |
if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) { |
if (hints.containsKey(StreamingRenderer.LABEL_CACHE_KEY)) { |
241 |
labelCache = (LabelCache) hints |
labelCache = (LabelCache) hints |
243 |
} else { |
} else { |
244 |
hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache); |
hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache); |
245 |
} |
} |
246 |
|
|
247 |
|
hints.put("memoryPreloadingEnabled", Boolean.TRUE); |
248 |
|
|
249 |
renderer.setRendererHints(hints); |
renderer.setRendererHints(hints); |
250 |
} |
} |
251 |
|
|
252 |
this.renderer = renderer; |
// this.highlightRenderer = new StreamingRenderer(); |
253 |
// this.highlightRenderer = new StreamingRenderer(); |
// this.selectionRenderer = new StreamingRenderer(); |
|
// this.selectionRenderer = new StreamingRenderer(); |
|
254 |
|
|
255 |
hints.put("memoryPreloadingEnabled", Boolean.FALSE); |
// highlightRenderer.setRendererHints(hints); |
256 |
// highlightRenderer.setRendererHints(hints); |
// selectionRenderer.setRendererHints(hints); |
257 |
// selectionRenderer.setRendererHints(hints); |
|
258 |
|
// renderer.setRendererHints(hints); |
259 |
|
|
260 |
if (this.context != null) { |
if (this.context != null) { |
261 |
this.renderer.setContext(this.context); |
this.renderer.setContext(this.context); |
266 |
return context; |
return context; |
267 |
} |
} |
268 |
|
|
269 |
public void setContext(MapContext context) { |
public void setContext(final MapContext context) { |
270 |
if (this.context != null) { |
if (this.context != null) { |
271 |
this.context.removeMapLayerListListener(this); |
this.context.removeMapLayerListListener(this); |
272 |
} |
} |
286 |
return mapArea; |
return mapArea; |
287 |
} |
} |
288 |
|
|
289 |
public void setMapArea(Envelope mapArea) { |
public void setMapArea(final Envelope mapArea) { |
290 |
this.mapArea = mapArea; |
this.mapArea = mapArea; |
291 |
} |
} |
292 |
|
|
294 |
return state; |
return state; |
295 |
} |
} |
296 |
|
|
297 |
public void setState(int state) { |
public void setState(final int state) { |
298 |
this.state = state; |
this.state = state; |
299 |
|
|
300 |
// System.out.println("State: " + state); |
// System.out.println("State: " + state); |
304 |
return zoomFactor; |
return zoomFactor; |
305 |
} |
} |
306 |
|
|
307 |
public void setZoomFactor(double zoomFactor) { |
public void setZoomFactor(final double zoomFactor) { |
308 |
this.zoomFactor = zoomFactor; |
this.zoomFactor = zoomFactor; |
309 |
} |
} |
310 |
|
|
311 |
public MapLayer getSelectionLayer() { |
protected void paintComponent(final Graphics g) { |
|
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; |
|
|
} |
|
|
|
|
|
protected void paintComponent(Graphics g) { |
|
312 |
super.paintComponent(g); |
super.paintComponent(g); |
313 |
|
|
314 |
if ((renderer == null) || (mapArea == null)) { |
if ((renderer == null) || (mapArea == null)) { |
315 |
return; |
return; |
316 |
} |
} |
317 |
|
|
318 |
Rectangle r = getBounds(); |
final Rectangle r = getBounds(); |
319 |
Rectangle dr = new Rectangle(r.width, r.height); |
final Rectangle dr = new Rectangle(r.width, r.height); |
320 |
|
|
321 |
if (!r.equals(oldRect) || reset) { |
if (!r.equals(oldRect) || reset) { |
322 |
if (!r.equals(oldRect) && (mapArea == null)) { |
if (!r.equals(oldRect) && (mapArea == null)) { |
323 |
try { |
try { |
324 |
mapArea = context.getLayerBounds(); |
mapArea = context.getLayerBounds(); |
325 |
} catch (IOException e) { |
} catch (final IOException e) { |
326 |
// TODO Auto-generated catch block |
LOGGER.warn("context.getLayerBounds()", e); |
|
e.printStackTrace(); |
|
327 |
} |
} |
328 |
} |
} |
329 |
|
|
333 |
reset = false; /* forget about the reset */ |
reset = false; /* forget about the reset */ |
334 |
oldRect = r; /* store what the current size is */ |
oldRect = r; /* store what the current size is */ |
335 |
|
|
336 |
mapArea = fixAspectRatio(r, mapArea); |
mapArea = fixAspectRatio(r, mapArea, false); |
337 |
} |
} |
338 |
} |
} |
339 |
|
|
346 |
.getCoordinateReferenceSystem()); |
.getCoordinateReferenceSystem()); |
347 |
} |
} |
348 |
|
|
349 |
if (changed ) { /* if the map changed then redraw */ |
if (changed) { /* if the map changed then redraw */ |
350 |
changed = false; |
changed = false; |
351 |
baseImage = new BufferedImage(dr.width, dr.height, |
baseImage = new BufferedImage(dr.width, dr.height, |
352 |
BufferedImage.TYPE_INT_ARGB); |
BufferedImage.TYPE_INT_ARGB); |
353 |
|
|
354 |
Graphics2D ig = baseImage.createGraphics(); |
final Graphics2D ig = baseImage.createGraphics(); |
355 |
/* System.out.println("rendering"); */ |
/* System.out.println("rendering"); */ |
356 |
renderer.setContext(context); |
if (renderer.getContext() != null) |
357 |
|
renderer.setContext(context); |
358 |
labelCache.clear(); // work around anoying labelcache bug |
labelCache.clear(); // work around anoying labelcache bug |
359 |
|
|
360 |
// draw the map |
// draw the map |
367 |
} |
} |
368 |
|
|
369 |
((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); |
|
|
} |
|
370 |
} |
} |
371 |
|
|
372 |
private Envelope fixAspectRatio(Rectangle r, Envelope mapArea) { |
/** |
373 |
|
* Returns an {@link Envelope} that has the same aspect ratio as the given rectangle |
374 |
double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
* @param grow |
375 |
double mapHeight = mapArea.getHeight(); |
* If <code>true</code>, than the area will be enlarged to match |
376 |
double scaleX = r.getWidth() / mapArea.getWidth(); /* |
* the aspect ratio. If <code>false</code>, it will only shrink. |
377 |
* calculate the new |
*/ |
378 |
* scale |
private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea, |
379 |
*/ |
boolean grow) { |
380 |
|
|
381 |
|
final double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
382 |
|
final double mapHeight = mapArea.getHeight(); |
383 |
|
final double scaleX = r.getWidth() / mapArea.getWidth(); /* |
384 |
|
* calculate the |
385 |
|
* new scale |
386 |
|
*/ |
387 |
|
|
388 |
double scaleY = r.getHeight() / mapArea.getHeight(); |
final double scaleY = r.getHeight() / mapArea.getHeight(); |
389 |
double scale = 1.0; // stupid compiler! |
double scale = 1.0; // stupid compiler! |
390 |
|
|
391 |
if (scaleX < scaleY) { /* pick the smaller scale */ |
if ((grow && scaleX < scaleY) || (!grow && scaleX > scaleY)) { |
392 |
scale = scaleX; |
scale = scaleX; |
393 |
} else { |
} else { |
394 |
scale = scaleY; |
scale = scaleY; |
395 |
} |
} |
396 |
|
|
397 |
/* calculate the difference in width and height of the new extent */ |
/* calculate the difference in width and height of the new extent */ |
398 |
double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth); |
final double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth); |
399 |
double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight); |
final double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight); |
400 |
|
|
401 |
/* |
/* |
402 |
* System.out.println("delta x " + deltaX); |
* System.out.println("delta x " + deltaX); |
404 |
*/ |
*/ |
405 |
|
|
406 |
/* create the new extent */ |
/* create the new extent */ |
407 |
Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0), |
final Coordinate ll = new Coordinate( |
408 |
mapArea.getMinY() - (deltaY / 2.0)); |
mapArea.getMinX() - (deltaX / 2.0), mapArea.getMinY() |
409 |
Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0), |
- (deltaY / 2.0)); |
410 |
mapArea.getMaxY() + (deltaY / 2.0)); |
final Coordinate ur = new Coordinate( |
411 |
|
mapArea.getMaxX() + (deltaX / 2.0), mapArea.getMaxY() |
412 |
|
+ (deltaY / 2.0)); |
413 |
|
|
414 |
return new Envelope(ll, ur); |
return new Envelope(ll, ur); |
415 |
} |
} |
416 |
|
|
417 |
public void doSelection(double x, double y, MapLayer layer) { |
public void mouseClicked(final MouseEvent e) { |
418 |
|
if (mapArea == null) |
|
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(Geometry geometry, MapLayer layer) |
|
|
throws IndexOutOfBoundsException { |
|
|
org.opengis.filter.spatial.BinarySpatialOperator f = null; |
|
|
|
|
|
if ((context == null) || (layer == null)) { |
|
419 |
return; |
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 (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 (IllegalFilterException e) { |
|
|
// TODO Auto-generated catch block |
|
|
e.printStackTrace(); |
|
|
} |
|
|
return; |
|
|
} |
|
|
|
|
|
public void mouseClicked(MouseEvent e) { |
|
|
if (mapArea == null) return; |
|
420 |
// System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+" |
// System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+" |
421 |
// h:"+mapArea.getHeight()); |
// h:"+mapArea.getHeight()); |
422 |
Rectangle bounds = this.getBounds(); |
final Rectangle bounds = this.getBounds(); |
423 |
double x = (double) (e.getX()); |
final double x = (double) (e.getX()); |
424 |
double y = (double) (e.getY()); |
final double y = (double) (e.getY()); |
425 |
double width = mapArea.getWidth(); |
final double width = mapArea.getWidth(); |
426 |
double height = mapArea.getHeight(); |
final double height = mapArea.getHeight(); |
427 |
// xulu.sc |
// xulu.sc |
428 |
// double width2 = mapArea.getWidth() / 2.0; |
// double width2 = mapArea.getWidth() / 2.0; |
429 |
// double height2 = mapArea.getHeight() / 2.0; |
// double height2 = mapArea.getHeight() / 2.0; |
430 |
double width2 = width / 2.0; |
final double width2 = width / 2.0; |
431 |
double height2 = height / 2.0; |
final double height2 = height / 2.0; |
432 |
// xulu.ec |
// xulu.ec |
433 |
double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX(); |
final double mapX = ((x * width) / (double) bounds.width) |
434 |
double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height) |
+ mapArea.getMinX(); |
435 |
|
final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height) |
436 |
+ mapArea.getMinY(); |
+ mapArea.getMinY(); |
437 |
|
|
438 |
/* |
/* |
462 |
zlevel = 1.0 / zoomFactor; |
zlevel = 1.0 / zoomFactor; |
463 |
|
|
464 |
break; |
break; |
465 |
|
// |
466 |
case Select: |
// case Select: |
467 |
doSelection(mapX, mapY, selectionLayer); |
// doSelection(mapX, mapY, selectionLayer); |
468 |
|
// |
469 |
return; |
// return; |
470 |
|
|
471 |
default: |
default: |
472 |
return; |
return; |
473 |
} |
} |
474 |
|
|
475 |
Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY |
final Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY |
476 |
- (height2 / zlevel)); |
- (height2 / zlevel)); |
477 |
Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY |
final Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY |
478 |
+ (height2 / zlevel)); |
+ (height2 / zlevel)); |
479 |
// xulu.sc SK: Check for min/max scale |
// xulu.sc SK: Check for min/max scale |
480 |
// mapArea = new Envelope(ll, ur); |
// mapArea = new Envelope(ll, ur); |
489 |
repaint(); |
repaint(); |
490 |
} |
} |
491 |
|
|
492 |
public void mouseEntered(MouseEvent e) { |
public void mouseEntered(final MouseEvent e) { |
493 |
} |
} |
494 |
|
|
495 |
public void mouseExited(MouseEvent e) { |
public void mouseExited(final MouseEvent e) { |
496 |
} |
} |
497 |
|
|
498 |
public void mousePressed(MouseEvent e) { |
public void mousePressed(final MouseEvent e) { |
499 |
startX = e.getX(); |
startX = e.getX(); |
500 |
startY = e.getY(); |
startY = e.getY(); |
501 |
lastX = 0; |
lastX = 0; |
502 |
lastY = 0; |
lastY = 0; |
503 |
} |
} |
504 |
|
|
505 |
public void mouseReleased(MouseEvent e) { |
public void mouseReleased(final MouseEvent e) { |
506 |
int endX = e.getX(); |
final int endX = e.getX(); |
507 |
int endY = e.getY(); |
final int endY = e.getY(); |
508 |
|
|
509 |
processDrag(startX, startY, endX, endY, e); |
processDrag(startX, startY, endX, endY, e); |
510 |
lastX = 0; |
lastX = 0; |
516 |
panning_started = false; |
panning_started = false; |
517 |
} |
} |
518 |
|
|
519 |
public void mouseDragged(MouseEvent e) { |
public void mouseDragged(final MouseEvent e) { |
520 |
Graphics graphics = this.getGraphics(); |
final Graphics graphics = this.getGraphics(); |
521 |
int x = e.getX(); |
final int x = e.getX(); |
522 |
int y = e.getY(); |
final int y = e.getY(); |
523 |
|
|
524 |
if ((state == JMapPane.Pan) |
if ((state == JMapPane.Pan) |
525 |
|| ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
|| ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
533 |
|
|
534 |
// move the image with the mouse |
// move the image with the mouse |
535 |
if ((lastX > 0) && (lastY > 0)) { |
if ((lastX > 0) && (lastY > 0)) { |
536 |
int dx = lastX - startX; |
final int dx = lastX - startX; |
537 |
int dy = lastY - startY; |
final int dy = lastY - startY; |
538 |
// System.out.println("translate "+dx+","+dy); |
// System.out.println("translate "+dx+","+dy); |
539 |
final Graphics2D g2 = panningImage.createGraphics(); |
final Graphics2D g2 = panningImage.createGraphics(); |
540 |
g2.setBackground(new Color(240, 240, 240)); // TODO richtige |
g2.setBackground(new Color(240, 240, 240)); // TODO richtige |
541 |
// farbe? am besten |
// farbe? am besten |
542 |
// vom L&F die |
// vom L&F die |
543 |
// hintergrundfarbe |
// hintergrundfarbe |
544 |
// auslesen... |
// auslesen... |
545 |
|
|
546 |
g2.clearRect(0, 0, this.getWidth(), this.getHeight()); |
g2.clearRect(0, 0, this.getWidth(), this.getHeight()); |
547 |
g2.drawImage(baseImage, dx, dy, this); |
g2.drawImage(baseImage, dx, dy, this); |
548 |
graphics.drawImage(panningImage, 0, 0, this); |
graphics.drawImage(panningImage, 0, 0, this); |
564 |
lastX = x; |
lastX = x; |
565 |
lastY = y; |
lastY = y; |
566 |
drawRectangle(graphics); |
drawRectangle(graphics); |
|
} else if (state == JMapPane.Select && selectionLayer != null) { |
|
|
|
|
|
// construct a new bbox filter |
|
|
Rectangle bounds = this.getBounds(); |
|
|
|
|
|
double mapWidth = mapArea.getWidth(); |
|
|
double mapHeight = mapArea.getHeight(); |
|
|
|
|
|
double x1 = ((this.startX * mapWidth) / (double) bounds.width) |
|
|
+ mapArea.getMinX(); |
|
|
double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height) |
|
|
+ mapArea.getMinY(); |
|
|
double x2 = ((x * mapWidth) / (double) bounds.width) |
|
|
+ mapArea.getMinX(); |
|
|
double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height) |
|
|
+ mapArea.getMinY(); |
|
|
double left = Math.min(x1, x2); |
|
|
double right = Math.max(x1, x2); |
|
|
double bottom = Math.min(y1, y2); |
|
|
double top = Math.max(y1, y2); |
|
|
|
|
|
String name = selectionLayer.getFeatureSource().getSchema() |
|
|
.getDefaultGeometry().getName(); |
|
|
|
|
|
if (name == "") { |
|
|
name = "the_geom"; |
|
|
} |
|
|
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); |
|
567 |
} |
} |
568 |
|
// else if (state == JMapPane.Select && selectionLayer != null) { |
569 |
|
// |
570 |
|
// // construct a new bbox filter |
571 |
|
// final Rectangle bounds = this.getBounds(); |
572 |
|
// |
573 |
|
// final double mapWidth = mapArea.getWidth(); |
574 |
|
// final double mapHeight = mapArea.getHeight(); |
575 |
|
// |
576 |
|
// final double x1 = ((this.startX * mapWidth) / (double) bounds.width) |
577 |
|
// + mapArea.getMinX(); |
578 |
|
// final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / |
579 |
|
// (double) bounds.height) |
580 |
|
// + mapArea.getMinY(); |
581 |
|
// final double x2 = ((x * mapWidth) / (double) bounds.width) |
582 |
|
// + mapArea.getMinX(); |
583 |
|
// final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) |
584 |
|
// bounds.height) |
585 |
|
// + mapArea.getMinY(); |
586 |
|
// final double left = Math.min(x1, x2); |
587 |
|
// final double right = Math.max(x1, x2); |
588 |
|
// final double bottom = Math.min(y1, y2); |
589 |
|
// final double top = Math.max(y1, y2); |
590 |
|
// |
591 |
|
// String name = selectionLayer.getFeatureSource().getSchema() |
592 |
|
// .getDefaultGeometry().getName(); |
593 |
|
// |
594 |
|
// if (name == "") { |
595 |
|
// name = "the_geom"; |
596 |
|
// } |
597 |
|
// final Filter bb = ff.bbox(ff.property(name), left, bottom, right, |
598 |
|
// top, |
599 |
|
// getContext().getCoordinateReferenceSystem().toString()); |
600 |
|
// if (selectionManager != null) { |
601 |
|
// selectionManager.selectionChanged(this, bb); |
602 |
|
// } |
603 |
|
// |
604 |
|
// graphics.setXORMode(Color.green); |
605 |
|
// |
606 |
|
// /* |
607 |
|
// * if ((lastX > 0) && (lastY > 0)) { drawRectangle(graphics); } |
608 |
|
// */ |
609 |
|
// |
610 |
|
// // draw new box |
611 |
|
// lastX = x; |
612 |
|
// lastY = y; |
613 |
|
// drawRectangle(graphics); |
614 |
|
// } |
615 |
|
|
616 |
} |
} |
617 |
|
|
619 |
// private void processDrag(int x1, int y1, int x2, int y2) { |
// private void processDrag(int x1, int y1, int x2, int y2) { |
620 |
// sk.ce |
// sk.ce |
621 |
protected void processDrag(final int x1, final int y1, final int x2, |
protected void processDrag(final int x1, final int y1, final int x2, |
622 |
final int y2, MouseEvent e) { |
final int y2, final MouseEvent e) { |
623 |
|
|
624 |
/**** |
/**** |
625 |
* If no layer is availabe we dont want a NullPointerException |
* If no layer is availabe we dont want a NullPointerException |
638 |
return; |
return; |
639 |
} |
} |
640 |
|
|
641 |
Rectangle bounds = this.getBounds(); |
final Rectangle bounds = this.getBounds(); |
642 |
|
|
643 |
double mapWidth = mapArea.getWidth(); |
final double mapWidth = mapArea.getWidth(); |
644 |
double mapHeight = mapArea.getHeight(); |
final double mapHeight = mapArea.getHeight(); |
645 |
|
|
646 |
double startX = ((x1 * mapWidth) / (double) bounds.width) |
final double startX = ((x1 * mapWidth) / (double) bounds.width) |
647 |
+ mapArea.getMinX(); |
+ mapArea.getMinX(); |
648 |
double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height) |
final double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height) |
649 |
+ mapArea.getMinY(); |
+ mapArea.getMinY(); |
650 |
double endX = ((x2 * mapWidth) / (double) bounds.width) |
final double endX = ((x2 * mapWidth) / (double) bounds.width) |
651 |
+ mapArea.getMinX(); |
+ mapArea.getMinX(); |
652 |
double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height) |
final double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height) |
653 |
+ mapArea.getMinY(); |
+ mapArea.getMinY(); |
654 |
|
|
655 |
if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) { |
if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) { |
656 |
// move the image with the mouse |
// move the image with the mouse |
657 |
// calculate X offsets from start point to the end Point |
// calculate X offsets from start point to the end Point |
658 |
double deltaX1 = endX - startX; |
final double deltaX1 = endX - startX; |
659 |
|
|
660 |
// System.out.println("deltaX " + deltaX1); |
// System.out.println("deltaX " + deltaX1); |
661 |
// new edges |
// new edges |
662 |
double left = mapArea.getMinX() - deltaX1; |
final double left = mapArea.getMinX() - deltaX1; |
663 |
double right = mapArea.getMaxX() - deltaX1; |
final double right = mapArea.getMaxX() - deltaX1; |
664 |
|
|
665 |
// now for Y |
// now for Y |
666 |
double deltaY1 = endY - startY; |
final double deltaY1 = endY - startY; |
667 |
|
|
668 |
// System.out.println("deltaY " + deltaY1); |
// System.out.println("deltaY " + deltaY1); |
669 |
double bottom = mapArea.getMinY() - deltaY1; |
final double bottom = mapArea.getMinY() - deltaY1; |
670 |
double top = mapArea.getMaxY() - deltaY1; |
final double top = mapArea.getMaxY() - deltaY1; |
671 |
Coordinate ll = new Coordinate(left, bottom); |
final Coordinate ll = new Coordinate(left, bottom); |
672 |
Coordinate ur = new Coordinate(right, top); |
final Coordinate ur = new Coordinate(right, top); |
673 |
// xulu.sc |
// xulu.sc |
674 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
675 |
setMapArea(fixAspectRatio(this.getBounds(), new Envelope(ll, ur))); |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
676 |
// xulu.ec |
// xulu.ec |
677 |
} else if (state == JMapPane.ZoomIn) { |
} else if (state == JMapPane.ZoomIn) { |
678 |
|
|
684 |
|
|
685 |
drawRectangle(this.getGraphics()); |
drawRectangle(this.getGraphics()); |
686 |
// make the dragged rectangle (in map coords) the new BBOX |
// make the dragged rectangle (in map coords) the new BBOX |
687 |
double left = Math.min(startX, endX); |
final double left = Math.min(startX, endX); |
688 |
double right = Math.max(startX, endX); |
final double right = Math.max(startX, endX); |
689 |
double bottom = Math.min(startY, endY); |
final double bottom = Math.min(startY, endY); |
690 |
double top = Math.max(startY, endY); |
final double top = Math.max(startY, endY); |
691 |
Coordinate ll = new Coordinate(left, bottom); |
final Coordinate ll = new Coordinate(left, bottom); |
692 |
Coordinate ur = new Coordinate(right, top); |
final Coordinate ur = new Coordinate(right, top); |
693 |
// xulu.sc |
// xulu.sc |
694 |
|
|
695 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
696 |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
697 |
|
|
698 |
// sk.sc |
// sk.sc |
699 |
// { |
// { |
700 |
// // SK tries to paint a preview of the zoom ;-9 aha.... well |
// // SK tries to paint a preview of the zoom ;-9 aha.... well |
701 |
// Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics(); |
// Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics(); |
702 |
// graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
// graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
703 |
// RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
// RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
704 |
// graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
// graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
705 |
// RenderingHints.VALUE_ANTIALIAS_OFF); |
// RenderingHints.VALUE_ANTIALIAS_OFF); |
706 |
// graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
// graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
707 |
// RenderingHints.VALUE_RENDER_SPEED); |
// RenderingHints.VALUE_RENDER_SPEED); |
708 |
// graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(), |
// graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(), |
709 |
// JMapPane.this.getHeight(), x1, y1, x2, y2, null); |
// JMapPane.this.getHeight(), x1, y1, x2, y2, null); |
710 |
// } |
// } |
711 |
// xulu.ec |
// xulu.ec |
712 |
} else if (state == JMapPane.ZoomOut) { |
} else if (state == JMapPane.ZoomOut) { |
713 |
drawRectangle(this.getGraphics()); |
drawRectangle(this.getGraphics()); |
714 |
|
|
715 |
// make the dragged rectangle in screen coords the new map size? |
// make the dragged rectangle in screen coords the new map size? |
716 |
double left = Math.min(startX, endX); |
final double left = Math.min(startX, endX); |
717 |
double right = Math.max(startX, endX); |
final double right = Math.max(startX, endX); |
718 |
double bottom = Math.min(startY, endY); |
final double bottom = Math.min(startY, endY); |
719 |
double top = Math.max(startY, endY); |
final double top = Math.max(startY, endY); |
720 |
double nWidth = (mapWidth * mapWidth) / (right - left); |
final double nWidth = (mapWidth * mapWidth) / (right - left); |
721 |
double nHeight = (mapHeight * mapHeight) / (top - bottom); |
final double nHeight = (mapHeight * mapHeight) / (top - bottom); |
722 |
double deltaX1 = left - mapArea.getMinX(); |
final double deltaX1 = left - mapArea.getMinX(); |
723 |
double nDeltaX1 = (deltaX1 * nWidth) / mapWidth; |
final double nDeltaX1 = (deltaX1 * nWidth) / mapWidth; |
724 |
double deltaY1 = bottom - mapArea.getMinY(); |
final double deltaY1 = bottom - mapArea.getMinY(); |
725 |
double nDeltaY1 = (deltaY1 * nHeight) / mapHeight; |
final double nDeltaY1 = (deltaY1 * nHeight) / mapHeight; |
726 |
Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1, |
final Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1, |
727 |
mapArea.getMinY() - nDeltaY1); |
mapArea.getMinY() - nDeltaY1); |
728 |
double deltaX2 = mapArea.getMaxX() - right; |
final double deltaX2 = mapArea.getMaxX() - right; |
729 |
double nDeltaX2 = (deltaX2 * nWidth) / mapWidth; |
final double nDeltaX2 = (deltaX2 * nWidth) / mapWidth; |
730 |
double deltaY2 = mapArea.getMaxY() - top; |
final double deltaY2 = mapArea.getMaxY() - top; |
731 |
double nDeltaY2 = (deltaY2 * nHeight) / mapHeight; |
final double nDeltaY2 = (deltaY2 * nHeight) / mapHeight; |
732 |
Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2, |
final Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2, |
733 |
mapArea.getMaxY() + nDeltaY2); |
mapArea.getMaxY() + nDeltaY2); |
734 |
// xulu.sc |
// xulu.sc |
735 |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur)); |
736 |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
setMapArea(bestAllowedMapArea(new Envelope(ll, ur))); |
737 |
|
|
738 |
// xulu.ec |
// xulu.ec |
|
} else if (state == JMapPane.Select && selectionLayer != null) { |
|
|
double left = Math.min(startX, endX); |
|
|
double right = Math.max(startX, endX); |
|
|
double bottom = Math.min(startY, endY); |
|
|
double top = Math.max(startY, endY); |
|
|
|
|
|
String name = selectionLayer.getFeatureSource().getSchema() |
|
|
.getDefaultGeometry().getLocalName(); |
|
|
|
|
|
if (name == "") { |
|
|
name = "the_geom"; |
|
|
} |
|
|
Filter bb = ff.bbox(ff.property(name), left, bottom, right, top, |
|
|
getContext().getCoordinateReferenceSystem().toString()); |
|
|
// System.out.println(bb.toString()); |
|
|
if (selectionManager != null) { |
|
|
selectionManager.selectionChanged(this, bb); |
|
|
} |
|
|
/* |
|
|
* FeatureCollection fc; selection = null; try { fc = |
|
|
* selectionLayer.getFeatureSource().getFeatures(bb); selection = |
|
|
* fc; } catch (IOException e) { e.printStackTrace(); } |
|
|
*/ |
|
739 |
} |
} |
740 |
|
// else if (state == JMapPane.Select && selectionLayer != null) { |
741 |
|
// final double left = Math.min(startX, endX); |
742 |
|
// final double right = Math.max(startX, endX); |
743 |
|
// final double bottom = Math.min(startY, endY); |
744 |
|
// final double top = Math.max(startY, endY); |
745 |
|
// |
746 |
|
// String name = selectionLayer.getFeatureSource().getSchema() |
747 |
|
// .getDefaultGeometry().getLocalName(); |
748 |
|
// |
749 |
|
// if (name == "") { |
750 |
|
// name = "the_geom"; |
751 |
|
// } |
752 |
|
// final Filter bb = ff.bbox(ff.property(name), left, bottom, right, |
753 |
|
// top, |
754 |
|
// getContext().getCoordinateReferenceSystem().toString()); |
755 |
|
// // System.out.println(bb.toString()); |
756 |
|
// if (selectionManager != null) { |
757 |
|
// selectionManager.selectionChanged(this, bb); |
758 |
|
// } |
759 |
|
// /* |
760 |
|
// * FeatureCollection fc; selection = null; try { fc = |
761 |
|
// * selectionLayer.getFeatureSource().getFeatures(bb); selection = |
762 |
|
// * fc; } catch (IOException e) { e.printStackTrace(); } |
763 |
|
// */ |
764 |
|
// } |
765 |
|
|
766 |
// xulu.so |
// xulu.so |
767 |
// setMapArea(mapArea); |
// setMapArea(mapArea); |
773 |
return clickable; |
return clickable; |
774 |
} |
} |
775 |
|
|
776 |
private org.geotools.styling.Style setupStyle(int type, Color color) { |
// |
777 |
StyleFactory sf = org.geotools.factory.CommonFactoryFinder |
// private org.geotools.styling.Style setupStyle(final int type, final Color |
778 |
.getStyleFactory(null); |
// color) { |
779 |
StyleBuilder sb = new StyleBuilder(); |
// final StyleFactory sf = org.geotools.factory.CommonFactoryFinder |
780 |
|
// .getStyleFactory(null); |
781 |
org.geotools.styling.Style s = sf.createStyle(); |
// final StyleBuilder sb = new StyleBuilder(); |
782 |
s.setTitle("selection"); |
// |
783 |
|
// org.geotools.styling.Style s = sf.createStyle(); |
784 |
// TODO parameterise the color |
// s.setTitle("selection"); |
785 |
PolygonSymbolizer ps = sb.createPolygonSymbolizer(color); |
// |
786 |
ps.setStroke(sb.createStroke(color)); |
// // TODO parameterise the color |
787 |
|
// final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color); |
788 |
LineSymbolizer ls = sb.createLineSymbolizer(color); |
// ps.setStroke(sb.createStroke(color)); |
789 |
Graphic h = sb.createGraphic(); |
// |
790 |
h.setMarks(new Mark[] { sb.createMark("square", color) }); |
// final LineSymbolizer ls = sb.createLineSymbolizer(color); |
791 |
|
// final Graphic h = sb.createGraphic(); |
792 |
PointSymbolizer pts = sb.createPointSymbolizer(h); |
// h.setMarks(new Mark[] { sb.createMark("square", color) }); |
793 |
|
// |
794 |
// Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts}); |
// final PointSymbolizer pts = sb.createPointSymbolizer(h); |
795 |
switch (type) { |
// |
796 |
case POLYGON: |
// // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts}); |
797 |
s = sb.createStyle(ps); |
// switch (type) { |
798 |
|
// case POLYGON: |
799 |
break; |
// s = sb.createStyle(ps); |
800 |
|
// |
801 |
case POINT: |
// break; |
802 |
s = sb.createStyle(pts); |
// |
803 |
|
// case POINT: |
804 |
break; |
// s = sb.createStyle(pts); |
805 |
|
// |
806 |
case LINE: |
// break; |
807 |
s = sb.createStyle(ls); |
// |
808 |
} |
// case LINE: |
809 |
|
// s = sb.createStyle(ls); |
810 |
return s; |
// } |
811 |
} |
// |
812 |
|
// return s; |
813 |
public void highlightChanged(HighlightChangedEvent e) { |
// } |
|
org.opengis.filter.Filter f = e.getFilter(); |
|
|
|
|
|
try { |
|
|
highlightFeature = highlightLayer.getFeatureSource().getFeatures(f); |
|
|
} catch (IOException e1) { |
|
|
// TODO Auto-generated catch block |
|
|
e1.printStackTrace(); |
|
|
} |
|
|
|
|
|
repaint(); |
|
|
} |
|
814 |
|
|
815 |
public void propertyChange(PropertyChangeEvent evt) { |
public void propertyChange(final PropertyChangeEvent evt) { |
816 |
String prop = evt.getPropertyName(); |
final String prop = evt.getPropertyName(); |
817 |
|
|
818 |
if (prop.equalsIgnoreCase("crs")) { |
if (prop.equalsIgnoreCase("crs")) { |
819 |
context.setAreaOfInterest(context.getAreaOfInterest(), |
context.setAreaOfInterest(context.getAreaOfInterest(), |
825 |
return reset; |
return reset; |
826 |
} |
} |
827 |
|
|
828 |
public void setReset(boolean reset) { |
public void setReset(final boolean reset) { |
829 |
this.reset = reset; |
this.reset = reset; |
830 |
} |
} |
831 |
|
|
832 |
public void layerAdded(MapLayerListEvent event) { |
public void layerAdded(final MapLayerListEvent event) { |
833 |
changed = true; |
changed = true; |
834 |
|
|
835 |
if (context.getLayers().length == 1) { // the first one |
if (context.getLayers().length == 1) { // the first one |
841 |
if (mapArea == null) |
if (mapArea == null) |
842 |
mapArea = context.getLayerBounds(); |
mapArea = context.getLayerBounds(); |
843 |
// xulu.ec |
// xulu.ec |
844 |
} catch (IOException e) { |
} catch (final IOException e) { |
845 |
// TODO Auto-generated catch block |
// TODO Auto-generated catch block |
846 |
e.printStackTrace(); |
e.printStackTrace(); |
847 |
} |
} |
852 |
repaint(); |
repaint(); |
853 |
} |
} |
854 |
|
|
855 |
public void layerRemoved(MapLayerListEvent event) { |
public void layerRemoved(final MapLayerListEvent event) { |
856 |
changed = true; |
changed = true; |
857 |
repaint(); |
repaint(); |
858 |
} |
} |
859 |
|
|
860 |
public void layerChanged(MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
861 |
changed = true; |
changed = true; |
862 |
// System.out.println("layer changed - repaint"); |
// System.out.println("layer changed - repaint"); |
863 |
repaint(); |
repaint(); |
864 |
} |
} |
865 |
|
|
866 |
public void layerMoved(MapLayerListEvent event) { |
public void layerMoved(final MapLayerListEvent event) { |
867 |
changed = true; |
changed = true; |
868 |
repaint(); |
repaint(); |
869 |
} |
} |
870 |
|
|
871 |
protected void drawRectangle(Graphics graphics) { |
protected void drawRectangle(final Graphics graphics) { |
872 |
// undraw last box/draw new box |
// undraw last box/draw new box |
873 |
int left = Math.min(startX, lastX); |
final int left = Math.min(startX, lastX); |
874 |
int right = Math.max(startX, lastX); |
final int right = Math.max(startX, lastX); |
875 |
int top = Math.max(startY, lastY); |
final int top = Math.max(startY, lastY); |
876 |
int bottom = Math.min(startY, lastY); |
final int bottom = Math.min(startY, lastY); |
877 |
int width = right - left; |
final int width = right - left; |
878 |
int height = top - bottom; |
final int height = top - bottom; |
879 |
// System.out.println("drawing rect("+left+","+bottom+","+ width+","+ |
// System.out.println("drawing rect("+left+","+bottom+","+ width+","+ |
880 |
// height+")"); |
// height+")"); |
881 |
graphics.drawRect(left, bottom, width, height); |
graphics.drawRect(left, bottom, width, height); |
887 |
* |
* |
888 |
* @param clickable |
* @param clickable |
889 |
*/ |
*/ |
890 |
public void setClickable(boolean clickable) { |
public void setClickable(final boolean clickable) { |
891 |
this.clickable = clickable; |
this.clickable = clickable; |
892 |
} |
} |
893 |
|
|
894 |
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(); |
|
|
} |
|
|
|
|
|
/* |
|
|
* (non-Javadoc) |
|
|
* |
|
|
* @see |
|
|
* org.geotools.gui.swing.event.SelectionChangeListener#selectionChanged |
|
|
* (org.geotools.gui.swing.event.SelectionChangedEvent) |
|
|
*/ |
|
|
public void selectionChanged(SelectionChangedEvent e) { |
|
|
|
|
|
try { |
|
|
selection = selectionLayer.getFeatureSource().getFeatures( |
|
|
e.getFilter()); |
|
|
repaint(); |
|
|
} catch (IOException e1) { |
|
|
e1.printStackTrace(); |
|
|
} |
|
|
} |
|
|
|
|
|
public SelectionManager getSelectionManager() { |
|
|
return selectionManager; |
|
|
} |
|
|
|
|
|
public void setSelectionManager(SelectionManager selectionManager) { |
|
|
this.selectionManager = selectionManager; |
|
|
this.selectionManager.addSelectionChangeListener(this); |
|
|
|
|
895 |
} |
} |
896 |
|
|
897 |
// xulu.sn |
// xulu.sn |
912 |
if (env == null) |
if (env == null) |
913 |
return env; |
return env; |
914 |
|
|
915 |
|
Envelope newArea = null; |
916 |
|
|
917 |
/** |
/** |
918 |
* Correct the aspect Ratio before we check the rest. Otherwise we might |
* Correct the aspect Ratio before we check the rest. Otherwise we might |
919 |
* easily fail. |
* easily fail. |
920 |
*/ |
*/ |
921 |
env = fixAspectRatio(this.getBounds(), env); |
env = fixAspectRatio(this.getBounds(), env, false); |
922 |
|
|
923 |
double scale = env.getWidth() / getWidth(); |
final double scale = env.getWidth() / getWidth(); |
924 |
double centerX = env.getMinX() + env.getWidth() / 2.; |
final double centerX = env.getMinX() + env.getWidth() / 2.; |
925 |
double centerY = env.getMinY() + env.getHeight() / 2.; |
final double centerY = env.getMinY() + env.getHeight() / 2.; |
926 |
double newWidth2; |
double newWidth2 = 0; |
927 |
double newHeight2; |
double newHeight2 = 0; |
928 |
if (scale < getMaxZoomScale()) { |
if (scale < getMaxZoomScale()) { |
929 |
// **************************************************************************** |
// **************************************************************************** |
930 |
// Wir zoomen weiter rein als erlaubt => Anpassen des envelope |
// Wir zoomen weiter rein als erlaubt => Anpassen des envelope |
941 |
// **************************************************************************** |
// **************************************************************************** |
942 |
// Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen |
// Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen |
943 |
// **************************************************************************** |
// **************************************************************************** |
944 |
return env; |
newArea = env; |
945 |
} |
} |
946 |
|
|
947 |
Coordinate ll = new Coordinate(centerX - newWidth2, centerY |
if (newArea == null) { |
|
- newHeight2); |
|
|
Coordinate ur = new Coordinate(centerX + newWidth2, centerY |
|
|
+ newHeight2); |
|
948 |
|
|
949 |
return new Envelope(ll, ur); |
final Coordinate ll = new Coordinate(centerX - newWidth2, centerY |
950 |
|
- newHeight2); |
951 |
|
final Coordinate ur = new Coordinate(centerX + newWidth2, centerY |
952 |
|
+ newHeight2); |
953 |
|
|
954 |
|
newArea = new Envelope(ll, ur); |
955 |
|
} |
956 |
|
|
957 |
|
Envelope maxAllowedExtend = getMaxExtend(); |
958 |
|
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)) { |
959 |
|
/* |
960 |
|
* If a maxExtend is set, we have to honour that... |
961 |
|
*/ |
962 |
|
|
963 |
|
// Exceeds top? Move down and maybe cut |
964 |
|
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
965 |
|
double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY(); |
966 |
|
LOGGER.debug("Moving area down by " + divY); |
967 |
|
|
968 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
969 |
|
newArea.getMinY() - divY), new Coordinate(newArea |
970 |
|
.getMaxX(), newArea.getMaxY() - divY)); |
971 |
|
|
972 |
|
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
973 |
|
LOGGER.debug("Now it exeeds the bottom border.. cut!"); |
974 |
|
// And cut the bottom if it moved out of the area |
975 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
976 |
|
maxAllowedExtend.getMinY()), new Coordinate(newArea |
977 |
|
.getMaxX(), newArea.getMaxY())); |
978 |
|
|
979 |
|
LOGGER.debug("and fix aspect ratio"); |
980 |
|
|
981 |
|
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
982 |
|
} |
983 |
|
} |
984 |
|
|
985 |
|
// Exceeds bottom? Move up and maybe cut |
986 |
|
if (newArea.getMinY() < maxAllowedExtend.getMinY()) { |
987 |
|
double divY = newArea.getMinY() - maxAllowedExtend.getMinY(); |
988 |
|
LOGGER.debug("Moving area up by " + divY); |
989 |
|
|
990 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
991 |
|
newArea.getMinY() - divY), new Coordinate(newArea |
992 |
|
.getMaxX(), newArea.getMaxY() - divY)); |
993 |
|
|
994 |
|
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
995 |
|
LOGGER.debug("Now it exeeds the top border.. cut!"); |
996 |
|
// And cut the bottom if it moved out of the area |
997 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
998 |
|
newArea.getMinY()), new Coordinate(newArea |
999 |
|
.getMaxX(), maxAllowedExtend.getMaxY())); |
1000 |
|
|
1001 |
|
LOGGER.debug("and fix aspect ratio"); |
1002 |
|
|
1003 |
|
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
1004 |
|
} |
1005 |
|
} |
1006 |
|
|
1007 |
|
// Exceeds to the right? move and maybe cut |
1008 |
|
if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) { |
1009 |
|
|
1010 |
|
// Move left.. |
1011 |
|
double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX(); |
1012 |
|
LOGGER.debug("Moving area left by " + divX); |
1013 |
|
|
1014 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX() - divX, |
1015 |
|
newArea.getMinY()), new Coordinate(newArea.getMaxX() |
1016 |
|
- divX, newArea.getMaxY())); |
1017 |
|
|
1018 |
|
if (newArea.getMinX() < maxAllowedExtend.getMinX()) { |
1019 |
|
LOGGER.debug("Now it exeeds the left border.. cut!"); |
1020 |
|
// And cut the left if it moved out of the area |
1021 |
|
newArea = new Envelope(new Coordinate(maxAllowedExtend.getMinX(), |
1022 |
|
newArea.getMinY()), new Coordinate(newArea |
1023 |
|
.getMaxX(), newArea.getMaxY())); |
1024 |
|
|
1025 |
|
LOGGER.debug("and fix aspect ratio"); |
1026 |
|
|
1027 |
|
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
1028 |
|
} |
1029 |
|
} |
1030 |
|
|
1031 |
|
// Exceeds to the left? move and maybe cut |
1032 |
|
if (newArea.getMinX() < maxAllowedExtend.getMinX()) { |
1033 |
|
|
1034 |
|
// Move right.. |
1035 |
|
double divX = newArea.getMinX() - maxAllowedExtend.getMinX(); |
1036 |
|
LOGGER.debug("Moving area right by " + divX); |
1037 |
|
|
1038 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX() - divX, |
1039 |
|
newArea.getMinY()), new Coordinate(newArea.getMaxX() |
1040 |
|
- divX, newArea.getMaxY())); |
1041 |
|
|
1042 |
|
if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) { |
1043 |
|
LOGGER.debug("Now it exeeds the right border.. cut!"); |
1044 |
|
// And cut the left if it moved out of the area |
1045 |
|
newArea = new Envelope(new Coordinate(newArea.getMinX(), |
1046 |
|
newArea.getMinY()), new Coordinate(maxAllowedExtend |
1047 |
|
.getMaxX(), newArea.getMaxY())); |
1048 |
|
|
1049 |
|
LOGGER.debug("and fix aspect ratio"); |
1050 |
|
|
1051 |
|
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
1052 |
|
} |
1053 |
|
} |
1054 |
|
|
1055 |
|
} |
1056 |
|
|
1057 |
|
return newArea; |
1058 |
} |
} |
1059 |
|
|
1060 |
/** |
/** |
1086 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
1087 |
* Krüger</a> |
* Krüger</a> |
1088 |
*/ |
*/ |
1089 |
public void setMaxZoomScale(Double maxZoomScale) { |
public void setMaxZoomScale(final Double maxZoomScale) { |
|
// System.out.println("setting max scale to "+maxZoomScale); |
|
1090 |
this.maxZoomScale = maxZoomScale; |
this.maxZoomScale = maxZoomScale; |
1091 |
} |
} |
1092 |
|
|
1097 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
1098 |
* Krüger</a> |
* Krüger</a> |
1099 |
*/ |
*/ |
1100 |
public void setMinZoomScale(Double minZoomScale) { |
public void setMinZoomScale(final Double minZoomScale) { |
1101 |
this.minZoomScale = minZoomScale; |
this.minZoomScale = minZoomScale; |
1102 |
} |
} |
1103 |
// xulu.en |
|
1104 |
|
/** |
1105 |
|
* Defines an evelope of the viwable area. The JMapPane will never show |
1106 |
|
* anything outside of this extend. |
1107 |
|
* |
1108 |
|
* @param maxExtend |
1109 |
|
* <code>null</code> to not have this restriction. |
1110 |
|
*/ |
1111 |
|
public void setMaxExtend(Envelope maxExtend) { |
1112 |
|
this.maxExtend = maxExtend; |
1113 |
|
} |
1114 |
|
|
1115 |
|
/** |
1116 |
|
* Returns the evelope of the viewable area. The JMapPane will never show |
1117 |
|
* anything outside of this extend. If this has been set to |
1118 |
|
* <code>null</code> via {@link #setMaxExtend(Envelope)}, it tries to return |
1119 |
|
* quickly the context's bounds. It it takes to long to determine the |
1120 |
|
* context bounds, <code>null</code> is returned. |
1121 |
|
* |
1122 |
|
* @param maxExtend |
1123 |
|
* <code>null</code> to not have this restriction. |
1124 |
|
*/ |
1125 |
|
|
1126 |
|
public Envelope getMaxExtend() { |
1127 |
|
if (maxExtend == null) { |
1128 |
|
try { |
1129 |
|
return fixAspectRatio(this.getBounds(), context.getLayerBounds(), true); |
1130 |
|
} catch (IOException e) { |
1131 |
|
LOGGER |
1132 |
|
.warn( |
1133 |
|
"maxExtend == null; faild to getLayerBounds of context", |
1134 |
|
e); |
1135 |
|
} |
1136 |
|
} |
1137 |
|
return maxExtend; |
1138 |
|
} |
1139 |
|
|
1140 |
} |
} |