
یک پنجره بازشو، محتوا (معمولاً متن یا تصاویر) را در یک پنجره حباب اطلاعات بالای نقشه، در یک مکان مشخص نمایش میدهد. این پنجره بازشو دارای یک ناحیه محتوا و یک ساقه مخروطی شکل است. نوک ساقه به یک مکان مشخص روی نقشه متصل است.
معمولاً یک popover را به یک marker وصل میکنید، اما میتوانید یک popover را به یک مختصات LatLng خاص نیز وصل کنید.
اضافه کردن یک پاپاوور
برای افزودن یک popover، یک شیء Popover ایجاد کنید و گزینههای آن، از جمله موقعیت و حالت ارتفاع، را تنظیم کنید. موقعیت یک شیء LatLng است که شامل عرض جغرافیایی، طول جغرافیایی و ارتفاع است که محل نمایش popover را تعیین میکند. اگر به یک نشانگر متصل باشد، از موقعیت نشانگر به جای آن استفاده میشود. همچنین میتوانید با تنظیم حالت ارتفاع، نحوه تفسیر ارتفاع را کنترل کنید.
محتوای یک popover باید درون یک AndroidView قرار گیرد. Popoverها به طور پیشفرض قابل اسکرول هستند و حداکثر ارتفاع از پیش تعریف شدهای دارند.
یک پاپاوور را به یک نشانگر متصل کنید
شما میتوانید پاپاوورها را به نشانگرها متصل کنید. هنگام اضافه کردن یک پاپاوور متصل به یک نشانگر، باید آن را به یک شیء 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)
}