ArthurGuibert / FSInteractiveMap

A charting library to visualize and interact with a vector map on iOS. It's like Geochart but for iOS!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swift 2 working example.

mmmattos opened this issue · comments

Hello

I am trying to use FSInteractiveMap inside a Swift iOS app.

I followed the How to use Section in the github repo

Added the library through the pod file.
The app builds fine but nothing gets displayed.

I debugged to check if the svg was loaded and indeed it was.
Here is the code I put in the swift file code:

import UIKit
import FSInteractiveMap

class ViewController: UIViewController {

    override func viewDidLoad() {
        let map: FSInteractiveMapView = FSInteractiveMapView()

        var mapData = [String: Int]()
        mapData["asia"] = 12
        mapData["australia"] = 2
        mapData["north_america"] = 5
        mapData["south_america"] = 14
        mapData["africa"] = 5
        mapData["europe"] = 20

        var mapColors = [UIColor]()
        mapColors.append(UIColor.lightGrayColor())
        mapColors.append(UIColor.darkGrayColor())

        let mapName: String! = String("world-continents-low")
        map.loadMap(mapName, withData:mapData, colorAxis:mapColors)

        view.addSubview(map)
        view.setNeedsDisplay()
         super.viewDidLoad()        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

I appreciate if you can point to any working swift example using it or identify what is wrong in this code.
Best!

Curious if you've managed to get this working. I'm experiencing similar issues in Swift, particularly when trying to put my FSInteractiveMapView inside a UIStackView

No, unfortunately not.
Still trying to get something similar on swift. Now attempting with D3 maps.

Miguel Miranda de Mattos | entrepreneur | software | mobile/web/cloud
|
Miranda Mattos Inf. Ltda. | Porto Alegre/RS | m. (51) 9198.9914
skype/miguelmmattos | face/miguel.mattos | linkedin/miguelmmattos

On Mon, Apr 11, 2016 at 5:08 PM, sdnakhla notifications@github.com wrote:

Curious if you've managed to get this working. I'm experiencing similar
issues in Swift, particularly when trying to put my FSInteractiveMapView
inside a UIStackView


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#7 (comment)

I believe you are missing to define a frame for your map.

Writing :

map.frame = self.view.frame

right below

let mapName: String! = String("world-continents-low")
map.loadMap(mapName, withData:mapData, colorAxis:mapColors)

should make it work.

Thanks @ArnaudRib 😄
I'll try that later today and let you know if that works fine.
Hope it does work on swift 3 too.

@mmmattos
The syntax for frame has not changed in Swift 3.0, so this little code should still be working :).

Did you manage to make the clickHandler work ? I still can't figure out how to use the function properly in swift.

Have a good day.