Package globus.glmap
Class GLMapManager
- java.lang.Object
-
- globus.glmap.GLMapManager
-
public class GLMapManager extends java.lang.ObjectGLMapManageris a singleton object that manages offline maps
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceGLMapManager.DownloadCallbackstatic interfaceGLMapManager.DownloadStatsCallbackstatic interfaceGLMapManager.ElevationCallbackstatic interfaceGLMapManager.MapListUpdateCallbackstatic interfaceGLMapManager.StateListenerstatic interfaceGLMapManager.TileDownloadProgress
-
Constructor Summary
Constructors Constructor Description GLMapManager()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static booleanAddDataSet(int dataSet, GLMapBBox bbox, java.lang.String path, android.content.res.AssetManager assetManager, ProgressCallback progressCallback)Adds vector map.static voidaddStateListener(GLMapManager.StateListener listener)Subscribes listener to events about map downloading progress.static voidCacheTiles(long[] tiles, GLMapManager.TileDownloadProgress progress)Deprecated.static voidCancelDownloadTask(long taskID)Cancel download task by idstatic voidDeleteDataSets(GLMapInfo info, int dataSets)Delete data sets associated with this map.static doubleDistanceToMap(GLMapInfo map, MapPoint point)Calculates distance from the map to the pointstatic longDownloadDataSet(int dataSet, java.lang.String path, GLMapBBox bbox, GLMapManager.DownloadCallback callback)Downloads custom data setstatic GLMapDownloadTaskDownloadDataSet(GLMapInfo mapInfo, int dataSet)Creates map downloading tasksstatic java.util.List<GLMapDownloadTask>DownloadDataSets(GLMapInfo mapInfo, int dataSets)Creates map downloading tasksstatic intElevationAtPoint(double lat, double lon)Returns elevation at given pointstatic voidElevationAtPointAsync(double lat, double lon, GLMapManager.ElevationCallback callback)Asynchronous request of elevationstatic GLMapInfoFindNearestMap(GLMapInfo[] maps, MapPoint point)Helper function iterates over maps param and returns closestGLMapInfoto the given point.static GLMapInfo[]GetChildMaps()Return array of maps including submapsstatic intGetDownloadedMapsCount()static GLMapDownloadTaskgetDownloadTask(long mapID, int dataSet)Returns download tasks for mapsstatic java.util.List<GLMapDownloadTask>getDownloadTasks(long mapID, int dataSets)Returns download tasks for mapsstatic java.util.List<GLMapDownloadTask>getMapDownloadTasks()static GLMapInfo[]GetMaps()static GLMapInfoGetMapWithID(long mapID)static booleanGetTileDownloadingAllowed()static booleanInitialize(android.content.Context context, java.lang.String apiKey, ProgressCallback progressCallback)Initializes GLMapManagerstatic GLMapInfo[]MapsAtPoint(MapPoint point)Returns mapID of vector map that contains given point.static long[]NotCachedVectorTilesAtBBox(GLMapBBox bbox)Returns not cached vector tiles that bbox contains or intersectsstatic voidpostOnMain(java.lang.Runnable runnable)static voidRemoveDataSet(int dataSet, java.lang.String fileName)Removes vector map from map manager.static voidremoveStateListener(GLMapManager.StateListener val)/** Removes listener added byaddStateListenerstatic voidSetDownloadStatsCallback(GLMapManager.DownloadStatsCallback callback)Callback will be called when subtask is completed or cancelled.static booleanSetStorages(android.content.Context context, java.lang.Object writeStorage, java.util.Set<java.lang.Object> customStorages)Sets location of caches before initialization.static voidSetTileDownloadingAllowed(boolean val)AllowsGLMapManagerto download single tiles when downloaded vector maps does not contain data.static voidSortMaps(GLMapInfo[] maps, MapPoint point)Sorts array ofGLMapInfoby distance from given pointstatic voidUpdateMapList(GLMapManager.MapListUpdateCallback complete)Updates map list from serverstatic long[]VectorTilesAtBBox(GLMapBBox bbox)Returns vector tiles that bbox contains or intersects
-
-
-
Method Detail
-
Initialize
public static boolean Initialize(@NonNull android.content.Context context, @NonNull java.lang.String apiKey, @Nullable ProgressCallback progressCallback)Initializes GLMapManagerDuring first initialization it copies world map file from app resources to cache directory. Framework uses progressCallback to notify about initialization(copying) progress
- Parameters:
context- Application contextapiKey- API key of this applicationprogressCallback- initialization progress callback- Returns:
- true if initialized successfully
-
SetStorages
public static boolean SetStorages(@NonNull android.content.Context context, @Nullable java.lang.Object writeStorage, @Nullable java.util.Set<java.lang.Object> customStorages)Sets location of caches before initialization. By default caches are set to getFilesDir() of context passed to initialize function, or getExternalFilesDir(null) if external storage is mounted.- Parameters:
context- the Context used to find default map locationswriteStorage- location to write maps (can be String, or CustomMapStorage)customStorages- Array of custom storages to read maps (write path will be automatically added)- Returns:
- Returns true on success
-
UpdateMapList
public static void UpdateMapList(@Nullable GLMapManager.MapListUpdateCallback complete)Updates map list from server- Parameters:
complete- runnable, called when map update is complete
-
DownloadDataSet
@NonNull public static GLMapDownloadTask DownloadDataSet(@NonNull GLMapInfo mapInfo, int dataSet)
Creates map downloading tasks- Parameters:
mapInfo- map info objectdataSet- data set to download- Returns:
- download task
-
DownloadDataSets
@NonNull public static java.util.List<GLMapDownloadTask> DownloadDataSets(@NonNull GLMapInfo mapInfo, int dataSets)
Creates map downloading tasks- Parameters:
mapInfo- map info objectdataSets- data sets to download- Returns:
- download task
-
DeleteDataSets
public static void DeleteDataSets(@NonNull GLMapInfo info, int dataSets)Delete data sets associated with this map.- Parameters:
info- map to deletedataSets- data sets to delete
-
DownloadDataSet
public static long DownloadDataSet(int dataSet, java.lang.String path, GLMapBBox bbox, GLMapManager.DownloadCallback callback)Downloads custom data set- Parameters:
dataSet- Data set to downloadpath- Full path to file where to download data setbbox- BBox of data to downloadcallback- callbacks for download task- Returns:
- taskID that can be used to cancel download
-
CancelDownloadTask
public static void CancelDownloadTask(long taskID)
Cancel download task by id- Parameters:
taskID- id of task to cancel
-
removeStateListener
public static void removeStateListener(@NonNull GLMapManager.StateListener val)/** Removes listener added byaddStateListener- Parameters:
val- Listener to remove- See Also:
addStateListener(StateListener)
-
addStateListener
public static void addStateListener(@NonNull GLMapManager.StateListener listener)Subscribes listener to events about map downloading progress.Event name is sent via
fieldName
finished0 at start, 1 at end of task
progressDownloadsent each time when download progress is changed.
task.addListener(new FieldListener(){ public void fieldValueChanged(Object obj, String fieldName, Object newValue){ ((MapsAdapter)listView.getAdapter()).notifyDataSetChanged(); } });- Parameters:
listener- that will receive events- See Also:
removeStateListener(StateListener)
-
postOnMain
public static void postOnMain(@NonNull java.lang.Runnable runnable)
-
getMapDownloadTasks
@NonNull public static java.util.List<GLMapDownloadTask> getMapDownloadTasks()
- Returns:
- Returns the list of created and not finished map download tasks
-
getDownloadTasks
@Nullable public static java.util.List<GLMapDownloadTask> getDownloadTasks(long mapID, int dataSets)
Returns download tasks for maps- Parameters:
mapID- Id of mapdataSets- data sets of download tasks- Returns:
- Returns download task for map
-
getDownloadTask
@Nullable public static GLMapDownloadTask getDownloadTask(long mapID, int dataSet)
Returns download tasks for maps- Parameters:
mapID- Id of mapdataSet- data set of download task- Returns:
- Returns download task for map
-
GetChildMaps
@NonNull public static GLMapInfo[] GetChildMaps()
Return array of maps including submaps- Returns:
- Returns array of maps including submaps
-
GetMaps
@NonNull public static GLMapInfo[] GetMaps()
- Returns:
- Returns array of maps
-
GetMapWithID
@Nullable public static GLMapInfo GetMapWithID(long mapID)
- Parameters:
mapID- MapId of map- Returns:
- Returns GLMapInfo for given mapID
-
AddDataSet
public static boolean AddDataSet(int dataSet, @Nullable GLMapBBox bbox, @NonNull java.lang.String path, @Nullable android.content.res.AssetManager assetManager, @Nullable ProgressCallback progressCallback)Adds vector map. Could be used for maps embed into the app resources.- Parameters:
dataSet- Type of data setbbox- optional bbox of data setpath- path for custom data setassetManager- if not `null` will extract file from assets and cache itprogressCallback- callback to track progress of caching- Returns:
- true if success
-
RemoveDataSet
public static void RemoveDataSet(int dataSet, @NonNull java.lang.String fileName)Removes vector map from map manager. When removed it is safe to delete cached map file.- Parameters:
dataSet- Type of data setfileName- name of custom map
-
MapsAtPoint
@Nullable public static GLMapInfo[] MapsAtPoint(@NonNull MapPoint point)
Returns mapID of vector map that contains given point. If there is no maps that contain given point null is returned.- Parameters:
point- point that vector map must contain- Returns:
- mapID of vector map or null
-
FindNearestMap
@NonNull public static GLMapInfo FindNearestMap(@NonNull GLMapInfo[] maps, @NonNull MapPoint point)
Helper function iterates over maps param and returns closestGLMapInfoto the given point.- Parameters:
maps- array of map objectspoint- point that vector map must contain- Returns:
- mapID of vector map
-
DistanceToMap
public static double DistanceToMap(@NonNull GLMapInfo map, @NonNull MapPoint point)Calculates distance from the map to the point- Parameters:
map- map objectpoint- some point- Returns:
- Measured distance in internal units
-
SortMaps
public static void SortMaps(@NonNull GLMapInfo[] maps, @NonNull MapPoint point)Sorts array ofGLMapInfoby distance from given point- Parameters:
maps- array of map objectspoint- center from where distance is calculated
-
SetTileDownloadingAllowed
public static void SetTileDownloadingAllowed(boolean val)
AllowsGLMapManagerto download single tiles when downloaded vector maps does not contain data.- Parameters:
val- true to enable tile downloading
-
GetTileDownloadingAllowed
public static boolean GetTileDownloadingAllowed()
- Returns:
- true if tile downloading allowed
-
VectorTilesAtBBox
public static long[] VectorTilesAtBBox(@NonNull GLMapBBox bbox)Returns vector tiles that bbox contains or intersects- Parameters:
bbox- bbox of area- Returns:
- vector tiles that bbox contains or intersects
-
NotCachedVectorTilesAtBBox
public static long[] NotCachedVectorTilesAtBBox(@NonNull GLMapBBox bbox)Returns not cached vector tiles that bbox contains or intersects- Parameters:
bbox- bbox of area- Returns:
- not cached vector tiles that bbox contains or intersects
-
CacheTiles
@Deprecated public static void CacheTiles(@NonNull long[] tiles, @Nullable GLMapManager.TileDownloadProgress progress)Deprecated.Check if tiles are cached. If not - tile will be downloaded. Deprecated. To get data for some bbox useDownloadDataSet(globus.glmap.GLMapInfo, int)andAddDataSet(int, globus.glmap.GLMapBBox, java.lang.String, android.content.res.AssetManager, globus.glmap.ProgressCallback)- Parameters:
tiles- tiles to checkprogress- callbacks that will be called when one tile is checked.
-
SetDownloadStatsCallback
public static void SetDownloadStatsCallback(@Nullable GLMapManager.DownloadStatsCallback callback)Callback will be called when subtask is completed or cancelled. It's used to analyze downloading speeds from different locations.- Parameters:
callback- callback to call when new stats available
-
GetDownloadedMapsCount
public static int GetDownloadedMapsCount()
- Returns:
- Returns number of the maps that have any downloaded data
-
ElevationAtPoint
public static int ElevationAtPoint(double lat, double lon)Returns elevation at given point- Parameters:
lat- latitude of pointlon- longitude of point- Returns:
- elevation at point in meters or INT16_MIN if no downloaded data for this point
-
ElevationAtPointAsync
public static void ElevationAtPointAsync(double lat, double lon, @NonNull GLMapManager.ElevationCallback callback)Asynchronous request of elevation- Parameters:
lat- latitude of pointlon- longitude of pointcallback- callback that will be called on completion
-
-