Android Google Maps:隐藏整个地图的多边形或形状 [英] Android Google Maps: Polygon or shape that hides entire map

查看:127
本文介绍了Android Google Maps:隐藏整个地图的多边形或形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试隐藏除区域以外的整个地图,因为我使用的多边形在要显示的区域中带有孔.

I am trying to hide the whole map except a zone, for that I am using a polygon with a hole in the area that I want to show.

问题是,根据缩放比例,空白区域会被多边形的颜色覆盖,或者多边形会失去其颜色.

The problem is that depending on the zoom the empty area is covered with the color of the polygon or the polygon loses its color.

这是代码:

//polygon hide all world map
float delta = 0.1f; //0.1f

List points = Arrays.asList(new LatLng(90, -180),

    new LatLng(-90+delta, -180+delta),

    new LatLng(-90+delta, 0),

    new LatLng(-90+delta, 180-delta),

    new LatLng(0, 180-delta),

    new LatLng(90-delta, 180-delta),

    new LatLng(90-delta, 0),

    new LatLng(90-delta, -180+delta),

    new LatLng(0,-180+delta));

PolygonOptions rectOptions = new PolygonOptions();
rectOptions.addAll(points);

//hole
ArrayList<LatLng> a = new ArrayList<>();
a.add(new LatLng(centro.getLatitud1(), centro.getLongitud1()));
a.add(new LatLng(centro.getLatitud2(), centro.getLongitud1()));
a.add(new LatLng(centro.getLatitud2(), centro.getLongitud2()));
a.add(new LatLng(centro.getLatitud1(), centro.getLongitud2()));
Iterable<LatLng> iterator = a;
rectOptions.addHole(iterator);
// Get back the mutable Polygon
rectOptions.fillColor(ResourcesCompat.getColor(getResources(), R.color.colorPrimary, null));

polygon = mMap.addPolygon(rectOptions);   

图片:

所有正确

多边形颜色消失

孔填充了多边形的颜色

如果我继续缩放,一切都会转正确.

If I keep zooming everything turns right.

我正在使用'com.google.android.gms:play-services:9.6.1'

Im using 'com.google.android.gms:play-services:9.6.1'

我不知道如何解决它,我是地图上的菜鸟,如果有人知道如何做或者知道其他方法来做我想做的事,我将不胜感激.

I do not know how to fix it and I am a noob in maps, if someone knows how to do it or knows some other method to do what I want I would be very grateful.

推荐答案

您的代码正确.有一个已知的打开错误(

Your code is correct. There is a known open bug (Issue 5241).

作为一种解决方法,我建议您看一下我的答案

As a workaround, I would recommend you to take a look at my answer here (You can draw rectangular holes instead of circular ones).

这篇关于Android Google Maps:隐藏整个地图的多边形或形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆