Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_freeworld
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
android
android_freeworld
Commits
a59fc2ca
Commit
a59fc2ca
authored
Aug 10, 2021
by
fengruiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
百度地图的sdk 地图缩放不移动,移动不缩放功能已完成
parent
d1913046
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
98 additions
and
64 deletions
+98
-64
DialogMapTailAdapter.kt
...ain/java/com/mints/street/adapter/DialogMapTailAdapter.kt
+1
-2
GridMapAdapter.kt
app/src/main/java/com/mints/street/adapter/GridMapAdapter.kt
+0
-6
HistoryRecordAdapter.kt
...ain/java/com/mints/street/adapter/HistoryRecordAdapter.kt
+1
-1
MainActivity.kt
app/src/main/java/com/mints/street/main/MainActivity.kt
+20
-5
HomeFragment.kt
app/src/main/java/com/mints/street/main/home/HomeFragment.kt
+76
-50
No files found.
app/src/main/java/com/mints/street/adapter/DialogMapTailAdapter.kt
View file @
a59fc2ca
...
...
@@ -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
{
...
...
app/src/main/java/com/mints/street/adapter/GridMapAdapter.kt
View file @
a59fc2ca
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
/**
...
...
app/src/main/java/com/mints/street/adapter/HistoryRecordAdapter.kt
View file @
a59fc2ca
...
...
@@ -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
...
...
app/src/main/java/com/mints/street/main/MainActivity.kt
View file @
a59fc2ca
...
...
@@ -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
->
{
//广场
...
...
app/src/main/java/com/mints/street/main/home/HomeFragment.kt
View file @
a59fc2ca
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment