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 |
1443 |
*/ |
*/ |
1444 |
public void onRenderingCompleted(final long l) { |
public void onRenderingCompleted(final long l) { |
1445 |
lastRenderingDuration = (lastRenderingDuration + l) / 2; |
lastRenderingDuration = (lastRenderingDuration + l) / 2; |
1446 |
LOGGER |
// LOGGER |
1447 |
.debug("complete rendering after " + lastRenderingDuration |
// .debug("complete rendering after " + lastRenderingDuration |
1448 |
+ "ms"); |
// + "ms"); |
1449 |
|
|
1450 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1451 |
|
|
2380 |
* @param center |
* @param center |
2381 |
* position in window coordinates |
* position in window coordinates |
2382 |
* @param zoomFaktor |
* @param zoomFaktor |
2383 |
* > 1 for zoom in, < 1 for zoom out. Default is 1.33. |
* > 1 for zoom out, < 1 for zoom in. Default is .5 |
2384 |
*/ |
*/ |
2385 |
public void zoomTo(Point center, Double zoomFaktor) { |
public void zoomTo(Point center, Double zoomFaktor) { |
2386 |
if (zoomFaktor == null || zoomFaktor == 0.) |
if (zoomFaktor == null || zoomFaktor == 0.) |
2387 |
zoomFaktor = 2.; |
zoomFaktor = .5; |
2388 |
|
|
2389 |
final Point2D gcenter = getScreenToWorld().transform(center, null); |
final Point2D gcenter = getScreenToWorld().transform(center, null); |
2390 |
center = null; |
center = null; |
2406 |
.getHeight()) / 2.); |
.getHeight()) / 2.); |
2407 |
|
|
2408 |
// // Move the newMapArea above the new center if we zoom in: |
// // Move the newMapArea above the new center if we zoom in: |
2409 |
if (zoomFaktor >= 1) { |
newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
2410 |
newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
.getY() |
2411 |
.getY() |
- mapArea.centre().y); |
|
- mapArea.centre().y); |
|
|
} |
|
2412 |
|
|
2413 |
setMapArea(newMapArea); |
setMapArea(newMapArea); |
2414 |
} |
} |