publicclassSampleTrimbleLayersActivityextendsAppCompatActivity{privateMapViewmapView;privateTrimbleMapsMapmap;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);// Authorize the api key for the session.
// .apiKey() requires your Trimble Maps API key
TrimbleMapsAccounttrimbleMapsAccount=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=(MapView)findViewById(R.id.mapView);// the onMapReadyCallback is fired when the map is ready to be worked with
mapView.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();}}
classSampleTrimbleLayersActivity: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()}}