cvp
Jul 20, 2018 - 13:35
If you are using MapView, like in demo of @JonB, you can display thumbs of your photos at their locations, with their original proportions or cropped and centered squares or even cropped and centered circles.
Assuming you pass the path of your photo as subtitle of anotations. In this case, the photo have to reside at an accessible path for your script (local or iCloud).

def mapView_viewForAnnotation_(self,cmd,mk_mapview,mk_annotation):
try:
# not specially called in the same sequence as pins created
# should have one MKPinAnnotationView by type (ex: pin color)
annotation = ObjCInstance(mk_annotation)
mapView = ObjCInstance(mk_mapview)
if annotation.isKindOfClass_(MKPointAnnotation):
tit = str(annotation.title())
subtit = str(annotation.subtitle())
#print('subtit',subtit)
if 'manuel' not in subtit:
#if tit != addr_loc:
id = 'photo=' + subtit
else:
id = 'address'
#print('id',id)
pinView = mapView.dequeueReusableAnnotationViewWithIdentifier_(id)
if not pinView:
# Modify pin color: use MKPinAnnotationView
# Modify pin image: use MKAnnotationView
if 'photo' in id:
# photo
pinView = MKAnnotationView.alloc().initWithAnnotation_reuseIdentifier_(annotation,id)
#print(dir(pinView.layer()))
img=ui.Image.named(os.path.expanduser(subtit)
wh = img.size
thumb = 64
if 1 == 0:
# no crop the photo as centered square
x = 0
y = 0
w = thumb
h = int(w * wh[1] / wh[0])
thumbx = w
thumby = h
else:
# crop the photo to show a square
if wh[0] >= wh[1]:
# photo is larger than high
# height will be shown, width will be cut and centralized
h = thumb
w = int(thumb * (wh[0]/wh[1]))
x = - (w-thumb)/2
y = 0
else:
# photo is higher than wide
# width will be shown, height will be cut and centralized
w = thumb
h = int(thumb * (wh[1]/wh[0]))
x = 0
y = - (h-thumb)/2
thumbx = thumb
thumby = thumb
with ui.ImageContext(thumbx,thumby) as ctx:
img.draw(x,y,w,h)
img = ctx.get_image()
pinView.setImage_(img.objc_instance)
# photo with corner, here photo cropped by a circle
pinView.layer().setMasksToBounds_(True)
pinView.layer().setCornerRadius_(thumb/2)
pinView.layer().setBorderWidth_(2.0)
pinView.layer().setBorderColor_(UIColor.blueColor().CGColor())
else:
# address
pinView = MKPinAnnotationView.alloc().initWithAnnotation_reuseIdentifier_(annotation,id)
pinView.canShowCallout = True # tap-> show title
pinView.animatesDrop = True # Animated pin falls like a drop
pinView.pinColor = 1 # 0=red 1=green 2=purple
else:
pinView.annotation = annotation
return pinView.ptr
return None
except Exception as e:
print('exception: ',e)