![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5yNxQDZkRDOyMzM0MTYwcjMzE2YwkTNihTYjljY4EDOw8CX0JXZ252bj91Ztl2Lc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
public class DrawLocate {
private static Graphic graphicCenterPoint;
private static Graphic graphicErrorRound;
public static void drawPoint(Point center, double radius,
GraphicsLayer graphicsLayer, Drawable centerImage,
int errorRoundColorFill, int errorRoundColorLine) {
if(graphicsLayer != null){
graphicsLayer.removeAll();
}
PictureMarkerSymbol symbol = new PictureMarkerSymbol(centerImage);
symbol.setOffsetY(10.0f);
graphicCenterPoint = new Graphic(center, symbol);
if(radius > 0){
Polygon polygon = new Polygon();
getCircle(center, radius, polygon);
FillSymbol fillSymbol = new SimpleFillSymbol(errorRoundColorFill);
fillSymbol.setAlpha(10);
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(errorRoundColorLine, 2.0f, SimpleLineSymbol.STYLE.SOLID);
fillSymbol.setOutline(lineSymbol);
graphicErrorRound = new Graphic(polygon, fillSymbol);
}
graphicsLayer.addGraphics(new Graphic[]{graphicCenterPoint, graphicErrorRound});
}
public static Polygon getCircle(Point center, double radius) {
Polygon polygon = new Polygon();
getCircle(center, radius, polygon);
return polygon;
}
private static void getCircle(Point center, double radius, Polygon circle) {
circle.setEmpty();
Point[] points = getPoints(center, radius);
circle.startPath(points[0]);
for (int i = 1; i < points.length; i++)
circle.lineTo(points[i]);
}
private static Point[] getPoints(Point center, double radius) {
Point[] points = new Point[50];
double sin;
double cos;
double x;
double y;
for (double i = 0; i < 50; i++) {
sin = Math.sin(Math.PI * 2 * i / 50);
cos = Math.cos(Math.PI * 2 * i / 50);
x = center.getX() + radius * sin;
y = center.getY() + radius * cos;
points[(int) i] = new Point(x, y);
}
return points;
}
}
引用方式:
DrawLocate.drawPoint(point, location.getRadius(), baiduLayer, image, Color.parseColor("#0099FF"), Color.parseColor("#0099FF"));