完成了小地图
This commit is contained in:
@@ -8,6 +8,15 @@ import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.CameraUpdate;
|
||||
import com.amap.api.maps.CameraUpdateFactory;
|
||||
import com.amap.api.maps.TextureMapView;
|
||||
import com.amap.api.maps.UiSettings;
|
||||
import com.amap.api.maps.model.BitmapDescriptor;
|
||||
import com.amap.api.maps.model.BitmapDescriptorFactory;
|
||||
import com.amap.api.maps.model.CustomMapStyleOptions;
|
||||
import com.amap.api.maps.model.MyLocationStyle;
|
||||
import com.mogo.module.common.view.RoundLayout;
|
||||
import com.mogo.module.small.map.animation.DirectionRotateAnimation;
|
||||
|
||||
@@ -20,6 +29,12 @@ import com.mogo.module.small.map.animation.DirectionRotateAnimation;
|
||||
public class SmallMapDirectionView extends RoundLayout {
|
||||
|
||||
private ImageView mIvMapBorder;
|
||||
private TextureMapView mTextureMapView;
|
||||
private AMap mAMap;
|
||||
private UiSettings mUiSettings;
|
||||
private CameraUpdate mCameraUpdate;
|
||||
private MyLocationStyle myLocationStyle;
|
||||
|
||||
private DirectionRotateAnimation mRotateAnimation;
|
||||
private int lastAngle = 0;
|
||||
|
||||
@@ -37,9 +52,43 @@ public class SmallMapDirectionView extends RoundLayout {
|
||||
}
|
||||
|
||||
private void initView(Context context) {
|
||||
mRotateAnimation = new DirectionRotateAnimation(context, null);
|
||||
|
||||
LayoutInflater.from(context).inflate(R.layout.module_small_map_view, this);
|
||||
mIvMapBorder = findViewById(R.id.ivMapBorder);
|
||||
mRotateAnimation = new DirectionRotateAnimation(context, null);
|
||||
mTextureMapView = findViewById(R.id.textureMapView);
|
||||
|
||||
mTextureMapView.onCreate(null);
|
||||
mAMap = mTextureMapView.getMap();
|
||||
// mAMap.setMapType(AMap.MAP_TYPE_NIGHT);//夜景地图,aMap是地图控制器对象。
|
||||
|
||||
mAMap.setCustomMapStyle(new CustomMapStyleOptions()
|
||||
.setEnable(true)
|
||||
.setStyleDataPath("file:///android_asset/small_map_style.data")
|
||||
.setStyleExtraPath("file:///android_asset/small_map_style_extra.data")
|
||||
);
|
||||
|
||||
myLocationStyle = new MyLocationStyle();//初始化定位蓝点样式类myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);//连续定位、且将视角移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。(1秒1次定位)如果不设置myLocationType,默认也会执行此种模式。
|
||||
myLocationStyle.interval(2000); //设置连续定位模式下的定位间隔,只在连续定位模式下生效,单次定位模式下不会生效。单位为毫秒。
|
||||
BitmapDescriptor location = BitmapDescriptorFactory.fromResource(R.drawable.module_small_map_view_my_location_logo);
|
||||
myLocationStyle.myLocationIcon(location);
|
||||
mAMap.setMyLocationStyle(myLocationStyle);//设置定位蓝点的Style
|
||||
mAMap.setMyLocationEnabled(true);// 设置为true表示启动显示定位蓝点,false表示隐藏定位蓝点并不进行定位,默认是false。
|
||||
|
||||
//设置希望展示的地图缩放级别
|
||||
mCameraUpdate = CameraUpdateFactory.zoomTo(12);
|
||||
mAMap.moveCamera(mCameraUpdate);
|
||||
|
||||
mUiSettings = mAMap.getUiSettings();
|
||||
mUiSettings.setZoomControlsEnabled(false);// 地图缩放级别的交换按钮
|
||||
// mUiSettings.setZoomGesturesEnabled(false);// 缩放手势
|
||||
// mUiSettings.setScrollGesturesEnabled(false);// 滑动手势
|
||||
// mUiSettings.setRotateGesturesEnabled(false);// 旋转手势
|
||||
// mUiSettings.setTiltGesturesEnabled(false);// 倾斜手势
|
||||
mUiSettings.setAllGesturesEnabled(false);// 所有手势
|
||||
mUiSettings.setMyLocationButtonEnabled(false); // 显示默认的定位按钮
|
||||
mUiSettings.setLogoBottomMargin(-150); //设置Logo下边界距离屏幕底部的边距,设置为负值即可
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class SmallMapService extends Service {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Logger.d(TAG, "onCreate");
|
||||
addMachineVisionMapView();
|
||||
addSmallMapView();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -46,7 +46,7 @@ public class SmallMapService extends Service {
|
||||
@Override
|
||||
public void onRebind(Intent intent) {
|
||||
super.onRebind(intent);
|
||||
addMachineVisionMapView();
|
||||
addSmallMapView();
|
||||
Logger.d(TAG, "onRebind");
|
||||
}
|
||||
|
||||
@@ -69,8 +69,8 @@ public class SmallMapService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private void addMachineVisionMapView() {
|
||||
Logger.d(TAG, "addMachineVisionMapView");
|
||||
private void addSmallMapView() {
|
||||
Logger.d(TAG, "addSmallMapView");
|
||||
|
||||
mWindowManagerView = new WindowManagerView.Builder(getApplicationContext())
|
||||
.contentView(R.layout.module_small_map_direction_view)
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
package com.mogo.module.small.map;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
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 androidx.annotation.RequiresApi;
|
||||
|
||||
import com.mogo.map.MogoBaseMapView;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* @author donghongyu
|
||||
* @date 12/10/20 1:35 PM
|
||||
*/
|
||||
public class SmallMapView extends MogoBaseMapView {
|
||||
|
||||
private static final String TAG = "SmallMapView";
|
||||
|
||||
public SmallMapView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public SmallMapView(Context context, @Nullable AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public SmallMapView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
protected void addMapView(Context context) {
|
||||
Logger.d(TAG, "addMapView");
|
||||
mMapView = SmallMapDelegateFactory.getMapView(context);
|
||||
if (mMapView != null) {
|
||||
final View mapView = mMapView.getMapView();
|
||||
if (mapView != null) {
|
||||
mapView.setOutlineProvider(new TextureVideoViewOutlineProvider(360));
|
||||
mapView.setClipToOutline(true);
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.mogo.module.small.map;
|
||||
|
||||
import android.graphics.Outline;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewOutlineProvider;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
/**
|
||||
* @author donghongyu
|
||||
* @date 12/15/20 8:47 PM
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public class TextureVideoViewOutlineProvider extends ViewOutlineProvider {
|
||||
private float mRadius;
|
||||
|
||||
public TextureVideoViewOutlineProvider(float radius) {
|
||||
this.mRadius = radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getOutline(View view, Outline outline) {
|
||||
Log.w("OutlineProvider", "======getOutline======");
|
||||
Rect rect = new Rect();
|
||||
view.getGlobalVisibleRect(rect);
|
||||
int leftMargin = 0;
|
||||
int topMargin = 0;
|
||||
Rect selfRect = new Rect(leftMargin, topMargin,
|
||||
rect.right - rect.left - leftMargin, rect.bottom - rect.top - topMargin);
|
||||
outline.setRoundRect(selfRect, mRadius);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user