2019-05-26

分视图显示导航

package com.amap.map3d.demo.basic;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.amap.api.maps.AMap;
import com.amap.api.maps.MapView;
import com.amap.api.maps.UiSettings;
import com.amap.map3d.demo.R;

/**
 * UI settings一些选项设置响应事件
 */
public class LogoSettingsActivity extends Activity implements View.OnClickListener {
    private AMap aMap;
    private MapView mapView;
    private UiSettings mUiSettings;

    private Button satBtn;
    private Button navBtn;
    private Button nightBtn;
    private Button normalBtn;
    private Button trafficBtn;
    private TextView tip;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.logo_settings_activity);

        tip=findViewById(R.id.tip);

        satBtn=findViewById(R.id.sat);
        navBtn=findViewById(R.id.nav);
        nightBtn=findViewById(R.id.night);
        normalBtn=findViewById(R.id.normal);
        trafficBtn=findViewById(R.id.traffic);

        satBtn.setOnClickListener(this);
        navBtn.setOnClickListener(this);
        nightBtn.setOnClickListener(this);
        normalBtn.setOnClickListener(this);
        trafficBtn.setOnClickListener(this);

        /*
         * 设置离线地图存储目录,在下载离线地图或初始化地图设置; 使用过程中可自行设置, 若自行设置了离线地图存储的路径,
         * 则需要在离线地图下载和使用地图页面都进行路径设置
         */
        // Demo中为了其他界面可以使用下载的离线地图,使用默认位置存储,屏蔽了自定义设置
        // MapsInitializer.sdcardDir =OffLineMapUtils.getSdCacheDir(this);


        //John: 指定离线地图的位置,默认为sdcard/amap下
        //设置完毕后,我的LG为"/storage/emulated/0/amapsdk/offlineMap/"
//      MapsInitializer.sdcardDir=OffLineMapUtils.getSdCacheDir(this);

        mapView = (MapView) findViewById(R.id.map);
        mapView.onCreate(savedInstanceState);// 此方法必须重写
        init();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.sat:
                aMap.setMapType(AMap.MAP_TYPE_SATELLITE);// 卫星地图模式
                tip.setText("卫星");
                break;
            case R.id.nav:
                aMap.setMapType(AMap.MAP_TYPE_NAVI);//导航地图模式
                tip.setText("导航");
                break;
            case R.id.night:
                aMap.setMapType(AMap.MAP_TYPE_NIGHT);//导航地图模式
                tip.setText("导航");
                break;
            case R.id.normal:
                aMap.setMapType(AMap.MAP_TYPE_NORMAL);//普通
                tip.setText("正常");
                break;
            case R.id.traffic:
                aMap.setMapType(AMap.MAP_TYPE_BUS);//交通模式
                tip.setText("交通");
                break;
        }
    }

    /**
     * 初始化AMap对象
     */
    private void init() {
        if (aMap == null) {
            aMap = mapView.getMap();
            mUiSettings = aMap.getUiSettings();

            //John: 并且距屏幕下边50px
            mUiSettings.setLogoBottomMargin(60);
            mUiSettings.setZoomControlsEnabled(true);
            mUiSettings.setIndoorSwitchEnabled(true);
            mUiSettings.setCompassEnabled(true);
            mUiSettings.setMyLocationButtonEnabled(true);
            mUiSettings.setScaleControlsEnabled(true);
            mUiSettings.setTiltGesturesEnabled(true);

            //此方式定位时,margin失效
            //mUiSettings.setLogoPosition(AMapOptions.LOGO_POSITION_BOTTOM_RIGHT);
        }

    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }
    /**
     * 方法必须重写
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }
}

转载于:https://www.jianshu.com/p/66d9695e5169

猜你喜欢

转载自blog.csdn.net/weixin_34007291/article/details/91215075