Select to view content in your preferred language

Map Viewer (and Dashboard): Alternate attachments and metadata

728
4
Jump to solution
11-06-2023 04:41 AM
mikaël
Frequent Contributor

I know I can display a layer/table attachments by using the widget in the pop-up tool in Map Viewer. I know I can configure a specific title and description and pull metadata from the attachments by using arcade.

But is it possible, using arcade or the default widget, to alternate metadata and image?

Basically, right now, what I believe is possible is:

Title

Description (using arcade to show all metadata)

Attachments

 

What I wish I could do is:

Title

Metadata for attachment 1

Attachment 1

Metadata for attachment 2

Attachment 2

Metadata for attachment 3

Attachment 3

...

 

Is this possible? I thought I would be able to solve this with arcade but I don't know how to return an attachment/image. I think it has to be only through the widget?

 

Thanks!

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

For the URL, you'll need to swap in your actual values, then include them in an image element.

<img src="https://some-portal.com/server/rest/services/Hosted/yourFeatureService/0/{parent_id}/attachments/{fi...}"></img>

Put that into a list widget and the images should show.

- Josh Carlson
Kendall County GIS

View solution in original post

4 Replies
jcarlson
MVP Esteemed Contributor

There is a way to do this if you use the Attachments function.

https://developers.arcgis.com/arcade/function-reference/featureset_functions/#attachments

This function isn't available in every context, and I don't think it's part of the Advanced Formatting profile, so you'll probably need to use a Data Expression. But essentially you just iterate through your features and use that function to get the information about each attachment.

https://developers.arcgis.com/arcade/guide/types/#attachment

You can see in the type definition that the objects in the Attachments array include EXIF metadata, among other things.

Here's what it might look like. You're looping through every attachment for every feature, so this can be quite a time-consuming expression to evaluate.

var fs = FeatureSetByPortalItem(
  Portal('your portal url'),
  'itemid of layer',
  0,
  ['objectid'],
  false
)

var fs_dict = {
  fields: [
    {name: 'filename', type: 'esriFieldTypeString'},
    {name: 'exif', type: 'esriFieldTypeString'},
    {name: 'parent_id', type: 'esriFieldTypeInteger'},
    {name: 'file_id', type: 'esriFieldTypeInteger'}
  ],
  geometryType: '',
  features: []
}

for ( var f in fs ) {
  var atts = Attachments(f)

  for ( var a in atts ) {
    Push(
      fs_dict['features'],
      { attributes: {
        filename: atts[a]['name'],
        exif: Text(atts[a]['exifInfo']),
        file_id: atts[a]['id'],
        parent_id: f['objectid']
      }}
    )
  }
}

return FeatureSet(fs_dict)

The output is just going to be a table, but you can use HTML to pull in the actual images using the format <feature service URL>/<parent_id>/attachments/<file_id>

In this way, you can embed the image itself into your list or table or what have you. Reworking the exif data might take some work, since it's just an array, and we don't know exactly what each file is going to be pulling in. We wrap the exif array in Text() in our expression, but you could easily use Advanced Formatting to turn that back into an array for better formatting.

- Josh Carlson
Kendall County GIS
0 Kudos
mikaël
Frequent Contributor

@jcarlson, yes getting the image metadata was not a problem. But you say that I can use HTML to pull and load the actual images. How to I do this? Where do I put "<feature service URL>/<parent_id>/attachments/<file_id>"? In a popup widget? It's that part that I don't know how to do. How to embed it and display it.

Thanks for your help!

0 Kudos
jcarlson
MVP Esteemed Contributor

For the URL, you'll need to swap in your actual values, then include them in an image element.

<img src="https://some-portal.com/server/rest/services/Hosted/yourFeatureService/0/{parent_id}/attachments/{fi...}"></img>

Put that into a list widget and the images should show.

- Josh Carlson
Kendall County GIS
mikaël
Frequent Contributor

yes!!! but then I guess that the feature service has to be public? that's too bad 😞

still you solved it!

thanks!!

0 Kudos