         } else {
             mapView.isHidden = true
         }
-        
-    
-        // MARK: Display Metadata
-        
-        // Request an image for the asset from the PHCachingImageManager.
-            //  cell.representedAssetIdentifier = asset.localIdentifier
-            imageManager.requestImage(for: getAsset(), targetSize: imageSize, contentMode: .aspectFit, options: options, resultHandler: { imageResult, infoArray in
-                // The cell may have been recycled by the time this handler gets called;
-                // set the cell's thumbnail image only if it's still showing the same asset.
-                
-                
-                // general information about the loaded asset
-                //print("Load information \(infoArray)")
-                // HERE WE GET THE IMAGE
-                
-                print("InfoArray:")
-                print(infoArray ?? "")
- 
-                
-                if(imageResult == nil){
-                    print("============= error loading image =========================")
-                    return
-                }
-                
-                
-
-                
-                // hide the preview image before setting the real image...
-                self.imageView2.alpha = 0
-                
-                self.imageView.image = imageResult
-
-                
-                //self.imageView.image = image! as UIImage
-                print("detail image was loaded")
-            })
- 
-            
+    }
+    
+    
+
+    
+    func loadImage(){
+        
+        // check and display the map overlay when needed
+        showMapOverlay()
+        
+
+        
+        loadImage(asset: getAsset(), resultHandler: { imageResult, infoArray in
+            // The cell may have been recycled by the time this handler gets called;
+            // set the cell's thumbnail image only if it's still showing the same asset.
+            
+            
+            // general information about the loaded asset
+            //print("Load information \(infoArray)")
+            // HERE WE GET THE IMAGE
+            
+            
+            if(imageResult == nil){
+                print("============= error loading image =========================")
+                return
+            }
+            
+            // hide the preview image before setting the real image...
+            self.imageView2.alpha = 0
+            self.imageView.image = imageResult
+
+        })
+
+        
 
     }
     

            }
            
            self.imageView2.image = imageResult
            
            //self.imageView.image = image! as UIImage
            print("detail image was loaded")
        })
        
        
    }

    

        
        let asset: PHAsset = getAsset(atIndex: previewPosition)

        loadImage(asset: asset, resultHandler: { imageResult, infoArray in

            if(imageResult == nil){
                print("============= error loading image =========================")
                return
            }
            
            self.imageView2.image = imageResult
        })
    }

    
    
    
    func showMapOverlay(){
        // MAP overlay display logic
        if (getAsset().location != nil){
            mapView.isHidden = false
            
