Open mahdigh99 opened 6 years ago
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()
}
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?
@rakeshbethu Make sure you do these things:
import FSInteractiveMap
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)
Thanks a lot mahi, This worked out really well. Very thanks for your quick turn around.
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
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
}
thanks alot bro
On Sat, Apr 27, 2019 at 7:33 PM mahdigh99 notifications@github.com wrote:
Hi mazharhameed, 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
}
`
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ArthurGuibert/FSInteractiveMap/issues/13#issuecomment-487290911, or mute the thread https://github.com/notifications/unsubscribe-auth/AL5SV2L5LU5AZJIEZUQ7R6DPSRPZZANCNFSM4EKMK4EA .
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 mazharhameed25@gmail.com wrote:
thanks alot bro
On Sat, Apr 27, 2019 at 7:33 PM mahdigh99 notifications@github.com wrote:
Hi mazharhameed, 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
}
`
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ArthurGuibert/FSInteractiveMap/issues/13#issuecomment-487290911, or mute the thread https://github.com/notifications/unsubscribe-auth/AL5SV2L5LU5AZJIEZUQ7R6DPSRPZZANCNFSM4EKMK4EA .
my map is not showing when i add state names on svg file
On Mon, Apr 29, 2019 at 3:39 PM mazhar hameed mazharhameed25@gmail.com wrote:
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 mazharhameed25@gmail.com wrote:
thanks alot bro
On Sat, Apr 27, 2019 at 7:33 PM mahdigh99 notifications@github.com wrote:
Hi mazharhameed, 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
}
`
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ArthurGuibert/FSInteractiveMap/issues/13#issuecomment-487290911, or mute the thread https://github.com/notifications/unsubscribe-auth/AL5SV2L5LU5AZJIEZUQ7R6DPSRPZZANCNFSM4EKMK4EA .
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.
bro. my map is not clickable when i zoom in
On Wed, May 1, 2019 at 3:09 PM mahdigh99 notifications@github.com wrote:
area. how to get clickable state and move accordingly
you can add this code to click event of each state to switch view controllers: performSegueWithIdentifier("nextViewController", sender: self)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ArthurGuibert/FSInteractiveMap/issues/13#issuecomment-488249393, or mute the thread https://github.com/notifications/unsubscribe-auth/AL5SV2ICAIWRCHVJZSYHIDLPTFT5VANCNFSM4EKMK4EA .
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?
in swift working with:
its working correctly but i cant add click Handler
how can i add click handler in Swift? @ArthurGuibert @birslip