修改了Marker的高亮展示逻辑,效率更高
This commit is contained in:
@@ -6,6 +6,7 @@ import com.mogo.map.MogoLatLng;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -52,6 +53,12 @@ public interface IMogoMarkerManager {
|
||||
* @return
|
||||
*/
|
||||
List< IMogoMarker > getMarkers( String tag );
|
||||
/**
|
||||
* 获取所有类型的marker。
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Map< String, List< IMogoMarker > > getAllMarkers( );
|
||||
|
||||
/**
|
||||
* 仅保留指定类型的tag
|
||||
|
||||
@@ -77,6 +77,11 @@ public class MogoMarkersHandler implements IMogoMarkerClickListener, IMogoMarker
|
||||
}
|
||||
|
||||
|
||||
public synchronized Map< String, List< IMogoMarker > > getAllMarkers() {
|
||||
return mServicesMarkers;
|
||||
}
|
||||
|
||||
|
||||
public synchronized void add( String tag, IMogoMarker marker ) {
|
||||
if ( marker == null ) {
|
||||
return;
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.mogo.map.marker.MogoMarkersHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -78,6 +79,11 @@ public class MogoMarkerManager implements IMogoMarkerManager {
|
||||
return MogoMarkersHandler.getInstance().getMarkers( tag );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map< String, List< IMogoMarker > > getAllMarkers() {
|
||||
return MogoMarkersHandler.getInstance().getAllMarkers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMarkersExcept( String tag ) {
|
||||
MogoMarkersHandler.getInstance().deleteAllExcept( tag );
|
||||
|
||||
@@ -92,9 +92,7 @@ public class MarkerShowEntity {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
MarkerShowEntity that = (MarkerShowEntity) o;
|
||||
return isChecked == that.isChecked &&
|
||||
isHighlighted == that.isHighlighted &&
|
||||
Objects.equals(iconUrl, that.iconUrl) &&
|
||||
return Objects.equals(iconUrl, that.iconUrl) &&
|
||||
Objects.equals(textContent, that.textContent) &&
|
||||
Objects.equals(markerType, that.markerType) &&
|
||||
Objects.equals(bindObj, that.bindObj) &&
|
||||
@@ -103,7 +101,7 @@ public class MarkerShowEntity {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(isChecked, isHighlighted, iconUrl, textContent, markerType, bindObj, markerLocation);
|
||||
return Objects.hash(iconUrl, textContent, markerType, bindObj, markerLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,8 +30,8 @@ import com.mogo.service.map.IMogoMapService;
|
||||
import com.mogo.service.statusmanager.IMogoStatusManager;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* author : donghongyu
|
||||
@@ -155,7 +155,7 @@ public class MarkerServiceHandler {
|
||||
lastMarkerShowEntity.setChecked(false);
|
||||
lastMarkerShowEntity.setHighlighted(false);
|
||||
|
||||
drawMapMarkerItem(lastMarkerShowEntity);
|
||||
drawMapMarker(lastMarkerShowEntity);
|
||||
|
||||
lastMarker.remove();
|
||||
}
|
||||
@@ -167,38 +167,38 @@ public class MarkerServiceHandler {
|
||||
markerShowEntity.setChecked(true);
|
||||
markerShowEntity.setHighlighted(true);
|
||||
|
||||
lastMarker = drawMapMarkerItem(markerShowEntity);
|
||||
lastMarker = drawMapMarker(markerShowEntity);
|
||||
if (lastMarker != null) {
|
||||
lastMarker.setAlpha(1f);
|
||||
}
|
||||
|
||||
marker.remove();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 记录所有的Marker
|
||||
private static List<MarkerShowEntity> markerShowEntities;
|
||||
|
||||
// 对指定类型高亮处理
|
||||
public static void highlightedMarker(String typeTag) {
|
||||
if (markerShowEntities != null) {
|
||||
if (lastMarker != null) {
|
||||
// 将上次选中 Marker 设置为未选中状态
|
||||
MarkerShowEntity lastMarkerShowEntity = (MarkerShowEntity) lastMarker.getObject();
|
||||
lastMarkerShowEntity.setChecked(false);
|
||||
lastMarkerShowEntity.setHighlighted(false);
|
||||
drawMapMarkerItem(lastMarkerShowEntity);
|
||||
}
|
||||
lastMarker = null;
|
||||
getMarkerManager().removeMarkers();
|
||||
try {
|
||||
Map<String, List<IMogoMarker>> allMarker = getMarkerManager().getAllMarkers();
|
||||
for (Map.Entry<String, List<IMogoMarker>> entry : allMarker.entrySet()) {
|
||||
String keyStr = entry.getKey();
|
||||
List<IMogoMarker> markerList = entry.getValue();
|
||||
|
||||
for (MarkerShowEntity markerShowEntity : markerShowEntities) {
|
||||
if (markerShowEntity.getMarkerType().equals(typeTag)) {
|
||||
markerShowEntity.setHighlighted(true);
|
||||
if (keyStr.equals(typeTag)) {
|
||||
for (IMogoMarker marker : markerList) {
|
||||
marker.setAlpha(1f);
|
||||
}
|
||||
} else {
|
||||
markerShowEntity.setHighlighted(false);
|
||||
for (IMogoMarker marker : markerList) {
|
||||
marker.setAlpha(0.7f);
|
||||
}
|
||||
}
|
||||
drawMapMarkerItem(markerShowEntity);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,11 +207,6 @@ public class MarkerServiceHandler {
|
||||
public static void drawMapMarker(MarkerResponse response) {
|
||||
lastMarker = null;
|
||||
getMarkerManager().removeMarkers();
|
||||
if (markerShowEntities == null) {
|
||||
markerShowEntities = new ArrayList<>();
|
||||
} else {
|
||||
markerShowEntities.clear();
|
||||
}
|
||||
|
||||
// 解析不同的Marker类型,然后对应的进行绘制
|
||||
if (response != null && response.getResult() != null) {
|
||||
@@ -299,7 +294,7 @@ public class MarkerServiceHandler {
|
||||
}
|
||||
|
||||
}
|
||||
// getMapUIController().changeZoom(8);
|
||||
// getMapUIController().changeZoom(12);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,15 +311,11 @@ public class MarkerServiceHandler {
|
||||
.latitude(markerShowEntity.getMarkerLocation().getLat())
|
||||
.longitude(markerShowEntity.getMarkerLocation().getLon());
|
||||
options.icon(markerView);
|
||||
options.alpha(0.8f);
|
||||
|
||||
IMogoMarker marker = getMarkerManager().addMarker(markerShowEntity.getMarkerType(), options);
|
||||
marker.setOnMarkerClickListener(mogoMarkerClickListener);
|
||||
marker.setObject(markerShowEntity);
|
||||
|
||||
if (markerShowEntities != null) {
|
||||
markerShowEntities.add(markerShowEntity);
|
||||
}
|
||||
marker.setAlpha(0.7f);
|
||||
return marker;
|
||||
} else {
|
||||
Logger.e(TAG, "Location 必须进行初始化!!!!!");
|
||||
@@ -335,37 +326,4 @@ public class MarkerServiceHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制Marker,这里绘制的不会添加到队列中
|
||||
*/
|
||||
public static IMogoMarker drawMapMarkerItem(MarkerShowEntity markerShowEntity) {
|
||||
Logger.e(TAG, "绘制Marker====drawMapMarkerItem:" + markerShowEntity);
|
||||
try {
|
||||
if (markerShowEntity.getMarkerLocation() != null) {
|
||||
View markerView = MapMarkerAdapter.getMarkerView(mContext, markerShowEntity);
|
||||
|
||||
MogoMarkerOptions options = new MogoMarkerOptions()
|
||||
.owner(markerShowEntity.getMarkerType())
|
||||
.latitude(markerShowEntity.getMarkerLocation().getLat())
|
||||
.longitude(markerShowEntity.getMarkerLocation().getLon());
|
||||
options.icon(markerView);
|
||||
if (markerShowEntity.isHighlighted()) {
|
||||
options.alpha(1f);
|
||||
} else {
|
||||
options.alpha(0.8f);
|
||||
}
|
||||
|
||||
IMogoMarker marker = getMarkerManager().addMarker(markerShowEntity.getMarkerType(), options);
|
||||
marker.setOnMarkerClickListener(mogoMarkerClickListener);
|
||||
marker.setObject(markerShowEntity);
|
||||
|
||||
return marker;
|
||||
} else {
|
||||
Logger.e(TAG, "Location 必须进行初始化!!!!!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user