publicclassSampleChangeStylesActivityextendsAppCompatActivityimplementsStyle.OnStyleLoaded{privateMapViewmapView;privateTrimbleMapsMapmap;privateStringchosenStyle="Day Style";// Used for toasts
@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_change_styles);// 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.
// Set the initial camera position for a starting location
map=trimbleMapsMap;CameraPositionposition=newCameraPosition.Builder().target(newLatLng(40.7584766,-73.9840227)).zoom(13).build();map.setCameraPosition(position);// Set the style, the callback is implemented into the class.
map.setStyle(Style.MOBILE_DAY,SampleChangeStylesActivity.this);}});}// When the buttons in the layout are clicked, this function is called to change the style
publicvoidonClickChangeStyle(Viewview){// Simple switch statement on the button's text, style will change depending on it.
StringbuttonText=((Button)view).getText().toString();switch(buttonText){case"Satellite":chosenStyle="Satellite Style";map.setStyle(Style.SATELLITE,this);break;case"Day":chosenStyle="Day Style";map.setStyle(Style.MOBILE_DAY,this);break;case"Night":chosenStyle="Night Style";map.setStyle(Style.MOBILE_NIGHT,this);break;}}// Implemented onStyleLoaded to the class. When the style is changed a small toast appears to
// confirm the choice.
@OverridepublicvoidonStyleLoaded(@NonNullStylestyle){Toasttoast=Toast.makeText(SampleChangeStylesActivity.this,chosenStyle,Toast.LENGTH_SHORT);toast.show();}/**
* 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();}}
classSampleChangeStylesActivity:Activity(),Style.OnStyleLoaded{privatevarmapView:MapView?=nullprivatevarmap:TrimbleMapsMap?=nullprivatevarchosenStyle="Day Style"// Used for toasts
overridefunonCreate(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_change_styles)// 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.
// Set the initial camera position for a starting location
map=trimbleMapsMapvalposition=CameraPosition.Builder().target(LatLng(40.7584766,-73.9840227)).zoom(13.0).build()map!!.cameraPosition=position// Set the style, the callback is implemented into the class.
map!!.setStyle(Style.MOBILE_DAY,this@SampleChangeStylesActivity)}}// When the buttons in the layout are clicked, this function is called to change the style
funonClickChangeStyle(view:View){// Simple switch statement on the button's text, style will change depending on it.
when((viewasButton).text.toString()){"Satellite"->{chosenStyle="Satellite Style"map?.setStyle(Style.SATELLITE,this)}"Day"->{chosenStyle="Day Style"map?.setStyle(Style.MOBILE_DAY,this)}"Night"->{chosenStyle="Night Style"map?.setStyle(Style.MOBILE_NIGHT,this)}}}// Implemented onStyleLoaded to the class. When the style is changed a small toast appears to
// confirm the choice.
overridefunonStyleLoaded(style:Style){valtoast=Toast.makeText(this@SampleChangeStylesActivity,chosenStyle,Toast.LENGTH_SHORT)toast.show()}/**
* 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()}}