我正在尝试在地图框中围绕用户当前位置绘制半径为500米的圆。当我使用下面提供的代码时,它会画一个大圆圈,并且不会随地图倾斜。
CircleManager circleManager = new CircleManager(mapView, mapboxMap, style);
CircleOptions options = new CircleOptions();
options.withLatLng(new LatLng(location.getLatitude(), location.getLongitude()));
options.withCircleRadius(500f);
options.withCircleOpacity(0.5f);
options.withCircleColor(ColorUtils.colorToRgbaString(getResources().getColor(R.color.blue2)));
circleManager.create(options);
已更新
我能够绘制具有精确坐标的圆,但是我希望该圆随我的位置移动。单击地图时添加了圆圈,但是从位置更改侦听器调用时无法添加圆圈。
private void moveRing(Point centerPoint) {
if (mapboxMap.getStyle() != null) {
Style style = mapboxMap.getStyle();
// Use Turf to calculate the coordinates for the outer ring of the final Polygon
Polygon outerCirclePolygon = getTurfPolygon(OUTER_CIRCLE_MILE_RADIUS, centerPoint);
GeoJsonSource outerCircleSource = source;
if (outerCircleSource != null) {
outerCircleSource.setGeoJson(Polygon.fromLngLats(outerCirclePolygon.coordinates()));
}
}
答案 0 :(得分:0)
CircleManager本身不支持此功能,但是您可以使用mapbox-java中的Turf将所需的属性转换为Polygon / Fill:
/**
* Takes a {@link Point} and calculates the circle polygon given a radius in degrees, radians,
* miles, or kilometers; and steps for precision. This uses the {@link #DEFAULT_STEPS} and
* {@link TurfConstants#UNIT_DEFAULT} values.
*
* @param center a {@link Point} which the circle will center around
* @param radius the radius of the circle
* @return a {@link Polygon} which represents the newly created circle
* @since 3.0.0
*/
public static Polygon circle(@NonNull Point center, double radius) {
return circle(center, radius, 64, TurfConstants.UNIT_DEFAULT);
}
您可以将此几何与来自注解插件的FillManager结合使用。
答案 1 :(得分:0)