Package globus.glmap

Class GLMapManager

java.lang.Object
globus.glmap.GLMapManager

public class GLMapManager extends Object
GLMapManager is a singleton object that manages offline maps
  • Method Details

    • Initialize

      public static boolean Initialize(@NonNull android.content.Context context, @NonNull String apiKey, @Nullable GLMapManager.ProgressCallback progressCallback)
      Initializes Core and all SDK modules included in the application.

      Call this once before using native APIs, including geometry. Core-only applications use the same method without a renderer. Map, Search (including ICU/categories) and Route are initialized only when their Java modules are present. No SDK class initializer loads native libraries.

      Before initialization, native calls throw UnsatisfiedLinkError. Do not use SDK APIs concurrently with initialization or after it fails. Pure Java values such as MapPoint and MapGeoPoint, and SetStorages(android.content.Context, java.lang.Object, java.util.Set<java.lang.Object>), can be used beforehand.

      Repeated calls with the same API key after success do nothing. A different key updates only the API key, without preparing resources or initializing modules again. Concurrent or reentrant configuration calls throw IllegalStateException instead of waiting. Resource setup can be retried after failure; libraries already loaded are not unloaded.

      Parameters:
      context - Application context
      apiKey - API key of this application; an empty key permits local geometry/offline use
      progressCallback - resource copying progress; must not call other SDK APIs
      Returns:
      true if all initialization stages succeeded, false if cache/storage setup failed
      Throws:
      IllegalStateException - if configuration is in progress or a module's resources cannot be initialized
      UnsatisfiedLinkError - if a required native library cannot be loaded
    • 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. Missing filesystem directories are created and the write storage is checked by writing and deleting a temporary file. Before Initialize(android.content.Context, java.lang.String, globus.glmap.GLMapManager.ProgressCallback), the validated configuration is saved without loading native libraries; initialization checks storage access again. Use String paths for pre-initialization configuration: GLMapStorage objects themselves own native resources and can only be constructed after initialization. After initialization this method applies the change immediately. Failed preparation leaves the previous configuration in place. Concurrent or reentrant configuration calls throw IllegalStateException.
      Parameters:
      context - the Context used to find default map locations
      writeStorage - 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
    • SetServerList

      public static void SetServerList(@Nullable String[] servers)
      Configures the preferred server list. Entries should be full base URLs (e.g. https://cdn.getyourmap.cc). The SDK evaluates the list in order and uses the first entry whose last-result metric is non-negative; otherwise it falls back to the server whose last failure happened longest ago.
      Parameters:
      servers - List of servers
    • GetServerList

      @Nullable public static String[] GetServerList()
      Returns the currently configured additional servers (excluding built-in defaults).
      Returns:
      Array of servers set by SetServerList
    • DownloadDataSet

      @NonNull public static GLMapDownloadTask DownloadDataSet(@NonNull GLMapInfo mapInfo, int dataSet)
      Creates map downloading tasks
      Parameters:
      mapInfo - map info object
      dataSet - 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 object
      dataSets - 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 delete
      dataSets - data sets to delete
    • DownloadDataSet

      public static long DownloadDataSet(int dataSet, @NonNull String path, @NonNull GLMapBBox bbox, @Nullable GLMapManager.DownloadCallback callback)
      Downloads custom data set
      Parameters:
      dataSet - Data set to download
      path - Full path to file where to download data set
      bbox - BBox of data to download
      callback - 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 by addStateListener
      Parameters:
      val - Listener to remove
      See Also:
    • addStateListener

      public static void addStateListener(@NonNull GLMapManager.StateListener listener)
      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

      public static void postOnMain(@NonNull Runnable runnable)
      Post runnable on main thread
      Parameters:
      runnable - runnable to post
    • getMapDownloadTasks

      @NonNull public static List<GLMapDownloadTask> getMapDownloadTasks()
      Retrieves a list of active map download tasks that have been created but not yet finished.
      Returns:
      A List of GLMapDownloadTask instances representing the ongoing download tasks.
    • getDownloadTasks

      @Nullable public static List<GLMapDownloadTask> getDownloadTasks(long mapID, int dataSets)
      Returns download tasks for maps
      Parameters:
      mapID - Id of map
      dataSets - 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 map
      dataSet - data set of download task
      Returns:
      Returns download task for map
    • StopDownloadingAll

      public static void StopDownloadingAll(long parentID)
      Stops downloading all submaps associated with the specified parent map.
      Parameters:
      parentID - The ID of the parent map.
    • GetChildMaps

      @NonNull public static GLMapInfo[] GetChildMaps()
      Retrieves an array of maps, including all submaps associated with them.
      Returns:
      An array of GLMapInfo objects representing maps and their submaps.
    • GetMaps

      @NonNull public static GLMapInfo[] GetMaps()
      Retrieves an array of all available maps.
      Returns:
      An array of GLMapInfo objects representing all maps.
    • GetMapWithID

      @Nullable public static GLMapInfo GetMapWithID(long mapID)
      Retrieves the map information for a specific map by its ID.
      Parameters:
      mapID - The ID of the map to retrieve.
      Returns:
      The GLMapInfo object corresponding to the given map ID, or null if no map is found with the specified ID.
    • 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 set
      bbox - optional bbox of data set
      path - path for custom data set
      assetManager - if not null will extract file from assets and cache it
      progressCallback - callback to track progress of caching
      Returns:
      true if success
    • RemoveDataSet

      public static void RemoveDataSet(int dataSet, @NonNull String fileName)
      Removes vector map from map manager. When removed it is safe to delete cached map file.
      Parameters:
      dataSet - Type of data set
      fileName - absolute path used with AddDataSet(int, globus.glmap.GLMapBBox, java.lang.String, android.content.res.AssetManager, globus.glmap.GLMapManager.ProgressCallback), or the asset name for a cached dataset
    • MapsAtPoint

      @Nullable public static GLMapInfo[] MapsAtPoint(@NonNull MapPoint point)
      Returns map infos of vector maps that contain the given point. If there are no maps that contain the given point, null is returned.
      Parameters:
      point - A point that a vector map must contain.
      Returns:
      An array of GLMapInfo for maps at the point, or null.
    • FindNearestMap

      @NonNull public static GLMapInfo FindNearestMap(@NonNull GLMapInfo[] maps, @NonNull MapPoint point)
      Finds the closest GLMapInfo to the given point.
      Parameters:
      maps - An array of map infos to search.
      point - The reference point.
      Returns:
      The nearest map info.
    • SortMaps

      public static void SortMaps(@NonNull GLMapInfo[] maps, @NonNull MapPoint point)
      Sorts array of GLMapInfo by distance from given point
      Parameters:
      maps - array of map objects
      point - center from where distance is calculated
    • SetTileDownloadingAllowed

      public static void SetTileDownloadingAllowed(boolean val)
      Controls whether the GLMapManager is allowed to download individual tiles when downloaded vector maps lack the necessary data.
      Parameters:
      val - true to enable tile downloading, false to disable it.
    • GetTileDownloadingAllowed

      public static boolean GetTileDownloadingAllowed()
      Indicates whether tile downloading is currently allowed.
      Returns:
      true if tile downloading is enabled, false otherwise.
    • 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.
    • GetVectorTileCacheSize

      public static long GetVectorTileCacheSize()
      Retrieves the on-disk size of the streamed vector tile cache.
      Returns:
      Size of the vector tile cache database in bytes, or 0 if no cache exists.
    • DropVectorTileCache

      public static void DropVectorTileCache()
      Drops all cached streamed vector tiles. Tiles will be re-downloaded on demand.
    • GetElevationCacheSize

      public static long GetElevationCacheSize()
      Retrieves the on-disk size of the elevation tile cache.
      Returns:
      Size of the elevation tile cache database in bytes, or 0 if no cache exists.
    • DropElevationCache

      public static void DropElevationCache()
      Drops all cached elevation tiles. Tiles will be re-downloaded on demand.
    • 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.
      Checks if the specified tiles are cached. If any tiles are missing, they will be downloaded.

      Deprecated: To fetch data for a given bounding box, use DownloadDataSet(globus.glmap.GLMapInfo, int) and AddDataSet(int, globus.glmap.GLMapBBox, java.lang.String, android.content.res.AssetManager, globus.glmap.GLMapManager.ProgressCallback) instead.

      Parameters:
      tiles - An array of tile identifiers to check.
      progress - A callback that is invoked each time a tile is checked.
    • GetDownloadedMapsCount

      public static int GetDownloadedMapsCount()
      Retrieves the number of maps that have any downloaded data.
      Returns:
      The number of maps with downloaded data.
    • GetMapListTimestamp

      public static long GetMapListTimestamp()
      Returns the timestamp of the last map list received from the server.
      Returns:
      Map list timestamp, or 0 if no server list has been loaded yet.
    • ElevationAtPoint

      public static float ElevationAtPoint(@FloatRange(from=-90.0,to=90.0) double lat, @FloatRange(from=-180.0,to=180.0) double lon)
      Returns elevation at given point
      Parameters:
      lat - latitude of point
      lon - longitude of point
      Returns:
      elevation at point in meters or NaN if no downloaded data for this point
    • ElevationAtPointAsync

      public static void ElevationAtPointAsync(@FloatRange(from=-90.0,to=90.0) double lat, @FloatRange(from=-180.0,to=180.0) double lon, @NonNull GLMapManager.ElevationCallback callback)
      Asynchronous request of elevation
      Parameters:
      lat - latitude of point
      lon - longitude of point
      callback - callback that will be called on completion