java - 有没有办法在mapbox中绘制半径以米为单位的圆?

标签 java android mapbox

我正在尝试在 map 框中围绕用户当前位置绘制半径为 500 米的圆。当我使用下面提供的代码时,它会绘制一个大圆圈,而且它不会随 map 倾斜。

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);

我希望我的应用程序像这样工作: Expected Results

但目前我遇到了这个问题: enter image description here

已更新

我可以用精确的坐标绘制圆圈,但我希望这个圆圈随着我的位置移动。单击 map 时会添加圆圈,但从位置更改监听器调用此函数时无法添加圆圈。

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()));
        }
    }

enter image description here

最佳答案

CircleManager 本身不支持此功能,但您可以使用 mapbox-java 中的 Turf将所需属性转换为多边形/填充:

  /**
   * 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 结合使用。

关于java - 有没有办法在mapbox中绘制半径以米为单位的圆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57146640/

相关文章:

java - "Not enough storage is avaliable to process this command"

java - 在 Openshift 上运行 Java 应用程序

java - 如何直接将 XML 中的字符串放入 java 数组中

javascript - 传单JS : How to remove the zoom control

java - Hbase列族设计重要性

java - 列出一个值在 Map 中的所有出现

在 Samsung Knox 上切换个人模式和工作模式时,Android 应用程序崩溃

PowerVR G6200 上带有 EGLConfigChooser 的 java.lang.RuntimeException

javascript - 通过 mapbox gl js 向 mapbox 中的 map 添加一些基本标记

android - 如何使用 Mapbox Android SDK 从本地 geojson 属性设置图标类型