|
|
@@ -1,5 +1,6 @@
|
|
|
package com.atmob.map_amap_android.overlays.marker;
|
|
|
|
|
|
+import android.annotation.SuppressLint;
|
|
|
import android.content.Context;
|
|
|
import android.graphics.Bitmap;
|
|
|
import android.graphics.Canvas;
|
|
|
@@ -18,8 +19,8 @@ import com.amap.api.maps.model.Marker;
|
|
|
import com.amap.api.maps.model.MarkerOptions;
|
|
|
import com.atmob.map_amap_android.R;
|
|
|
import com.atmob.map_amap_android.bean.MakerInfo;
|
|
|
-import com.atmob.map_amap_android.bean.Popup;
|
|
|
import com.atmob.map_amap_android.contants.Constants;
|
|
|
+import com.atmob.map_amap_android.databinding.ItemElectricMarkerBinding;
|
|
|
import com.atmob.map_amap_android.databinding.ItemLocationMarkerBinding;
|
|
|
import com.atmob.map_amap_android.databinding.ItemTrackErrorMarkerBinding;
|
|
|
import com.atmob.map_amap_android.databinding.ItemTrackPassingMarkerBinding;
|
|
|
@@ -56,6 +57,7 @@ public class MarkersController implements MyMethodCallHandler, AMap.OnMarkerClic
|
|
|
private final HashMap<String, Marker> currentMarkers = new HashMap<>(10);
|
|
|
|
|
|
private ItemLocationMarkerBinding markerBinding;
|
|
|
+ private ItemElectricMarkerBinding electricMarkerBinding;
|
|
|
|
|
|
private final Gson gson;
|
|
|
|
|
|
@@ -86,7 +88,7 @@ public class MarkersController implements MyMethodCallHandler, AMap.OnMarkerClic
|
|
|
|
|
|
|
|
|
private void removeMarker(MethodCall call, MethodChannel.Result result) {
|
|
|
- LogUtil.i(TAG, "removeMarker===>" + call.arguments());
|
|
|
+ LogUtil.d(TAG, "removeMarker===>" + call.arguments());
|
|
|
Map<String, Object> arguments = call.arguments();
|
|
|
if (arguments == null || arguments.isEmpty()) {
|
|
|
result.error("-1", "removeMarker.arguments is empty", null);
|
|
|
@@ -97,13 +99,13 @@ public class MarkersController implements MyMethodCallHandler, AMap.OnMarkerClic
|
|
|
if (marker != null) {
|
|
|
marker.remove();
|
|
|
currentMarkers.remove(markerId);
|
|
|
- LogUtil.i(TAG, "removeMarker===>成功删除marker:" + markerId);
|
|
|
+ LogUtil.d(TAG, "removeMarker===>成功删除marker:" + markerId);
|
|
|
}
|
|
|
result.success(null);
|
|
|
}
|
|
|
|
|
|
private void replaceAllMarkers(MethodCall call, MethodChannel.Result result) {
|
|
|
- LogUtil.i(TAG, "replaceAllMarkers===>" + call.arguments());
|
|
|
+ LogUtil.d(TAG, "replaceAllMarkers===>" + call.arguments());
|
|
|
try {
|
|
|
String arguments = call.arguments();
|
|
|
List<MakerInfo> list = null;
|
|
|
@@ -152,7 +154,7 @@ public class MarkersController implements MyMethodCallHandler, AMap.OnMarkerClic
|
|
|
}
|
|
|
|
|
|
private void updateMarkers(MethodCall call, MethodChannel.Result result) {
|
|
|
- LogUtil.i(TAG, "updateMarkers===>" + call.arguments());
|
|
|
+ LogUtil.d(TAG, "updateMarkers===>" + call.arguments());
|
|
|
String arguments = call.arguments();
|
|
|
if (arguments == null || TextUtils.isEmpty(arguments)) {
|
|
|
result.error("-1", "updateMarkers.arguments is empty", null);
|
|
|
@@ -189,9 +191,10 @@ public class MarkersController implements MyMethodCallHandler, AMap.OnMarkerClic
|
|
|
boolean nameChanged = !Objects.equals(cacheInfo.getMarkerName(), makerInfo.getMarkerName());
|
|
|
boolean selectedChanged = cacheInfo.isSelected() != makerInfo.isSelected();
|
|
|
boolean avatarChanged = !Objects.equals(cacheInfo.getCustomAvatarUrl(), makerInfo.getCustomAvatarUrl());
|
|
|
+ boolean tagsChanged = checkMarkerTagsChanged(cacheInfo,makerInfo);
|
|
|
|
|
|
- if (nameChanged || selectedChanged || avatarChanged) {
|
|
|
- LogUtil.i(TAG, "updateMarkers==修改头像");
|
|
|
+ if (nameChanged || selectedChanged || avatarChanged || tagsChanged) {
|
|
|
+ LogUtil.d(TAG, "updateMarkers==marker内容发生变化,更新样式");
|
|
|
ImageCacheLoader.loadBitmapAsync(context, makerInfo.getCustomAvatarUrl(), new BitmapCallback() {
|
|
|
@Override
|
|
|
public void onStartLoading() {
|
|
|
@@ -201,30 +204,40 @@ public class MarkersController implements MyMethodCallHandler, AMap.OnMarkerClic
|
|
|
public void onBitmapLoaded(Bitmap bitmap) {
|
|
|
BitmapDescriptor markerBitmap = getMarkerBitmap(makerInfo, bitmap);
|
|
|
marker.setIcon(markerBitmap);
|
|
|
- LogUtil.i(TAG, "updateMarkers=成功修改头像:id=" + makerInfo.getId());
|
|
|
+ LogUtil.d(TAG, "updateMarkers=url头像:id=" + makerInfo.getId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onError(String errorMessage) {
|
|
|
- LogUtil.i(TAG, "updateMarkers==修改失败:" + errorMessage);
|
|
|
+ LogUtil.d(TAG, "updateMarkers==url头像失败:" + errorMessage);
|
|
|
+ BitmapDescriptor markerBitmap = getMarkerBitmap(makerInfo, null);
|
|
|
+ marker.setIcon(markerBitmap);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
marker.setZIndex(makerInfo.isSelected() ? 100 : 0);
|
|
|
}
|
|
|
- marker.setObject(makerInfo);
|
|
|
}
|
|
|
+ marker.setObject(makerInfo);
|
|
|
} else {
|
|
|
+ LogUtil.d(TAG, "updateMarkers==>marker不存在,创建新 marker:" + makerInfo);
|
|
|
// 创建新 marker
|
|
|
loadAvatarAndCreateMarker(makerInfo, latLng);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private boolean checkMarkerTagsChanged(MakerInfo cacheInfo, MakerInfo makerInfo) {
|
|
|
+ if(makerInfo.getMarkerType() == MakerInfo.MarkerType.FRIEND){
|
|
|
+ if(!Objects.equals(cacheInfo.getTags(), makerInfo.getTags())){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
private void loadAvatarAndCreateMarker(final MakerInfo makerInfo, final LatLng latLng) {
|
|
|
- if (TextUtils.isEmpty(makerInfo.getCustomAvatarUrl())) {
|
|
|
- // 无头像,使用默认图标
|
|
|
- addMarkerToMap(makerInfo, latLng, null);
|
|
|
- } else {
|
|
|
+ Marker marker = addMarkerToMap(makerInfo, latLng, null);
|
|
|
+ if (!TextUtils.isEmpty(makerInfo.getCustomAvatarUrl())) {
|
|
|
// 加载头像后再添加 marker
|
|
|
ImageCacheLoader.loadBitmapAsync(context, makerInfo.getCustomAvatarUrl(), new BitmapCallback() {
|
|
|
@Override
|
|
|
@@ -233,21 +246,20 @@ public class MarkersController implements MyMethodCallHandler, AMap.OnMarkerClic
|
|
|
|
|
|
@Override
|
|
|
public void onBitmapLoaded(Bitmap bitmap) {
|
|
|
- addMarkerToMap(makerInfo, latLng, bitmap);
|
|
|
- LogUtil.i(TAG, "updateMarkers=成功修改头像:id=" + makerInfo.getId());
|
|
|
+ BitmapDescriptor markerBitmap = getMarkerBitmap(makerInfo, bitmap);
|
|
|
+ marker.setIcon(markerBitmap);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onError(String errorMessage) {
|
|
|
- addMarkerToMap(makerInfo, latLng, null);
|
|
|
- LogUtil.i(TAG, "updateMarkers=使用默认头像:id=" + makerInfo.getId() + ",errorMessage:" + errorMessage);
|
|
|
+
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void addMarkerToMap(MakerInfo makerInfo, LatLng latLng, Bitmap avatarBitmap) {
|
|
|
+ private Marker addMarkerToMap(MakerInfo makerInfo, LatLng latLng, Bitmap avatarBitmap) {
|
|
|
BitmapDescriptor markerBitmap = getMarkerBitmap(makerInfo, avatarBitmap);
|
|
|
MarkerOptions markerOption = new MarkerOptions()
|
|
|
.position(latLng)
|
|
|
@@ -264,6 +276,7 @@ public class MarkersController implements MyMethodCallHandler, AMap.OnMarkerClic
|
|
|
newMarker.setObject(makerInfo);
|
|
|
newMarker.setZIndex(makerInfo.isSelected() ? 999 : 0);
|
|
|
currentMarkers.put(makerInfo.getId(), newMarker);
|
|
|
+ return newMarker;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -273,25 +286,62 @@ public class MarkersController implements MyMethodCallHandler, AMap.OnMarkerClic
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @SuppressLint("SetTextI18n")
|
|
|
public BitmapDescriptor getMarkerBitmap(MakerInfo markerInfo, Bitmap customAvatarBitmap) {
|
|
|
- if (markerInfo.getMarkerType() == MakerInfo.MarkerType.MINE || markerInfo.getMarkerType() == MakerInfo.MarkerType.FRIEND) {
|
|
|
+ if (markerInfo.getMarkerType() == MakerInfo.MarkerType.MINE) {
|
|
|
if (markerBinding == null) {
|
|
|
markerBinding = ItemLocationMarkerBinding.inflate(LayoutInflater.from(context));
|
|
|
}
|
|
|
ConstraintLayout view = markerBinding.getRoot();
|
|
|
markerBinding.locationMarkerTvName.setText(markerInfo.getMarkerName());
|
|
|
if (customAvatarBitmap == null) {
|
|
|
- markerBinding.ivMarkerAvatar.setImageResource(markerInfo.getMarkerType() == MakerInfo.MarkerType.MINE ? R.drawable.icon_default_mine_avatar : R.drawable.icon_default_friend_avatar);
|
|
|
+ markerBinding.ivMarkerAvatar.setImageResource(R.drawable.icon_default_mine_avatar);
|
|
|
} else {
|
|
|
markerBinding.ivMarkerAvatar.setImageBitmap(customAvatarBitmap);
|
|
|
}
|
|
|
- if (markerInfo.getMarkerType() == MakerInfo.MarkerType.MINE) {
|
|
|
- markerBinding.vBottom.setBackgroundResource(markerInfo.isSelected() ? R.drawable.icon_mine_marker_selected_bottom_circle : R.drawable.icon_mine_marker_normal_bottom_circle);
|
|
|
- } else {
|
|
|
+ markerBinding.vBottom.setBackgroundResource(markerInfo.isSelected() ? R.drawable.icon_mine_marker_selected_bottom_circle : R.drawable.icon_mine_marker_normal_bottom_circle);
|
|
|
+ markerBinding.locationMarkerIvBg.setImageResource(markerInfo.isSelected() ? R.drawable.icon_location_mine_marker_selected : R.drawable.icon_location_marker_normal);
|
|
|
+
|
|
|
+ return viewGetBitmapDescriptor(view);
|
|
|
+ } else if (markerInfo.getMarkerType() == MakerInfo.MarkerType.FRIEND) {
|
|
|
+ Object tags = markerInfo.getTags();
|
|
|
+ Integer electric = null;
|
|
|
+ if (tags instanceof Map) {
|
|
|
+ Map<String, Object> tagsMap = (Map<String, Object>) tags;
|
|
|
+ electric = ParamUtil.getInt(tagsMap, "electric");
|
|
|
+ }
|
|
|
+ if (!markerInfo.isSelected() || electric == null) {
|
|
|
+ if (markerBinding == null) {
|
|
|
+ markerBinding = ItemLocationMarkerBinding.inflate(LayoutInflater.from(context));
|
|
|
+ }
|
|
|
+ ConstraintLayout view = markerBinding.getRoot();
|
|
|
+ markerBinding.locationMarkerTvName.setText(markerInfo.getMarkerName());
|
|
|
+ if (customAvatarBitmap == null) {
|
|
|
+ markerBinding.ivMarkerAvatar.setImageResource(R.drawable.icon_default_friend_avatar);
|
|
|
+ } else {
|
|
|
+ markerBinding.ivMarkerAvatar.setImageBitmap(customAvatarBitmap);
|
|
|
+ }
|
|
|
markerBinding.vBottom.setBackgroundResource(markerInfo.isSelected() ? R.drawable.icon_marker_selected_bottom_circle : R.drawable.icon_marker_normal_bottom_circle);
|
|
|
+ markerBinding.locationMarkerIvBg.setImageResource(markerInfo.isSelected() ? R.drawable.icon_location_marker_selected : R.drawable.icon_location_marker_normal);
|
|
|
+
|
|
|
+ return viewGetBitmapDescriptor(view);
|
|
|
+ } else {
|
|
|
+ if (electricMarkerBinding == null) {
|
|
|
+ electricMarkerBinding = ItemElectricMarkerBinding.inflate(LayoutInflater.from(context));
|
|
|
+ }
|
|
|
+ ConstraintLayout view = electricMarkerBinding.getRoot();
|
|
|
+ electricMarkerBinding.batteryView.setBatteryLevel(electric);
|
|
|
+ electricMarkerBinding.tvElectric.setText(electric + "%");
|
|
|
+ if (customAvatarBitmap == null) {
|
|
|
+ electricMarkerBinding.ivMarkerAvatar.setImageResource(R.drawable.icon_default_friend_avatar);
|
|
|
+ } else {
|
|
|
+ electricMarkerBinding.ivMarkerAvatar.setImageBitmap(customAvatarBitmap);
|
|
|
+ }
|
|
|
+ electricMarkerBinding.vBottom.setBackgroundResource(markerInfo.isSelected() ? R.drawable.icon_marker_selected_bottom_circle : R.drawable.icon_marker_normal_bottom_circle);
|
|
|
+ electricMarkerBinding.locationMarkerIvBg.setImageResource(markerInfo.isSelected() ? R.drawable.icon_location_marker_selected : R.drawable.icon_location_marker_normal);
|
|
|
+
|
|
|
+ return viewGetBitmapDescriptor(view);
|
|
|
}
|
|
|
- markerBinding.locationMarkerIvBg.setImageResource(markerInfo.isSelected() ? (markerInfo.getMarkerType() == MakerInfo.MarkerType.MINE ? R.drawable.icon_location_mine_marker_selected : R.drawable.icon_location_marker_selected) : R.drawable.icon_location_marker_normal);
|
|
|
- return viewGetBitmapDescriptor(view);
|
|
|
} else if (markerInfo.getMarkerType() == MakerInfo.MarkerType.TRACE_START_POINT) {
|
|
|
ItemTrackStartMarkerBinding trackStartPointMarkerBinding = ItemTrackStartMarkerBinding.inflate(LayoutInflater.from(context));
|
|
|
ConstraintLayout view = trackStartPointMarkerBinding.getRoot();
|