Showing attachments in Popups

3217
9
09-06-2013 12:47 PM
StevenGraf1
Occasional Contributor III
Hello there, I have been trying to get my attachments to load into a pop up window but it just won't work.  I have a web application with a link to an edit application where you can see the attachment.  Setting the attachment works fine, but it doesn't show up in the popup on the web application.

Here is the code (where I think I am supposed to be editing).  I'm fairly new to coding and was asked to look into this.

[HTML]var deferred = identifyTask.execute(identifyParams);

        deferred.addCallback(function(response) {   
 
          // response is an array of identify result objects    
          // Let's return an array of features.
          return dojo.map(response, function(result) {
            var feature = result.feature;
            feature.attributes.layerName = result.layerName;
   //alert(feature.attributes.layerName);
   //alert("Something");
            if(result.layerName == 'Building Interior Space - Floor 1'){
     //alert("did we make it?");
              //console.log(feature.attributes.PROPID);
             var template = new esri.InfoTemplate("", "Building Name: ${Building Name} <br/> Floor Number: ${Floor Number} <br/> Space Name: ${Short Name of Space} <br/> Full Space Name: ${Full Name of Space} <br/> Space Type: ${Space Type} <br/> Staff Name: ${STAFFNM} <br/> Phone: ${PHONE} <br/> Access Type: ${Access Type} <br/>");
     feature.setInfoTemplate(template);
            }
   return feature;
          });
        });
   map.infoWindow.setFeatures([ deferred ]);
        map.infoWindow.show(evt.mapPoint);

       }[/HTML]

I've been searching all over and found several threads dealing with it but I can't get their fixes to work.

Any help would be greatly appreciated, Thanks!
0 Kudos
9 Replies
JohnGravois
Frequent Contributor
steven, welcome to the Esri forums!

perhaps i'm missing something, but i don't see anything in your identifyTask callback for handling attachments.

have you considered using the map popup widget in your application?  it exposes a fairly straightforward technique to "turn on" the display of attachments.
0 Kudos
StevenGraf1
Occasional Contributor III
Hello, I am inserting the popup widget into my application but I can't seem to get it to display anything.  The popup window is blank.

[HTML]function executeIdentifyTask(evt) { 
  
   //alert("one");

   var measureMode =   dojo.query(".esriButton .dijitButtonNode").some(function(node, index, arr){
          if(node.childNodes[0].checked){
            //at least one of the measure tools is active so disable identify
            return true;
           
          }
       });


        if(isBufferOn) {
     //alert("on");
     map.graphics.clear();
           var params = new esri.tasks.BufferParameters();
           params.geometries = [ evt.mapPoint ];

          //buffer in linear units such as meters, km, miles etc.
    if (numberOfRings == "2")
    {
       var ringOne = document.getElementById('ringDist1').value;
    var ringTwo = document.getElementById('ringDist2').value;
             params.distances = [ ringOne, ringTwo ];
    } else {
      var ringOne = document.getElementById('ringDist1').value;
            params.distances = [ ringOne ];
    }
          //params.distances = [ 2, 10 ];
          params.unit = esri.tasks.GeometryService.UNIT_FEET;
          params.outSpatialReference = map.spatialReference;

           gsvc.buffer(params, showBuffer);
     dojo.disconnect(handler);
    
  }
  
         //alert("did we make it?");

   //test for measurement
   if(! measureMode && ! isBufferOn) {

   map.graphics.clear();
        //identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
  identifyParams.layerIds = layer.visibleLayers
        identifyParams.geometry = evt.mapPoint;
        identifyParams.mapExtent = map.extent;
       
  //define a popup template
        var popupTemplate = new esri.dijit.PopupTemplate({
          title: "{Test}",
          fieldInfos: [
          {fieldName: "BUILDING", visible: true, label:"Building Name"},
          {fieldName: "FLOOR", visible:true, label:"Floor Number"}
          ],
          showAttachments:true
        });
 
        var featureLayer = new esri.layers.FeatureLayer("http://gis.aoscloud.net/aosmaps/rest/services/Test/Test/MapServer/0", {
          mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,
          infoTemplate: popupTemplate,
          outFields: ["BUILDING", "FLOOR"]
        });
        featureLayer.setDefinitionExpression("Test != ''");
 
  
      }

 
        map.infoWindow.show(evt.mapPoint);

    //end the test for measurement

    isBufferOn = false;

      }[/HTML]
0 Kudos
JohnGravois
Frequent Contributor
i think the problem here is that you define a popup template for your feature layer, but then make a call directly to the generic map.infoWindow to display at the location defined by your event handler mapPoint.

perhaps you might try setting your popup template directly in the map constructor instead of the the feature layer constructor?  if you have trouble and are willing to share an entire simplified application pointing at public services, id be happy to take a look.
0 Kudos
StevenGraf1
Occasional Contributor III
You can view the source of the html here: http://gis.aoscloud.net/Test/s3.html
0 Kudos
JohnGravois
Frequent Contributor
yeah, what i said in my last post is definitely true.

what exactly are you trying to accomplish?  do you just want people to be able to click on your building footprints and see a popup?  if so, the identifyTask is unnecessary.  you can just move your featureLayer constructor and associated code to make sure it happens when the map is loading.  afterwards, since the featureLayer already ensures that graphics are drawn on the client, the popups should appear automatically when you click on features from that layer.
0 Kudos
StevenGraf1
Occasional Contributor III
Hello, sorry for the delayed reply but I got pulled away on some different projects.  I changed the code back to the original version in the previous link (http://gis.aoscloud.net/Test/s3.html) before I tried to institute the popup widget.  I want to use my original code to display popups instead of the popup widget you suggested.  

You mentioned I need to use the IdentifyTask callback for handling attachments. Could you link me some information on this?

Thanks
0 Kudos
StevenGraf1
Occasional Contributor III
I've come up with a work around for my problem but it would be time consuming.  I added in the direct link from the attachment and scaled the image so it would fit in the popup.
0 Kudos
StevenGraf1
Occasional Contributor III
I have the popup widget working in my application and added the mediaInfos to it to show image attachments.  I'm not sure what the sourceURL and the linkURL are there for. There is the 'no picture' icon and my attachment isn't showing.

[HTML]
var popupTemplate = new esri.dijit.PopupTemplate({
          title: "{BUILDING}",
          fieldInfos: [
          {fieldName: "FLOOR", visible: true, label:"Floor"},
    {fieldName: "BUILDING", visible: true, label:"Building Name"},
    {fieldName: "CAMERA", visible: false, label:"Camera"},
          ],
    mediaInfos: [{
   "title": "Image:",
   "caption": "",
   "type": "image",
   "value": {
     "sourceURL": "{}",
     "linkURL": "{}"
   }
    }],
        });
 
  //create a feature layer based on the feature collection
        var featureLayer = new esri.layers.FeatureLayer("http://gis.aoscloud.net/aosmaps/rest/services/Test/Test/MapServer/0", {
          mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,
          infoTemplate: popupTemplate,
          outFields: ["*"]
        });
[/HTML]
0 Kudos
GaneshSolai_Sambandam
New Contributor III
Hi Steven
Your sample  Edit application looks extremely good (http://gis.aoscloud.net/Test/s3Edit.html). I think you can help me creating similar kind of functionality which I am trying to integrate with my application.
In your test Edit application, you only added one layer at a time, but in my case, I have around 8 layers to be integrated and I added those layers to my edit application. But the problem, when I select Edit Layers Drop down list, it renders the selected feature layer and updates all the template picker and editor widget for the first time, when I choose another layer from the edit drop down menu, it renders the feature layers but it doesn't udpate the template picker on the template picker widget.

Is that anything you can help me to fix this. You can add an another layer into application to show how this can be amended.

Your help in this regard is greatly appreciated. I think you are the expert in this line, Can you please me on this.
0 Kudos