Results 1 to 4 of 4

Thread: renderMapImageInBoundingBox doesn't do anything on iOS

  1. #1
    Erfahrener skobbler
    Join Date
    11.02.2015
    Posts
    123

    renderMapImageInBoundingBox doesn't do anything on iOS

    Hi, I posted a question on StackOverflow regarding renderMapImageInBoundingBox. It appears it's not working. Bug???
    Did not have any response on StackOverflow yet so I thought I tried it here:

    I have a UITableView where each cell should display a map. As it's a known limitation to have several independent instances of SKMapView in one view (see http://developer.skobbler.com/getting-started/ios#sec29) and I don't want a SKMapView in each cell anyway (performance) I thought I'd use renderMapImageInBoundingBox and create an image of the map to display in the tableCells.

    I've tried several things and stripped down the code to just render an image for the first map. This is a stripped down versions of what I have in my UITableViewController's viewDidAppear (I also tried viewDidLoad, but nothing).

    Code:
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(true)
    
        //Initialize, set delegate, and customize map appearance
        var mapView = SKMapView(frame: CGRectMake(0, 0, 963, 200))
        mapView.delegate = self
        mapView.applySettingsFromFileAtPath(JSONFilePath)
        mapView.mapScaleView.hidden = true
        mapView.settings.showAccuracyCircle = false
        mapView.settings.panningEnabled = false
        mapView.settings.rotationEnabled = false
        mapView.settings.showStreetBadges = false
        mapView.settings.showHouseNumbers = false
        mapView.settings.showMapPoiIcons = false
        mapView.settings.showOneWays = false
    
        //Draw a track on the map
        let track = tracks[0]
        var polyline = SKPolyline()
        polyline.coordinates = track.points
        polyline.fillColor = themeTintColor
        polyline.lineWidth = 3
        polyline.backgroundLineWidth = 4
        polyline.borderDotsSize = 1
        polyline.borderDotsSpacingSize = 5
        mapView.addPolyline(polyline)
    
        //Set BoundingBox        
        let boundingBox = SKBoundingBox(topLeftCoordinate: CLLocationCoordinate2DMake(track.ne.coordinate.latitude, track.sw.coordinate.longitude), bottomRightCoordinate: CLLocationCoordinate2DMake(track.sw.coordinate.latitude, track.ne.coordinate.longitude))
    
        // Add the mapView to the view just to see if it displays correctly. (It does!)
        mapView.fitBounds(boundingBox, withPadding: CGSizeMake(20, 20))
        self.view.addSubview(mapView)
    
        // Actual PNG rendering
        let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
        mapView.renderMapImageInBoundingBox(boundingBox, toPath: documentsPath, withSize: CGSizeMake(1000, 220))
        println("Rendering in progress")
    }
    
    
    func mapViewDidFinishRenderingImageInBoundingBox(mapView: SKMapView!) {
        println("ImageRenderingFinished")
    }
    The mapView is displayed correctly (with correct bounding box) and in the log I see the "Rendering in progress" message, but mapViewDidFinishRenderingImageInBoundingBox is not being called and I don't see a png file created in my App Container. No compiler or run-time errors. (btw I did not forget to add the SKMapViewDelegate)

    Anyone have an idea what I'm doing wrong? Or did I run into a bug? Using Xcode 6.1, developing for iOS8 in Swift.

  2. #2
    Oberskobbler
    Join Date
    22.07.2014
    Posts
    399
    Hello,
    We've passed the issue to our dev team. We'll get back to you as soon as possible with an answer.

    Thank you for your understanding,

  3. #3
    Erfahrener skobbler
    Join Date
    11.02.2015
    Posts
    123

    Working now. STUPID STUPID STUPID mistake

    Hi Guys,

    Sorry about this. I made a VERY VERY stupid mistake.
    I gave the documentsPath as a parameter to the function, which is a directory, but the function needs a full path, including filename.

    This made it work:

    Code:
            let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
            let imagePath = documentsPath.stringByAppendingPathComponent("images/mapImage.png")
            mapView.renderMapImageInBoundingBox(boundingBox, toPath: imagePath, withSize: CGSizeMake(1000, 220))
    Apologies for the inconvenience and the effort this costs on your side.

  4. #4
    Oberskobbler
    Join Date
    22.07.2014
    Posts
    399
    Thanks guidove for letting us know.
    Keep up the got work!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •