Class MapSurface

java.lang.Object
com.trimblemaps.mapsdk.maps.MapSurface

public class MapSurface extends Object

A MapView provides an embeddable map interface. You use this class to display map information and to manipulate the map contents from your application. You can center the map on a given coordinate, specify the size of the area you want to display, and style the features of the map to fit your application's use case.

Use of MapView requires a TrimbleMaps API access token. Obtain an access token on the TrimbleMaps account page.

Warning: Please note that you are responsible for getting permission to use the map data, and for ensuring your use adheres to the relevant terms of use.
  • Field Details

  • Constructor Details

    • MapSurface

      @UiThread public MapSurface(@NonNull android.content.Context context, android.view.Surface surface)
    • MapSurface

      @UiThread public MapSurface(@NonNull android.content.Context context, android.view.Surface surface, TrimbleMapsMapOptions options)
  • Method Details

    • initialize

      @CallSuper @UiThread protected void initialize(@NonNull android.content.Context context, @NonNull TrimbleMapsMapOptions options)
    • getContext

      public android.content.Context getContext()
    • onCreate

      @UiThread public void onCreate(@Nullable android.os.Bundle savedInstanceState)

      You must call this method from the parent's Activity#onCreate(Bundle)} or Fragment#onViewCreated(View, Bundle).

      You must set a valid access token with TrimbleMaps.getInstance(Context, com.trimblemaps.account.models.TrimbleMapsAccount, com.trimblemaps.mapsdk.WellKnownTileServer) before you call this method or an exception will be thrown.
      Parameters:
      savedInstanceState - Pass in the parent's savedInstanceState.
      See Also:
    • onSaveInstanceState

      @UiThread public void onSaveInstanceState(@NonNull android.os.Bundle outState)
      You must call this method from the parent's Activity#onSaveInstanceState(Bundle) or Fragment#onSaveInstanceState(Bundle).
      Parameters:
      outState - Pass in the parent's outState.
    • onStart

      @UiThread public void onStart()
      You must call this method from the parent's Activity#onStart() or Fragment#onStart()
    • onResume

      @UiThread public void onResume()
      You must call this method from the parent's Activity#onResume() or Fragment#onResume().
    • onPause

      @UiThread public void onPause()
      You must call this method from the parent's Activity#onPause() or Fragment#onPause().
    • onStop

      @UiThread public void onStop()
      You must call this method from the parent's Activity#onStop() or Fragment#onStop().
    • onDestroy

      @UiThread public void onDestroy()
      You must call this method from the parent's Activity#onDestroy() or Fragment#onDestroyView().
    • queueEvent

      public void queueEvent(@NonNull Runnable runnable)
      Queue a runnable to be executed on the map renderer thread.
      Parameters:
      runnable - the runnable to queue
    • setMaximumFps

      public void setMaximumFps(int maximumFps)
      The maximum frame rate at which the map view is rendered, but it can't excess the ability of device hardware.
      Parameters:
      maximumFps - Can be set to arbitrary integer values.
    • isDestroyed

      @UiThread public boolean isDestroyed()
      Returns if the map has been destroyed.

      This method can be used to determine if the result of an asynchronous operation should be set.

      Returns:
      true, if the map has been destroyed
    • onLowMemory

      @UiThread public void onLowMemory()
      You must call this method from the parent's Activity#onLowMemory() or Fragment#onLowMemory().
    • onSizeChanged

      public void onSizeChanged(int width, int height, int oldw, int oldh)
    • getWidth

      public float getWidth()
    • getHeight

      public float getHeight()
    • getPixelRatio

      public float getPixelRatio()
      Returns the map pixel ratio, by default it returns the device pixel ratio. Can be overwritten using TrimbleMapsMapOptions.pixelRatio(float).
      Returns:
      the current map pixel ratio
    • addOnCameraWillChangeListener

      public void addOnCameraWillChangeListener(@NonNull MapView.OnCameraWillChangeListener listener)
      Set a callback that's invoked when the camera region will change.
      Parameters:
      listener - The callback that's invoked when the camera region will change
    • removeOnCameraWillChangeListener

      public void removeOnCameraWillChangeListener(@NonNull MapView.OnCameraWillChangeListener listener)
      Remove a callback that's invoked when the camera region will change.
      Parameters:
      listener - The callback that's invoked when the camera region will change
    • addOnCameraIsChangingListener

      public void addOnCameraIsChangingListener(@NonNull MapView.OnCameraIsChangingListener listener)
      Set a callback that's invoked when the camera is changing.
      Parameters:
      listener - The callback that's invoked when the camera is changing
    • removeOnCameraIsChangingListener

      public void removeOnCameraIsChangingListener(@NonNull MapView.OnCameraIsChangingListener listener)
      Remove a callback that's invoked when the camera is changing.
      Parameters:
      listener - The callback that's invoked when the camera is changing
    • addOnCameraDidChangeListener

      public void addOnCameraDidChangeListener(@NonNull MapView.OnCameraDidChangeListener listener)
      Set a callback that's invoked when the camera region did change.
      Parameters:
      listener - The callback that's invoked when the camera region did change
    • removeOnCameraDidChangeListener

      public void removeOnCameraDidChangeListener(@NonNull MapView.OnCameraDidChangeListener listener)
      Set a callback that's invoked when the camera region did change.
      Parameters:
      listener - The callback that's invoked when the camera region did change
    • addOnWillStartLoadingMapListener

      public void addOnWillStartLoadingMapListener(@NonNull MapView.OnWillStartLoadingMapListener listener)
      Set a callback that's invoked when the map will start loading.
      Parameters:
      listener - The callback that's invoked when the map will start loading
    • removeOnWillStartLoadingMapListener

      public void removeOnWillStartLoadingMapListener(@NonNull MapView.OnWillStartLoadingMapListener listener)
      Set a callback that's invoked when the map will start loading.
      Parameters:
      listener - The callback that's invoked when the map will start loading
    • addOnDidFinishLoadingMapListener

      public void addOnDidFinishLoadingMapListener(@NonNull MapView.OnDidFinishLoadingMapListener listener)
      Set a callback that's invoked when the map has finished loading.
      Parameters:
      listener - The callback that's invoked when the map has finished loading
    • removeOnDidFinishLoadingMapListener

      public void removeOnDidFinishLoadingMapListener(@NonNull MapView.OnDidFinishLoadingMapListener listener)
      Set a callback that's invoked when the map has finished loading.
      Parameters:
      listener - The callback that's invoked when the map has finished loading
    • addOnDidFailLoadingMapListener

      public void addOnDidFailLoadingMapListener(@NonNull MapView.OnDidFailLoadingMapListener listener)
      Set a callback that's invoked when the map failed to load.
      Parameters:
      listener - The callback that's invoked when the map failed to load
    • removeOnDidFailLoadingMapListener

      public void removeOnDidFailLoadingMapListener(@NonNull MapView.OnDidFailLoadingMapListener listener)
      Set a callback that's invoked when the map failed to load.
      Parameters:
      listener - The callback that's invoked when the map failed to load
    • addOnWillStartRenderingFrameListener

      public void addOnWillStartRenderingFrameListener(@NonNull MapView.OnWillStartRenderingFrameListener listener)
      Set a callback that's invoked when the map will start rendering a frame.
      Parameters:
      listener - The callback that's invoked when the camera will start rendering a frame
    • removeOnWillStartRenderingFrameListener

      public void removeOnWillStartRenderingFrameListener(@NonNull MapView.OnWillStartRenderingFrameListener listener)
      Set a callback that's invoked when the map will start rendering a frame.
      Parameters:
      listener - The callback that's invoked when the camera will start rendering a frame
    • addOnDidFinishRenderingFrameListener

      public void addOnDidFinishRenderingFrameListener(@NonNull MapView.OnDidFinishRenderingFrameListener listener)
      Set a callback that's invoked when the map has finished rendering a frame.
      Parameters:
      listener - The callback that's invoked when the map has finished rendering a frame
    • removeOnDidFinishRenderingFrameListener

      public void removeOnDidFinishRenderingFrameListener(@NonNull MapView.OnDidFinishRenderingFrameListener listener)
      Set a callback that's invoked when the map has finished rendering a frame.
      Parameters:
      listener - The callback that's invoked when the map has finished rendering a frame
    • addOnWillStartRenderingMapListener

      public void addOnWillStartRenderingMapListener(@NonNull MapView.OnWillStartRenderingMapListener listener)
      Set a callback that's invoked when the map will start rendering.
      Parameters:
      listener - The callback that's invoked when the map will start rendering
    • removeOnWillStartRenderingMapListener

      public void removeOnWillStartRenderingMapListener(@NonNull MapView.OnWillStartRenderingMapListener listener)
      Set a callback that's invoked when the map will start rendering.
      Parameters:
      listener - The callback that's invoked when the map will start rendering
    • addOnDidFinishRenderingMapListener

      public void addOnDidFinishRenderingMapListener(@NonNull MapView.OnDidFinishRenderingMapListener listener)
      Set a callback that's invoked when the map has finished rendering.
      Parameters:
      listener - The callback that's invoked when the map has finished rendering
    • removeOnDidFinishRenderingMapListener

      public void removeOnDidFinishRenderingMapListener(MapView.OnDidFinishRenderingMapListener listener)
      Remove a callback that's invoked when the map has finished rendering.
      Parameters:
      listener - The callback that's invoked when the map has has finished rendering.
    • addOnDidBecomeIdleListener

      public void addOnDidBecomeIdleListener(@NonNull MapView.OnDidBecomeIdleListener listener)
      Set a callback that's invoked when the map has entered the idle state.
      Parameters:
      listener - The callback that's invoked when the map has entered the idle state.
    • removeOnDidBecomeIdleListener

      public void removeOnDidBecomeIdleListener(@NonNull MapView.OnDidBecomeIdleListener listener)
      Remove a callback that's invoked when the map has entered the idle state.
      Parameters:
      listener - The callback that's invoked when the map has entered the idle state.
    • addOnDidFinishLoadingStyleListener

      public void addOnDidFinishLoadingStyleListener(@NonNull MapView.OnDidFinishLoadingStyleListener listener)
      Set a callback that's invoked when the style has finished loading.
      Parameters:
      listener - The callback that's invoked when the style has finished loading
    • removeOnDidFinishLoadingStyleListener

      public void removeOnDidFinishLoadingStyleListener(@NonNull MapView.OnDidFinishLoadingStyleListener listener)
      Set a callback that's invoked when the style has finished loading.
      Parameters:
      listener - The callback that's invoked when the style has finished loading
    • addOnSourceChangedListener

      public void addOnSourceChangedListener(@NonNull MapView.OnSourceChangedListener listener)
      Set a callback that's invoked when a map source has changed.
      Parameters:
      listener - The callback that's invoked when the source has changed
    • removeOnSourceChangedListener

      public void removeOnSourceChangedListener(@NonNull MapView.OnSourceChangedListener listener)
      Set a callback that's invoked when a map source has changed.
      Parameters:
      listener - The callback that's invoked when the source has changed
    • addOnStyleImageMissingListener

      public void addOnStyleImageMissingListener(@NonNull MapView.OnStyleImageMissingListener listener)
      Set a callback that's invoked when the id of an icon is missing.
      Parameters:
      listener - The callback that's invoked when the id of an icon is missing
    • removeOnStyleImageMissingListener

      public void removeOnStyleImageMissingListener(@NonNull MapView.OnStyleImageMissingListener listener)
      Set a callback that's invoked when a map source has changed.
      Parameters:
      listener - The callback that's invoked when the source has changed
    • addOnCanRemoveUnusedStyleImageListener

      public void addOnCanRemoveUnusedStyleImageListener(@NonNull MapView.OnCanRemoveUnusedStyleImageListener listener)
      Set a callback that's invoked when map needs to release unused image resources.

      A callback will be called only for unused images that were provided by the client via MapView.OnStyleImageMissingListener.onStyleImageMissing(String) listener interface.

      By default, platform will remove unused images from the style. By adding listener, default behavior can be overridden and client can control whether to release unused resources.

      Parameters:
      listener - The callback that's invoked when map needs to release unused image resources
    • removeOnCanRemoveUnusedStyleImageListener

      public void removeOnCanRemoveUnusedStyleImageListener(@NonNull MapView.OnCanRemoveUnusedStyleImageListener listener)
      Removes a callback that's invoked when map needs to release unused image resources.

      When all listeners are removed, platform will fallback to default behavior, which is to remove unused images from the style.

      Parameters:
      listener - The callback that's invoked when map needs to release unused image resources
    • getMapAsync

      @UiThread public void getMapAsync(@NonNull OnMapReadyCallback callback)
      Sets a callback object which will be triggered when the TrimbleMapsMap instance is ready to be used.
      Parameters:
      callback - The callback object that will be triggered when the map is ready to be used.
    • setMapStrictModeEnabled

      public static void setMapStrictModeEnabled(boolean strictModeEnabled)
      Sets the strict mode that will throw the MapStrictModeException whenever the map would fail silently otherwise.
      Parameters:
      strictModeEnabled - true to enable the strict mode, false otherwise