-1

I'm trying to show a Polygon under Nutiteq in a properly Bounding Box but I get something like this. Sight of a field wrong bounded

and what I want is

Sight of that field properly bounded

My code is the following

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!!!");   
    }

}

Could anyone say me, what I'm making wrong?

Thanks in advance.

Gödel77
  • 839
  • 3
  • 15
  • 27
  • Perhaps @JaakL can explain better, how `screenToWorld(...)` works, because I call `screenToWorld(...)` with the `MapPos` [11.396879,48.264547] and [11.400575,48.268546] and I get [x=-80971.58271822847, y=289300.71649931633, z=0.0] and [x=-80971.58252842074, y=289300.71632176096, z=0.0] as associated Screen Coordinates. I'm testing my App in a Nexus 9, so, I should get coordinates in Range [0x0,1535x2047] because screen dims for this device are 1536*2048. – Gödel77 Nov 10 '14 at 08:37
  • Of Course, if I had neither Action Bar nor down control bar, with them the effective mapView Coordinates are 1536*1790. – Gödel77 Nov 10 '14 at 09:37
  • Assuming you are using EPSG3857 projection, this is the expected result - you are converting screen coordinates to map coordinates. In EPSG3857 case, these are in range [-20037508.34, 20037508.34] – MarkT Nov 12 '14 at 15:48
  • @MarkT Please, take a look at worldToScreen, no, I'm converting map coordinates to screen coordinates. – Gödel77 Nov 12 '14 at 16:30

1 Answers1

1

You are using wrong rect argument - in your case it should probably contain your view dimensions (you do not need to call worldToScreen, worldToScreen calculates screen coordinates based on current camera parameters).

MarkT
  • 301
  • 2
  • 2
  • Hi @MarkT, my desire is to fit the sight to this bounds (what I get as Parameter with name `Limits`). I thought, the best stategy to do it, is to fix `upRight` to the up right Corner of screen and `downLeft` to the down left corner of screen and `Nutiteq` already has those 2 Methods to convert map-coordinates to screen-coordinates and screen-coordinates into map-coordinates. How would you suggest, that I do that without those 2 methods? Thx. – Gödel77 Nov 07 '14 at 12:02
  • Though I do not understand your explanation, I think you should simply replace 2 lines in your code with the following lines: MapPos downLeftPos = new MapPos(left, bottom, 0); MapPos rightUpPos = new MapPos(right, top, 0); – MarkT Nov 12 '14 at 15:45
  • downLeftPos and upRightPos are screen Positions, if I would make, what you suggest, what should I do with? Rect inherits from Graphics and refers in my case to Device Screen and that's what that Calling of setBoundingBox needs, a Box of map coordinates and a box of screen coordinates. The Range for screen coordinates is [0,0]-[1535,1789] – Gödel77 Nov 12 '14 at 16:28
  • Did you try my suggestion, simply replace rect with fixed coordinates, like (0, 0) - (1536, 1789)? This should work. – MarkT Nov 14 '14 at 09:59
  • Hi Mark, your suggestion was downLeftPos = new MapPos(left, bottom, 0)... and left and bottom was coordinates in Wgs84. I tried what you now say with (0,0) and (100,100) and I got the whole earth. – Gödel77 Nov 14 '14 at 10:13