importandroid.os.Bundle;importandroid.view.View;importandroid.widget.Button;importandroidx.annotation.NonNull;importandroidx.appcompat.app.AppCompatActivity;importcom.trimblemaps.account.LicensedFeature;importcom.trimblemaps.account.TrimbleMapsAccountManager;importcom.trimblemaps.account.models.TrimbleMapsAccount;importcom.trimblemaps.mapsdk.TrimbleMaps;importcom.trimblemaps.mapsdk.camera.CameraPosition;importcom.trimblemaps.mapsdk.geometry.LatLng;importcom.trimblemaps.mapsdk.maps.MapView;importcom.trimblemaps.mapsdk.maps.OnMapReadyCallback;importcom.trimblemaps.mapsdk.maps.Style;importcom.trimblemaps.mapsdk.maps.TrimbleMapsMap;publicclassSampleTrimbleLayersActivityextendsAppCompatActivity{privateMapViewmapView;privateTrimbleMapsMapmap;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);// Authorize the API key for the session.// .apiKey() requires your Trimble Maps API keyTrimbleMapsAccounttrimbleMapsAccount=TrimbleMapsAccount.builder().apiKey("Your-API-key-here").addLicensedFeature(LicensedFeature.MAPS_SDK).build();// Initialize the sessionTrimbleMapsAccountManager.initialize(trimbleMapsAccount);TrimbleMapsAccountManager.awaitInitialization();// Get an instance of the map, done before the layout is set.TrimbleMaps.getInstance(this);setContentView(R.layout.activity_sample_trimble_layers);// Set up the MapView from the layoutmapView=(MapView)findViewById(R.id.mapView);// the onMapReadyCallback is fired when the map is ready to be worked withmapView.getMapAsync(newOnMapReadyCallback(){@OverridepublicvoidonMapReady(@NonNullTrimbleMapsMaptrimbleMapsMap){// The TrimbleMapsMap object is created, now a style can be applied to render a map.map=trimbleMapsMap;CameraPositionposition=newCameraPosition.Builder().target(newLatLng(40.7584766,-73.9840227)).zoom(13).build();map.setCameraPosition(position);map.setStyle(Style.MOBILE_DEFAULT);}});}// Function called when a button in the layout is pressed.publicvoidonClickToggleTrimbleLayer(Viewview){// Simple switch statement on the button's text, layers will toggle depending on what was pressed// The button's label is used for the switch statement for readability purposes.// Toggle's are used here, but these layers can also be implicitly set with boolean values.// E.g. map.setTrafficVisibility(true);StringbuttonText=((Button)view).getText().toString().toLowerCase();switch(buttonText){case"traffic":map.toggleTrafficVisibility();break;case"3d buildings":map.toggle3dBuildingVisibility();break;case"pois":map.togglePoiVisibility();break;case"weather":map.toggleWeatherAlertVisibility();break;}}/**
* Activity Overrides
*/@OverridepublicvoidonLowMemory(){super.onLowMemory();mapView.onLowMemory();}@OverridepublicvoidonStart(){super.onStart();mapView.onStart();}@OverridepublicvoidonResume(){super.onResume();mapView.onResume();}@OverridepublicvoidonStop(){super.onStop();mapView.onStop();}@OverridepublicvoidonPause(){super.onPause();mapView.onPause();}@OverridepublicvoidonDestroy(){super.onDestroy();mapView.onDestroy();}}
importandroid.app.Activityimportandroid.os.Bundleimportandroid.view.Viewimportandroid.widget.Buttonimportcom.trimblemaps.account.LicensedFeatureimportcom.trimblemaps.account.TrimbleMapsAccountManagerimportcom.trimblemaps.account.models.TrimbleMapsAccountimportcom.trimblemaps.mapsdk.TrimbleMapsimportcom.trimblemaps.mapsdk.camera.CameraPositionimportcom.trimblemaps.mapsdk.geometry.LatLngimportcom.trimblemaps.mapsdk.maps.MapViewimportcom.trimblemaps.mapsdk.maps.Styleimportcom.trimblemaps.mapsdk.maps.TrimbleMapsMapclassSampleTrimbleLayersActivity:Activity(){privatevarmapView:MapView?=nullprivatevarmap:TrimbleMapsMap?=nulloverridefunonCreate(savedInstanceState:Bundle?){super.onCreate(savedInstanceState)// Authorize the API key for the session.
// .apiKey() requires your Trimble Maps API key
valtrimbleMapsAccount=TrimbleMapsAccount.builder().apiKey("Your-API-key-here").addLicensedFeature(LicensedFeature.MAPS_SDK).build()// Initialize the session
TrimbleMapsAccountManager.initialize(trimbleMapsAccount)TrimbleMapsAccountManager.awaitInitialization()// Get an instance of the map, done before the layout is set.
TrimbleMaps.getInstance(this)setContentView(R.layout.activity_sample_trimble_layers)// Set up the MapView from the layout
mapView=findViewById<View>(R.id.mapView)asMapView// the onMapReadyCallback is fired when the map is ready to be worked with
mapView!!.getMapAsync{trimbleMapsMap->// The TrimbleMapsMap object is created, now a style can be applied to render a map.
map=trimbleMapsMapvalposition=CameraPosition.Builder().target(LatLng(40.7584766,-73.9840227)).zoom(13.0).build()map!!.cameraPosition=positionmap!!.setStyle(Style.MOBILE_DEFAULT)}}// Function called when a button in the layout is pressed.
funonClickToggleTrimbleLayer(view:View){// Simple switch statement on the button's text, layers will toggle depending on what was pressed
// The button's label is used for the switch statement for readability purposes.
// Toggle's are used here, but these layers can also be implicitly set with boolean values.
// E.g. map.setTrafficVisibility(true);
when((viewasButton).text.toString().lowercase()){"traffic"->map!!.toggleTrafficVisibility()"3d buildings"->map!!.toggle3dBuildingVisibility()"pois"->map!!.togglePoiVisibility()"weather"->map!!.toggleWeatherAlertVisibility()}}/**
* Activity Overrides
*/overridefunonStart(){super.onStart()mapView?.onStart()}overridefunonResume(){super.onResume()mapView?.onResume()}overridefunonPause(){super.onPause()mapView?.onPause()}overridefunonStop(){super.onStop()mapView?.onStop()}overridefunonLowMemory(){super.onLowMemory()mapView?.onLowMemory()}overridefunonDestroy(){super.onDestroy()mapView?.onDestroy()}}