在保留Google Maps Android平台上的多边形中存在的多边形填充颜色时,我遇到了问题。当多边形路径重叠时,填充颜色消失。我使用相同的方法在iOS上突出显示我的路径,但没有此行为。请查看这些图像,以注意在多边形路径重叠时填充颜色如何消失。
这是重叠前正确的颜色填充:
当同一多边形内有多个多边形路径点时,颜色消失:
iOS上的行为不同。多边形会在iOS上保持填充状态。这是Google Maps文档的摘录:
Fill color in ARGB format, the same format
used by Color. The default value is
transparent (0x00000000). If the polygon
geometry is not specified correctly (see
above for Outline and Holes), then no fill
will be drawn.
这是我正在使用的代码。基本上,我有一个宽度为X的路径,该宽度为X的路径被突出显示:
随着位置的变化,我以当前位置为例,计算出一个左右点:
LatLng leftPoint =
SphericalUtil.computeOffset(presentLoc,
widthInFeet * 0.3048, heading - 90);
接下来,我将在右侧并反转数组,然后将其添加到左侧以创建多边形路径。然后,我将该点数组传递到多边形中,以便在位置更改时进行更新。
polygon.setPoints(polyPoints);
polygon.setFillColor(YELLOW);
polygon.setStrokeWidth(1);
当不可避免的重叠时(例如急转弯等),如何使上面的图像保留其填充颜色?
我从下面使用了com.google.maps.android.PolyUtil.simplify进行了Douglas-Peucker简化,但是这不利于重叠或沿路径返回的急转弯。我很想使用多个较小的多边形而不是一个较大的多边形,但是我不想浪费系统资源,尤其是当应用程序具有相当大的路径时。
答案 0 :(得分:2)
我认为我至少会演示简化可以完成的工作,并让您决定是否需要简化。坦白说,我还没有看到很多有关其算法性能的示例。
问题变成了公差参数是什么-在一般情况下可能会很困难。
代码简单明了-创建了两个多边形,一个是简化的结果。这也演示了未填充透明多边形的错误。
List<LatLng> points = new ArrayList<>();
points.add(new LatLng(39.182937,-76.823560));
points.add(new LatLng(39.180741,-76.821758));
points.add(new LatLng(39.190454, -76.810985));
points.add(new LatLng( 39.190221, -76.812530));
points.add(new LatLng(39.186961, -76.808239));
points.add(new LatLng(39.188724,-76.806264));
points.add(new LatLng(39.192882, -76.811328));
points.add(new LatLng(39.182937, -76.823560));
PolygonOptions rectOptions = new PolygonOptions()
.addAll(points);
// Get back the mutable Polygon
Polygon polygon = mMap.addPolygon(rectOptions);
polygon.setFillColor(Color.YELLOW);
points = new ArrayList<>();
points.add(new LatLng(39.182937,-76.834560));
points.add(new LatLng(39.180741,-76.832758));
points.add(new LatLng(39.190454, -76.821985));
points.add(new LatLng( 39.190221, -76.823530));
points.add(new LatLng(39.186961, -76.819239));
points.add(new LatLng(39.188724,-76.817264));
points.add(new LatLng(39.192882, -76.822328));
points.add(new LatLng(39.182937, -76.834560));
points = PolyUtil.simplify(points, 200.0);
rectOptions = new PolygonOptions()
.addAll(points);
// Get back the mutable Polygon
polygon = mMap.addPolygon(rectOptions);
polygon.setFillColor(Color.YELLOW);
最后是结果-很明显,在简化过程中牺牲了一些保真度,即内部三角形的一个顶点在算法中胜出-但有趣的是:
请注意,在此示例中,公差阈值约为120米-起作用的点。
我确实同意@MartinZeitler的观点,最有可能为您解决的方法是删除内部点。
答案 1 :(得分:0)
在onMapReady中可以调用方法-onpostExe();
job.lastBuild.timestamp
可以重叠,但是当使用宽度大小来缩小解决重叠问题时的差异