Show Attachments in Web Map Popup

129437
416
12-14-2015 08:10 AM

Show Attachments in Web Map Popup

I work with a lot of customers that request the ability to display their feature service attachments in the web map's popup rather than a hyperlink.  The attached script will convert the feature services attachments URL to a field.  You can then display the attachment directly in the popup after some configuration.

 

Here is a screen shot on how attachments display within a web map popup by default:

 

Screen1.PNG

 

Below are the steps to show the attached image directly in the popup:

 

1.  Add a TEXT/STRING field (i.e. "Picture")  to the feature service that can support a large amount of characters (i.e. 1,000).

2.  Execute the attached GP tool.

3.  Configure the pop-up to Show Images.  Ex:

 

Screen2.PNG

 

The image will now display directly in the popup.  Ex:

 

Screen3.PNG

 

Notes:

  • the timeout for an ArcGIS Online feature service is set to the max of 15 days.
  • the timeout for an ArcGIS Server service is set to the default 'Lifespan of long lived token'.  The default is 1 day.  This can be changed by going to Server Manager > Security > Settings.  After the long lived token is updated, you can update the expiration parameter on line 33.
  • Since the token will timeout, you can update the parameters in the script so this can be executed with Windows Task Scheduler.  Here is an example of how to configure the parameters:

 

A video of the workflow can be found below:

https://www.youtube.com/watch?v=WpLJBZ9gnuw

Attachments
Comments
DickieRigdon
Regular Contributor

@JakeSkinner Great, thanks Jake!

VivianGriffey
New Explorer

Hi Jake, thanks for being so responsive to all of our questions. I have on regarding the image itself not showing-- I saw in a previous comment that it was due to not being a jpeg. However, mine are JPG Files (.jpg) so I am not sure of the problem and thought I would ask. At some points it shows this and sometimes it's just blank. Thank you!

 

EDIT: somehow they were still coming through as .HEIC photos...I just manually removed everything and added the jpegs in manually. Not a great solution for others unfortunately

VivianGriffey_0-1665953991050.png

 

DickieRigdon
Regular Contributor

Hi @JakeSkinner 

Returned to my web map app with the popup photos after a short hiatus today. I reran the Pro tool to refresh the photos but got the Line 34 error.  I had earlier changed the alias to the Picture field name as Full Size Image so that would display in the Pop Up menu.  I tried running the tool with both names but no luck.  I also deleted the Picture field and recreated it.  Editing is enabled and attachments are enabled.  I also made sure to use upper/lower case in login.  So far nothing is working.  I just sent you an invitation to share the layer.  Could you take a look?  

Thanks, Dickie

JakeSkinner
Esri Esteemed Contributor

@DickieRigdon line 34 is attempting to generate a token, so I believe it's something with your username/password.  Are you using the following username, DRigdon_cadoc?

The tool worked for me successfully:

JakeSkinner_0-1666048827082.png

 

DickieRigdon
Regular Contributor

@JakeSkinner  Yes, I'm using that user name.  I think I've somehow lost connection between AGOL and Pro for the layer.

lost connection?lost connection?

DickieRigdon
Regular Contributor

@JakeSkinner 

Strange.  Even though it was giving me the line 34 error and quit running, my photos populated in the app.  I recently setup two factor authentication on my AGOL/ArcGIS Pro accounts.  Could that be causing an issue with the tool not running properly?

JakeSkinner
Esri Esteemed Contributor

@DickieRigdon I did execute the tool yesterday, so that's why you may be seeing the Picture field updated with the URL.  

The two factor authentication could be causing the issue.  I would try temporarily disabling it and see if the tool works successfully.

DickieRigdon
Regular Contributor

@JakeSkinner  Yes, the two factor authentication was the issue.  I disabled it and the tool ran perfectly.  Would there be a way to write the tool to work with 2-factor?  We are going to 2-factor for all our accounts.  I'm looking to publish an App using your tool and Windows Task Scheduler to always keep the photos visible.  Thanks for your help Jake.

JakeSkinner
Esri Esteemed Contributor

@DickieRigdon no, unfortunately there will not be.  The two-factor authentication requires another interaction from the end user (i.e. accessing Google Authenticator).  

TaylorCarnell1
Occasional Contributor

Copying my answer from the same SO post that brought me here.

 

If your layer is hosted in AGOL, you can now use the map viewer beta and select the gallery option for attachments under configure pop-up.

This option is currently disabled for enterprise/portal hosted layers. An ideal workaround is to create a web app with the attachment viewer template.

If you're on an older version of enterprise (as we are) there is a bug where an attachment viewer app doesn't honour image orientation. The workaround I've developed, which may be useful to others in similar circumstance, is:

Calculate a field (using arcade) including comma-separated attachment IDs:

//calculate the attach IDs field
function IDs(f){
    return f.ID;
}

var Attach_ = Attachments($feature);
var AttachIDs = Map(Attach_, IDs);
return Concatenate(AttachIDs,','); 

This must be a field CALCULATE as attribute expressions do not currently support the Attachments function. I believe an attribute rule may also work.

Once the above is available, you can add attribute expressions in your pop-up (1 per attached image) as:

//build the URL for image attachment <ImageNumber>
var ImageNumber = 0
var AttachIDs = split($feature.AttachmentIDs,',')

if(ImageNumber > count(AttachIDs) - 1)
    return ''

var AttachID = AttachIDs[ImageNumber]
var BaseURL = "<your_domain>/server/rest/services/Hosted/LayerName/FeatureServer/0/"
var ObjectID = $feature.OBJECTID
return BaseURL + ObjectID + "/attachments/" + AttachID

ImageNumber must be incremented for each expression, starting from 0.

After that you can add an image per attachment as pop-up media, referencing the matching attribute expression for the url and link fields.

DickieRigdon
Regular Contributor

@JakeSkinner  Hi Jake, meeting some resistance on running the Task Scheduler on the organizational level so I would like to ask you about some alternative workflows.

a) Can the Task Scheduler for the toolbox be run in an ArcGIS Notebook instead?

b) Or, if I created my web map app in Experience Builder, would it require the toolbox/task scheduler workflow as well?

c) Lastly, if I used a new Map Viewer map with its automatic photo display and then used that map inside a Dashboard App, would the photos always display after publishing without having to run any refresh scheduling?

I love my current web map app with its widgets and your popup workflow but I may be forced to employ one of these other workflows if they are viable.  Thank you for your time.

JakeSkinner
Esri Esteemed Contributor

@DickieRigdon 

1.  Yes, you can run this script in ArcGIS Notebook.  You would need to hardcode the values for the # Variables section in the script

2.  If you create an Experience Builder app, you do not need to execute this tool as it will automatically read the attachments

3.  If you create an Dashboard, you do not need to execute this tool as it will automatically read the attachments

DickieRigdon
Regular Contributor

@JakeSkinner  Great information, thank you Jake!

 

MarkGambordella
Regular Contributor

is there a way to write the script to query by kewords and only create URL for those with that keyword?  I have a signature and a photo column in the attribute table, which have keywords of 'photo' and 'sign'.  Can i filter or query or only build an URL for the 'photo' keyword attachments.

JakeSkinner
Esri Esteemed Contributor

@MarkGambordella, yes you can update the where statement on line 87:

JakeSkinner_0-1703085412259.png

 

MarkGambordella
Regular Contributor

would i just write is as  'where':'photo'    or do i need to write it a differnet way and say keywords: photo.

 

Im really new to coding and using python and could use the help.

 

thanks

Version history
Last update:
‎02-28-2022 04:19 AM
Updated by:
Contributors