/osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/v2/Projection.java

http://osmdroid.googlecode.com/ · Java · 55 lines · 44 code · 11 blank · 0 comment · 2 complexity · 414aa62a8be6a7c147aa093b895593d7 MD5 · raw file

  1. package org.osmdroid.google.wrapper.v2;
  2. import com.google.android.gms.maps.model.LatLng;
  3. import com.google.android.gms.maps.model.LatLngBounds;
  4. import org.osmdroid.api.IGeoPoint;
  5. import org.osmdroid.api.IProjection;
  6. import android.graphics.Point;
  7. public class Projection implements IProjection {
  8. private final com.google.android.gms.maps.Projection mProjection;
  9. private final Point mPoint = new Point();
  10. public Projection(final com.google.android.gms.maps.Projection aProjection) {
  11. mProjection = aProjection;
  12. }
  13. @Override
  14. public Point toPixels(final IGeoPoint in, final Point out) {
  15. final LatLng latLng = new LatLng(in.getLatitude(), in.getLongitude());
  16. final Point point = mProjection.toScreenLocation(latLng);
  17. if (out != null) {
  18. out.x = point.x;
  19. out.y = point.y;
  20. }
  21. return point;
  22. }
  23. @Override
  24. public IGeoPoint fromPixels(final int x, final int y) {
  25. mPoint.x = x;
  26. mPoint.y = y;
  27. final LatLng latLng = mProjection.fromScreenLocation(mPoint);
  28. return new GeoPoint(latLng);
  29. }
  30. @Override
  31. public float metersToEquatorPixels(final float meters) {
  32. return 0; // TODO implement this
  33. }
  34. @Override
  35. public IGeoPoint getNorthEast() {
  36. final LatLngBounds bounds = mProjection.getVisibleRegion().latLngBounds;
  37. return new GeoPoint(bounds.northeast);
  38. }
  39. @Override
  40. public IGeoPoint getSouthWest() {
  41. final LatLngBounds bounds = mProjection.getVisibleRegion().latLngBounds;
  42. return new GeoPoint(bounds.southwest);
  43. }
  44. }