diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/MarkerServiceHandler.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/MarkerServiceHandler.java index 33b6a55df7..3908badf6b 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/MarkerServiceHandler.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/MarkerServiceHandler.java @@ -1,49 +1,22 @@ package com.mogo.module.service; import android.content.Context; -import android.os.Handler; -import android.os.Looper; -import android.view.View; import com.alibaba.android.arouter.launcher.ARouter; -import com.mogo.map.MogoLatLng; import com.mogo.map.location.IMogoLocationClient; -import com.mogo.map.marker.IMogoMarker; -import com.mogo.map.marker.IMogoMarkerClickListener; import com.mogo.map.marker.IMogoMarkerManager; -import com.mogo.map.marker.MogoMarkerOptions; -import com.mogo.map.marker.MogoMarkersHandler; import com.mogo.map.navi.IMogoNavi; import com.mogo.map.uicontroller.IMogoMapUIController; -import com.mogo.module.common.entity.MarkerCarChat; -import com.mogo.module.common.entity.MarkerCardResult; -import com.mogo.module.common.entity.MarkerExploreWay; -import com.mogo.module.common.entity.MarkerLocation; -import com.mogo.module.common.entity.MarkerNoveltyInfo; -import com.mogo.module.common.entity.MarkerOnlineCar; -import com.mogo.module.common.entity.MarkerPoiTypeEnum; import com.mogo.module.common.entity.MarkerResponse; -import com.mogo.module.common.entity.MarkerShareMusic; import com.mogo.module.common.entity.MarkerShowEntity; -import com.mogo.module.service.marker.MapMarkerAdapter; +import com.mogo.module.service.marker.MapMarkerManager; import com.mogo.service.MogoServicePaths; import com.mogo.service.analytics.IMogoAnalytics; -import com.mogo.service.cardmanager.IMogoCardChangedListener; import com.mogo.service.cardmanager.IMogoCardManager; -import com.mogo.service.connection.IMogoOnMessageListener; import com.mogo.service.connection.IMogoSocketManager; import com.mogo.service.imageloader.IMogoImageloader; import com.mogo.service.map.IMogoMapService; import com.mogo.service.statusmanager.IMogoStatusManager; -import com.mogo.utils.logger.Logger; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; /** * author : donghongyu @@ -55,7 +28,6 @@ import java.util.Map; public class MarkerServiceHandler { private static final String TAG = "MarkerServiceHandler"; - private static MoGoMarkerClickListener mogoMarkerClickListener; private static IMogoMapService mMapService; private static IMogoMarkerManager mMarkerManager; @@ -70,17 +42,13 @@ public class MarkerServiceHandler { private static IMogoCardManager mMogoCardManager; private static IMogoAnalytics mMogoAnalytics; - private static Context mContext; + private static MapMarkerManager mMapMarkerManager; - // 第一次请求到地图的Marker数据 - private static boolean isFirstMarker = true; public static void init(final Context context) { - mContext = context; mMapService = (IMogoMapService) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICES_MAP).navigation(context); mImageloader = (IMogoImageloader) ARouter.getInstance().build(MogoServicePaths.PATH_UTILS_IMAGE_LOADER).navigation(context); mMogoStatusManager = (IMogoStatusManager) ARouter.getInstance().build(MogoServicePaths.PATH_STATUS_MANAGER).navigation(context); - mMogoStatusManager = (IMogoStatusManager) ARouter.getInstance().build(MogoServicePaths.PATH_STATUS_MANAGER).navigation(context); mMogoSocketManager = (IMogoSocketManager) ARouter.getInstance().build(MogoServicePaths.PATH_SOCKET_MANAGER).navigation(); mMogoCardManager = (IMogoCardManager) ARouter.getInstance().build(MogoServicePaths.PATH_CARD_MANAGER).navigation(); mMogoAnalytics = (IMogoAnalytics) ARouter.getInstance().build(MogoServicePaths.PATH_UTILS_ANALYTICS).navigation(); @@ -89,40 +57,9 @@ public class MarkerServiceHandler { mNavi = mMapService.getNavi(context); mMapUIController = mMapService.getMapUIController(); mLocationClient = mMapService.getLocationClient(context); - mogoMarkerClickListener = new MoGoMarkerClickListener(); - // 长连接 - mMogoSocketManager.registerOnMessageListener(401001, new IMogoOnMessageListener() { - - @Override - public Class target() { - return MarkerResponse.class; - } - - @Override - public void onMsgReceived(final MarkerResponse response) { - Logger.e(TAG, "======MarkerResponse:" + response); - if (!getMogoStatusManager().isSearchUIShow() && !getMogoStatusManager().isV2XShow()) { - isFirstMarker = true; - Handler handler = new Handler(Looper.getMainLooper()); - handler.post(new Runnable() { - @Override - public void run() { - drawMapMarker(response); - } - }); - } - } - }); - - getMogoCardManager().registerCardChangedListener("LAUNCHER_MARKER_MODULE", new IMogoCardChangedListener() { - - @Override - public void onSwitched(int position, String moduleName) { - Logger.e(TAG, "======moduleName:" + moduleName); - highlightedMarker(moduleName); - } - }); + mMapMarkerManager = MapMarkerManager.getInstance(context); + mMapMarkerManager.init(context); } public static IMogoMapService getMapService() { @@ -161,356 +98,44 @@ public class MarkerServiceHandler { return mMogoAnalytics; } - private static IMogoMarker lastMarker; - - /** - * 地图上的Marker点击回调 - */ - static class MoGoMarkerClickListener implements IMogoMarkerClickListener { - - @Override - public boolean onMarkerClicked(IMogoMarker marker) { - Logger.i(TAG, "onMarkerClicked 点击了大而全中的Marker:" + marker); - try { - if (lastMarker != null) { - // 判断点击的是否是同一个 - if (marker.equals(lastMarker)) { - Logger.w(TAG, "onMarkerClicked 与上一次点击的Marker一样,不做处理:" + marker); - return false; - } - - // 将上次选中 Marker 设置为未选中状态 - MarkerShowEntity lastMarkerShowEntity = (MarkerShowEntity) lastMarker.getObject(); - - Logger.i(TAG, "onMarkerClicked 点击了大而全中的Marker lastMarkerShowEntity:" + lastMarkerShowEntity); - - lastMarkerShowEntity.setChecked(false); - lastMarkerShowEntity.setHighlighted(false); - - drawMapMarker(lastMarkerShowEntity); - - lastMarker.remove(); - } - - // 将当前的Marker设置为选中 - MarkerShowEntity markerShowEntity = (MarkerShowEntity) marker.getObject(); - Logger.i(TAG, "onMarkerClicked 点击了大而全中的Marker markerShowEntity:" + markerShowEntity); - - markerShowEntity.setChecked(true); - markerShowEntity.setHighlighted(true); - - lastMarker = drawMapMarker(markerShowEntity); - if (lastMarker != null) { - lastMarker.setAlpha(1f); - } - - marker.remove(); - - final Map properties = new HashMap<>(); - switch (lastMarker.getOwner()) { - case ServiceConst.CARD_TYPE_CARS_CHATTING: - properties.put("type", 3); - break; - case ServiceConst.CARD_TYPE_USER_DATA: - properties.put("type", 5); - break; - case ServiceConst.CARD_TYPE_ROAD_CONDITION: - properties.put("type", 2); - break; - case ServiceConst.CARD_TYPE_NOVELTY: - MarkerShowEntity showEntity = (MarkerShowEntity) lastMarker.getObject(); - Object bindObj = showEntity.getBindObj(); - if (bindObj instanceof MarkerNoveltyInfo) { - switch (((MarkerNoveltyInfo) bindObj).getPoiType()) { - case MarkerPoiTypeEnum.GAS_STATION: - properties.put("type", 4); - break; - case MarkerPoiTypeEnum.TRAFFIC_CHECK: - properties.put("type", 8); - break; - case MarkerPoiTypeEnum.ROAD_CLOSED: - properties.put("type", 7); - break; - case MarkerPoiTypeEnum.SHOP_DISCOUNT: - properties.put("type", 9); - break; - case MarkerPoiTypeEnum.FOURS_SHOP: - properties.put("type", 10); - break; - } - } - break; - case ServiceConst.CARD_TYPE_SHARE_MUSIC: - properties.put("type", 6); - break; - } - - getMogoAnalytics().track("Launcher_Icon_Click", properties); - - } catch (Exception e) { - e.printStackTrace(); - } - return false; - } + public static IMogoLocationClient getMogoLocationClient() { + return mLocationClient; } - // 对指定类型高亮处理 - public static void highlightedMarker(String typeTag) { - try { - Map> allMarker = getMarkerManager().getAllMarkers(); - for (Map.Entry> entry : allMarker.entrySet()) { - String keyStr = entry.getKey(); - List markerList = entry.getValue(); + public static MapMarkerManager getMapMarkerManager() { + return mMapMarkerManager; + } - if (keyStr.equals(typeTag)) { - for (IMogoMarker marker : markerList) { - marker.setAlpha(1f); - } - } else { - for (IMogoMarker marker : markerList) { - marker.setAlpha(0.7f); - } - } - } - } catch (Exception e) { - e.printStackTrace(); - } + //TODO -------------以下方法是临时过度使用的,后面统一使用,getMapMarkerManager进行调用 + + /** + * 绘制Marker + * 建议使用 + * @see MapMarkerManager#drawMapMarker(MarkerResponse) + */ + @Deprecated + public static void drawMapMarker(MarkerResponse response) { + getMapMarkerManager().drawMapMarker(response); } /** * 绘制Marker + * 建议使用 + * @see MapMarkerManager#drawMapMarker(MarkerShowEntity) */ - public static void drawMapMarker(MarkerResponse response) { - lastMarker = null; - - JSONArray array = new JSONArray(); - - // 解析不同的Marker类型,然后对应的进行绘制 - if (response != null && response.getResult() != null) { - - MarkerCardResult markerCardResult = response.getResult(); - - // 语音触发的在线车辆搜索,采用增量的形式绘制 - if (markerCardResult.getDataType() != null && - markerCardResult.getDataType().size() == 1 && - markerCardResult.getDataType().contains(ServiceConst.CARD_TYPE_USER_DATA)) { - getMarkerManager().removeMarkers(ServiceConst.CARD_TYPE_USER_DATA); - getMogoCardManager().switch2(ServiceConst.CARD_TYPE_USER_DATA); - isFirstMarker = true; - } else { - // 清空所有地图上绘制的Marker - getMarkerManager().removeMarkers(); - } - - List carChatList = markerCardResult.getCarChat(); - List onlineCarList = markerCardResult.getOnlineCar(); - List exploreWayList = markerCardResult.getExploreWay(); - List shareMusicList = markerCardResult.getShareMusic(); - List noveltyInfoList = markerCardResult.getNoveltyInfo(); - - if (carChatList != null) { - for (MarkerCarChat markerCarChat : carChatList) { - MarkerLocation markerLocation = markerCarChat.getLocation(); - - MarkerShowEntity markerShowEntity = new MarkerShowEntity(); - markerShowEntity.setBindObj(markerCarChat); - markerShowEntity.setMarkerLocation(markerLocation); - markerShowEntity.setMarkerType(markerCarChat.getType()); - markerShowEntity.setTextContent(markerCarChat.getUserInfo().getUserName()); - markerShowEntity.setIconUrl(markerCarChat.getUserInfo().getUserHead()); - - drawMapMarker(markerShowEntity); - } - } - - if (onlineCarList != null) { - IMogoMarker nearlyMogoMarker = null; - double nearlyDistance = Double.MAX_VALUE; - for (MarkerOnlineCar markerOnlineCar : onlineCarList) { - MarkerLocation markerLocation = markerOnlineCar.getLocation(); - - MarkerShowEntity markerShowEntity = new MarkerShowEntity(); - markerShowEntity.setBindObj(markerOnlineCar); - markerShowEntity.setMarkerLocation(markerLocation); - markerShowEntity.setMarkerType(markerOnlineCar.getType()); - markerShowEntity.setTextContent(markerOnlineCar.getUserInfo().getUserName()); - markerShowEntity.setIconUrl(markerOnlineCar.getUserInfo().getUserHead()); - - IMogoMarker iMogoMarker = drawMapMarker(markerShowEntity); - // 计算在线车辆距离当前车辆的距离,每次都与最后一次距离最近的进行比较,保留距离最近的车辆,进行卡片展示 - try { - double calculateDistance = Utils.calculateLineDistance( - new MogoLatLng(markerLocation.getLat(), markerLocation.getLat()), - new MogoLatLng(mLocationClient.getLastKnowLocation().getLatitude(), mLocationClient.getLastKnowLocation().getLongitude()) - ); - - // 进行比较,保留最近的一个数据 - if (calculateDistance < nearlyDistance) { - nearlyMogoMarker = iMogoMarker; - } - - } catch (Exception e) { - e.printStackTrace(); - } - } - fillNumberTrackEventBody(array, 3, onlineCarList.size()); - - try { - // 在ACC on 之后第一次获取到了在线车辆数据,选中最近的一个Marker - if (isFirstMarker) { - if (nearlyMogoMarker != null) { -// getMogoCardManager().switch2(ServiceConst.CARD_TYPE_USER_DATA); -// MarkerShowEntity markerShowEntity = (MarkerShowEntity) nearlyMogoMarker.getObject(); -// MarkerOnlineCar markerOnlineCar = (MarkerOnlineCar) markerShowEntity.getBindObj(); -// onLineCarCardViewProvider.updateView(markerOnlineCar); - MogoMarkersHandler.getInstance().onMarkerClicked(nearlyMogoMarker); - isFirstMarker = false; - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - if (exploreWayList != null) { - for (MarkerExploreWay markerExploreWay : exploreWayList) { - if (!markerExploreWay.getCanLive()) { - MarkerLocation markerLocation = markerExploreWay.getLocation(); - - MarkerShowEntity markerShowEntity = new MarkerShowEntity(); - markerShowEntity.setBindObj(markerExploreWay); - markerShowEntity.setMarkerLocation(markerLocation); - markerShowEntity.setMarkerType(markerExploreWay.getType()); - markerShowEntity.setTextContent(markerExploreWay.getAddr()); - - drawMapMarker(markerShowEntity); - } - } - fillNumberTrackEventBody(array, 1, exploreWayList.size()); - } - - if (shareMusicList != null) { - for (MarkerShareMusic markerShareMusic : shareMusicList) { - MarkerLocation markerLocation = markerShareMusic.getLocation(); - - MarkerShowEntity markerShowEntity = new MarkerShowEntity(); - markerShowEntity.setBindObj(markerShareMusic); - markerShowEntity.setMarkerLocation(markerLocation); - markerShowEntity.setMarkerType(markerShareMusic.getType()); - markerShowEntity.setTextContent(markerShareMusic.getMediaName()); - markerShowEntity.setIconUrl(markerShareMusic.getMediaImg()); - - drawMapMarker(markerShowEntity); - } - fillNumberTrackEventBody(array, 4, shareMusicList.size()); - } - - if (noveltyInfoList != null) { - int num_gas_station = 0; - int num_traffic_check = 0; - int num_road_closed = 0; - int num_shop_discount = 0; - int num_fours_shop = 0; - - for (MarkerNoveltyInfo noveltyInfo : noveltyInfoList) { - MarkerLocation markerLocation = noveltyInfo.getLocation(); - - MarkerShowEntity markerShowEntity = new MarkerShowEntity(); - markerShowEntity.setBindObj(noveltyInfo); - markerShowEntity.setMarkerLocation(markerLocation); - markerShowEntity.setMarkerType(noveltyInfo.getType()); - markerShowEntity.setTextContent(noveltyInfo.getLocation().getAddress()); - - drawMapMarker(markerShowEntity); - - switch (noveltyInfo.getPoiType()) { - case MarkerPoiTypeEnum.GAS_STATION: - num_gas_station++; - break; - case MarkerPoiTypeEnum.TRAFFIC_CHECK: - num_traffic_check++; - break; - case MarkerPoiTypeEnum.ROAD_CLOSED: - num_road_closed++; - break; - case MarkerPoiTypeEnum.SHOP_DISCOUNT: - num_shop_discount++; - break; - case MarkerPoiTypeEnum.FOURS_SHOP: - num_fours_shop++; - break; - } - } - fillNumberTrackEventBody(array, 2, num_gas_station); - fillNumberTrackEventBody(array, 6, num_road_closed); - fillNumberTrackEventBody(array, 5, num_traffic_check); - fillNumberTrackEventBody(array, 7, num_shop_discount); - fillNumberTrackEventBody(array, 8, num_fours_shop); - } - analyticData(array); - } - } - - - private static void fillNumberTrackEventBody(JSONArray arr, int type, int size) { - JSONObject object = new JSONObject(); - try { - object.put("type", type); - object.put("num", size); - if (arr != null) { - arr.put(object); - } - } catch (JSONException e) { - e.printStackTrace(); - } + @Deprecated + public static void drawMapMarker(MarkerShowEntity markerShowEntity) { + getMapMarkerManager().drawMapMarker(markerShowEntity); } /** - * 统计地图内数据获取 - * - * @param array 埋点数据 + * 对指定类型高亮处理 + * 建议使用 + * @see MapMarkerManager#highlightedMarker(String) */ - private static void analyticData(JSONArray array) { - try { - if (array == null || array.length() == 0) { - return; - } - final Map properties = new HashMap<>(); - properties.put("data", array.toString()); - getMogoAnalytics().track("Launcher_Data_Get", properties); - } catch (Exception e) { - e.printStackTrace(); - } + @Deprecated + public static void highlightedMarker(String typeTag) { +// getMapMarkerManager().highlightedMarker(typeTag); } - - /** - * 绘制Marker,这里绘制的会使用markerShowEntities队列进行维护 - */ - public static IMogoMarker drawMapMarker(MarkerShowEntity markerShowEntity) { -// Logger.i(TAG, "绘制Marker====drawMapMarker:" + markerShowEntity); - try { - if (markerShowEntity.getMarkerLocation() != null) { - - MogoMarkerOptions options = new MogoMarkerOptions() - .owner(markerShowEntity.getMarkerType()) - .alpha(0.7f) - .object(markerShowEntity) - .latitude(markerShowEntity.getMarkerLocation().getLat()) - .longitude(markerShowEntity.getMarkerLocation().getLon()); - View markerView = MapMarkerAdapter.getMarkerView(mContext, markerShowEntity, options); - options.icon(markerView); - - IMogoMarker marker = getMarkerManager().addMarker(markerShowEntity.getMarkerType(), options); - marker.setOnMarkerClickListener(mogoMarkerClickListener); - return marker; - } else { - Logger.e(TAG, "Location 必须进行初始化!!!!!"); - } - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerManager.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerManager.java new file mode 100644 index 0000000000..3c47c25a32 --- /dev/null +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerManager.java @@ -0,0 +1,466 @@ +package com.mogo.module.service.marker; + +import android.content.Context; +import android.os.Handler; +import android.os.Looper; +import android.view.View; + +import com.mogo.map.MogoLatLng; +import com.mogo.map.marker.IMogoMarker; +import com.mogo.map.marker.IMogoMarkerClickListener; +import com.mogo.map.marker.MogoMarkerOptions; +import com.mogo.map.marker.MogoMarkersHandler; +import com.mogo.module.common.entity.MarkerCarChat; +import com.mogo.module.common.entity.MarkerCardResult; +import com.mogo.module.common.entity.MarkerExploreWay; +import com.mogo.module.common.entity.MarkerLocation; +import com.mogo.module.common.entity.MarkerNoveltyInfo; +import com.mogo.module.common.entity.MarkerOnlineCar; +import com.mogo.module.common.entity.MarkerPoiTypeEnum; +import com.mogo.module.common.entity.MarkerResponse; +import com.mogo.module.common.entity.MarkerShareMusic; +import com.mogo.module.common.entity.MarkerShowEntity; +import com.mogo.module.service.MarkerServiceHandler; +import com.mogo.module.service.ServiceConst; +import com.mogo.module.service.Utils; +import com.mogo.service.cardmanager.IMogoCardChangedListener; +import com.mogo.service.connection.IMogoOnMessageListener; +import com.mogo.utils.logger.Logger; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * author : donghongyu + * e-mail : 1358506549@qq.com + * date : 2020-02-1010:44 + * desc : 大而全的Marker管理 + * version: 1.0 + */ +public class MapMarkerManager implements IMogoMarkerClickListener, IMogoOnMessageListener { + private static final String TAG = "MarkerManager"; + // 第一次请求到地图的Marker数据 + private boolean isFirstMarker = true; + private Context mContext; + private IMogoMarker lastMarker; + private static MapMarkerManager mMarkerManager; + + private MapMarkerManager() { + } + + public static synchronized MapMarkerManager getInstance(Context context) { + synchronized (MapMarkerManager.class) { + if (mMarkerManager == null) { + mMarkerManager = new MapMarkerManager(); + } + } + return mMarkerManager; + } + + + /** + * 初始化大而全的 Marker 管理 + * + * @param context + */ + public void init(Context context) { + mContext = context; + // 长连接 + MarkerServiceHandler + .getMogoSocketManager() + .registerOnMessageListener(401001, this); + + MarkerServiceHandler.getMogoCardManager().registerCardChangedListener("LAUNCHER_MARKER_MODULE", new IMogoCardChangedListener() { + + @Override + public void onSwitched(int position, String moduleName) { + Logger.e(TAG, "======moduleName:" + moduleName); + highlightedMarker(moduleName); + } + }); + } + + + /** + * 地图上的Marker点击回调 + */ + @Override + public boolean onMarkerClicked(IMogoMarker marker) { + Logger.i(TAG, "onMarkerClicked 点击了大而全中的Marker:" + marker); + try { + if (lastMarker != null) { + // 判断点击的是否是同一个 + if (marker.equals(lastMarker)) { + Logger.w(TAG, "onMarkerClicked 与上一次点击的Marker一样,不做处理:" + marker); + return false; + } + + // 将上次选中 Marker 设置为未选中状态 + MarkerShowEntity lastMarkerShowEntity = (MarkerShowEntity) lastMarker.getObject(); + + Logger.i(TAG, "onMarkerClicked 点击了大而全中的Marker lastMarkerShowEntity:" + lastMarkerShowEntity); + + lastMarkerShowEntity.setChecked(false); + lastMarkerShowEntity.setHighlighted(false); + + drawMapMarker(lastMarkerShowEntity); + + lastMarker.remove(); + } + + // 将当前的Marker设置为选中 + MarkerShowEntity markerShowEntity = (MarkerShowEntity) marker.getObject(); + Logger.i(TAG, "onMarkerClicked 点击了大而全中的Marker markerShowEntity:" + markerShowEntity); + + markerShowEntity.setChecked(true); + markerShowEntity.setHighlighted(true); + + lastMarker = drawMapMarker(markerShowEntity); + if (lastMarker != null) { + lastMarker.setAlpha(1f); + } + + marker.remove(); + + final Map properties = new HashMap<>(); + switch (lastMarker.getOwner()) { + case ServiceConst.CARD_TYPE_CARS_CHATTING: + properties.put("type", 3); + break; + case ServiceConst.CARD_TYPE_USER_DATA: + properties.put("type", 5); + break; + case ServiceConst.CARD_TYPE_ROAD_CONDITION: + properties.put("type", 2); + break; + case ServiceConst.CARD_TYPE_NOVELTY: + MarkerShowEntity showEntity = (MarkerShowEntity) lastMarker.getObject(); + Object bindObj = showEntity.getBindObj(); + if (bindObj instanceof MarkerNoveltyInfo) { + switch (((MarkerNoveltyInfo) bindObj).getPoiType()) { + case MarkerPoiTypeEnum.GAS_STATION: + properties.put("type", 4); + break; + case MarkerPoiTypeEnum.TRAFFIC_CHECK: + properties.put("type", 8); + break; + case MarkerPoiTypeEnum.ROAD_CLOSED: + properties.put("type", 7); + break; + case MarkerPoiTypeEnum.SHOP_DISCOUNT: + properties.put("type", 9); + break; + case MarkerPoiTypeEnum.FOURS_SHOP: + properties.put("type", 10); + break; + } + } + break; + case ServiceConst.CARD_TYPE_SHARE_MUSIC: + properties.put("type", 6); + break; + } + + MarkerServiceHandler.getMogoAnalytics().track("Launcher_Icon_Click", properties); + + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + + // 对指定类型高亮处理 + public static void highlightedMarker(String typeTag) { + try { + Map> allMarker = MarkerServiceHandler.getMarkerManager().getAllMarkers(); + for (Map.Entry> entry : allMarker.entrySet()) { + String keyStr = entry.getKey(); + List markerList = entry.getValue(); + + if (keyStr.equals(typeTag)) { + for (IMogoMarker marker : markerList) { + marker.setAlpha(1f); + } + } else { + for (IMogoMarker marker : markerList) { + marker.setAlpha(0.7f); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 绘制Marker + */ + public void drawMapMarker(MarkerResponse response) { + lastMarker = null; + + JSONArray array = new JSONArray(); + + // 解析不同的Marker类型,然后对应的进行绘制 + if (response != null && response.getResult() != null) { + + MarkerCardResult markerCardResult = response.getResult(); + + // 语音触发的在线车辆搜索,采用增量的形式绘制 + if (markerCardResult.getDataType() != null && + markerCardResult.getDataType().size() == 1 && + markerCardResult.getDataType().contains(ServiceConst.CARD_TYPE_USER_DATA)) { + MarkerServiceHandler.getMarkerManager().removeMarkers(ServiceConst.CARD_TYPE_USER_DATA); + MarkerServiceHandler.getMogoCardManager().switch2(ServiceConst.CARD_TYPE_USER_DATA); + isFirstMarker = true; + } else { + // 清空所有地图上绘制的Marker + MarkerServiceHandler.getMarkerManager().removeMarkers(); + } + + List carChatList = markerCardResult.getCarChat(); + List onlineCarList = markerCardResult.getOnlineCar(); + List exploreWayList = markerCardResult.getExploreWay(); + List shareMusicList = markerCardResult.getShareMusic(); + List noveltyInfoList = markerCardResult.getNoveltyInfo(); + + if (carChatList != null) { + for (MarkerCarChat markerCarChat : carChatList) { + MarkerLocation markerLocation = markerCarChat.getLocation(); + + MarkerShowEntity markerShowEntity = new MarkerShowEntity(); + markerShowEntity.setBindObj(markerCarChat); + markerShowEntity.setMarkerLocation(markerLocation); + markerShowEntity.setMarkerType(markerCarChat.getType()); + markerShowEntity.setTextContent(markerCarChat.getUserInfo().getUserName()); + markerShowEntity.setIconUrl(markerCarChat.getUserInfo().getUserHead()); + + drawMapMarker(markerShowEntity); + } + } + + if (onlineCarList != null) { + IMogoMarker nearlyMogoMarker = null; + double nearlyDistance = Double.MAX_VALUE; + for (MarkerOnlineCar markerOnlineCar : onlineCarList) { + MarkerLocation markerLocation = markerOnlineCar.getLocation(); + + MarkerShowEntity markerShowEntity = new MarkerShowEntity(); + markerShowEntity.setBindObj(markerOnlineCar); + markerShowEntity.setMarkerLocation(markerLocation); + markerShowEntity.setMarkerType(markerOnlineCar.getType()); + markerShowEntity.setTextContent(markerOnlineCar.getUserInfo().getUserName()); + markerShowEntity.setIconUrl(markerOnlineCar.getUserInfo().getUserHead()); + + IMogoMarker iMogoMarker = drawMapMarker(markerShowEntity); + // 计算在线车辆距离当前车辆的距离,每次都与最后一次距离最近的进行比较,保留距离最近的车辆,进行卡片展示 + try { + double calculateDistance = Utils.calculateLineDistance( + new MogoLatLng(markerLocation.getLat(), markerLocation.getLat()), + new MogoLatLng( + MarkerServiceHandler.getMogoLocationClient().getLastKnowLocation().getLatitude(), + MarkerServiceHandler.getMogoLocationClient().getLastKnowLocation().getLongitude() + ) + ); + + // 进行比较,保留最近的一个数据 + if (calculateDistance < nearlyDistance) { + nearlyMogoMarker = iMogoMarker; + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + fillNumberTrackEventBody(array, 3, onlineCarList.size()); + + try { + // 在ACC on 之后第一次获取到了在线车辆数据,选中最近的一个Marker + if (isFirstMarker) { + if (nearlyMogoMarker != null) { +// getMogoCardManager().switch2(ServiceConst.CARD_TYPE_USER_DATA); +// MarkerShowEntity markerShowEntity = (MarkerShowEntity) nearlyMogoMarker.getObject(); +// MarkerOnlineCar markerOnlineCar = (MarkerOnlineCar) markerShowEntity.getBindObj(); +// onLineCarCardViewProvider.updateView(markerOnlineCar); + MogoMarkersHandler.getInstance().onMarkerClicked(nearlyMogoMarker); + isFirstMarker = false; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + if (exploreWayList != null) { + for (MarkerExploreWay markerExploreWay : exploreWayList) { + if (!markerExploreWay.getCanLive()) { + MarkerLocation markerLocation = markerExploreWay.getLocation(); + + MarkerShowEntity markerShowEntity = new MarkerShowEntity(); + markerShowEntity.setBindObj(markerExploreWay); + markerShowEntity.setMarkerLocation(markerLocation); + markerShowEntity.setMarkerType(markerExploreWay.getType()); + markerShowEntity.setTextContent(markerExploreWay.getAddr()); + + drawMapMarker(markerShowEntity); + } + } + fillNumberTrackEventBody(array, 1, exploreWayList.size()); + } + + if (shareMusicList != null) { + for (MarkerShareMusic markerShareMusic : shareMusicList) { + MarkerLocation markerLocation = markerShareMusic.getLocation(); + + MarkerShowEntity markerShowEntity = new MarkerShowEntity(); + markerShowEntity.setBindObj(markerShareMusic); + markerShowEntity.setMarkerLocation(markerLocation); + markerShowEntity.setMarkerType(markerShareMusic.getType()); + markerShowEntity.setTextContent(markerShareMusic.getMediaName()); + markerShowEntity.setIconUrl(markerShareMusic.getMediaImg()); + + drawMapMarker(markerShowEntity); + } + fillNumberTrackEventBody(array, 4, shareMusicList.size()); + } + + if (noveltyInfoList != null) { + int num_gas_station = 0; + int num_traffic_check = 0; + int num_road_closed = 0; + int num_shop_discount = 0; + int num_fours_shop = 0; + + for (MarkerNoveltyInfo noveltyInfo : noveltyInfoList) { + MarkerLocation markerLocation = noveltyInfo.getLocation(); + + MarkerShowEntity markerShowEntity = new MarkerShowEntity(); + markerShowEntity.setBindObj(noveltyInfo); + markerShowEntity.setMarkerLocation(markerLocation); + markerShowEntity.setMarkerType(noveltyInfo.getType()); + markerShowEntity.setTextContent(noveltyInfo.getLocation().getAddress()); + + drawMapMarker(markerShowEntity); + + switch (noveltyInfo.getPoiType()) { + case MarkerPoiTypeEnum.GAS_STATION: + num_gas_station++; + break; + case MarkerPoiTypeEnum.TRAFFIC_CHECK: + num_traffic_check++; + break; + case MarkerPoiTypeEnum.ROAD_CLOSED: + num_road_closed++; + break; + case MarkerPoiTypeEnum.SHOP_DISCOUNT: + num_shop_discount++; + break; + case MarkerPoiTypeEnum.FOURS_SHOP: + num_fours_shop++; + break; + } + } + fillNumberTrackEventBody(array, 2, num_gas_station); + fillNumberTrackEventBody(array, 6, num_road_closed); + fillNumberTrackEventBody(array, 5, num_traffic_check); + fillNumberTrackEventBody(array, 7, num_shop_discount); + fillNumberTrackEventBody(array, 8, num_fours_shop); + } + analyticData(array); + } + } + + + /** + * 统计埋点 + */ + private static void fillNumberTrackEventBody(JSONArray arr, int type, int size) { + JSONObject object = new JSONObject(); + try { + object.put("type", type); + object.put("num", size); + if (arr != null) { + arr.put(object); + } + } catch (JSONException e) { + e.printStackTrace(); + } + } + + /** + * 统计地图内数据获取 + * + * @param array 埋点数据 + */ + private static void analyticData(JSONArray array) { + try { + if (array == null || array.length() == 0) { + return; + } + final Map properties = new HashMap<>(); + properties.put("data", array.toString()); + MarkerServiceHandler.getMogoAnalytics().track("Launcher_Data_Get", properties); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 绘制Marker,这里绘制的会使用markerShowEntities队列进行维护 + * + * @param markerShowEntity marker 绘制数据实体 + * @return 绘制的Marker + */ + public IMogoMarker drawMapMarker(MarkerShowEntity markerShowEntity) { + //Logger.i(TAG, "绘制Marker====drawMapMarker:" + markerShowEntity); + try { + if (markerShowEntity.getMarkerLocation() != null) { + + MogoMarkerOptions options = new MogoMarkerOptions() + .owner(markerShowEntity.getMarkerType()) + .alpha(0.7f) + .object(markerShowEntity) + .latitude(markerShowEntity.getMarkerLocation().getLat()) + .longitude(markerShowEntity.getMarkerLocation().getLon()); + View markerView = MapMarkerAdapter.getMarkerView(mContext, markerShowEntity, options); + options.icon(markerView); + + IMogoMarker marker = MarkerServiceHandler.getMarkerManager().addMarker(markerShowEntity.getMarkerType(), options); + marker.setOnMarkerClickListener(this); + return marker; + } else { + Logger.e(TAG, "Location 必须进行初始化!!!!!"); + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + + @Override + public Class target() { + return MarkerResponse.class; + } + + @Override + public void onMsgReceived(final MarkerResponse response) { + Logger.e(TAG, "MarkerResponse======" + response); + if (!MarkerServiceHandler.getMogoStatusManager().isSearchUIShow() && + !MarkerServiceHandler.getMogoStatusManager().isV2XShow()) { + isFirstMarker = true; + Handler handler = new Handler(Looper.getMainLooper()); + handler.post(new Runnable() { + @Override + public void run() { + drawMapMarker(response); + } + }); + } + } +}