166 lines
4.7 KiB
Java
166 lines
4.7 KiB
Java
package com.mogo.map;
|
|
|
|
import android.content.Context;
|
|
import android.os.Bundle;
|
|
import android.util.AttributeSet;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.FrameLayout;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import com.mogo.map.impl.amap.AMapBaseMapView;
|
|
import com.mogo.map.impl.amap.uicontroller.AMapUIController;
|
|
import com.mogo.map.impl.custom.CustomMapView;
|
|
import com.mogo.utils.logger.Logger;
|
|
|
|
/**
|
|
* @author congtaowang
|
|
* @since 2019-12-18
|
|
* <p>
|
|
* 地图实例
|
|
*/
|
|
public class MogoMapView extends MogoBaseMapView implements ILifeCycle {
|
|
|
|
private static final String TAG = "MogoMapView";
|
|
|
|
public MogoMapView( Context context ) {
|
|
super( context );
|
|
}
|
|
|
|
public MogoMapView( Context context, @Nullable AttributeSet attrs ) {
|
|
super( context, attrs );
|
|
}
|
|
|
|
public MogoMapView( Context context, @Nullable AttributeSet attrs, int defStyleAttr ) {
|
|
super( context, attrs, defStyleAttr );
|
|
}
|
|
|
|
private boolean mIsVrMode = false;
|
|
|
|
@Override
|
|
protected void addDleMaps() {
|
|
|
|
display2DMap( true, true );
|
|
}
|
|
|
|
private void addAMapView(){
|
|
mAMapView = new AMapBaseMapView().create( getContext() );
|
|
if ( mAMapView != null ) {
|
|
final View mapView = mAMapView.getMapView();
|
|
if ( mapView != null ) {
|
|
addView( mapView, new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ) );
|
|
} else {
|
|
Logger.e( TAG, "create MapView instance failed." );
|
|
}
|
|
} else {
|
|
Logger.e( TAG, "create IMogoMapView instance failed." );
|
|
}
|
|
}
|
|
|
|
private void addVrMapView(){
|
|
mCustomMapView = new CustomMapView().create( getContext() );
|
|
if ( mCustomMapView != null ) {
|
|
final View mapView = mCustomMapView.getMapView();
|
|
if ( mapView != null ) {
|
|
addView( mapView, new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ) );
|
|
} else {
|
|
Logger.e( TAG, "create MapView instance failed." );
|
|
}
|
|
} else {
|
|
Logger.e( TAG, "create IMogoMapView instance failed." );
|
|
}
|
|
mCustomMapView.onCreate( null );
|
|
}
|
|
|
|
private void removeVrMapView(){
|
|
try {
|
|
mCustomMapView.onDestroy();
|
|
removeView( mCustomMapView.getMapView() );
|
|
} catch ( Exception e ) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
private void removeAMapView(){
|
|
try {
|
|
mAMapView.onPause();
|
|
removeView( mAMapView.getMapView() );
|
|
} catch ( Exception e ) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void display2DMap( boolean invokeCreateAuto, boolean invokeResumeAuto ) {
|
|
mIsVrMode = false;
|
|
MogoMarkerManager.getInstance( getContext() ).removeMarkers();
|
|
removeVrMapView();
|
|
addAMapView();
|
|
mMapView = mAMapView;
|
|
MogoMap.getInstance().init( getContext(), mMapView.getMap() );
|
|
MogoMapUIController.getInstance().setDelegate( AMapUIController.getInstance() );
|
|
mAMapView.onResume();
|
|
}
|
|
|
|
@Override
|
|
public void displayVRMap( boolean invokeCreateAuto, boolean invokeResumeAuto ) {
|
|
mIsVrMode = true;
|
|
MogoMarkerManager.getInstance( getContext() ).removeMarkers();
|
|
removeAMapView();
|
|
addVrMapView();
|
|
mMapView = mCustomMapView;
|
|
MogoMap.getInstance().init( getContext(), mMapView.getMap() );
|
|
MogoMapUIController.getInstance().setDelegate( com.mogo.map.impl.custom.uicontroller.AMapUIController.getInstance() );
|
|
mCustomMapView.onResume();
|
|
post( new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
try {
|
|
getMap().getUIController().showMyLocation( true );
|
|
} catch ( Exception e ) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
} );
|
|
}
|
|
|
|
public boolean isVrMode() {
|
|
return mIsVrMode;
|
|
}
|
|
|
|
@Override
|
|
public void onCreate( Bundle bundle ) {
|
|
super.onCreate( bundle );
|
|
Logger.d( TAG, "onCreate" );
|
|
}
|
|
|
|
@Override
|
|
public void onResume() {
|
|
super.onResume();
|
|
Logger.d( TAG, "onResume" );
|
|
}
|
|
|
|
@Override
|
|
public void onPause() {
|
|
super.onPause();
|
|
Logger.d( TAG, "onPause" );
|
|
}
|
|
|
|
@Override
|
|
public void onDestroy() {
|
|
super.onDestroy();
|
|
Logger.d( TAG, "onDestroy" );
|
|
}
|
|
|
|
@Override
|
|
public void onSaveInstanceState( Bundle outState ) {
|
|
super.onSaveInstanceState( outState );
|
|
}
|
|
|
|
@Override
|
|
public void onLowMemory() {
|
|
super.onLowMemory();
|
|
}
|
|
}
|