Package globus.glmap
Class GLMapManager
java.lang.Object
globus.glmap.GLMapManager
GLMapManager
is a singleton object that manages offline maps-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Callbacks for download taskstatic interface
Callback for elevation querystatic interface
Callback for map list updatestatic interface
Called to notify about GLMapManager initialization progress updatesstatic interface
Callbacks for map statestatic interface
Callbacks for bulk tile operation -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
AddDataSet
(int dataSet, GLMapBBox bbox, String path, android.content.res.AssetManager assetManager, GLMapManager.ProgressCallback progressCallback) Adds vector map.static void
addStateListener
(GLMapManager.StateListener listener) Subscribes listener to events about map downloading progress.static void
CacheTiles
(long[] tiles, GLMapManager.TileDownloadProgress progress) Deprecated.static void
CancelDownloadTask
(long taskID) Cancel download task by idstatic void
DeleteDataSets
(GLMapInfo info, int dataSets) Delete data sets associated with this map.static long
DownloadDataSet
(int dataSet, String path, GLMapBBox bbox, GLMapManager.DownloadCallback callback) Downloads custom data setstatic GLMapDownloadTask
DownloadDataSet
(GLMapInfo mapInfo, int dataSet) Creates map downloading tasksstatic List<GLMapDownloadTask>
DownloadDataSets
(GLMapInfo mapInfo, int dataSets) Creates map downloading tasksstatic float
ElevationAtPoint
(double lat, double lon) Returns elevation at given pointstatic void
ElevationAtPointAsync
(double lat, double lon, GLMapManager.ElevationCallback callback) Asynchronous request of elevationstatic GLMapInfo
FindNearestMap
(GLMapInfo[] maps, MapPoint point) Helper function iterates over maps param and returns closestGLMapInfo
to the given point.static GLMapInfo[]
Return array of maps including submapsstatic int
static GLMapDownloadTask
getDownloadTask
(long mapID, int dataSet) Returns download tasks for mapsstatic List<GLMapDownloadTask>
getDownloadTasks
(long mapID, int dataSets) Returns download tasks for mapsstatic List<GLMapDownloadTask>
static GLMapInfo[]
GetMaps()
static GLMapInfo
GetMapWithID
(long mapID) static boolean
static long
Retrieves the current refresh interval for cached tiles.static boolean
Initialize
(android.content.Context context, String apiKey, GLMapManager.ProgressCallback progressCallback) Initializes GLMapManagerstatic GLMapInfo[]
MapsAtPoint
(MapPoint point) Returns mapID of vector map that contains given point.static long[]
Returns not cached vector tiles that bbox contains or intersectsstatic void
postOnMain
(Runnable runnable) Post runnable on main threadstatic void
RemoveDataSet
(int dataSet, String fileName) Removes vector map from map manager.static void
/** Removes listener added byaddStateListener
static boolean
SetStorages
(android.content.Context context, Object writeStorage, Set<Object> customStorages) Sets location of caches before initialization.static void
SetTileDownloadingAllowed
(boolean val) AllowsGLMapManager
to download single tiles when downloaded vector maps does not contain data.static void
SetTileRefreshInterval
(long interval) Sets the tile refresh interval for cached tiles.static void
Sorts array ofGLMapInfo
by distance from given pointstatic void
StopDownloadingAll
(long parentID) Stop downloading all submapsstatic void
Updates map list from serverstatic long[]
VectorTilesAtBBox
(GLMapBBox bbox) Returns vector tiles that bbox contains or intersects
-
Constructor Details
-
GLMapManager
public GLMapManager()
-
-
Method Details
-
Initialize
public static boolean Initialize(@NonNull android.content.Context context, @NonNull String apiKey, @Nullable GLMapManager.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 Object writeStorage, @Nullable Set<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
Updates map list from server- Parameters:
complete
- runnable, called when map update is complete
-
DownloadDataSet
Creates map downloading tasks- Parameters:
mapInfo
- map info objectdataSet
- data set to download- Returns:
- download task
-
DownloadDataSets
@NonNull public static 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
Delete data sets associated with this map.- Parameters:
info
- map to deletedataSets
- data sets to delete
-
DownloadDataSet
public static long DownloadDataSet(int dataSet, 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
/** Removes listener added byaddStateListener
- Parameters:
val
- Listener to remove- See Also:
-
addStateListener
Subscribes listener to events about map downloading progress.Event name is sent via
fieldName
finished
0 at start, 1 at end of task
progressDownload
sent 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:
-
postOnMain
Post runnable on main thread- Parameters:
runnable
- runnable to post
-
getMapDownloadTasks
- Returns:
- Returns the list of created and not finished map download tasks
-
getDownloadTasks
Returns download tasks for maps- Parameters:
mapID
- Id of mapdataSets
- data sets of download tasks- Returns:
- Returns download task for map
-
getDownloadTask
Returns download tasks for maps- Parameters:
mapID
- Id of mapdataSet
- data set of download task- Returns:
- Returns download task for map
-
StopDownloadingAll
public static void StopDownloadingAll(long parentID) Stop downloading all submaps- Parameters:
parentID
- parent map ID
-
GetChildMaps
Return array of maps including submaps- Returns:
- Returns array of maps including submaps
-
GetMaps
- Returns:
- Returns array of maps
-
GetMapWithID
- Parameters:
mapID
- MapId of map- Returns:
- Returns GLMapInfo for given mapID
-
AddDataSet
public static boolean AddDataSet(int dataSet, @Nullable GLMapBBox bbox, @NonNull String path, @Nullable android.content.res.AssetManager assetManager, @Nullable GLMapManager.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
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
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
Helper function iterates over maps param and returns closestGLMapInfo
to the given point.- Parameters:
maps
- array of map objectspoint
- point that vector map must contain- Returns:
- mapID of vector map
-
SortMaps
Sorts array ofGLMapInfo
by distance from given point- Parameters:
maps
- array of map objectspoint
- center from where distance is calculated
-
SetTileDownloadingAllowed
public static void SetTileDownloadingAllowed(boolean val) AllowsGLMapManager
to 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
-
SetTileRefreshInterval
public static void SetTileRefreshInterval(long interval) Sets the tile refresh interval for cached tiles. Default: 30 days or 2,592,000 seconds. If the interval is negative, tiles won't be refreshed. Note: Tiles will continue to operate offline even after the refresh interval has passed, although the framework will attempt to download them.- Parameters:
interval
- Refresh interval in seconds.
-
GetTileRefreshInterval
public static long GetTileRefreshInterval()Retrieves the current refresh interval for cached tiles. A returned value indicates the number of seconds between tile refreshes. A negative value indicates that tiles won't be refreshed. Note: Tiles will continue to operate offline even after the refresh interval has passed, although the framework will attempt to download them.- Returns:
- The tile refresh interval in seconds.
-
VectorTilesAtBBox
Returns vector tiles that bbox contains or intersects- Parameters:
bbox
- bbox of area- Returns:
- vector tiles that bbox contains or intersects
-
NotCachedVectorTilesAtBBox
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.GLMapManager.ProgressCallback)
- Parameters:
tiles
- tiles to checkprogress
- callbacks that will be called when one tile is checked.
-
GetDownloadedMapsCount
public static int GetDownloadedMapsCount()- Returns:
- Returns number of the maps that have any downloaded data
-
ElevationAtPoint
public static float 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 NaN 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
-