cos sdk android,绘图圈Android MapBox SDK

正如Zugaldia回答的那样,绘制一个圆形图层是最简单的方法。但只有当你想绘制一个圆圈时,不考虑尺寸精度。

另一种选择是围绕你的点绘制一个圆形的边界,以获得正确的距离和可视化(如果倾斜),稍后我会解释它。

在Kotlin,抱歉没有抱歉。

第一部分,画一个圆圈层:

mapView.getMapAsync {

map = it

// Add the source (at start, an 'empty' GeoJsonSource)

map?.addSource(GeoJsonSource(SOURCE_ID))

// Create a circle layer from previously defined source

// don't forget source identifier

val layer = CircleLayer(CIRCLE_LAYER_ID, SOURCE_ID)

layer.withProperties(

circleRadius(50f),

circleOpacity(.4f),

circleColor(Color.WHITE)

)

map?.addLayer(layer)

}

而当你拥有了位置,你想周围画:

private fun updateCircleLayer() {

// Update the GeoJsonSource

// !!! Beware, (longitude, latitude), not the other way around !!!

val center = Point.fromCoordinates(doubleArrayOf(longitude, latitude))

map?.getSourceAs(SOURCE_ID)?.setGeoJson(center)

}

第二部分,画一个周长:

private fun getPerimeterFeature(radiusInKilometers: Double = .05, sides: Int = 64): Feature {

// here, currentPosition is a class property, get your lat & long as you'd like

val latitude = currentPosition.latitude

val longitude = currentPosition.longitude

val positions = mutableListOf()

// these are conversion constants

val distanceX: Double = radiusInKilometers/(111.319 * Math.cos(latitude * Math.PI/180))

val distanceY: Double = radiusInKilometers/110.574

val slice = (2 * Math.PI)/sides

var theta: Double

var x: Double

var y: Double

var position: Position

for (i in 0..sides) {

theta = i * slice

x = distanceX * Math.cos(theta)

y = distanceY * Math.sin(theta)

position = Position.fromCoordinates(longitude + x, latitude + y)

positions.add(position)

}

return Feature.fromGeometry(Polygon.fromCoordinates(listOf(positions)))

}

请参阅updateCircleLayer()在第一部分提供返回Feature到GeoJSonSource就是这样。

希望这会有所帮助。玩的开心 !

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值