public LatLong fromPixels ( double x , double y ) { if ( this . mapView . getWidth ( ) <= 0 || this . mapView . getHeight ( ) <= 0 ) { return null ; } // this uses the framebuffer position, the mapview position can be out of sync with // what the user sees on the screen if an animation is in progress MapPosition mapPosition = this . mapView . getModel ( ) . frameBufferModel . getMapPosition ( ) ; // this means somehow the mapview is not yet properly set up, see issue #308. if ( mapPosition == null ) { return null ; } // calculate the pixel coordinates of the top left corner LatLong latLong = mapPosition . latLong ; long mapSize = MercatorProjection . getMapSize ( mapPosition . zoomLevel , this . mapView . getModel ( ) . displayModel . getTileSize ( ) ) ; double pixelX = MercatorProjection . longitudeToPixelX ( latLong . longitude , mapSize ) ; double pixelY = MercatorProjection . latitudeToPixelY ( latLong . latitude , mapSize ) ; pixelX -= this . mapView . getWidth ( ) >> 1 ; pixelY -= this . mapView . getHeight ( ) >> 1 ; // catch outer map limits try { // convert the pixel coordinates to a LatLong and return it return new LatLong ( MercatorProjection . pixelYToLatitude ( pixelY + y , mapSize ) , MercatorProjection . pixelXToLongitude ( pixelX + x , mapSize ) ) ; } catch ( Exception e ) { return null ; } }
Computes the geographic coordinates of a screen point .