【问题标题】:SetBoundings under Nutiteq doesn't work properlyNutiteq 下的 SetBoundings 无法正常工作
【发布时间】:2023-03-24 00:33:01
【问题描述】:

我试图在 Nutiteq 下以正确的 Bounding Box 显示 Polygon,但我得到了类似的东西。

而我想要的是

我的代码如下

private void setClipBounds(Intent intent, MapView mapView) {
    ArrayList<ArrayList<String>> limits = null;
    if (intent.hasExtra(Constants._LIMITS)) {
        limits = (ArrayList<ArrayList<String>>) intent.getSerializableExtra(Constants._LIMITS);


        ArrayList<String> downLeft = limits.get(0);
        ArrayList<String> upRight  = limits.get(1);

        double left                = Double.parseDouble((String)(downLeft.get(0)));
        double top                 = Double.parseDouble((String)(upRight.get(1))); 
        double right               = Double.parseDouble((String)(upRight.get(0))); 
        double bottom              = Double.parseDouble((String)(downLeft.get(1))); 

        MapPos downLeftPos         =  mapView.worldToScreen(left, bottom, 0);
        MapPos rightUpPos          =  mapView.worldToScreen(right, top, 0);             

        Rect rect                  = new Rect(Math.round((float)downLeftPos.x), Math.round((float)rightUpPos.y), Math.round((float)rightUpPos.x), Math.round((float)downLeftPos.y));


        Bounds bounds              = new Bounds(left, top, right, bottom);

        mapView.setBoundingBox(bounds, rect, false, false, false, 1000);
        //mapView.setBoundingBox(bounds, false);

    } else {
        Log.i("TAG", "WmsMapActivity::setClipBounds:: NO limits!!!");   
    }

}

谁能告诉我,我做错了什么?

提前致谢。

【问题讨论】:

  • 也许@JaakL 可以更好地解释screenToWorld(...) 的工作原理,因为我用MapPos [11.396879,48.264547] 和[11.396879,48.264546] 调用screenToWorld(...) 并得到[x=- 80971.58271822847, y=289300.71649931633, z=0.0] 和 [x=-80971.58252842074, y=289300.71632176096, z=0.0] 作为关联的屏幕坐标。我正在 Nexus 9 中测试我的应用程序,因此,我应该获得范围 [0x0,1535x2047] 中的坐标,因为此设备的屏幕暗度为 1536*2048。
  • 当然,如果我既没有 Action Bar 也没有向下控制栏,那么有效的 mapView 坐标是 1536*1790。
  • 假设您使用的是 EPSG3857 投影,这是预期的结果 - 您正在将屏幕坐标转换为地图坐标。在 EPSG3857 的情况下,这些在 [-20037508.34, 20037508.34] 范围内
  • @MarkT 请看一下worldToScreen,不,我正在将地图坐标转换为屏幕坐标。

标签: android bounding-box boundary nutiteq


【解决方案1】:

您使用了错误的 rect 参数 - 在您的情况下,它可能应该包含您的视图尺寸(您不需要调用 worldToScreen,worldToScreen 会根据当前相机参数计算屏幕坐标)。

【讨论】:

  • 嗨@MarkT,我的愿望是让视线适应这个界限(我得到的参数名称为Limits)。我认为,最好的策略是将upRight 固定在屏幕的右上角,将downLeft 固定在屏幕的左下角,Nutiteq 已经有这两种方法将地图坐标转换为屏幕- 坐标和屏幕坐标转换为地图坐标。如果没有这两种方法,你会如何建议我这样做?谢谢。
  • 虽然我不明白你的解释,但我认为你应该简单地将代码中的两行替换为以下行: MapPos downLeftPos = new MapPos(left, bottom, 0); MapPos rightUpPos = new MapPos(right, top, 0);
  • downLeftPos 和 upRightPos 是屏幕位置,如果我愿意,您的建议是什么,我该怎么做? Rect 继承自 Graphics 并在我的情况下指的是设备屏幕,这就是 setBoundingBox 的调用所需要的,一个地图坐标框和一个屏幕坐标框。屏幕坐标的范围是 [0,0]-[1535,1789]
  • 您是否尝试过我的建议,只需将 rect 替换为固定坐标,例如 (0, 0) - (1536, 1789)?这应该有效。
  • 嗨,马克,您的建议是 downLeftPos = new MapPos(left, bottom, 0)... 而 left 和 bottom 是 Wgs84 中的坐标。我用 (0,0) 和 (100,100) 尝试了你现在所说的,我得到了整个地球。
猜你喜欢
  • 1970-01-01
  • 2023-03-11
  • 2016-12-01
  • 2020-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多