पोपओवर, मैप पर किसी जगह की जानकारी देने वाली विंडो में कॉन्टेंट (आम तौर पर टेक्स्ट या इमेज) दिखाता है. यह विंडो, मैप के ऊपर दिखती है. पॉपओवर में कॉन्टेंट एरिया और पतला तना होता है. स्टेम का सिरा, मैप पर किसी तय जगह से जुड़ा होता है.
आम तौर पर, पॉपओवर को मार्कर से जोड़ा जाता है. हालांकि, पॉपओवर को किसी खास LatLng कोऑर्डिनेट से भी जोड़ा जा सकता है.
पॉपओवर जोड़ना
पॉपओवर जोड़ने के लिए, एक Popover ऑब्जेक्ट बनाएं और उसके विकल्प सेट करें. इनमें पोज़िशन और ऊंचाई का मोड शामिल है. पोजीशन एक LatLng ऑब्जेक्ट है. इसमें अक्षांश, देशांतर, और ऊंचाई शामिल होती है. इससे यह तय होता है कि पॉपओवर कहां दिखेगा. अगर मार्कर से एंकर किया जा रहा है, तो मार्कर की पोज़िशन का इस्तेमाल किया जाता है.
ऊंचाई के मोड को सेट करके, यह भी कंट्रोल किया जा सकता है कि ऊंचाई को कैसे समझा जाए.
पॉपओवर का कॉन्टेंट, AndroidView में शामिल होना चाहिए. पॉपओवर को डिफ़ॉल्ट रूप से स्क्रोल किया जा सकता है. साथ ही, इनकी ज़्यादा से ज़्यादा ऊंचाई पहले से तय होती है.
किसी मार्कर पर पॉपओवर को ऐंकर करना
पॉपओवर को मार्कर से जोड़ा जा सकता है. किसी मार्कर से जुड़े पॉपओवर को जोड़ते समय, आपको पॉपओवर को Marker ऑब्जेक्ट से जोड़ना होगा.
class MapManager(private val map: MapView) {
/**
* Adds a popover anchored to a marker.
* @param context The Context required to instantiate UI views.
*/
fun addPopoverToMarker(context: Context) {
// 1. Create a marker
val markerOptions = markerOptions {
position = latLngAltitude {
latitude = 37.422
longitude = -122.084
altitude = 0.0
}
}
val marker = map.addMarker(markerOptions) ?: return
// 2. Create the custom view using the passed-in context
val textView = TextView(context).apply {
text = context.getString(R.string.popover_hello)
setPadding(16, 16, 16, 16)
setBackgroundColor(Color.WHITE)
setTextColor(Color.BLACK)
}
// 3. Configure and display the popover
val options = popoverOptions {
content = textView
positionAnchor = marker
altitudeMode = AltitudeMode.RELATIVE_TO_GROUND
}
val popover = map.addPopover(options)
popover.show()
}
}
कॉन्फ़िगर किया गया पॉपओवर जोड़ना
यहां दिए गए सैंपल में, एक पॉपओवर जोड़ा गया है. यह पॉपओवर, उपयोगकर्ता के पॉपओवर के बाहर टैप करने पर अपने-आप बंद हो जाता है. साथ ही, यह नए पॉपओवर खुलने पर अपने-आप पैन नहीं होता:
/**
* Adds a configured popover (auto-close enabled, auto-pan disabled).
* @param context The Context used to inflate the UI and retrieve string resources.
*/
fun addConfiguredPopover(context: Context) {
// 1. Initialize the view with the explicit context
val textView = TextView(context).apply {
text = context.getString(com.example.snippets.common.R.string.popover_info)
setPadding(12, 12, 12, 12)
setBackgroundColor(Color.WHITE)
setTextColor(Color.BLACK)
}
// 2. Configure popover behavior
val options = popoverOptions {
content = textView
// Setting a fixed coordinate anchor
positionAnchor = latLngAltitude {
latitude = 0.0
longitude = 0.0
altitude = 0.0
}
autoCloseEnabled = true // Closes automatically when the map is tapped elsewhere
autoPanEnabled = false // Map camera remains stationary when popover appears
}
// 3. Add to the map instance
map.addPopover(options)
}