/** * Links two WorldWindows so that the eye position of the master window is copied to the * eye position of the slave. Does not set up the reverse link. However, the caller may call * again with the arguments reversed to have both windows reflect each others position. * * @param master * @param slave */ public static void linkWorldWindToWorldWind( final WorldWindow master, final WorldWindow slave ) { master.addPositionListener( new PositionListener( ) { @Override public void moved( PositionEvent event ) { Position pos = master.getView( ).getCurrentEyePosition( ); slave.getView( ).setEyePosition( pos ); slave.redraw( ); } } ); }
/** * Sets up a listener to update the center of the provided axes to reflect the current eye * position of the WorldWindow. The zoom level of the axes is never changed. * * @param wwd * @param projection * @param axis */ public static void linkAxisToWorldWind( final WorldWindow wwd, final GeoProjection projection, final Axis2D axis ) { wwd.addPositionListener( new PositionListener( ) { @Override public void moved( PositionEvent event ) { Position pos = wwd.getView( ).getCurrentEyePosition( ); LatLonGeo latlon = fromPosition( pos ); Vector2d center = projection.project( latlon ); double diffX = axis.getMaxX( ) - axis.getMinX( ); double diffY = axis.getMaxY( ) - axis.getMinY( ); double newMinX = center.getX( ) - diffX / 2.0; double newMaxX = center.getX( ) + diffX / 2.0; double newMinY = center.getY( ) - diffY / 2.0; double newMaxY = center.getY( ) + diffY / 2.0; axis.set( newMinX, newMaxX, newMinY, newMaxY ); axis.validate( ); } } ); }
worldWindow.addPositionListener(positionListener); thePanel.setPreferredSize(new Dimension(0, 0)); thePanel.add((Component)worldWindow, BorderLayout.CENTER);