use ItemizedOverlay utility 'makeMarker'

set marker bounds only once
This commit is contained in:
Hannes Janetzek 2013-03-13 13:47:59 +01:00
parent 1a1345aa70
commit 8c0e2525ce

View File

@ -16,6 +16,11 @@
package org.oscim.overlay; package org.oscim.overlay;
// TODO
// - need to sort items back to front for rendering
// - and to make this work for multiple overlays
// a global scenegraph is probably required.
import org.oscim.core.GeoPoint; import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.core.MercatorProjection; import org.oscim.core.MercatorProjection;
@ -24,6 +29,7 @@ import org.oscim.renderer.layer.SymbolLayer;
import org.oscim.renderer.overlays.BasicOverlay; import org.oscim.renderer.overlays.BasicOverlay;
import org.oscim.view.MapView; import org.oscim.view.MapView;
import android.content.res.Resources;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.opengl.Matrix; import android.opengl.Matrix;
@ -60,8 +66,6 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
/* package */InternalItem mItems; /* package */InternalItem mItems;
/* package */Object lock = new Object(); /* package */Object lock = new Object();
// /* package */final ArrayList<Item> mInternalItemList;
private final Rect mRect = new Rect();
/* package */Item mFocusedItem; /* package */Item mFocusedItem;
/* package */boolean mUpdate; /* package */boolean mUpdate;
@ -87,7 +91,7 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
boolean positionChanged, boolean positionChanged,
boolean tilesChanged) { boolean tilesChanged) {
if (!tilesChanged && !mUpdate) if (!positionChanged && !mUpdate)
return; return;
mUpdate = false; mUpdate = false;
@ -205,8 +209,6 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
// } else // } else
// marker = item.getMarker(state); // marker = item.getMarker(state);
boundToHotspot(marker, item.getMarkerHotspot());
mSymbolLayer.addDrawable(marker, state, it.x, it.y); mSymbolLayer.addDrawable(marker, state, it.x, it.y);
} }
@ -244,7 +246,6 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
this.mDefaultMarker = pDefaultMarker; this.mDefaultMarker = pDefaultMarker;
mLayer = new ItemOverlay(mapView); mLayer = new ItemOverlay(mapView);
} }
/** /**
@ -370,6 +371,8 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
return mFocusedItem; return mFocusedItem;
} }
private static final Rect mRect = new Rect();
/** /**
* Adjusts a drawable's bounds so that (0,0) is a pixel in the location * Adjusts a drawable's bounds so that (0,0) is a pixel in the location
* described by the hotspot parameter. Useful for "pin"-like graphics. For * described by the hotspot parameter. Useful for "pin"-like graphics. For
@ -381,7 +384,7 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
* the hotspot for the drawable * the hotspot for the drawable
* @return the same drawable that was passed in. * @return the same drawable that was passed in.
*/ */
protected synchronized Drawable boundToHotspot(final Drawable marker, HotspotPlace hotspot) { public static synchronized Drawable boundToHotspot(final Drawable marker, HotspotPlace hotspot) {
final int markerWidth = marker.getIntrinsicWidth(); final int markerWidth = marker.getIntrinsicWidth();
final int markerHeight = marker.getIntrinsicHeight(); final int markerHeight = marker.getIntrinsicHeight();
@ -427,6 +430,14 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
return marker; return marker;
} }
public static Drawable makeMarker(Resources res, int id, HotspotPlace place){
Drawable marker = res.getDrawable(id);
if (place == null)
boundToHotspot(marker, HotspotPlace.CENTER);
else
boundToHotspot(marker, place);
return marker;
}
// /** // /**
// * Draw a marker on each of our items. populate() must have been called // * Draw a marker on each of our items. populate() must have been called
// * first.<br/> // * first.<br/>