有没有办法在 mapbox 中绘制半径为米的圆?

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

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

https://i.stack.imgur.com/huLZ3.gif

但目前我遇到了这个问题:

http://img4.mukewang.com/64375fa90001360a06571241.jpg

隔江千里
浏览 243回答 1
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 结合使用。

qq_花开花谢_0

https://github.com/mapbox/mapbox-java/blob/master/services-turf/src/main/java/com/mapbox/turf/TurfTransformation.java#L66。通过 360 度以获得最佳外观的步数。这是http://turfjs.org/docs/#circle的 Java 端口。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java