PDA

View Full Version : renderMapImageInBoundingBox doesn't do anything on iOS



guidove
11.02.2015, 23:08
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).



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.lat itude, track.sw.coordinate.longitude), bottomRightCoordinate: CLLocationCoordinate2DMake(track.sw.coordinate.lat itude, 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(.DocumentDirec tory, .UserDomainMask, true)[0] as String
mapView.renderMapImageInBoundingBox(boundingBox, toPath: documentsPath, withSize: CGSizeMake(1000, 220))
println("Rendering in progress")
}


func mapViewDidFinishRenderingImageInBoundingBox(mapVie w: 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.

Adela_Silvia
12.02.2015, 10:31
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,

guidove
12.02.2015, 18:27
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:


let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirec tory, .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.

Adela_Silvia
13.02.2015, 10:44
Thanks guidove for letting us know.
Keep up the got work!