|
|
@@ -22,7 +22,9 @@ import com.atmob.map_amap_android.contants.Constants;
|
|
|
import com.atmob.map_amap_android.databinding.ItemLocationMarkerBinding;
|
|
|
import com.atmob.map_amap_android.databinding.ItemTrackStartMarkerBinding;
|
|
|
import com.atmob.map_amap_android.overlays.MyMethodCallHandler;
|
|
|
+import com.atmob.map_amap_android.util.BitmapCallback;
|
|
|
import com.atmob.map_amap_android.util.GsonUtil;
|
|
|
+import com.atmob.map_amap_android.util.ImageCacheLoader;
|
|
|
import com.atmob.map_amap_android.util.LogUtil;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
@@ -142,46 +144,91 @@ public class MarkersController implements MyMethodCallHandler, AMap.OnMarkerClic
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void updateMarker(MakerInfo makerInfo) {
|
|
|
- LatLng latLng = new LatLng(makerInfo.getLatitude(), makerInfo.getLongitude());
|
|
|
- Marker marker = currentMarkers.get(makerInfo.getId());
|
|
|
- LogUtil.d(TAG, "updateMarkers==>" + makerInfo);
|
|
|
+ private void updateMarker(final MakerInfo makerInfo) {
|
|
|
+ final LatLng latLng = new LatLng(makerInfo.getLatitude(), makerInfo.getLongitude());
|
|
|
+ final Marker marker = currentMarkers.get(makerInfo.getId());
|
|
|
+
|
|
|
if (marker != null) {
|
|
|
marker.setPosition(latLng);
|
|
|
+
|
|
|
Object object = marker.getObject();
|
|
|
if (object instanceof MakerInfo) {
|
|
|
MakerInfo cacheInfo = (MakerInfo) object;
|
|
|
- if (!Objects.equals(cacheInfo.getMarkerName(), makerInfo.getMarkerName())
|
|
|
- || cacheInfo.isSelected() != makerInfo.isSelected()) {
|
|
|
- BitmapDescriptor markerBitmap = getMarkerBitmap(makerInfo);
|
|
|
- marker.setIcon(markerBitmap);
|
|
|
+ boolean nameChanged = !Objects.equals(cacheInfo.getMarkerName(), makerInfo.getMarkerName());
|
|
|
+ boolean selectedChanged = cacheInfo.isSelected() != makerInfo.isSelected();
|
|
|
+ boolean avatarChanged = !Objects.equals(cacheInfo.getCustomAvatarUrl(), makerInfo.getCustomAvatarUrl());
|
|
|
+
|
|
|
+ if (nameChanged || selectedChanged || avatarChanged) {
|
|
|
+ LogUtil.i(TAG, "updateMarkers==修改头像");
|
|
|
+ ImageCacheLoader.loadBitmapAsync(context, makerInfo.getCustomAvatarUrl(), new BitmapCallback() {
|
|
|
+ @Override
|
|
|
+ public void onStartLoading() {}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onBitmapLoaded(Bitmap bitmap) {
|
|
|
+ BitmapDescriptor markerBitmap = getMarkerBitmap(makerInfo, bitmap);
|
|
|
+ marker.setIcon(markerBitmap);
|
|
|
+ LogUtil.i(TAG, "updateMarkers=成功修改头像:id=" + makerInfo.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(String errorMessage) {
|
|
|
+ LogUtil.i(TAG, "updateMarkers==修改失败:" + errorMessage);
|
|
|
+ }
|
|
|
+ });
|
|
|
marker.setObject(makerInfo);
|
|
|
}
|
|
|
- if (makerInfo.isSelected()) {
|
|
|
- marker.setZIndex(999);
|
|
|
- } else {
|
|
|
- marker.setZIndex(0);
|
|
|
- }
|
|
|
+
|
|
|
+ marker.setZIndex(makerInfo.isSelected() ? 999 : 0);
|
|
|
}
|
|
|
- LogUtil.i(TAG, "updateMarkers=marker..updateSuccess,id=" + makerInfo.getId());
|
|
|
} else {
|
|
|
- BitmapDescriptor markerBitmap = getMarkerBitmap(makerInfo);
|
|
|
- MarkerOptions markerOption = new MarkerOptions()
|
|
|
- .position(latLng)
|
|
|
- .icon(markerBitmap)
|
|
|
- .anchor(0.5f, 0.9f);
|
|
|
- marker = map.addMarker(markerOption);
|
|
|
- marker.setObject(makerInfo);
|
|
|
- if (makerInfo.isSelected()) {
|
|
|
- marker.setZIndex(999);
|
|
|
- } else {
|
|
|
- marker.setZIndex(0);
|
|
|
- }
|
|
|
- currentMarkers.put(makerInfo.getId(), marker);
|
|
|
- LogUtil.i(TAG, "updateMarkers=marker..addSuccess,id=" + makerInfo.getId());
|
|
|
+ // 创建新 marker
|
|
|
+ loadAvatarAndCreateMarker(makerInfo, latLng);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void loadAvatarAndCreateMarker(final MakerInfo makerInfo, final LatLng latLng) {
|
|
|
+ if (TextUtils.isEmpty(makerInfo.getCustomAvatarUrl())) {
|
|
|
+ // 无头像,使用默认图标
|
|
|
+ addMarkerToMap(makerInfo, latLng, null);
|
|
|
+ } else {
|
|
|
+ // 加载头像后再添加 marker
|
|
|
+ ImageCacheLoader.loadBitmapAsync(context, makerInfo.getCustomAvatarUrl(), new BitmapCallback() {
|
|
|
+ @Override
|
|
|
+ public void onStartLoading() {}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onBitmapLoaded(Bitmap bitmap) {
|
|
|
+ addMarkerToMap(makerInfo, latLng, bitmap);
|
|
|
+ LogUtil.i(TAG, "updateMarkers=成功修改头像:id=" + makerInfo.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @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) {
|
|
|
+ BitmapDescriptor markerBitmap = getMarkerBitmap(makerInfo, avatarBitmap);
|
|
|
+ MarkerOptions markerOption = new MarkerOptions()
|
|
|
+ .position(latLng)
|
|
|
+ .icon(markerBitmap)
|
|
|
+ .anchor(0.5f, 0.9f);
|
|
|
+
|
|
|
+ Marker newMarker = map.addMarker(markerOption);
|
|
|
+ newMarker.setObject(makerInfo);
|
|
|
+ newMarker.setZIndex(makerInfo.isSelected() ? 999 : 0);
|
|
|
+ currentMarkers.put(makerInfo.getId(), newMarker);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public String[] getRegisterMethodIdArray() {
|
|
|
@@ -189,15 +236,23 @@ public class MarkersController implements MyMethodCallHandler, AMap.OnMarkerClic
|
|
|
}
|
|
|
|
|
|
|
|
|
- public BitmapDescriptor getMarkerBitmap(MakerInfo markerInfo) {
|
|
|
+ public BitmapDescriptor getMarkerBitmap(MakerInfo markerInfo, Bitmap customAvatarBitmap) {
|
|
|
if (markerInfo.getMarkerType() == MakerInfo.MarkerType.MINE || markerInfo.getMarkerType() == MakerInfo.MarkerType.FRIEND) {
|
|
|
if (markerBinding == null) {
|
|
|
markerBinding = ItemLocationMarkerBinding.inflate(LayoutInflater.from(context));
|
|
|
}
|
|
|
ConstraintLayout view = markerBinding.getRoot();
|
|
|
markerBinding.locationMarkerTvName.setText(markerInfo.getMarkerName());
|
|
|
- markerBinding.ivMarkerAvatar.setImageResource(markerInfo.getMarkerType() == MakerInfo.MarkerType.MINE ? R.drawable.icon_default_mine_avatar : R.drawable.icon_default_friend_avatar);
|
|
|
- markerBinding.vBottom.setBackgroundResource(markerInfo.isSelected() ? R.drawable.icon_marker_selected_bottom_circle : R.drawable.icon_marker_normal_bottom_circle);
|
|
|
+ if (customAvatarBitmap == null) {
|
|
|
+ markerBinding.ivMarkerAvatar.setImageResource(markerInfo.getMarkerType() == MakerInfo.MarkerType.MINE ? R.drawable.icon_default_mine_avatar : R.drawable.icon_default_friend_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_marker_selected_bottom_circle : R.drawable.icon_marker_normal_bottom_circle);
|
|
|
+ }
|
|
|
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) {
|
|
|
@@ -208,7 +263,11 @@ public class MarkersController implements MyMethodCallHandler, AMap.OnMarkerClic
|
|
|
ItemLocationMarkerBinding trackEndPointMarkerBinding = ItemLocationMarkerBinding.inflate(LayoutInflater.from(context));
|
|
|
ConstraintLayout view = trackEndPointMarkerBinding.getRoot();
|
|
|
trackEndPointMarkerBinding.locationMarkerTvName.setText(markerInfo.getMarkerName());
|
|
|
- trackEndPointMarkerBinding.ivMarkerAvatar.setImageResource(markerInfo.getMarkerType() == MakerInfo.MarkerType.TRACE_END_MINE_POINT ? R.drawable.icon_default_mine_avatar : R.drawable.icon_default_friend_avatar);
|
|
|
+ if (customAvatarBitmap == null) {
|
|
|
+ trackEndPointMarkerBinding.ivMarkerAvatar.setImageResource(markerInfo.getMarkerType() == MakerInfo.MarkerType.TRACE_END_MINE_POINT ? R.drawable.icon_default_mine_avatar : R.drawable.icon_default_friend_avatar);
|
|
|
+ } else {
|
|
|
+ trackEndPointMarkerBinding.ivMarkerAvatar.setImageBitmap(customAvatarBitmap);
|
|
|
+ }
|
|
|
trackEndPointMarkerBinding.locationMarkerIvBg.setImageResource(R.drawable.icon_location_marker_normal);
|
|
|
trackEndPointMarkerBinding.vBottom.setBackgroundResource(R.drawable.icon_marker_track_bottom_circle);
|
|
|
return viewGetBitmapDescriptor(view);
|