Unresolved identifier in mapkit

The following code was the same question on stack overflow. However it looks like the code was in swift 2. I added a image jj for some of the code but I am getting 1 error message. The error message is var anView = thisMAP.dequeueReusableAnnotationView(withIdentifier: reuseId ). The error message states that reuseId is a unresolved identifier That is the only error message. If that is fixed the code will compile.

import UIKit
import MapKit

class Annotation: NSObject, MKAnnotation
var coordinate: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)
var custom_image: Bool = true
var color: MKPinAnnotationColor = MKPinAnnotationColor.purple
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet var thisMAP: MKMapView!

override func viewDidLoad() {
    self.thisMAP.delegate = self;

    let annotation = Annotation()
    let annotation2 = Annotation()
    annotation2.coordinate = CLLocationCoordinate2D(latitude: 0.0, longitude: 1.0)
    annotation2.custom_image = false
    let annotation3 = Annotation()
    annotation3.coordinate = CLLocationCoordinate2D(latitude: 1.0, longitude:  0.0)
    annotation3.custom_image = false
    annotation3.color = MKPinAnnotationColor.green

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    if (annotation is MKUserLocation) {
        return nil
    var anView = thisMAP.dequeueReusableAnnotationView(withIdentifier: reuseId )
    if anView == nil {
        if let anAnnotation = annotation as? Annotation {
            if anAnnotation.custom_image {
                let reuseId = "jj.png"
                anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
                anView.image = UIImage(named:"jj.png")
            else {
                let reuseId = "pin"
                let pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
                pinView.pinColor = anAnnotation.color
                anView = pinView
        anView.canShowCallout = false
    else {
        anView.annotation = annotation

In this line:
var anView = thisMAP.dequeueReusableAnnotationView(withIdentifier: reuseId )
you’re using ‘reuseId’ but you haven’t declared it yet. You’re declaring two different reuseId constants later in the function, if anView is nil, but you can’t use it before it’s declared.
You may have to duplicate some of your code, to ask annotation for its custom_image property and thus the appropriate reuseId, so you can dequeue with it, and if nil create the appropriate view.