仅当建筑物完全位于相机视图内时显示地面覆盖层。

huangapple go评论78阅读模式
英文:

Display GroundOverlay only when building is entirely within cameraView

问题

如标题所述,我只想在相机完全看到整个建筑物时显示GroundOverlay。我应该如何在onCameraMove()方法中实现此目标?目前,即使建筑物的一部分出现在相机视图中,覆盖层也会出现。

@Override
public void onCameraMove() {
    LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
    private static final LatLng Building1 = new LatLng(54.69726685890506, -2.7379201682812226);

    if (mMap.getCameraPosition().zoom > 17) {
        if (bounds.contains(Building1)) {
            displayOverlay();
        }
    }
}
英文:

As stated in the title, essentially I only want to display the GroundOverlay when the camera is in view of the entire building. How would I accomplish this within the onCameraMove() method? As of now the overlay appears even when part of the building is within the camera view.

@Override
    public void onCameraMove(){
        LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
        private static final LatLng Building1 = new LatLng(54.69726685890506,-2.7379201682812226);

        if(mMap.getCameraPosition().zoom > 17){
            if (bounds.contains(Building1)) {
                  displayOverlay(); 
            }
         }

答案1

得分: 1

似乎 Building1 应该是建筑物边界点的列表,并且您应该在循环中检查它们是否全部包含在 bounds 中:

...
List<LatLng> buildingPoints = new ArrayList<>();
buildingPoints.add(new LatLng(..., ...));
buildingPoints.add(new LatLng(..., ...));
...

...
if (mMap.getCameraPosition().zoom > 17) {
    boolean allPointsVisible = true;
    for (LatLng currBuildingPoint : buildingPoints) {
        if (!bounds.contains(currBuildingPoint)) {
            allPointsVisible = false;
            break;
        }
    }
    if (allPointsVisible) {
        displayOverlay();
    }
}
...
英文:

It seems that Building1 should be a list of the boundary points of the building, and you should check in a loop that ALL of them are contained in bounds:

...
List&lt;LatLng&gt; buildingPoints = new ArrayList&lt;&gt;();
buildingPoints.add(new LatLng(...,...))
buildingPoints.add(new LatLng(...,...))
...

...
if(mMap.getCameraPosition().zoom &gt; 17){
    boolean allPointsVisible = true;
    for (LatLng currBuildingPoint: buildingPoints) {
        if (!bounds.contains(currBuildingPoint)) {
            allPointsVisible = false;
            break;
        }
    }
    if (allPointsVisible) {
        displayOverlay();
    }
 }
 ...

huangapple
  • 本文由 发表于 2020年3月17日 04:19:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/60712693.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定