Package globus.glmap

Class GLMapTrackData

java.lang.Object
globus.glmap.GLNativeObject
globus.glmap.GLMapTrackData

public class GLMapTrackData extends GLNativeObject
Holds track geometry and precomputed information used to optimize drawing at different zoom levels.

Track coordinates are usually expressed in internal map units (see MapPoint). Some methods work in meters explicitly and mention it in their documentation.

  • Constructor Details

    • GLMapTrackData

      public GLMapTrackData(@NonNull GLMapTrackData.PointsCallback pointsCallback, int size)
      Constructor with callback
      Parameters:
      pointsCallback - callback that will provide information about points
      size - number of points in track
    • GLMapTrackData

      public GLMapTrackData(@NonNull List<byte[]> data)
      Constructor from raw data
      Parameters:
      data - List of byte arrays with raw data. Each element of this array defines track segment
  • Method Details

    • setPointData

      public static void setPointData(long nativePoint, int x, int y, int color)
      Sets data for a point in internal map coordinates.

      To start a new segment, pass -1 for both x and y (it will be converted to NaN internally).

      Parameters:
      nativePoint - nativePoint passed to callback
      x - x coordinate of point (internal map units)
      y - y coordinate of point (internal map units)
      color - point color as an ARGB integer (0xAARRGGBB)
    • setPointDataGeo

      public static void setPointDataGeo(long nativePoint, double lat, double lon, int color)
      Sets data for a point in geographic coordinates (WGS84 degrees).
      Parameters:
      nativePoint - nativePoint passed to callback
      lat - latitude in degrees
      lon - longitude in degrees
      color - point color as an ARGB integer (0xAARRGGBB)
    • getByteCount

      public int getByteCount()
      Size of internal data of GLMapTrackData.
      Returns:
      Size of internal data of GLMapTrackData.
    • getBBox

      @NonNull public GLMapBBox getBBox()
      Returns bounding box of the track (in internal map coordinates).
      Returns:
      bbox of track
    • calculateLength

      public double calculateLength()
      Calculates total length of the track geometry.
      Returns:
      Length in internal map units (same units as MapPoint.distance(MapPoint)).
    • sample

      public double[] sample(double[] locations)
      Samples the track at distances from the start.
      Parameters:
      locations - distances from start of track, in internal map units
      Returns:
      flattened array [x1, y1, dx1, dy1, x2, y2, dx2, dy2, ...], where (x, y) is position in internal map coordinates and (dx, dy) is a normalized direction vector.
    • copyTrackAndAddPoint

      @NonNull public GLMapTrackData copyTrackAndAddPoint(double x, double y, int color, boolean startNewSegment)
      Copies points to new track and add new point to track. When frequently updated track is displayed is a good idea to add new points into small segments. Up to 100 points per segment. And then merge segments together. Track uses optimized Ramer-Douglas-Peucker, but it still can have O(n^2) complexity in the worst case. With the described solution GLMap could record tracks up to million points.
      Parameters:
      x - x coordinate (internal map units)
      y - y coordinate (internal map units)
      color - color at point
      startNewSegment - If true, a new segment will be started.
      Returns:
      A new track data object.
    • copyTrackAndAddGeoPoint

      @NonNull public GLMapTrackData copyTrackAndAddGeoPoint(double lat, double lon, int color, boolean startNewSegment)
      Copies points to new track and add new point to track. When frequently updated track is displayed is a good idea to add new points into small segments. Up to 100 points per segment. And then merge segments together. Track uses optimized Ramer-Douglas-Peucker, but it still can have O(n^2) complexity in the worst case. With the described solution GLMap could record tracks up to million points.
      Parameters:
      lat - latitude coordinate in degrees
      lon - longitude coordinate in degrees
      color - color at point
      startNewSegment - If true, a new segment will be started.
      Returns:
      A new track data object.
    • findNearestPoint

      @Nullable public MapPoint findNearestPoint(@NonNull GLMapViewRenderer mapView, @NonNull MapPoint point, double distanceInPoints)
      Finds the nearest point on the track to the provided map point.
      Parameters:
      mapView - renderer where the track is displayed (must be attached to a surface to compute screen distances)
      point - reference point in internal map coordinates (for example, from GLMapViewRenderer.convertDisplayToInternal(double, double))
      distanceInPoints - maximum distance from the track in screen points (dp)
      Returns:
      nearest point on the track in internal map coordinates, or null if the track is too far
    • pointAtLineDistance

      @NonNull public MapPoint pointAtLineDistance(double distance)
      Finds a point located at the given distance from the start of the track.
      Parameters:
      distance - distance in meters along the track
      Returns:
      point on track in internal map coordinates; if the track is empty, the returned point contains NaN
    • lineDistanceToPoint

      public double lineDistanceToPoint(MapPoint point, @Nullable MapPoint nearestPoint, double maxDistance)
      Finds the nearest point on the track and returns distance from the track start to it.
      Parameters:
      point - point to test (internal map coordinates)
      nearestPoint - output: nearest point on the track (optional)
      maxDistance - maximum distance from the track in internal map units
      Returns:
      distance from the start of the track to the nearest point, in meters, or NaN if nothing is within maxDistance