VectorLayer: add sort when displaying drawables (#1043)
This commit is contained in:
parent
1ee201a41f
commit
fb0b88e916
@ -44,6 +44,8 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.oscim.core.MercatorProjection.latitudeToY;
|
import static org.oscim.core.MercatorProjection.latitudeToY;
|
||||||
@ -66,6 +68,7 @@ public class VectorLayer extends AbstractVectorLayer<Drawable> implements Gestur
|
|||||||
protected final SpatialIndex<Drawable> mDrawables = new QuadTree<Drawable>(1 << 30, 18);
|
protected final SpatialIndex<Drawable> mDrawables = new QuadTree<Drawable>(1 << 30, 18);
|
||||||
|
|
||||||
protected final List<Drawable> tmpDrawables = new ArrayList<Drawable>(128);
|
protected final List<Drawable> tmpDrawables = new ArrayList<Drawable>(128);
|
||||||
|
private final Comparator<Drawable> mComparator;
|
||||||
|
|
||||||
protected final JtsConverter mConverter;
|
protected final JtsConverter mConverter;
|
||||||
protected double mMinX;
|
protected double mMinX;
|
||||||
@ -74,10 +77,16 @@ public class VectorLayer extends AbstractVectorLayer<Drawable> implements Gestur
|
|||||||
private static class GeometryWithStyle implements Drawable {
|
private static class GeometryWithStyle implements Drawable {
|
||||||
final Geometry geometry;
|
final Geometry geometry;
|
||||||
final Style style;
|
final Style style;
|
||||||
|
final int priority;
|
||||||
|
|
||||||
GeometryWithStyle(Geometry g, Style s) {
|
GeometryWithStyle(Geometry g, Style s) {
|
||||||
|
this(g, s, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
GeometryWithStyle(Geometry g, Style s, int p) {
|
||||||
geometry = g;
|
geometry = g;
|
||||||
style = s;
|
style = s;
|
||||||
|
priority = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -89,6 +98,11 @@ public class VectorLayer extends AbstractVectorLayer<Drawable> implements Gestur
|
|||||||
public Geometry getGeometry() {
|
public Geometry getGeometry() {
|
||||||
return geometry;
|
return geometry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return priority;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Polygon mEnvelope;
|
protected Polygon mEnvelope;
|
||||||
@ -100,6 +114,12 @@ public class VectorLayer extends AbstractVectorLayer<Drawable> implements Gestur
|
|||||||
public VectorLayer(Map map) {
|
public VectorLayer(Map map) {
|
||||||
super(map);
|
super(map);
|
||||||
mConverter = new JtsConverter(Tile.SIZE / UNSCALE_COORD);
|
mConverter = new JtsConverter(Tile.SIZE / UNSCALE_COORD);
|
||||||
|
mComparator = new Comparator<Drawable>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Drawable o1, Drawable o2) {
|
||||||
|
return Integer.compare(o1.getPriority(), o2.getPriority());
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Box bbox(Geometry geometry, Style style) {
|
private static Box bbox(Geometry geometry, Style style) {
|
||||||
@ -199,7 +219,8 @@ public class VectorLayer extends AbstractVectorLayer<Drawable> implements Gestur
|
|||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
tmpDrawables.clear();
|
tmpDrawables.clear();
|
||||||
mDrawables.search(bbox, tmpDrawables);
|
mDrawables.search(bbox, tmpDrawables);
|
||||||
// TODO sort by some order...
|
// sort by some order...
|
||||||
|
Collections.sort(tmpDrawables, mComparator);
|
||||||
|
|
||||||
for (Drawable d : tmpDrawables) {
|
for (Drawable d : tmpDrawables) {
|
||||||
Style style = d.getStyle();
|
Style style = d.getStyle();
|
||||||
|
@ -13,4 +13,11 @@ public interface Drawable {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Geometry getGeometry();
|
public Geometry getGeometry();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Priority of drawable, the larger the value, the higher it will appear when drawn in the VectorLayer.
|
||||||
|
*
|
||||||
|
* @see org.oscim.layers.vector.VectorLayer processFeatures() method
|
||||||
|
*/
|
||||||
|
public int getPriority();
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ public class JtsDrawable implements Drawable {
|
|||||||
|
|
||||||
protected Style style;
|
protected Style style;
|
||||||
protected Geometry geometry;
|
protected Geometry geometry;
|
||||||
|
protected int priority = 0;
|
||||||
|
|
||||||
public JtsDrawable(Style style) {
|
public JtsDrawable(Style style) {
|
||||||
this.style = style;
|
this.style = style;
|
||||||
@ -53,6 +54,15 @@ public class JtsDrawable implements Drawable {
|
|||||||
return geometry;
|
return geometry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPriority(int priority) {
|
||||||
|
this.priority = priority;
|
||||||
|
}
|
||||||
|
|
||||||
protected static GeomBuilder loadPoints(GeomBuilder gb, List<GeoPoint> points) {
|
protected static GeomBuilder loadPoints(GeomBuilder gb, List<GeoPoint> points) {
|
||||||
for (GeoPoint point : points) {
|
for (GeoPoint point : points) {
|
||||||
gb.point(point.getLongitude(),
|
gb.point(point.getLongitude(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user