js如何同时打开多个信息窗口 高德地图_高德地图显示单个窗体和显示多个窗体的方法...
高德地圖是我經(jīng)常使用過的組件,今天想跟大家討論下信息窗體的創(chuàng)建與顯示的方法,這種就是屬于自定的內(nèi)容了,需要到高德開發(fā)者中心查看一些相應(yīng)的文檔
image.png
LatLng latLng = new LatLng(39.906901,116.397972);
final Marker marker = aMap.addMarker(new MarkerOptions().position(latLng).title("北京").snippet("DefaultMarker"));
官方是只有這寥寥數(shù)語,個(gè)中意味需要開發(fā)者仔細(xì)研究
image.png
經(jīng)過我的而不斷探索,最終吧還是搞懂了,其實(shí)這都是之前做好的,今天總結(jié)出來學(xué)習(xí)(裝逼)而已,哈哈
顯示單個(gè)信息窗體的,支持自定義布局
class BubbleInfoUpActivity : BaseActivity(), LocationSource, AMapLocationListener, AMap.InfoWindowAdapter,
AMap.OnInfoWindowClickListener, AMap.OnCameraChangeListener {
//省略若干無用代碼
override fun onLocationChanged(aMapLocation: AMapLocation) {
}
override fun getInfoWindow(marker: Marker?): View {
var infoWindow = LayoutInflater.from(this@BubbleInfoUpActivity).inflate(R.layout.layout_gd_map_distance, null)
var name = infoWindow.findViewById(R.id.gd_distance)
name.text = "我在這里"
marker?.isVisible = true
return infoWindow
}
override fun getInfoContents(marker: Marker?): View? {
return null
}
override fun onInfoWindowClick(marker: Marker?) {
marker?.isVisible = true
marker?.showInfoWindow()
}
override fun activate(onLocationChangedListener: LocationSource.OnLocationChangedListener) {
}
override fun deactivate() {
}
override fun onCameraChange(cameraPosition: CameraPosition) {
}
override fun onCameraChangeFinish(cameraPosition: CameraPosition) {
val infoWindowAnimationManager = aMap?.infoWindowAnimationManager
infoWindowAnimationManager?.startAnimation()
mMarker?.showInfoWindow()
mMarker?.isInfoWindowEnable = true
onInfoWindowClick(mMarker)
}
}
Ok,就是這樣,實(shí)現(xiàn)這幾個(gè)接口,然后就能在一個(gè)定位點(diǎn)上顯示一個(gè)小的信息窗體了,至于窗體的形狀樣式,自己可以在layout_gd_map_distance里更改
顯示多個(gè)信息窗體的
這種的就是類似小黃車ofo 或者哈羅單車的效果了,在一個(gè)聚合區(qū)域里顯示多個(gè)定位點(diǎn),點(diǎn)上呢都有個(gè)信息的彈窗,也是可以自定義的,效果呢,大家就參考哈羅單車吧
image.png
我們還是直接看代碼
aMap?.myLocationStyle = myLocationStyle
//實(shí)例化UiSettings類對(duì)象
mUiSettings = aMap?.uiSettings
//不顯示縮放按鈕
mUiSettings?.isZoomControlsEnabled = false
//不顯示我的位置
myLocationStyle.showMyLocation(false)
// 設(shè)置默認(rèn)定位按鈕是否顯示
aMap?.uiSettings?.isMyLocationButtonEnabled = false
aMap?.isMyLocationEnabled = false
//自定義InfoWindow
aMap?.setInfoWindowAdapter(this)//AMap類中
aMap?.setOnInfoWindowClickListener(this)
//自己的位置
val latLng = LatLng(worker_lat, worker_lon)
mMarker = aMap?.addMarker(MarkerOptions().position(latLng)
.title("運(yùn)送位置")
.snippet("運(yùn)送位置")
.setFlat(true)
.icon(getBitamap()))
// .icon(BitmapDescriptorFactory.fromResource(R.drawable.new_location_icon)))
最重要的就是這個(gè)icon方法了
private fun getBitamap(): BitmapDescriptor? {
var view = LayoutInflater.from(this@BubbleInfoUpActivity).inflate(R.layout.layout_title, null)
return BitmapDescriptorFactory.fromView(view)
}
Ok,想要什么樣的彈窗就自己添加就好了
以上呢就是添加彈窗的兩種方法,"磚廠繁忙,告辭了",搬磚碼字去了。
總結(jié)
以上是生活随笔為你收集整理的js如何同时打开多个信息窗口 高德地图_高德地图显示单个窗体和显示多个窗体的方法...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++结构体案例
- 下一篇: const修饰是指针和常量