【问题标题】:Is there an way draw circle with radius in meters in mapbox?有没有办法在mapbox中绘制半径以米为单位的圆圈?
【发布时间】:2019-07-23 16:12:44
【问题描述】:

我正在尝试在地图框中围绕用户当前位置绘制半径为 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()));
        }
    }

【问题讨论】:

    标签: java android mapbox


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多