importandroid.os.Bundle;importandroid.view.View;importandroid.widget.Button;importandroid.widget.Toast;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;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 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_change_styles);// 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.// Set the initial camera position for a starting locationmap=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,MainActivity.this);}});}// When the buttons in the layout are clicked, this function is called to change the stylepublicvoidonClickChangeStyle(Viewview){// Simple switch statement on the button's text, style will change depending on it.StringbuttonText=((Button)view).getText().toString();switch(buttonText){case"Mobile_Satellite":chosenStyle="Mobile_Satellite Style";map.setStyle(Style.MOBILE_SATELLITE,this);break;case"Mobile_Day":chosenStyle="Mobile_Day Style";map.setStyle(Style.MOBILE_DAY,this);break;case"Mobile_Night":chosenStyle="Mobile_Night Style";map.setStyle(Style.MOBILE_NIGHT,this);break;case"Terrain":chosenStyle="Terrain Style";map.setStyle(Style.TERRAIN,this);break;case"Transportation":chosenStyle="Transportation Style";map.setStyle(Style.TRANSPORTATION,this);break;case"Basic":chosenStyle="Basic Style";map.setStyle(Style.BASIC,this);break;case"DataDark":chosenStyle="DataDark Style";map.setStyle(Style.DATADARK,this);break;case"DataLight":chosenStyle="DataLight Style";map.setStyle(Style.DATALIGHT,this);break;case"Default":chosenStyle="Default Style";map.setStyle(Style.DEFAULT,this);break;case"Mobile_Default":chosenStyle="Mobile_Default Style";map.setStyle(Style.MOBILE_DEFAULT,this);break;case"Satellite":chosenStyle="Satellite Style";map.setStyle(Style.SATELLITE,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(MainActivity.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();}}
importandroid.app.Activityimportandroid.os.Bundleimportandroid.view.Viewimportandroid.widget.Buttonimportandroid.widget.Toastimportcom.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.TrimbleMapsMapclassSampleChangeStylesActivity: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@MainActivity)}}// 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()){"Mobile_Satellite"->{chosenStyle="Mobile_Satellite Style"map?.setStyle(Style.MOBILE_SATELLITE,this)}"Mobile_Day"->{chosenStyle="Mobile_Day Style"map?.setStyle(Style.MOBILE_DAY,this)}"Mobile_Night"->{chosenStyle="Mobile_Night Style"map?.setStyle(Style.MOBILE_NIGHT,this)}"Terrain"->{chosenStyle="Terrain Style"map?.setStyle(Style.TERRAIN,this)}"Transportation"->{chosenStyle="Transportation Style"map?.setStyle(Style.TRANSPORTATION,this)}"Basic"->{chosenStyle="Basic Style"map?.setStyle(Style.BASIC,this)}"DataDark"->{chosenStyle="DataDark Style"map?.setStyle(Style.DATADARK,this)}"DataLight"->{chosenStyle="DataLight Style"map?.setStyle(Style.DATALIGHT,this)}"Default"->{chosenStyle="Default Style"map?.setStyle(Style.DEFAULT,this)}"Mobile_Default"->{chosenStyle="Mobile_Default Style"map?.setStyle(Style.MOBILE_DEFAULT,this)}"Satellite"->{chosenStyle="Satellite Style"map?.setStyle(Style.SATELLITE,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@MainActivity,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()}}