Commit 474f8297 authored by fengruiyu's avatar fengruiyu

地图样式的功能已完成

景点推荐的功能已完成
街景地图的功能已完成
js->android 的.弹出景点弹框已完成(展示页面已完成)
地图的小icon布局修改
parent f9dcd277
......@@ -26,6 +26,6 @@
"name": "常用"
}
],
"isRecommendedPlaces": true,
"isStreetViewMap": false
"isRecommendedPlaces": false,
"isStreetViewMap": true
}
......@@ -204,6 +204,7 @@ connectWebViewJavascriptBridge(function (bridge) {
});
bridge.registerHandler("showScenics", function (data, responseCallback) {
data = JSON.parse(data)
console.log('ksssssssssssssssssss',data)
vm.doShowScenics(data.list);
responseCallback(getVmMsg("suc:showScenics"));
});
......
......@@ -41,7 +41,7 @@ class DialogMapContentAdapter(val context: Context, var list: List<MapStyleList>
it.isSelected = false
}
list?.get(position)?.isSelected =true
onItemMapStyleChange?.onItemChange()
onItemMapStyleChange?.onItemChange(list?.get(position)?.img?:0)
notifyDataSetChanged()
}
......@@ -58,6 +58,6 @@ class DialogMapContentAdapter(val context: Context, var list: List<MapStyleList>
override fun getLayoutId(viewType: Int) = R.layout.dialog_map_content_item
interface OnItemMapStyleChange{
fun onItemChange()
fun onItemChange(type:Int)
}
}
\ No newline at end of file
......@@ -29,13 +29,13 @@ class DialogMapTailAdapter(val context: Context, private var mapStyleBean: MapS
override fun toggleToOn(view: SwitchView) {
mapStyleBean?.isRecommendedPlaces = !view.isOpened
view.isOpened = !view.isOpened
onDataChange?.onDataChange()
onDataChange?.onRecommendedPlacesChange(view.isOpened)
}
override fun toggleToOff(view: SwitchView) {
mapStyleBean?.isRecommendedPlaces = !view.isOpened
view.isOpened = !view.isOpened
onDataChange?.onDataChange()
onDataChange?.onRecommendedPlacesChange(view.isOpened)
}
})
holder.binding.svStreetView.setOnStateChangedListener(object :
......@@ -43,13 +43,13 @@ class DialogMapTailAdapter(val context: Context, private var mapStyleBean: MapS
override fun toggleToOn(view: SwitchView) {
mapStyleBean?.isStreetViewMap = !view.isOpened
view.isOpened = !view.isOpened
onDataChange?.onDataChange()
onDataChange?.onStreetViewMapChange( view.isOpened)
}
override fun toggleToOff(view: SwitchView) {
mapStyleBean?.isStreetViewMap = !view.isOpened
view.isOpened = !view.isOpened
onDataChange?.onDataChange()
onDataChange?.onStreetViewMapChange( view.isOpened)
}
......@@ -64,6 +64,7 @@ class DialogMapTailAdapter(val context: Context, private var mapStyleBean: MapS
override fun getLayoutId(viewType: Int) = R.layout.dialog_map_tail_item
interface OnDataChange{
fun onDataChange()
fun onRecommendedPlacesChange(isSelected:Boolean)
fun onStreetViewMapChange(isSelected:Boolean)
}
}
\ No newline at end of file
......@@ -145,9 +145,4 @@ interface MainApi {
@POST("na/getAttractionsList")
fun getHotView(@Body vo:@JvmSuppressWildcards Map<String,Any>):Observable<Response<BaseResponse<HotViewBean>>>
/**
* 景点推荐
*/
@POST("na/getAttractionsList")
fun getViewRecommed(@Body vo:@JvmSuppressWildcards Map<String,Any>):Observable<Response<BaseResponse<ViewRecommed>>>
}
\ No newline at end of file
......@@ -9,4 +9,6 @@ class MutualBean {
var lat:String?=null
var lng:String?=null
var inner:Int=0
var show:Int=0//展示地图的选择地址按钮
var type:String?=null//切换图层 hybrid=卫星路网混合 'roadmap'=路网图 'satellite’=卫星图 'terrain'=地形图
}
\ No newline at end of file
package com.mints.street.bean
import java.io.Serializable
class ViewRecommed : Serializable {
val list: List<dataslist>? = null
inner class dataslist : Serializable {
val desc: String? = null
val img: String? = null
val lat: String? = null
val lng: String? = null
val name: String? = null
}
}
package com.mints.street.bean
/**
* Created by 冯瑞雨 on 2021/8/13.
*/
class ViewRecommedBean {
val desc: String? = null
val img: String? = null
val lat: String? = null
val lng: String? = null
val name: String? = null
val distance: Double? = null
// blng:百度经度
val blng: String? = null
// blat:百度纬度
val blat: String? = null
// bvid: 全景id
val bvid: String? = null
}
\ No newline at end of file
......@@ -20,6 +20,7 @@ import com.mints.street.R
import com.mints.street.bean.GPS
import com.mints.street.bean.HotViewBean
import com.mints.street.bean.MutualBean
import com.mints.street.bean.ViewRecommedBean
import com.mints.street.databinding.ActivityGoogleMapBinding
import com.mints.street.main.home.HomeViewModel
import com.mints.street.main.home.SearchMapActivity
......@@ -27,6 +28,7 @@ import com.mints.street.webview.MintsWebViewActivity
import com.mints.street.widget.ScrollLayout
import com.mints.street.widget.dialog.DialogMapStyle
import com.mints.street.widget.dialog.HotViewDialog
import com.mints.street.widget.dialog.ViewRecommedDialog
import me.goldze.mvvmhabit.base.AppManager
import me.goldze.mvvmhabit.utils.CommonDialogUtils
import me.goldze.mvvmhabit.utils.KLog
......@@ -144,6 +146,16 @@ class GoogleMapFragment() : BaseFragment<ActivityGoogleMapBinding, HomeViewModel
binding.webview.registerHandler("allIsOk") { _, _ ->
initZsMap()
}
//android->js 景点推荐 弹出景点弹框
binding.webview.registerHandler("openScenicsFrame") { data, _ ->
var bean: ViewRecommedBean? = null
try {
bean = Gson().fromJson(data, ViewRecommedBean::class.java)
} catch (e: Exception) {
KLog.e("实体类转换错误")
}
ViewRecommedDialog(context,bean,gps,viewModel).init().show()
}
viewModel.getMapBean()
//定位
......@@ -172,7 +184,28 @@ class GoogleMapFragment() : BaseFragment<ActivityGoogleMapBinding, HomeViewModel
RxUtils.onMultiClick(binding.imageMapChangeIcon) {
context?.apply {
if (dialogMapStyle == null) {
dialogMapStyle = DialogMapStyle(this,viewModel.mapStyleSortBean)
dialogMapStyle = DialogMapStyle(this,viewModel.mapStyleSortBean.value,
object :DialogMapStyle.OnMapStyleDataChange{
override fun onMapStyleItemChange(type: Int) {
changeMapType(type)
}
override fun onRecommendedPlacesChange(isSelected: Boolean) {
if (isSelected){
if(viewModel.viewRecommed.value==null){
viewModel.getviewrecommend()
}else{
openScenics(viewModel.viewRecommed.value)
}
}else{
closeScenics()
}
}
override fun onStreetViewMapChange(isSelected: Boolean) {
changeVrButton(isSelected)
}
})
}
if (this@GoogleMapFragment.fragmentManager != null) {
dialogMapStyle?.show(this@GoogleMapFragment.fragmentManager!!, "dialogMapStyle")
......@@ -211,9 +244,11 @@ class GoogleMapFragment() : BaseFragment<ActivityGoogleMapBinding, HomeViewModel
/**
* 开关街景按钮
*/
private fun changeVrButton(){
private fun changeVrButton(isShow:Boolean){
var mutualBean=MutualBean()
mutualBean.show= if (isShow)1 else 0
binding.webview.callHandler("changeVrButton"
,Gson().toJson(gps) ) {
,Gson().toJson(mutualBean) ) {
}
}
......@@ -221,9 +256,9 @@ class GoogleMapFragment() : BaseFragment<ActivityGoogleMapBinding, HomeViewModel
* 调用JS方法
* 开启景点
*/
private fun openScenics(){
binding.webview.callHandler("openScenics"
,Gson().toJson(gps) ) {
private fun openScenics(bean :HotViewBean?){
binding.webview.callHandler("showScenics"
,Gson().toJson(bean) ) {
}
}
/**
......@@ -235,6 +270,22 @@ class GoogleMapFragment() : BaseFragment<ActivityGoogleMapBinding, HomeViewModel
,null ) {
}
}
/**
* 调用JS方法
* 切换图层
*/
private fun changeMapType(type:Int=0){
var mutualBean=MutualBean()
when(type){
1->mutualBean.type="hybrid"
2->mutualBean.type="roadmap"
3->mutualBean.type="satellite"
4->mutualBean.type="terrain"
}
binding.webview.callHandler("changeMapType"
,Gson().toJson(mutualBean) ) {
}
}
private fun initPosition() {
//定位
......@@ -303,11 +354,16 @@ class GoogleMapFragment() : BaseFragment<ActivityGoogleMapBinding, HomeViewModel
viewModel.mapStyleSortBean.observe(this, Observer {
it?.apply {
dialogMapStyle?.apply {
this.mapStyleBean = viewModel.mapStyleSortBean
this.mapStyleBean = it
}
}
})
viewModel.viewRecommed.observe(this, Observer {
it?.apply {
openScenics(this)
}
})
}
override fun onDestroy() {
super.onDestroy()
......
......@@ -32,7 +32,6 @@ import com.mints.street.widget.dialog.DialogMapStyle
import com.mints.street.widget.dialog.DialogUtils
import com.mints.street.widget.dialog.DialogUtils.showupgradevipDialog
import com.mints.street.widget.dialog.HotViewDialog
import com.mints.street.widget.dialog.ViewRecommedDialog
import me.goldze.mvvmhabit.base.AppManager
import me.goldze.mvvmhabit.utils.KLog
import me.goldze.mvvmhabit.utils.RxUtils
......@@ -44,14 +43,6 @@ import me.goldze.mvvmhabit.utils.SPUtils
*/
class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorEventListener {
private val viewrecommedDialog by lazy {
ViewRecommedDialog(
requireActivity(),
viewModel,
this
).init()
}
companion object {
val IS_FIRST_OPEN: String = "isFirstOpen"
}
......
......@@ -198,11 +198,6 @@ class HomeViewModel(application: Application) : BaseViewModel(application) {
override fun onBusinessSuccess(response: BaseResponse<HotViewBean>) {
hotviewData.value = response.result
}
override fun onError(e: Throwable) {
super.onError(e)
}
}
)
}
......@@ -210,25 +205,18 @@ class HomeViewModel(application: Application) : BaseViewModel(application) {
/**
* 获取景点推荐数据
*/
var viewRecommed=MutableLiveData<ViewRecommed>()
var viewRecommed=MutableLiveData<HotViewBean?>()
fun getviewrecommend(){
val vo = HashMap<String, Any>()
//2-景点推荐 3-热门景点
vo["type"] = 2
ApiModel.getViewRecommed(lifecycleProvider,vo).safeSubscribe(
object : HttpSubscribeImpl<BaseResponse<ViewRecommed>>(
ApiModel.getHotView(lifecycleProvider,vo).safeSubscribe(
object : HttpSubscribeImpl<BaseResponse<HotViewBean>>(
this@HomeViewModel, true) {
override fun onBusinessSuccess(response: BaseResponse<ViewRecommed>) {
override fun onBusinessSuccess(response: BaseResponse<HotViewBean>) {
viewRecommed.value = response.result
KLog.e("getmyInfo", response.result.toString())
}
override fun onError(e: Throwable) {
super.onError(e)
KLog.e("getmyInfo", "用户登录信息请求失败")
}
}
)
}
......
......@@ -153,10 +153,4 @@ object ApiModel {
return HttpManager.getInstance().execute(lifecycleProvider,MainApi.newInstance().getHotView(map))
}
/**
* 请求景点推荐数据
*/
fun getViewRecommed(lifecycleProvider: LifecycleProvider<Any>?, map: Map<String, Any>):Observable<Response<BaseResponse<ViewRecommed>>>{
return HttpManager.getInstance().execute(lifecycleProvider,MainApi.newInstance().getViewRecommed(map))
}
}
\ No newline at end of file
......@@ -24,7 +24,7 @@ import com.mints.street.bean.MapStyleSortBean
*/
class DialogMapStyle(
var mContext: Context,
var mapStyleBean: MutableLiveData<MapStyleSortBean>?
var mapStyleBean: MapStyleSortBean?,val onMapStyleDataChange :OnMapStyleDataChange?=null
) : BaseDialogFragment() {
private var recycler: RecyclerView? = null
private var vLayout: VirtualLayoutManager? = null
......@@ -63,13 +63,13 @@ class DialogMapStyle(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
mapStyleBean?.value?.mapStyleSort?.forEach {
mapStyleBean?.mapStyleSort?.forEach {
mAdapter?.addAdapter(DialogMapHeadAdapter(mContext, it.name))
mAdapter?.addAdapter(
DialogMapContentAdapter(mContext, it.mapStyleList,
object : DialogMapContentAdapter.OnItemMapStyleChange {
override fun onItemChange() {
mapStyleBean?.value = mapStyleBean?.value
override fun onItemChange(type: Int) {
onMapStyleDataChange?.onMapStyleItemChange(type)
}
})
)
......@@ -77,15 +77,23 @@ class DialogMapStyle(
mAdapter?.addAdapter(DialogMapHeadAdapter(mContext, "地图设置"))
mAdapter?.addAdapter(
DialogMapTailAdapter(mContext, mapStyleBean?.value,
DialogMapTailAdapter(mContext, mapStyleBean,
object : DialogMapTailAdapter.OnDataChange {
override fun onDataChange() {
mapStyleBean?.value = mapStyleBean?.value
override fun onRecommendedPlacesChange(isSelected: Boolean) {
onMapStyleDataChange?.onRecommendedPlacesChange(isSelected)
}
override fun onStreetViewMapChange(isSelected: Boolean) {
onMapStyleDataChange?.onStreetViewMapChange(isSelected)
}
})
)
}
interface OnMapStyleDataChange{
fun onMapStyleItemChange(type:Int)
fun onRecommendedPlacesChange(isSelected: Boolean)
fun onStreetViewMapChange(isSelected: Boolean)
}
}
package com.mints.street.widget.dialog
import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.vlayout.DelegateAdapter
import com.alibaba.android.vlayout.VirtualLayoutManager
import com.baidu.mapapi.model.LatLng
import com.baidu.mapapi.utils.DistanceUtil
import com.fry.base.utils.ImageLoader
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.mints.street.R
import com.mints.street.adapter.ItemHotViewAdapter
import com.mints.street.bean.GPS
import com.mints.street.bean.ViewRecommedBean
import com.mints.street.main.home.HomeFragment
import com.mints.street.main.home.HomeViewModel
import com.mints.street.webview.MintsWebViewActivity
import com.mints.street.widget.GridItemDecoration
import com.mints.street.widget.XCRoundRectImageView
import me.goldze.mvvmhabit.utils.RxUtils
import java.text.DecimalFormat
class ViewRecommedDialog (context: FragmentActivity, viewModel: HomeViewModel, homeFragment: HomeFragment) {
class ViewRecommedDialog (context: Context?, bean: ViewRecommedBean?,gps:GPS?,homeViewModel: HomeViewModel) {
private var mBottomSheetDialog: BottomSheetDialog?=null
private var context: FragmentActivity
private var viewModel: HomeViewModel?=null
private var homeFragment: HomeFragment?=null
private var context: Context?=null
private var bean: ViewRecommedBean?=null
private var homeViewModel: HomeViewModel?=null
private var gps: GPS?=null
init {
this.context=context
this.viewModel=viewModel
this.homeFragment=homeFragment
this.bean=bean
this.gps=gps
this.homeViewModel=homeViewModel
}
//
fun init(): ViewRecommedDialog {
//创建弹窗
if (mBottomSheetDialog!=null) return this
mBottomSheetDialog= BottomSheetDialog(context)
mBottomSheetDialog= BottomSheetDialog(context!!)
val view1: View = LayoutInflater.from(context).inflate(R.layout.layout_viewrecommed,null)
mBottomSheetDialog!!.setContentView(view1)
mBottomSheetDialog!!.window!!.findViewById<View>(R.id.design_bottom_sheet).setBackgroundColor(Color.TRANSPARENT)
val iv_close: ImageView =view1.findViewById(R.id.iv_close)
val recycler_view: RecyclerView =view1.findViewById(R.id.recycler_view)
val viewname: TextView =view1.findViewById(R.id.viewname)
val tvDistance: TextView =view1.findViewById(R.id.tv_distance)
val image1: XCRoundRectImageView =view1.findViewById(R.id.image1)
val tvDescribe: TextView =view1.findViewById(R.id.tv_describe)
val textView5: TextView =view1.findViewById(R.id.textView5)
viewModel?.getHotView()
viewModel?.hotviewData?.observe(homeFragment!!, androidx.lifecycle.Observer {
viewname.text = bean?.name
val a = DistanceUtil.getDistance(LatLng(bean?.blat?.toDouble()?:0.0,
bean?.blng?.toDouble()?:0.0) ,LatLng(
gps?.lat?:0.0,gps?.lng?:0.0))
tvDistance.text = "距离${DecimalFormat("0.00").format(a/1000).toString()}km"
ImageLoader.ImageBuilder.with(context)
.setUrl(bean?.img).setTargetView(image1).start()
tvDescribe.text = bean?.desc
RxUtils.onMultiClick(textView5){
homeViewModel?.authorized( bean?.bvid,bean?.name)
})
iv_close.setOnClickListener{
mBottomSheetDialog!!.dismiss()
}
return this
}
......
......@@ -25,8 +25,8 @@
<ImageView
android:visibility="gone"
android:id="@+id/image_map_history"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="15dp"
android:src="@mipmap/map_history_icon"
app:layout_constraintEnd_toEndOf="parent"
......@@ -34,8 +34,8 @@
<ImageView
android:id="@+id/image_location_icon"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginBottom="220dp"
android:layout_marginTop="15dp"
android:src="@mipmap/location_icon"
......@@ -44,18 +44,18 @@
<ImageView
android:id="@+id/image_map_change_icon"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginBottom="220dp"
android:layout_marginTop="35dp"
android:layout_marginTop="40dp"
android:src="@mipmap/map_change_icon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<ImageView
android:id="@+id/ly_hotview"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="3dp"
android:layout_marginTop="10dp"
android:src="@mipmap/icon_hotview"
......@@ -64,8 +64,8 @@
<LinearLayout
android:id="@+id/map_a_d"
android:layout_width="31dp"
android:layout_height="63dp"
android:layout_width="36dp"
android:layout_height="73dp"
android:layout_marginBottom="10dp"
android:layout_marginEnd="2dp"
android:background="@drawable/shape_gold_card"
......@@ -77,24 +77,26 @@
<ImageView
android:id="@+id/image_in"
android:layout_width="31dp"
android:layout_height="31dp"
android:layout_width="36dp"
android:layout_height="36dp"
android:padding="10dp"
android:src="@mipmap/scale_add_icon" />
<View
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginEnd="12dp"
android:layout_marginStart="12dp"
android:background="@color/color_333" />
<ImageView
android:id="@+id/image_out"
android:layout_width="31dp"
android:layout_height="31dp"
android:layout_width="36dp"
android:layout_height="36dp"
android:padding="10dp"
android:src="@mipmap/scale_shrink_icon" />
<View
android:layout_width="wrap_content"
android:layout_height="0.5dp"
android:layout_marginEnd="12dp"
android:layout_marginStart="12dp"
android:background="@color/color_333" />
</LinearLayout>
......
......@@ -31,8 +31,8 @@
<ImageView
android:id="@+id/image_map_history"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="25dp"
android:src="@mipmap/map_history_icon"
android:visibility="gone"
......@@ -41,8 +41,8 @@
<ImageView
android:id="@+id/ly_hotview"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="3dp"
android:layout_marginTop="10dp"
android:src="@mipmap/icon_hotview"
......@@ -51,8 +51,8 @@
<ImageView
android:id="@+id/image_location_icon"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="220dp"
android:src="@mipmap/location_icon"
......@@ -60,8 +60,8 @@
app:layout_constraintEnd_toEndOf="parent" />
<ImageView
android:id="@+id/image_map_change_icon"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginBottom="220dp"
android:layout_marginTop="35dp"
android:src="@mipmap/map_change_icon"
......@@ -71,8 +71,8 @@
<LinearLayout
android:id="@+id/map_a_d"
android:layout_width="31dp"
android:layout_height="63dp"
android:layout_width="36dp"
android:layout_height="73dp"
android:layout_marginEnd="2dp"
android:layout_marginBottom="10dp"
android:background="@drawable/shape_gold_card"
......@@ -82,24 +82,25 @@
<ImageView
android:id="@+id/image_in"
android:layout_width="31dp"
android:layout_height="31dp"
android:layout_width="36dp"
android:layout_height="36dp"
android:padding="10dp"
android:src="@mipmap/scale_add_icon" />
<View
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:background="@color/color_333" />
<ImageView
android:id="@+id/image_out"
android:layout_width="31dp"
android:layout_height="31dp"
android:layout_width="36dp"
android:layout_height="36dp"
android:padding="10dp"
android:src="@mipmap/scale_shrink_icon" />
<View
android:layout_width="wrap_content"
android:layout_height="0.5dp"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:background="@color/color_333" />
</LinearLayout>
......
......@@ -12,7 +12,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:text="景点名称"
tools:text="景点名称"
android:textColor="@color/black"
android:textSize="18dp"
app:layout_constraintStart_toStartOf="parent"
......@@ -33,7 +33,6 @@
android:id="@+id/tv_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="距离"
android:textColor="#99000000"
android:textSize="14dp"
app:layout_constraintBottom_toBottomOf="@+id/viewname"
......@@ -61,7 +60,6 @@
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_marginTop="10dp"
android:src="@mipmap/icon_card6"
app:layout_constraintEnd_toEndOf="@+id/textView5"
app:layout_constraintStart_toStartOf="@+id/viewname"
app:layout_constraintTop_toBottomOf="@+id/viewname"
......
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