CartoDB / mobile-ios-samples

iOS mobile app with CARTO Mobile SDK
BSD 2-Clause "Simplified" License
30 stars 12 forks source link

how to to get zoomed mapview #18

Closed LakshmanaSwamy closed 6 years ago

LakshmanaSwamy commented 6 years ago

I have a method for calculating bounding box , for this method i am passing baseMap as an argument it always returns same coordinates even i zoomin /zoomout . Map coordinates remains same Expected Result :- i want a map with respect to screen size when i zoom-in/ zoom-out

    func getBoundingBoxInMapPos(mapView:NTMapView)->[NTMapPos]{
        let topLeft :NTMapPos = mapView.screen(toMap: NTScreenPos.init(x: 0, y: 0))
        let topRight :NTMapPos = mapView.screen(toMap: NTScreenPos.init(x: Float(mapView.frame.width), y: 0))
        let bottomRight :NTMapPos = mapView.screen(toMap: NTScreenPos.init(x: Float(mapView.frame.height), y: Float(mapView.frame.width)))
        let bottomLeft :NTMapPos = mapView.screen(toMap: NTScreenPos.init(x: 0, y: Float(mapView.frame.height)))
        return [topLeft,topRight,bottomRight,bottomLeft,topLeft]
    }
mtehver commented 6 years ago

This should work. Are you sure that mapView.frame.width and height are non-zero? During app initialization phase view dimensions may not have been set yet and that could explain the effect you are seeing.

jaakla commented 6 years ago

Related SDK feature requests to make it safer: https://github.com/CartoDB/mobile-sdk/issues/162