I draw polygon on my map using a code similar to this :
GeoPoint pt1=new GeoPoint(13002798,77580000);
GeoPoint pt2= new GeoPoint(pt1.getLatitudeE6()+diff, pt1.getLongitudeE6());
GeoPoint pt3= new GeoPoint(pt1.getLatitudeE6()+diff, pt1.getLongitudeE6()+diff);
GeoPoint pt4= new GeoPoint(pt1.getLatitudeE6(), pt1.getLongitudeE6()+diff);
GeoPoint pt5= new GeoPoint(pt1);
PathOverlay myOverlay= new PathOverlay(Color.RED, this);
myOverlay.getPaint().setStyle(Paint.Style.FILL);
myOverlay.addPoint(pt1);
myOverlay.addPoint(pt2);
myOverlay.addPoint(pt3);
myOverlay.addPoint(pt4);
myOverlay.addPoint(pt5);
map.getOverlays().add(myOverlay);
Now I want to offset my overlay polygon exactly 10px up, independent of zoom or other parameters. How can I do that? I need this to draw line above my POI marker arrows.
Something like that:
Projection pj = mapView.getProjection();
Point pix = pj.toPixels(p);
pix.y -= 10; //10 pixels up
GeoPoint p2 = pj.fromPixels(pix2.x, pix2.y);
double offset = p2.getLatitude() - p.getLatitude();
Then you can offset latitude of all points by adding offset.
However, this solution is a little bit strange. Instead, you could also display your polygon "under" your POI markers. osmdroid displays overlays following their order: first at the bottom, latest on top.
Latest point: never use PathOverlay for filled polygons, you will get weird behaviours in some cases (when a part of polygon is inside the view, a part is outside). You can use OSMBonusPack Polygon instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.