Commit 2ebe1a42 authored by fengruiyu's avatar fengruiyu

定位功能完成

vr全景功能已完成80%
parent 48a74b8d
...@@ -172,6 +172,7 @@ ...@@ -172,6 +172,7 @@
android:exported="false" android:exported="false"
android:screenOrientation="behind" android:screenOrientation="behind"
android:windowSoftInputMode="adjustResize|stateHidden" /> android:windowSoftInputMode="adjustResize|stateHidden" />
<activity android:name=".main.vr.PanoramicActivity"/>
</application> </application>
</manifest> </manifest>
\ No newline at end of file
package com.mints.street package com.mints.street
import android.content.Context
import android.os.StrictMode import android.os.StrictMode
import android.os.StrictMode.VmPolicy import android.os.StrictMode.VmPolicy
import android.util.Log import android.util.Log
import android.widget.Toast
import com.baidu.lbsapi.BMapManager
import com.baidu.mapapi.CoordType import com.baidu.mapapi.CoordType
import com.baidu.mapapi.SDKInitializer import com.baidu.mapapi.SDKInitializer
import com.cuieney.rxpay_annotation.WX import com.cuieney.rxpay_annotation.WX
import com.fry.base.base.BaseApp import com.fry.base.base.BaseApp
import com.mints.street.main.vr.PanoramicActivity
import com.mints.street.manager.CsjGroMoreManager import com.mints.street.manager.CsjGroMoreManager
import com.mints.street.manager.UmengManager import com.mints.street.manager.UmengManager
import me.goldze.mvvmhabit.utils.KLog
import java.util.concurrent.TimeoutException import java.util.concurrent.TimeoutException
/** /**
...@@ -54,10 +59,24 @@ class AppApplication : BaseApp() { ...@@ -54,10 +59,24 @@ class AppApplication : BaseApp() {
//自4.3.0起,百度地图SDK所有接口均支持百度坐标和国测局坐标,用此方法设置您使用的坐标类型. //自4.3.0起,百度地图SDK所有接口均支持百度坐标和国测局坐标,用此方法设置您使用的坐标类型.
//包括BD09LL和GCJ02两种坐标,默认是BD09LL坐标。 //包括BD09LL和GCJ02两种坐标,默认是BD09LL坐标。
SDKInitializer.setCoordType(CoordType.BD09LL) SDKInitializer.setCoordType(CoordType.BD09LL)
//百度全景
initEngineManager(this)
}
/**
* 初始化百度全景
*/
private fun initEngineManager(context: Context) {
if (mBMapManager == null) {
mBMapManager = BMapManager(context)
}
if (mBMapManager?.init(PanoramicActivity.MyGeneralListener())==false) {
KLog.e("BMapManager","BMapManager 初始化错误!")
}
} }
companion object { companion object {
var mContext: AppApplication? = null var mContext: AppApplication? = null
var mBMapManager: BMapManager? = null
fun getContext(): AppApplication? { fun getContext(): AppApplication? {
return mContext return mContext
......
...@@ -8,7 +8,9 @@ import com.fry.base.adapter.BindingViewHolder ...@@ -8,7 +8,9 @@ import com.fry.base.adapter.BindingViewHolder
import com.fry.base.binding.setMargin import com.fry.base.binding.setMargin
import com.mints.street.R import com.mints.street.R
import com.mints.street.databinding.ItemGridMapAdapterBinding import com.mints.street.databinding.ItemGridMapAdapterBinding
import com.mints.street.main.vr.PanoramicActivity
import me.goldze.mvvmhabit.utils.AppUtils import me.goldze.mvvmhabit.utils.AppUtils
import me.goldze.mvvmhabit.utils.RxUtils
/** /**
* Created by 冯瑞雨 on 2021/7/9. * Created by 冯瑞雨 on 2021/7/9.
...@@ -24,6 +26,11 @@ class GridMapAdapter(val context: Context,val list :List<String>):AbstractVLayo ...@@ -24,6 +26,11 @@ class GridMapAdapter(val context: Context,val list :List<String>):AbstractVLayo
}else{ }else{
holder.binding.bg.setMargin(0,AppUtils.dp2Px(context,10F),AppUtils.dp2Px(context,10F),0,null,null,null) holder.binding.bg.setMargin(0,AppUtils.dp2Px(context,10F),AppUtils.dp2Px(context,10F),0,null,null,null)
} }
RxUtils.onMultiClick(holder.binding.bg){
PanoramicActivity.starPanoramicActivity(context,""
,PanoramicActivity.WGS84,lat =39.906283536127169,lon = 116.39129554889048 )
}
} }
override fun getItemCount() = list.size override fun getItemCount() = list.size
......
package com.mints.street.main.vr
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.Window
import com.baidu.lbsapi.BMapManager
import com.baidu.lbsapi.MKGeneralListener
import com.baidu.lbsapi.panoramaview.PanoramaView
import com.baidu.lbsapi.panoramaview.PanoramaViewListener
import com.fry.base.base.BaseActivity
import com.mints.street.AppApplication
import com.mints.street.BR
import com.mints.street.R
import com.mints.street.databinding.ActivityPanoramicBinding
import me.goldze.mvvmhabit.base.AppManager
import me.goldze.mvvmhabit.utils.KLog
/**
* Created by 冯瑞雨 on 2021/7/12.
* 全景页面
*/
class PanoramicActivity : BaseActivity<ActivityPanoramicBinding, PanoramicViewModel>() {
companion object {
const val PID = 0 // PID方式
const val GEO = 1 // 经纬度方式
const val MERCATOR = 2 // 墨卡托方式
const val UID_STREET = 3 // UID方式展示外景
const val UID_INTERIOR = 4 // UID方式展示内景
const val UID_STREET_CUSTOMALBUM = 5 // UID方式展示外景(使用自定义相册)
const val MARKER = 6 // 标注
const val OTHER = 7 // 其他测试
const val COORDINATE_CONVERTER = 8 // 坐标转换测试
const val WGS84 = 9 // 大地坐标系方式
const val GCJ02 = 10 // 国测局加密方式
fun starPanoramicActivity(
context: Context,
name: String,
type: Int,
pid: String? = null,
lon: Double? = null,
lat: Double? = null
) {
val intent = Intent(context,PanoramicActivity::class.java)
intent.putExtra("name",name)
intent.putExtra("type",type)
intent.putExtra("pid",pid)
intent.putExtra("lon",lon)
intent.putExtra("lat",lat)
context.startActivity(intent)
}
}
internal class MyGeneralListener : MKGeneralListener {
override fun onGetPermissionState(iError: Int) {
// 非零值表示key验证未通过
if (iError != 0) {
// 授权Key错误:
KLog.e(
"BMapManager",
"请在AndoridManifest.xml中输入正确的授权Key,并检查您的网络连接是否正常!error: $iError"
)
} else {
KLog.a("BMapManager", "key认证成功")
}
}
}
override fun initContentView(savedInstanceState: Bundle?) = R.layout.activity_panoramic
override fun initVariableId() = BR.viewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//requestWindowFeature(Window.FEATURE_NO_TITLE)
initBMapManager()
}
override fun initData() {
super.initData()
val intent = intent
if (intent != null) {
testPanoByType(
name = intent.getStringExtra("name") ?: "全景",
type = intent.getIntExtra("type", -1),
pid = intent.getStringExtra("pid"),
lon = intent.getDoubleExtra("lon", 0.0),
lat = intent.getDoubleExtra("lat", 0.0)
)
}
}
private fun initBMapManager() {
if (AppApplication.mBMapManager == null) {
AppApplication.mBMapManager = BMapManager(AppApplication.mContext)
AppApplication.mBMapManager?.init(MyGeneralListener())
}
}
/**
* 加载全景
* @param name 标题名称 必填
* @param type type类型 必选
* @param pid 百度pid 非必填
* @param lon 纬度 非必填
* @param lat 经度 非必填
*/
private fun testPanoByType(
name: String,
type: Int,
pid: String? = null,
lon: Double? = null,
lat: Double? = null
) {
KLog.e("PanoramicActivity", "测试--------------- $name $type $pid $lon $lat")
if (type == -1) {
KLog.e("PanoramicActivity", "错误类型")
return
}
binding.panorama.setShowTopoLink(true)
// 测试回调函数,需要注意的是回调函数要在setPanorama()之前调用,否则回调函数可能执行异常
binding.panorama.setPanoramaViewListener(object : PanoramaViewListener {
override fun onDescriptionLoadEnd(p0: String?) {
KLog.i("PanoramicActivity", "onLoadPanoramaStart...")
}
override fun onLoadPanoramaBegin() {
KLog.i("PanoramicActivity", "onLoadPanoramaBegin...")
}
override fun onLoadPanoramaEnd(p0: String?) {
KLog.i("PanoramicActivity", "onLoadPanoramaEnd...")
}
override fun onLoadPanoramaError(p0: String?) {
}
override fun onMessage(p0: String?, p1: Int) {
}
override fun onCustomMarkerClick(p0: String?) {
}
override fun onMoveStart() {
}
override fun onMoveEnd() {
}
})
binding.ctbTitle.setTitle(name)
when (type) {
//通过百度全景ID(PID)获取全景
PID -> {
if (pid == null) {
return
}
binding.panorama.setPanoramaImageLevel(
PanoramaView.ImageDefinition.ImageDefinitionHigh
)
binding.panorama.setPanorama(pid)
}
//通过大地坐标系(WGS84)获取全景
WGS84 -> {
if (lon == null || lat == null || lon <= 0 || lat <= 0) {
return
}
binding.panorama.setPanoramaImageLevel(
PanoramaView.ImageDefinition.ImageDefinitionMiddle
)
binding.panorama.setPanorama(lon, lat, PanoramaView.COORDTYPE_WGS84)
}
//通过国测局加密坐标(GCJ02)获取全景
GCJ02 -> {
if (lon == null || lat == null || lon <= 0 || lat <= 0) {
return
}
binding.panorama.setPanoramaImageLevel(
PanoramaView.ImageDefinition.ImageDefinitionMiddle
)
binding.panorama.setPanorama(lon, lat, PanoramaView.COORDTYPE_GCJ02)
}
//通过百度经纬度坐标(BD09LL)获取全景
GEO -> {
if (lon == null || lat == null || lon <= 0 || lat <= 0) {
return
}
binding.panorama.setPanoramaImageLevel(
PanoramaView.ImageDefinition.ImageDefinitionMiddle
)
binding.panorama.setPanorama(lon, lat, PanoramaView.COORDTYPE_BD09LL)
}
//通过百度墨卡托坐标(BD09MC)获取全景
MERCATOR -> {
if (lon == null || lat == null || lon <= 0 || lat <= 0) {
return
}
binding.panorama.setPanoramaImageLevel(
PanoramaView.ImageDefinition.ImageDefinitionMiddle
)
binding.panorama.setPanorama(
lon, lat,
PanoramaView.COORDTYPE_BD09MC
)
}
}
}
}
\ No newline at end of file
package com.mints.street.main.vr
import android.app.Application
import me.goldze.mvvmhabit.base.BaseViewModel
/**
* Created by 冯瑞雨 on 2021/7/12.
*/
class PanoramicViewModel(application: Application):BaseViewModel(application) {
}
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<data> <data>
<variable <variable
name="ViewModel" name="viewModel"
type="com.mints.street.main.my.AboutusViewModel" /> type="com.mints.street.main.my.AboutusViewModel" />
</data> </data>
<RelativeLayout <RelativeLayout
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<data> <data>
<variable <variable
name="ViewModel" name="viewModel"
type="com.mints.street.main.my.MoresettingsViewModel" /> type="com.mints.street.main.my.MoresettingsViewModel" />
</data> </data>
......
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com.mints.street.main.vr.PanoramicViewModel" />
</data>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<com.fry.base.ui.widget.CommonTitleBar
android:id="@+id/ctb_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:ctb_theme="dark"
app:ctb_title="全景"
app:layout_constraintTop_toTopOf="parent"/>
<com.baidu.lbsapi.panoramaview.PanoramaView
android:id="@+id/panorama"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true" />
</LinearLayout>
</layout>
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<data> <data>
<variable <variable
name="ViewModel" name="viewModel"
type="com.mints.street.main.my.PermissionsViewModel" /> type="com.mints.street.main.my.PermissionsViewModel" />
</data> </data>
......
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