[Update]缓存全局路径规划数据

This commit is contained in:
chenfufeng
2022-07-21 17:41:50 +08:00
parent 6a23f600e9
commit eeb11d0120
5 changed files with 116 additions and 54 deletions

View File

@@ -12,12 +12,14 @@ import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.commons.mvp.MvpFragment;
import com.mogo.eagle.core.data.constants.MoGoFragmentPaths;
import com.mogo.eagle.core.data.map.CenterLine;
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotPlanningListener;
import com.mogo.eagle.core.function.api.map.hd.IMoGoMapFragmentProvider;
import com.mogo.eagle.core.function.api.setting.IMoGoSkinModeChangeListener;
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningListenerManager;
import com.mogo.eagle.core.function.call.map.CallerHDMapManager;
import com.mogo.eagle.core.function.call.setting.CallerSkinModeListenerManager;
import com.mogo.eagle.core.function.overview.InfStructureManager;
import com.mogo.eagle.core.function.overview.Infrastructure;
import com.mogo.eagle.core.function.overview.ViewModelExtKt;
import com.mogo.eagle.core.function.overview.vm.OverViewModel;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
@@ -28,6 +30,13 @@ import com.mogo.map.uicontroller.IMogoMapUIController;
import com.zhidaoauto.map.sdk.open.MapAutoApi;
import com.zhidaoauto.map.sdk.open.business.PointCloudHelper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import ch.hsr.geohash.GeoHash;
import mogo.telematics.pad.MessagePad;
/**
* @author donghongyu
* @since 2021-11-09
@@ -37,7 +46,8 @@ import com.zhidaoauto.map.sdk.open.business.PointCloudHelper;
*/
@Route(path = MoGoFragmentPaths.PATH_FRAGMENT_MAP)
public class MapFragment extends MvpFragment<MapView, MapPresenter>
implements MapView, IMoGoMapFragmentProvider, IMoGoSkinModeChangeListener {
implements MapView, IMoGoMapFragmentProvider, IMoGoSkinModeChangeListener,
IMoGoAutopilotPlanningListener {
private static final String TAG = "MapFragment";
@@ -330,4 +340,31 @@ public class MapFragment extends MvpFragment<MapView, MapPresenter>
public void setDebugMode(boolean debugMode) {
MapAutoApi.INSTANCE.setDebugMode(debugMode);
}
@Override
public void onAutopilotTrajectory(@NonNull List<MessagePad.TrajectoryPoint> trajectoryInfos) {
}
@Override
public void onAutopilotRotting(@Nullable MessagePad.GlobalPathResp globalPathResp) {
if (globalPathResp != null) {
HashMap<String, ArrayList<Infrastructure>> pathMap = new HashMap();
String geoHash;
ArrayList<Infrastructure> infList;
for (MessagePad.Location location : globalPathResp.getWayPointsList()) {
geoHash = GeoHash.withCharacterPrecision(location.getLatitude(), location.getLongitude(), 7).toBase32();
// 网格内的轨迹点只取一次
if (!pathMap.containsKey(geoHash)) {
// 从缓存的新基建数据中去取对应geoHash的新基建数据集合
infList = InfStructureManager.INSTANCE.getData().get(geoHash);
if (infList != null) {
pathMap.put(geoHash, infList);
}
}
}
// 全局路径规划只回调一次保存供全览模式所在Fragment使用
InfStructureManager.INSTANCE.savePathData(pathMap);
}
}
}

View File

@@ -10,6 +10,11 @@ object InfStructureManager {
HashMap<String, ArrayList<Infrastructure>>()
}
// 全局路径规划中所有点的GeoHash网格对应的新基建数据集合
private val _pathMap by lazy {
HashMap<String, ArrayList<Infrastructure>>()
}
fun saveData(map: HashMap<String, java.util.ArrayList<Infrastructure>>) {
if (_infMap.isNotEmpty()) {
_infMap.clear()
@@ -18,4 +23,13 @@ object InfStructureManager {
}
fun getData(): Map<String, ArrayList<Infrastructure>> = _infMap
fun savePathData(map: HashMap<String, java.util.ArrayList<Infrastructure>>) {
if (_pathMap.isNotEmpty()) {
_pathMap.clear()
}
_pathMap.putAll(map)
}
fun getPathData(): Map<String, ArrayList<Infrastructure>> = _pathMap
}

View File

@@ -732,58 +732,62 @@ public class AMapCustomView
}
}
}
// 绘制新基建数据
if (!posInfMap.isEmpty()) {
posInfMap.clear();
}
ArrayList<MarkerOptions> markerOptionsList = new ArrayList();
for (ArrayList<Infrastructure> structureList : pathMap.values()) {
int firstQuadrantCt = 0, secondQuadrantCt = 0, thirdQuadrantCt = 0, forthQuadrantCt = 0;
// 每个GeoHash内根据坐标系象限分散开摄像头icon显示
for (Infrastructure structure : structureList) {
MarkerOptions markerOption = new MarkerOptions();
LatLng latLng = new LatLng(Double.valueOf(structure.getLat()),
Double.valueOf(structure.getLon()));
markerOption.position(latLng);
if (structure.getHeading() >= 0 && structure.getHeading() <= 90) {
markerOption.anchor(0.5f * firstQuadrantCt, 0.5f + 0.5f * firstQuadrantCt);
markerOption.icon(BitmapDescriptorFactory.fromBitmap(
BitmapFactory.decodeResource(getResources(),R.drawable.video_icon_right)
));
firstQuadrantCt++;
} else if (structure.getHeading() >= 90 && structure.getHeading() <= 180) {
markerOption.anchor(0.5f * secondQuadrantCt, 0.5f * secondQuadrantCt);
markerOption.icon(BitmapDescriptorFactory.fromBitmap(
BitmapFactory.decodeResource(getResources(),R.drawable.video_icon_right)
));
secondQuadrantCt++;
} else if (structure.getHeading() >= 180 && structure.getHeading() <= 270) {
markerOption.anchor(0.5f + 0.5f * thirdQuadrantCt, 0.5f * thirdQuadrantCt);
markerOption.icon(BitmapDescriptorFactory.fromBitmap(
BitmapFactory.decodeResource(getResources(),R.drawable.video_icon_left)
));
thirdQuadrantCt++;
} else {
markerOption.anchor(0.75f + 0.25f * forthQuadrantCt, 0.75f + 0.25f * forthQuadrantCt);
markerOption.icon(BitmapDescriptorFactory.fromBitmap(
BitmapFactory.decodeResource(getResources(),R.drawable.video_icon_left)
));
forthQuadrantCt++;
}
posInfMap.put(latLng, structure);
markerOptionsList.add(markerOption);
}
}
mAMap.addMarkers(markerOptionsList, false);
mAMap.setOnMarkerClickListener(marker -> {
Infrastructure infrastructure = posInfMap.get(marker.getPosition());
// 如果是摄像头
if (0 == infrastructure.getCategory() && infrastructure.getIp() != null) {
CallerHmiManager.INSTANCE.showVideoDialog(infrastructure.getIp());
return true;
}
return false;
});
drawInfMarkers(pathMap);
}
}
public void drawInfMarkers(Map<String, ArrayList<Infrastructure>> infStruMap) {
// 绘制新基建数据
if (!posInfMap.isEmpty()) {
posInfMap.clear();
}
ArrayList<MarkerOptions> markerOptionsList = new ArrayList();
for (ArrayList<Infrastructure> structureList : infStruMap.values()) {
int firstQuadrantCt = 0, secondQuadrantCt = 0, thirdQuadrantCt = 0, forthQuadrantCt = 0;
// 每个GeoHash内根据坐标系象限分散开摄像头icon显示
for (Infrastructure structure : structureList) {
MarkerOptions markerOption = new MarkerOptions();
LatLng latLng = new LatLng(Double.valueOf(structure.getLat()),
Double.valueOf(structure.getLon()));
markerOption.position(latLng);
if (structure.getHeading() >= 0 && structure.getHeading() <= 90) {
markerOption.anchor(0.5f * firstQuadrantCt, 0.5f + 0.5f * firstQuadrantCt);
markerOption.icon(BitmapDescriptorFactory.fromBitmap(
BitmapFactory.decodeResource(getResources(),R.drawable.video_icon_right)
));
firstQuadrantCt++;
} else if (structure.getHeading() >= 90 && structure.getHeading() <= 180) {
markerOption.anchor(0.5f * secondQuadrantCt, 0.5f * secondQuadrantCt);
markerOption.icon(BitmapDescriptorFactory.fromBitmap(
BitmapFactory.decodeResource(getResources(),R.drawable.video_icon_right)
));
secondQuadrantCt++;
} else if (structure.getHeading() >= 180 && structure.getHeading() <= 270) {
markerOption.anchor(0.5f + 0.5f * thirdQuadrantCt, 0.5f * thirdQuadrantCt);
markerOption.icon(BitmapDescriptorFactory.fromBitmap(
BitmapFactory.decodeResource(getResources(),R.drawable.video_icon_left)
));
thirdQuadrantCt++;
} else {
markerOption.anchor(0.75f + 0.25f * forthQuadrantCt, 0.75f + 0.25f * forthQuadrantCt);
markerOption.icon(BitmapDescriptorFactory.fromBitmap(
BitmapFactory.decodeResource(getResources(),R.drawable.video_icon_left)
));
forthQuadrantCt++;
}
posInfMap.put(latLng, structure);
markerOptionsList.add(markerOption);
}
}
mAMap.addMarkers(markerOptionsList, false);
mAMap.setOnMarkerClickListener(marker -> {
Infrastructure infrastructure = posInfMap.get(marker.getPosition());
// 如果是摄像头
if (0 == infrastructure.getCategory() && infrastructure.getIp() != null) {
CallerHmiManager.INSTANCE.showVideoDialog(infrastructure.getIp());
return true;
}
return false;
});
}
}

View File

@@ -17,12 +17,15 @@ import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener;
import com.mogo.eagle.core.function.api.map.smp.IMogoSmallMapProvider;
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningListenerManager;
import com.mogo.eagle.core.function.map.R;
import com.mogo.eagle.core.function.overview.InfStructureManager;
import com.mogo.eagle.core.function.overview.Infrastructure;
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import mogo.telematics.pad.MessagePad;
import mogo_msg.MogoReportMsg;
@@ -102,6 +105,10 @@ public class SmallMapFragment extends BaseFragment
if (mAMapCustomView != null) {
mAMapCustomView.onResume();
}
Map<String, ArrayList<Infrastructure>> map = InfStructureManager.INSTANCE.getPathData();
if (!map.isEmpty()) {
mAMapCustomView.drawInfMarkers(map);
}
}
@Override