Package globus.glmap
Class GLMapTrackData
java.lang.Object
globus.glmap.GLNativeObject
globus.glmap.GLMapTrackData
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback for filling track data -
Constructor Summary
ConstructorsConstructorDescriptionGLMapTrackData(GLMapTrackData.PointsCallback pointsCallback, int size) Constructor with callbackGLMapTrackData(List<byte[]> data) Constructor from raw data -
Method Summary
Modifier and TypeMethodDescriptiondoubleCalculates total length of the track geometry.copyTrackAndAddGeoPoint(double lat, double lon, int color, boolean startNewSegment) Copies points to new track and add new point to track.copyTrackAndAddPoint(double x, double y, int color, boolean startNewSegment) Copies points to new track and add new point to track.findNearestPoint(GLMapViewRenderer mapView, MapPoint point, double distanceInPoints) Finds the nearest point on the track to the provided map point.getBBox()Returns bounding box of the track (in internal map coordinates).intSize of internal data of GLMapTrackData.doublelineDistanceToPoint(MapPoint point, MapPoint nearestPoint, double maxDistance) Finds the nearest point on the track and returns distance from the track start to it.pointAtLineDistance(double distance) Finds a point located at the given distance from the start of the track.double[]sample(double[] locations) Samples the track at distances from the start.static voidsetPointData(long nativePoint, int x, int y, int color) Sets data for a point in internal map coordinates.static voidsetPointDataGeo(long nativePoint, double lat, double lon, int color) Sets data for a point in geographic coordinates (WGS84 degrees).Methods inherited from class globus.glmap.GLNativeObject
dispose
-
Constructor Details
-
GLMapTrackData
Constructor with callback- Parameters:
pointsCallback- callback that will provide information about pointssize- number of points in track
-
GLMapTrackData
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
-1for bothxandy(it will be converted toNaNinternally).- Parameters:
nativePoint- nativePoint passed to callbackx- 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 callbacklat- latitude in degreeslon- longitude in degreescolor- 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
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 pointstartNewSegment- Iftrue, 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 degreeslon- longitude coordinate in degreescolor- color at pointstartNewSegment- Iftrue, 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, fromGLMapViewRenderer.convertDisplayToInternal(double, double))distanceInPoints- maximum distance from the track in screen points (dp)- Returns:
- nearest point on the track in internal map coordinates, or
nullif the track is too far
-
pointAtLineDistance
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
NaNif nothing is withinmaxDistance
-