summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/VisibleRegion.java
blob: 349120d1f33f5ff26c456ef25e1ca141d06d8c3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.mapbox.mapboxsdk.geometry;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Contains the four points defining the four-sided polygon that is visible in a map's camera.
 * This polygon can be a trapezoid instead of a rectangle, because a camera can have tilt.
 * If the camera is directly over the center of the camera, the shape is rectangular,
 * but if the camera is tilted, the shape will appear to be a trapezoid whose
 * smallest side is closest to the point of view.
 */
public class VisibleRegion implements Parcelable {

    /**
     * LatLng object that defines the far left corner of the camera.
     */
    public final LatLng farLeft;

    /**
     * LatLng object that defines the far right corner of the camera.
     */
    public final LatLng farRight;

    /**
     * LatLng object that defines the bottom left corner of the camera.
     */
    public final LatLng nearLeft;

    /**
     * LatLng object that defines the bottom right corner of the camera.
     */
    public final LatLng nearRight;

    /**
     * The smallest bounding box that includes the visible region defined in this class.
     */
    public final LatLngBounds latLngBounds;

    private VisibleRegion(Parcel in) {
        this.farLeft = in.readParcelable(LatLng.class.getClassLoader());
        this.farRight = in.readParcelable(LatLng.class.getClassLoader());
        this.nearLeft = in.readParcelable(LatLng.class.getClassLoader());
        this.nearRight = in.readParcelable(LatLng.class.getClassLoader());
        this.latLngBounds = in.readParcelable(LatLngBounds.class.getClassLoader());
    }

    /**
     * Creates a new VisibleRegion given the four corners of the camera.
     *
     * @param farLeft      A LatLng object containing the latitude and longitude of the near left corner of the region.
     * @param farRight     A LatLng object containing the latitude and longitude of the near left corner of the region.
     * @param nearLeft     A LatLng object containing the latitude and longitude of the near left corner of the region.
     * @param nearRight    A LatLng object containing the latitude and longitude of the near left corner of the region.
     * @param latLngBounds The smallest bounding box that includes the visible region defined in this class.
     */
    public VisibleRegion(LatLng farLeft, LatLng farRight, LatLng nearLeft, LatLng nearRight, LatLngBounds latLngBounds) {
        this.farLeft = farLeft;
        this.farRight = farRight;
        this.nearLeft = nearLeft;
        this.nearRight = nearRight;
        this.latLngBounds = latLngBounds;
    }

    /**
     * Compares this VisibleRegion to another object.
     * If the other object is actually a pointer to this object,
     * or if all four corners and the bounds of the two objects are the same,
     * this method returns true. Otherwise, this method returns false.
     * @param o The Object to compare with.
     * @return true if both objects are the same object.
     */
    @Override
    public boolean equals(Object o) {
        if (!(o instanceof VisibleRegion)) {
            return false;
        }
        if (o == this) {
            return true;
        }

        VisibleRegion visibleRegion = (VisibleRegion) o;
        return farLeft.equals(visibleRegion.farLeft)
                && farRight.equals(visibleRegion.farRight)
                && nearLeft.equals(visibleRegion.nearLeft)
                && nearRight.equals(visibleRegion.nearRight)
                && latLngBounds.equals(visibleRegion.latLngBounds);
    }

    @Override
    public String toString() {
        return "[farLeft [" + farLeft + "], farRight [" + farRight + "], nearLeft [" + nearLeft + "], nearRight [" + nearRight + "], latLngBounds ["+latLngBounds+"]]";
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeParcelable(farLeft, flags);
        out.writeParcelable(farRight, flags);
        out.writeParcelable(nearLeft, flags);
        out.writeParcelable(nearRight, flags);
        out.writeParcelable(latLngBounds, flags);
    }

    public static final Parcelable.Creator<VisibleRegion> CREATOR
            = new Parcelable.Creator<VisibleRegion>() {
        public VisibleRegion createFromParcel(Parcel in) {
            return new VisibleRegion(in);
        }

        public VisibleRegion[] newArray(int size) {
            return new VisibleRegion[size];
        }
    };

}