Tengo un MapView
y superpongo 1,700 puntos, cada uno con el mismo dibujo pero con información diferente. Actualmente estoy usando la opción de Superposición detallada para agregar todas las superposiciones que se rellenan una vez que se pescan. Esto funciona, pero el rendimiento es lento. Cambiar el nivel de zoom y el enfoque es nervioso. Ahora, ¿sería mejor usar ArrayItemizedOverlay
ya que es el mismo dibujable, o el mapa sería tan lento?(elementos de superposición MapView y 1700) .equals ("Lento")
import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.app.Activity;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
public class Points extends ItemizedOverlay <OverlayItem> {
Context mContext;
private ArrayList mOverlays = new ArrayList();
String newLine = String.format("%n");
public Points(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
// TODO Auto-generated constructor stub
}
@Override
protected OverlayItem createItem(int i) {
return (OverlayItem) mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
@Override
public void draw(Canvas canvas,
MapView mapView,
boolean shadow) {
if (!shadow)
super.draw(canvas, mapView, shadow);
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
}
public void populateNow(){
setLastFocusedIndex(-1);
populate();
}
public Points(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext = context;
}
@Override
protected boolean onTap(int index) {
Intent intent = new Intent();
OverlayItem item = (OverlayItem) mOverlays.get(index);
AlertDialog.Builder dialog1 = new AlertDialog.Builder(mContext);
dialog1.setTitle(item.getTitle());
String info = item.getSnippet();
String delims = "[$]";
String [] tokens = info.split(delims);
String info1 = tokens [0];
String info2 = tokens[1];
String delims2 = "[!]";
String [] tokens2 = info1.split(delims2);
double lat = Double.parseDouble(tokens2[0]);
double lon = Double.parseDouble(tokens2[1]);
final String location = tokens2[0]+","+tokens2[1];
dialog1.setMessage(info2);
dialog1.setPositiveButton("Navigate", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Nav(location);
}
});
dialog1.setNegativeButton("Directions", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Direction(location);
}
}) ;
dialog1.show();
return true;
}
public void Nav(String location) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + location));
mContext.startActivity(i);
}
public void Direction(String location) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?daddr=" + location));
mContext.startActivity(i);
}
}
artículos Cómo estoy añadiendo:
mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.plug);
itemizedoverlay = new Points(drawable, this);
while (...) {
point = new GeoPoint((int) (lat * 1000000), (int) (lon * 1000000));
overlayitem = new OverlayItem(point, Station_Name, comb);
itemizedoverlay.addOverlay(overlayitem);
}
Intenté esto y para mí no fue más rápido. Tenía 108 elementos para agregar, y los dividí en tres particiones. Era aproximadamente la misma velocidad, independientemente del método que usaba. – dermatthias
Sí, es por eso que utilicé 100 artículos en mi ejemplo. Supongo que el límite es de 150 elementos cuando la velocidad comienza a disminuir, por lo que no tiene que preocuparse. –