omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Display thumbs of your photos at their locations on a map

    Pythonista
    1
    1
    1109
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cvp
      cvp last edited by

      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)
      
      1 Reply Last reply Reply Quote 2
      • First post
        Last post
      Powered by NodeBB Forums | Contributors