-
Notifications
You must be signed in to change notification settings - Fork 3k
/
CloudBasedMapStylingDemoActivity.kt
74 lines (67 loc) · 2.97 KB
/
CloudBasedMapStylingDemoActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* DO NOT EDIT THIS FILE.
*
* This source code was autogenerated from source code within the `app/src/gms` directory
* and is not intended for modifications. If any edits should be made, please do so in the
* corresponding file under the `app/src/gms` directory.
*/
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.kotlindemos
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.google.android.libraries.maps.GoogleMap
import com.google.android.libraries.maps.OnMapReadyCallback
import com.google.android.libraries.maps.SupportMapFragment
/**
* This shows how to use Cloud-based Map Styling in a simple Activity. For more information on how
* to style a map using this method, see:
* https://developers.google.com/maps/documentation/android-sdk/cloud-based-map-styling
*/
class CloudBasedMapStylingDemoActivity : AppCompatActivity(), OnMapReadyCallback {
private var map: GoogleMap? = null
private var currentMapType = GoogleMap.MAP_TYPE_NORMAL
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (savedInstanceState != null) {
currentMapType = savedInstanceState.getInt(MAP_TYPE_KEY)
}
// The underlying style the map will use has been set in the layout
// `cloud_styling_basic_demo` under the SupportMapFragment's `map:mapId` attribute.
setContentView(R.layout.cloud_styling_basic_demo)
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
mapFragment!!.getMapAsync(this)
setUpButtonListeners()
}
override fun onMapReady(map: GoogleMap) {
this.map = map
map.mapType = currentMapType
}
private fun setUpButtonListeners() {
findViewById<View>(R.id.styling_normal_mode).setOnClickListener { setMapType(GoogleMap.MAP_TYPE_NORMAL) }
findViewById<View>(R.id.styling_satellite_mode).setOnClickListener { setMapType(GoogleMap.MAP_TYPE_SATELLITE) }
findViewById<View>(R.id.styling_hybrid_mode).setOnClickListener { setMapType(GoogleMap.MAP_TYPE_HYBRID) }
findViewById<View>(R.id.styling_terrain_mode).setOnClickListener { setMapType(GoogleMap.MAP_TYPE_TERRAIN) }
}
private fun setMapType(mapType: Int) {
currentMapType = mapType
map?.mapType = mapType
}
companion object {
private const val MAP_TYPE_KEY = "map_type"
}
}