Java Code Examples for org.osmdroid.views.Projection#getWidth()

The following examples show how to use org.osmdroid.views.Projection#getWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PolyOverlayWithIW.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * @since 6.2.0
    * We pre-check if it's worth computing and drawing a poly.
    * How do we do that? As an approximation, we consider both the poly and the screen as disks.
    * Then, we compute the distance between both centers: if it's greater than the sum of the radii
    * the poly won't be visible.
 */
private boolean isVisible(final Projection pProjection) {
       // projecting the center and a corner of the bounding box to the screen, close to the screen center
	final BoundingBox boundingBox = getBounds();
       pProjection.toProjectedPixels(boundingBox.getCenterLatitude(), boundingBox.getCenterLongitude(),
               mVisibilityProjectedCenter);
       pProjection.toProjectedPixels(boundingBox.getLatNorth(), boundingBox.getLonEast(),
               mVisibilityProjectedCorner);
       pProjection.getLongPixelsFromProjected(mVisibilityProjectedCenter,
               pProjection.getProjectedPowerDifference(), true, mVisibilityRectangleCenter);
       pProjection.getLongPixelsFromProjected(mVisibilityProjectedCorner,
               pProjection.getProjectedPowerDifference(), true, mVisibilityRectangleCorner);

       // computing the distance and the radii
       final int screenCenterX = pProjection.getWidth() / 2;
       final int screenCenterY = pProjection.getHeight() / 2;
       final double radius = Math.sqrt(Distance.getSquaredDistanceToPoint(
               mVisibilityRectangleCenter.x, mVisibilityRectangleCenter.y,
               mVisibilityRectangleCorner.x, mVisibilityRectangleCorner.y));
       final double distanceBetweenCenters = Math.sqrt(Distance.getSquaredDistanceToPoint(
               mVisibilityRectangleCenter.x, mVisibilityRectangleCenter.y,
               screenCenterX, screenCenterY));
       final double screenRadius = Math.sqrt(Distance.getSquaredDistanceToPoint(
               0, 0,
               screenCenterX, screenCenterY));

       return distanceBetweenCenters <= radius + screenRadius;
}