Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift documentation #13

Open
mahdigh99 opened this issue Jan 4, 2018 · 12 comments
Open

Swift documentation #13

mahdigh99 opened this issue Jan 4, 2018 · 12 comments

Comments

@mahdigh99
Copy link

mahdigh99 commented Jan 4, 2018

in swift working with:

let map: FSInteractiveMapView = FSInteractiveMapView()
 map.frame = self.view.frame
 var mapData = [String: Int]()
 mapData["IR-01"] = 0
 mapData["IR-02"] = 10
 var mapColors = [UIColor]()
 mapColors.append(UIColor(red:0.26, green:0.112, blue:0.0, alpha:1.0))
 mapColors.append(UIColor(red:0.45, green:0.132, blue:0.0, alpha:1.0))


 map.loadMap("iranHigh", withData:mapData, colorAxis:mapColors)
 view.addSubview(map)
 view.setNeedsDisplay()

its working correctly but i cant add click Handler

how can i add click handler in Swift?
@ArthurGuibert @birslip

@mahdigh99
Copy link
Author

Its working for me:


 override func viewDidLoad() {
        super.viewDidLoad()

        let map: FSInteractiveMapView = FSInteractiveMapView()
        weak var oldClickedLayer = CAShapeLayer()

        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.lightGray)
        mapColors.append(UIColor.darkGray)
        map.frame = self.view.frame
        map.clickHandler = {(identifier: String? , _ layer: CAShapeLayer?) -> Void in
            if (oldClickedLayer != nil) {
                oldClickedLayer?.zPosition = 0
                oldClickedLayer?.shadowOpacity = 0
            }
            oldClickedLayer = layer
            // We set a simple effect on the layer clicked to highlight it
            layer?.zPosition = 10
            layer?.shadowOpacity = 0.5
            layer?.shadowColor = UIColor.black.cgColor
            layer?.shadowRadius = 5
            layer?.shadowOffset = CGSize(width: 0, height: 0)

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

        view.addSubview(map)
        view.setNeedsDisplay()

    }

@rakeshdev6
Copy link

Hello mahdigh99,
When I add this code in the ViewDidLoad() and run the project nothing is displayed in the simulator. Do you have working example for it?

@mahdigh99
Copy link
Author

@rakeshbethu Make sure you do these things:

  1. correctly add FSInteractiveMap library in your Project ( you can easily add it by CocoaPod )
  2. make sure before deceleration of Viewcontroller you have -> import FSInteractiveMap
  3. make sure you have an SVG file named "world-continents-low" in the same directory with ViewController
    let mapName: String! = String("world-continents-low")
    if your SVG file name is different just edit this line of code.

I'm attaching my working project you can use it to understand better. (if it doesn't work in your computer just open the terminal and go to project directory and Run pod install in terminal)

Map-chart-Test.zip

@rakeshdev6
Copy link

Thanks a lot mahi, This worked out really well. Very thanks for your quick turn around.

@mazharhameed25
Copy link

Hello mahdigh99,
i want to show state names and change color of map also want to zoom in and zoom out map. can you please help me

@mahdigh99
Copy link
Author

mahdigh99 commented Apr 27, 2019

Hi @mazharhameed25 ,
I think the best way to show state names is adding state names to SVG files.
you can change the color of the map by this code:

        var mapColors = [UIColor]()
            mapColors.append(UIColor(red:1.00, green:0.00, blue:0.00, alpha:1.0))
            mapColors.append(UIColor(red:1.00, green:0.20, blue:0.00, alpha:1.0))
            mapColors.append(UIColor(red:1.00, green:0.40, blue:0.00, alpha:1.0))
            mapColors.append(UIColor(red:1.00, green:0.71, blue:0.00, alpha:1.0))
            mapColors.append(UIColor(red:1.00, green:0.94, blue:0.00, alpha:1.0))
            mapColors.append(UIColor(red:0.44, green:0.71, blue:0.00, alpha:1.0))
            mapColors.append(UIColor(red:0.00, green:0.50, blue:0.00, alpha:1.0))

        mapColors.reverse()
        
        map.loadMap(mapName, withData:mapData, colorAxis:mapColors)

and for zoom in and & zoom out I think the best way is using scroll view,

scrollView.minimumZoomScale = 1.0; scrollView.maximumZoomScale = 3.0

but the alternative is :

var previousScale:CGFloat = 1.0

    override func viewDidLoad() {
        super.viewDidLoad()

        let gesture = UIPinchGestureRecognizer(target: self, action: #selector(pinchAction(sender:)))
        self.view.addGestureRecognizer(gesture)
    }

    func pinchAction(sender:UIPinchGestureRecognizer) {
        let scale:CGFloat = previousScale * sender.scale
        self.view.transform = CGAffineTransform(scaleX: scale, y: scale);

        previousScale = sender.scale
    }

@mazharhameed25
Copy link

mazharhameed25 commented Apr 29, 2019 via email

@mazharhameed25
Copy link

mazharhameed25 commented Apr 29, 2019 via email

@mazharhameed25
Copy link

mazharhameed25 commented Apr 29, 2019 via email

@mahdigh99
Copy link
Author

mahdigh99 commented May 1, 2019

bro i need your help. i want to switch on new controller on map clickable area. how to get clickable state and move accordingly On Mon, Apr 29, 2019 at 1:58 PM mazhar hameed

you can add this code to click event of each state to switch view controllers:
performSegueWithIdentifier("nextViewController", sender: self)


my map is not showing when i add state names on svg file On Mon, Apr 29, 2019 at 3:39 PM mazhar

send me your SVG file to check it.

@mazharhameed25
Copy link

mazharhameed25 commented May 2, 2019 via email

@BrettKessler
Copy link

I'm confused by the UIViewController, is there a way to add this to a view so I can get it to render a preview?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants