33 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
34 |
import org.geotools.factory.GeoTools; |
import org.geotools.factory.GeoTools; |
35 |
import org.geotools.feature.FeatureCollection; |
import org.geotools.feature.FeatureCollection; |
36 |
|
import org.geotools.geometry.DirectPosition2D; |
37 |
import org.geotools.geometry.jts.JTS; |
import org.geotools.geometry.jts.JTS; |
38 |
import org.geotools.geometry.jts.ReferencedEnvelope; |
import org.geotools.geometry.jts.ReferencedEnvelope; |
39 |
import org.geotools.map.DefaultMapContext; |
import org.geotools.map.DefaultMapContext; |
252 |
* @param e |
* @param e |
253 |
* Maus-Ereignis |
* Maus-Ereignis |
254 |
*/ |
*/ |
255 |
public static Point2D getMapCoordinatesFromEvent(final MouseEvent e) { |
public static DirectPosition2D getMapCoordinatesFromEvent(final MouseEvent e) { |
256 |
// aktuelle Geo-Position aus GeoMouseEvent ermitteln |
// aktuelle Geo-Position aus GeoMouseEvent ermitteln |
257 |
if (e != null && e instanceof MapMouseEvent) |
if (e != null && e instanceof MapMouseEvent) |
258 |
try { |
try { |
259 |
return ((MapMouseEvent) e).getMapPosition().toPoint2D(); |
return ((MapMouseEvent) e).getMapPosition(); |
260 |
} catch (final Exception err) { |
} catch (final Exception err) { |
261 |
LOGGER |
LOGGER |
262 |
.error( |
.error( |
273 |
return null; |
return null; |
274 |
|
|
275 |
final AffineTransform at = xMapPane.getScreenToWorld(); |
final AffineTransform at = xMapPane.getScreenToWorld(); |
276 |
if (at != null) |
if (at != null) { |
277 |
return at.transform(e.getPoint(), null); |
Point2D transformed = at.transform(e.getPoint(), null); |
278 |
|
return new DirectPosition2D(xMapPane.getMapContext().getCoordinateReferenceSystem(), transformed.getX(), transformed.getY()); |
279 |
|
} |
280 |
return null; |
return null; |
281 |
} |
} |
282 |
throw new IllegalArgumentException( |
throw new IllegalArgumentException( |
283 |
"MouseEvent has to be of instance MapMouseEvent or come from an XMapPane"); |
"MouseEvent has to be of instance MapMouseEvent or come from an XMapPane"); |
284 |
} |
} |
285 |
|
|
286 |
|
|
287 |
|
|
288 |
/** |
/** |
289 |
* Listens to changes of the "background" {@link MapContext} and triggers |
* Listens to changes of the "background" {@link MapContext} and triggers |