Load Venue Map Data

To start with, identify the base url where your VMD assets are deployed. This can be a remote url, or a local file path. Note: If this is a local file path, add the VMD assets to your application and refer to that folder using file paths, instead of http urls.

let fileCollection = VMDFileCollection(basePath: "https://myserver.com/[VENUE_ID]/venue_map_[VENUE_ID]", andVenueId: "VENUE_ID")
let parser = VMDParser(withFileCollection: fileCollection, delegate: self)
parser.parse()

After you’ve initiated the loading, register your VMDParserDelegate and wait for the didFinishLoadingVenueMapData callback to be invoked. At this point you can proceed to Display a venue map.

public func didFinishLoadingVenueMapData(_ vmd: VMMSMap) {
    //display venue map
}

Handling a failed load

Loading fetches the venue XML and the geojson archive over the network, so it can fail: the assets may be missing, or the transfer may time out. Implement didFailToLoadVenueMapData to surface that to the user and offer a retry. The method is optional, so if you do not implement it a failed load is silent and presents as an empty map.

public func didFailToLoadVenueMapData(error: Error?) {
    //show an error and offer a retry
}

To determine what actually went wrong, walk the NSUnderlyingErrorKey chain to its root. The error handed to the delegate is a wrapper, and the originating error sits several levels down. A transfer that times out surfaces as an NSURLErrorDomain code, most commonly NSURLErrorTimedOut (-1001). FileDownloadTimedOutError in VMDFileErrorDomain is a last-resort backstop and is rare in practice.

var cause = error as NSError?
while let next = cause?.userInfo[NSUnderlyingErrorKey] as? NSError {
    cause = next
}
//cause now holds the originating error

Threading

  • parse() returns immediately. It has always been asynchronous, so the parsed map is never available on the line after the call. Use the delegate callbacks.
  • As of 2.2.15 the download and parse run on a background queue. Earlier versions ran them on the main queue, which froze the UI for the duration of the load.
  • Delegate callbacks are delivered on the main thread, so you can update UI directly from them.
  • Parses are serialized. Starting a second load while one is in flight queues it behind the first rather than running both at once.
  • If you subclass VMDParser and override onXMLParsedSuccessfully(_:) or onGeojsonParsedSuccessfully(_:), or assign a custom VMBaseVMDFactory to factory, that code runs on the background queue and must not touch UIKit.