summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java
blob: 831c1db5a313cf260d2e96c061d6037b18bfadb6 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.mapbox.mapboxsdk.annotations;

import android.support.annotation.NonNull;

import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;

/**
 * Annotation is an overlay on top of a {@link MapView},
 * from which {@link Polygon}, {@link Polyline} and {@link Marker} are derived.
 * <p>
 * it manages attachment to a map and identification, but does not require
 * content to be placed at a geographical point.
 * </p>
 */
public abstract class Annotation implements Comparable<Annotation> {

  /**
   * <p>
   * The annotation id
   * </p>
   * Internal C++ id is stored as unsigned int.
   */
  private long id = -1; // -1 unless added to a MapView
  protected MapboxMap mapboxMap;
  protected MapView mapView;

  protected Annotation() {
  }

  /**
   * <p>
   * Gets the annotation's unique ID.
   * </p>
   * This ID is unique for a MapView instance and is suitable for associating your own extra
   * data with.
   *
   * @return the assigned id.
   */
  public long getId() {
    return id;
  }

  /**
   * Do not use this method, used internally by the SDK.
   */
  public void remove() {
    if (mapboxMap == null) {
      return;
    }
    mapboxMap.removeAnnotation(this);
  }

  /**
   * Do not use this method, used internally by the SDK.
   *
   * @param id the assigned id
   */
  public void setId(long id) {
    this.id = id;
  }

  /**
   * Do not use this method, used internally by the SDK.
   *
   * @param mapboxMap the hosting mapbox map
   */
  public void setMapboxMap(MapboxMap mapboxMap) {
    this.mapboxMap = mapboxMap;
  }

  /**
   * Gets the hosting mapbox map.
   *
   * @return the MapboxMap
   */
  protected MapboxMap getMapboxMap() {
    return mapboxMap;
  }

  /**
   * Do not use this method, used internally by the SDK.
   *
   * @param mapView the hosting map view
   */
  public void setMapView(MapView mapView) {
    this.mapView = mapView;
  }

  /**
   * Gets the hosting map view.
   *
   * @return The MapView
   */
  protected MapView getMapView() {
    return mapView;
  }

  @Override
  public int compareTo(@NonNull Annotation annotation) {
    if (id < annotation.getId()) {
      return 1;
    } else if (id > annotation.getId()) {
      return -1;
    }
    return 0;
  }

  /**
   * Compares this {@link PolylineOptions} object with another {@link PolylineOptions} and
   * determines if their color, alpha, width, and vertices match.
   *
   * @param object Another {@link PolylineOptions} to compare with this object.
   * @return True if color, alpha, width, and vertices match this {@link PolylineOptions} object.
   * Else, false.
   */
  @Override
  public boolean equals(Object object) {
    if (this == object) {
      return true;
    }
    if (object == null || !(object instanceof Annotation)) {
      return false;
    }
    Annotation that = (Annotation) object;
    return id == that.getId();
  }

  /**
   * Gives an integer which can be used as the bucket number for storing elements of the set/map.
   * This bucket number is the address of the element inside the set/map. There's no guarantee
   * that this hash value will be consistent between different Java implementations, or even
   * between different execution runs of the same program.
   *
   * @return integer value you can use for storing element.
   */
  @Override
  public int hashCode() {
    return (int) (getId() ^ (getId() >>> 32));
  }
}