高德地图的覆盖物添加API提供了很多种指定覆盖物的添加和自定义覆盖物添加的方法。标记、矢量图形元素(包括:折线、多边形和圆)等。覆盖物拥有自己的地理坐标,当拖动或缩放地图时,它们也会随地图移动。
在添加多边形(Polygon)的时候,我发现并没有设置Polygon区域内color的透明度的方法。
aMap.addPolygon(new PolygonOptions()
.addAll(createRectangle(Constants.SHANGHAI, 1, 1))
.fillColor(Color.LTGRAY).strokeColor(Color.RED).strokeWidth(1));
PolygonOptions options = new PolygonOptions();
int numPoints = 400;
float semiHorizontalAxis = 5f;
float semiVerticalAxis = 2.5f;
double phase = 2 * Math.PI / numPoints;
for (int i = 0; i <= numPoints; i++) {
options.add(new LatLng(Constants.BEIJING.latitude
+ semiVerticalAxis * Math.sin(i * phase),
Constants.BEIJING.longitude + semiHorizontalAxis
* Math.cos(i * phase)));
}
polygon = aMap.addPolygon(options.strokeWidth(4f)
.strokeColor(Color.BLACK).fillColor(Color.LTGRAY));
其实Color本身就是带透明度属性的,只不过我们平常构造的时候都不这么用,默认为255的alpha值,所以根本就是不透明。
使用Int color = Color.argb(127,255,0,255);Color中的静态方法返回一个int的color值,这样就解决了问题。
aMap.addPolygon(new PolygonOptions()
.addAll(createRectangle(Constants.SHANGHAI, 1, 1))
.fillColor(Color.LTGRAY).strokeColor(Color.argb(127,255,0,255)).strokeWidth(1));
PolygonOptions options = new PolygonOptions();
int numPoints = 400;
float semiHorizontalAxis = 5f;
float semiVerticalAxis = 2.5f;
double phase = 2 * Math.PI / numPoints;
for (int i = 0; i <= numPoints; i++) {
options.add(new LatLng(Constants.BEIJING.latitude
+ semiVerticalAxis * Math.sin(i * phase),
Constants.BEIJING.longitude + semiHorizontalAxis
* Math.cos(i * phase)));
}
polygon = aMap.addPolygon(options.strokeWidth(4f)
.strokeColor(Color.BLACK).fillColor(Color.LTGRAY));
这个问题确实比较简单,是一个很小的知识点。