swift3 - if statement to load marker image swift 3 mapbox ios sdk -
i using swift 3. when hit specific string while going through loop of iterated geojson data (jsonobj[i]) need call right image file. able return right pass type , load markers in map correctly. can't seem figure out how app load right color per marker type.
i have tried switch statement no luck. have looked @ if statement documentation among many other stack overflow posts , tutorials.
var pass : string? var brown = uiimage(named: "brown.png") var purple = uiimage(named: "purple.png") var green = uiimage(named: "green.png") var image : uiimage?
the block of code below in loop. each record iterated through loads marker title , subtitle. code reads first marker color "purple" , loads points purple marker instead of selecting based on pass1, pass2 returned.
var pass = jsonobj[i]["properties"]["pass"] print("propertiespassstring: ", pass) if pass == "pass1" { print("pass1!") image = purple } else if pass == "pass2" { print("pass2") image = brown } else if pass == "" { print("pass3") image = green }
here func loads marker, not sure if needed applies or loads "image" or custom marker/variable in each iteration of loop. largely copy , pasted mapbox ios sdk
func mapview(_ mapview: mglmapview, annotationcanshowcallout annotation: mglannotation) -> bool { // try show callout when annotation tapped. return true } func mapview(_ mapview: mglmapview, imagefor annotation: mglannotation) -> mglannotationimage? { // try reuse existing ‘point’ annotation image, if exists. var annotationimage = mapview.dequeuereusableannotationimage(withidentifier: "point") if annotationimage == nil { print("annotationimage") image = image?.withalignmentrectinsets(uiedgeinsets(top: 0, left: 0, bottom: (image?.size.height)!/2, right: 0)) // initialize ‘point’ annotation image uiimage loaded. annotationimage = mglannotationimage(image: image!, reuseidentifier: "point") } //image = nil return annotationimage! }
if have advice/suggestions newer programmer in swift 3 appreciate it. i've been stuck on several days now. still learning how utilize stack overflow please let me know if there better way go posting question, open constructive critiques.
Comments
Post a Comment