Commit a59fc2ca authored by fengruiyu's avatar fengruiyu

百度地图的sdk 地图缩放不移动,移动不缩放功能已完成

parent d1913046
......@@ -12,7 +12,7 @@ import com.mints.street.databinding.ItemGridMapAdapterBinding
* Created by 冯瑞雨 on 2021/8/9.
*/
class DialogMapTailAdapter(val context: Context) :
AbstractVLayoutBaseAdapter<ItemGridMapAdapterBinding, Any>(context, null, 3) {
AbstractVLayoutBaseAdapter<ItemGridMapAdapterBinding, List<String>>(context, null, 3) {
override fun onBindViewHolder(
holder: BindingViewHolder<ItemGridMapAdapterBinding>,
......@@ -21,7 +21,6 @@ class DialogMapTailAdapter(val context: Context) :
}
override fun getItemCount() = 1
override fun onCreateLayoutHelper(): LayoutHelper {
......
package com.mints.street.adapter
import android.app.ActionBar
import android.content.Context
import android.icu.number.IntegerWidth
import android.view.WindowManager
import android.widget.ImageView
import com.alibaba.android.vlayout.LayoutHelper
import com.alibaba.android.vlayout.layout.GridLayoutHelper
import com.bumptech.glide.Glide
......@@ -14,10 +10,8 @@ import com.fry.base.binding.setMargin
import com.mints.street.R
import com.mints.street.bean.VrmapBean
import com.mints.street.databinding.ItemGridMapAdapterBinding
import com.mints.street.main.vr.PanoramicActivity
import com.mints.street.webview.MintsWebViewActivity
import me.goldze.mvvmhabit.utils.AppUtils
import me.goldze.mvvmhabit.utils.KLog
import me.goldze.mvvmhabit.utils.RxUtils
/**
......
......@@ -64,7 +64,7 @@ class HistoryRecordAdapter(val activity: SearchMapActivity,val viewModel: Search
}
private fun getHistoryData(): MutableList<HistoryBean>? {
val instance = SPUtils.getInstance(SearchMapActivity.HISTORY_NAME)
val instance = SPUtils.getInstance( SearchMapActivity.HISTORY_NAME)
val string = instance.decodeString(if (type==0){"Territory"}else{"Abroad"})
if (TextUtils.isEmpty(string)) {
return null
......
......@@ -4,10 +4,10 @@ import android.Manifest
import android.os.Build
import android.os.Bundle
import android.view.KeyEvent
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.fry.base.base.BaseActivity
......@@ -19,7 +19,6 @@ import com.mints.street.databinding.ActivityMainBinding
import com.mints.street.main.googlemap.GoogleMapFragment
import com.mints.street.main.home.HomeFragment
import com.mints.street.main.my.MyFragment
import com.mints.street.main.my.OpenvipActivity
import com.mints.street.main.vr.VRFragment
import com.mints.street.manager.UserManager
import com.mints.street.manager.oaid.OaidManager
......@@ -38,13 +37,14 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
override fun getStatusBarHeightView(): View? {
return null
}
private val homeFragment = HomeFragment()
override fun initData() {
super.initData()
OaidManager.init()
//初始化viewpager2
binding.mainViewpager.initMain(this)
binding.mainViewpager.initMain(this,homeFragment)
//初始化 bottomBarF
binding.mainBottom.init {
when (it) {
......@@ -108,6 +108,21 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
return true
}
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
if (ev.action == MotionEvent.ACTION_MOVE){
//触点的个数,就是有几个手指同时接触屏幕
if (ev.pointerCount==1){
homeFragment.updateGesture(true)
}else{
homeFragment.updateGesture(false)
}
}
return super.dispatchTouchEvent(ev)
}
}
......@@ -123,7 +138,7 @@ private fun BottomNavigationViewEx.init(navigationItemSelectedAction: (Int) -> U
return this
}
private fun ViewPager2.initMain(activity: MainActivity): ViewPager2 {
private fun ViewPager2.initMain(activity: MainActivity,homeFragment:HomeFragment): ViewPager2 {
//是否可滑动
this.isUserInputEnabled = false
//预加载
......@@ -135,7 +150,7 @@ private fun ViewPager2.initMain(activity: MainActivity): ViewPager2 {
return when (position) {
0 -> {
//首页
HomeFragment()
homeFragment
}
1 -> {
//广场
......
......@@ -25,7 +25,6 @@ import com.mints.street.R
import com.mints.street.bean.MapBean
import com.mints.street.bean.PositioningBean
import com.mints.street.databinding.FragmentHomeBinding
import com.mints.street.main.MainActivity
import com.mints.street.manager.UmengManager
import com.mints.street.widget.ScrollLayout
import com.mints.street.widget.dialog.DialogMapStyle
......@@ -35,7 +34,6 @@ import me.goldze.mvvmhabit.base.AppManager
import me.goldze.mvvmhabit.utils.KLog
import me.goldze.mvvmhabit.utils.RxUtils
import me.goldze.mvvmhabit.utils.SPUtils
import me.goldze.mvvmhabit.utils.ToastUtils
/**
* Created by 冯瑞雨 on 2021/7/2.
......@@ -56,6 +54,8 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
// 定位图层显示方式
private var mCurrentMode: MyLocationConfiguration.LocationMode? = null
private var mSensorManager: SensorManager? = null
private var mUiSettings: UiSettings? = null
private var lastX = 0.0
//// 此处设置开发者获取到的方向信息,顺时针0-360
......@@ -86,7 +86,7 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
private var myLocationData: MyLocationData? = null
//弹出框
private var dialogMapStyle: DialogMapStyle?=null
private var dialogMapStyle: DialogMapStyle? = null
override fun initContentView(
......@@ -118,17 +118,19 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
SearchMapActivity.startSearchMapActivity(this)
}
RxUtils.onMultiClick(binding.ivClick) {
viewModel.authorized("",
viewModel.authorized(
"",
currentLat.toString(), currentLon.toString(),
false)
false
)
}
RxUtils.onMultiClick(binding.imageMapChangeIcon){
RxUtils.onMultiClick(binding.imageMapChangeIcon) {
context?.apply {
if (dialogMapStyle==null){
if (dialogMapStyle == null) {
dialogMapStyle = DialogMapStyle(this)
}
if (this@HomeFragment.fragmentManager!=null){
dialogMapStyle?.show(this@HomeFragment.fragmentManager!!,"dialogMapStyle")
if (this@HomeFragment.fragmentManager != null) {
dialogMapStyle?.show(this@HomeFragment.fragmentManager!!, "dialogMapStyle")
}
}
......@@ -152,6 +154,11 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
private fun initMap() {
mBaiduMap = binding.bmapView.map
mUiSettings = mBaiduMap?.uiSettings
mUiSettings?.setAllGesturesEnabled(false)
mUiSettings?.isScrollGesturesEnabled = true
mBaiduMap?.mapType = BaiduMap.MAP_TYPE_SATELLITE
//设置是否显示缩放控件
......@@ -191,7 +198,7 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
KLog.a("百度map", "移动结束")
currentLat = status?.target?.latitude ?: 0.0
currentLon = status?.target?.longitude ?: 0.0
currentMapZoom = status?.zoom?:0f
currentMapZoom = status?.zoom ?: 0f
// 发起反地理编码请求
mSearch.reverseGeoCode(ReverseGeoCodeOption().location(status?.target))
......@@ -199,11 +206,11 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
})
//使地图缩放级别增大一级
binding.imageIn.setOnClickListener {
mBaiduMap?.animateMapStatus(MapStatusUpdateFactory.zoomIn(),300)
mBaiduMap?.animateMapStatus(MapStatusUpdateFactory.zoomIn(), 300)
}
//使地图缩放级别减小一级
binding.imageOut.setOnClickListener {
mBaiduMap?.animateMapStatus(MapStatusUpdateFactory.zoomOut(),300)
mBaiduMap?.animateMapStatus(MapStatusUpdateFactory.zoomOut(), 300)
}
//历史影像
binding.imageMapHistory.setOnClickListener {
......@@ -219,7 +226,7 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
val mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(builder.build())
// 设置地图状态
mBaiduMap?.animateMapStatus(mapStatusUpdate,300)
mBaiduMap?.animateMapStatus(mapStatusUpdate, 300)
}
//定位初始化
initLocation()
......@@ -258,46 +265,49 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
mLocClient?.locOption = option
mLocClient?.start()
}
/**
*逆地理编码
*/
val mSearch = GeoCoder.newInstance()
private fun geoCoder(){
val listener: OnGetGeoCoderResultListener = object : OnGetGeoCoderResultListener{
private fun geoCoder() {
val listener: OnGetGeoCoderResultListener = object : OnGetGeoCoderResultListener {
override fun onGetGeoCodeResult(p0: GeoCodeResult?) {
}
override fun onGetReverseGeoCodeResult(reverseGeoCodeResult : ReverseGeoCodeResult?) {
override fun onGetReverseGeoCodeResult(reverseGeoCodeResult: ReverseGeoCodeResult?) {
if (reverseGeoCodeResult == null || reverseGeoCodeResult.error !== SearchResult.ERRORNO.NO_ERROR) {
//没有找到检索结果
return
} else {
if ("CN".equals(reverseGeoCodeResult.addressDetail.countryCodeIso2)){
if(currentMapZoom >= 15){
var zoom = 13f
// 默认 天安门
val center = LatLng(currentLat, currentLon)
// 默认 11级
val builder = MapStatus.Builder()
builder.target(center).zoom(zoom)
val mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(builder.build())
showupgradevipDialog(requireContext())
// 设置地图状态
mBaiduMap?.animateMapStatus(mapStatusUpdate,200)
}
}else{
var zoom = 13f
// 默认 天安门
val center = LatLng(mCurrentLat, mCurrentLon)
// 默认 11级
val builder = MapStatus.Builder()
builder.target(center).zoom(zoom)
val mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(builder.build())
showupgradevipDialog(requireContext())
// 设置地图状态
mBaiduMap?.animateMapStatus(mapStatusUpdate,500)
}
if ("CN".equals(reverseGeoCodeResult.addressDetail.countryCodeIso2)) {
if (currentMapZoom >= 15) {
var zoom = 13f
// 默认 天安门
val center = LatLng(currentLat, currentLon)
// 默认 11级
val builder = MapStatus.Builder()
builder.target(center).zoom(zoom)
val mapStatusUpdate =
MapStatusUpdateFactory.newMapStatus(builder.build())
showupgradevipDialog(requireContext())
// 设置地图状态
mBaiduMap?.animateMapStatus(mapStatusUpdate, 200)
}
} else {
var zoom = 13f
// 默认 天安门
val center = LatLng(mCurrentLat, mCurrentLon)
// 默认 11级
val builder = MapStatus.Builder()
builder.target(center).zoom(zoom)
val mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(builder.build())
showupgradevipDialog(requireContext())
// 设置地图状态
mBaiduMap?.animateMapStatus(mapStatusUpdate, 500)
}
}
}
......@@ -332,6 +342,22 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
}
/**
* 更新手势状态
*/
fun updateGesture(isMove: Boolean) {
if (isMove) {
mUiSettings?.isZoomGesturesEnabled = false
} else {
if (mUiSettings?.isZoomGesturesEnabled == false) {
mUiSettings?.isZoomGesturesEnabled = true
}
}
}
/**
* 定位SDK监听函数
......@@ -341,7 +367,7 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
inner class MyLocationListener : BDLocationListener {
override fun onReceiveLocation(location: BDLocation?) {
if( location?.latitude == 4.9E-324 ||location?.longitude == 4.9E-324){
if (location?.latitude == 4.9E-324 || location?.longitude == 4.9E-324) {
return
}
if (sp == null) {
......@@ -364,19 +390,19 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
sp?.encode(SPUtils.POSITIONING_MAP, Gson().toJson(positioningBean).toString())
// MapView 销毁后不在处理新接收的位置
mBaiduMap?.apply {
mCurrentLat = location?.latitude?:0.0
mCurrentLon = location?.longitude?:0.0
mCurrentAccracy = location?.radius?:0f
mCurrentLat = location?.latitude ?: 0.0
mCurrentLon = location?.longitude ?: 0.0
mCurrentAccracy = location?.radius ?: 0f
myLocationData = MyLocationData.Builder()
.accuracy(location?.radius?:0f) // 设置定位数据的精度信息,单位:米
.accuracy(location?.radius ?: 0f) // 设置定位数据的精度信息,单位:米
.direction(mCurrentDirection.toFloat()) // 此处设置开发者获取到的方向信息,顺时针0-360
.latitude(location?.latitude?:0.0)
.longitude(location?.longitude?:0.0)
.latitude(location?.latitude ?: 0.0)
.longitude(location?.longitude ?: 0.0)
.build()
this.setMyLocationData(myLocationData)
if (isFirstLoc) {
isFirstLoc = false
val ll = LatLng(location?.latitude?:0.0, location?.longitude?:0.0)
val ll = LatLng(location?.latitude ?: 0.0, location?.longitude ?: 0.0)
val builder = MapStatus.Builder()
builder.target(ll).zoom(14.0f)
this.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()))
......@@ -415,7 +441,7 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
val builder = MapStatus.Builder()
builder.target(latLng).zoom(18.5f).overlook(-21f).rotate(0f)
// 更新地图状态
mBaiduMap!!.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()),300)
mBaiduMap!!.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()), 300)
//mMarker.setPosition(latLng)
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment