feat: Adds sort when displaying drawable on a VectorLayer
This commit is contained in:
parent
1ee201a41f
commit
ab81b7838c
@ -18,11 +18,21 @@
|
||||
*/
|
||||
package org.oscim.layers.vector;
|
||||
|
||||
import static org.oscim.core.MercatorProjection.latitudeToY;
|
||||
import static org.oscim.core.MercatorProjection.longitudeToX;
|
||||
|
||||
import org.locationtech.jts.geom.Envelope;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.LineString;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.locationtech.jts.geom.*;
|
||||
import org.locationtech.jts.geom.Polygon;
|
||||
import org.locationtech.jts.simplify.DouglasPeuckerSimplifier;
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.core.*;
|
||||
import org.oscim.core.Box;
|
||||
import org.oscim.core.GeoPoint;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.event.Gesture;
|
||||
import org.oscim.event.GestureListener;
|
||||
import org.oscim.event.MotionEvent;
|
||||
@ -44,11 +54,10 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static org.oscim.core.MercatorProjection.latitudeToY;
|
||||
import static org.oscim.core.MercatorProjection.longitudeToX;
|
||||
|
||||
/* TODO keep bounding box of geometries - only try to render when bbox intersects viewport */
|
||||
|
||||
/**
|
||||
@ -75,9 +84,15 @@ public class VectorLayer extends AbstractVectorLayer<Drawable> implements Gestur
|
||||
final Geometry geometry;
|
||||
final Style style;
|
||||
|
||||
final int priority;
|
||||
GeometryWithStyle(Geometry g, Style s) {
|
||||
this(g, s, 0);
|
||||
}
|
||||
|
||||
GeometryWithStyle(Geometry g, Style s, int p) {
|
||||
geometry = g;
|
||||
style = s;
|
||||
priority = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -89,6 +104,11 @@ public class VectorLayer extends AbstractVectorLayer<Drawable> implements Gestur
|
||||
public Geometry getGeometry() {
|
||||
return geometry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected Polygon mEnvelope;
|
||||
@ -199,7 +219,18 @@ public class VectorLayer extends AbstractVectorLayer<Drawable> implements Gestur
|
||||
synchronized (this) {
|
||||
tmpDrawables.clear();
|
||||
mDrawables.search(bbox, tmpDrawables);
|
||||
// TODO sort by some order...
|
||||
// sort by some order...
|
||||
Collections.sort(tmpDrawables, new Comparator<Drawable>() {
|
||||
@Override
|
||||
public int compare(Drawable o1, Drawable o2) {
|
||||
if (o1.getPriority()<o2.getPriority()) {
|
||||
return -1;
|
||||
} else if (o1.getPriority()>o2.getPriority()) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
for (Drawable d : tmpDrawables) {
|
||||
Style style = d.getStyle();
|
||||
|
@ -13,4 +13,10 @@ public interface Drawable {
|
||||
* @return
|
||||
*/
|
||||
public Geometry getGeometry();
|
||||
|
||||
/**
|
||||
* priority for drawable, The larger the value, the higher it will appear when drawn in the Vectorlayer
|
||||
* @see org.oscim.layers.vector.VectorLayer draw() method
|
||||
* */
|
||||
public int getPriority();
|
||||
}
|
||||
|
@ -20,14 +20,20 @@ public class JtsDrawable implements Drawable {
|
||||
|
||||
protected Style style;
|
||||
protected Geometry geometry;
|
||||
protected int priority = 0;
|
||||
|
||||
public JtsDrawable(Style style) {
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
public JtsDrawable(Geometry geometry, Style style) {
|
||||
this(geometry, style, 0);
|
||||
}
|
||||
|
||||
public JtsDrawable(Geometry geometry, Style style, int priority) {
|
||||
this.geometry = geometry;
|
||||
this.style = style;
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,6 +59,15 @@ public class JtsDrawable implements Drawable {
|
||||
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) {
|
||||
for (GeoPoint point : points) {
|
||||
gb.point(point.getLongitude(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user