cmv / cmv-app

CMV - The Configurable Map Viewer - A community supported open source mapping framework built with the Esri JavaScript API and the Dojo Toolkit
https://demo.cmv.io/
MIT License
323 stars 278 forks source link

showAttachments not honored in Identify.js against MapService #177

Closed kcarrier closed 7 years ago

kcarrier commented 9 years ago

REST Service : http://engineer05.gomvo.org/arcgis/rest/services/SP/RoadRecords/MapServer

LayerId: 13

identify.js

roadrecords: {
            13: {
                title: 'Road Records Index',
                showAttachments: true,
                description: [
                    '<table class="attrTable">',
                    '<tr valign="top">',
                    '<td class="attrName">Document :</td>',
                    '<td class="attrValue">{Document}</td>',
                    '</tr>',
                    '</table>'
                ].join('')
            }

viewer.js

{
            type: 'dynamic',
            url: 'http://engineer05.gomvo.org/arcgis/rest/services/SP/RoadRecords/MapServer',
            title: 'Road Records',
            noLegend: true,
            collapsed: true,
            identifyLayerInfos: {
                layerIds: [1, 3, 5, 7, 9, 11, 13]
            },
            options: {
                id: 'roadrecords',
                opacity: 1.0,
                visible: true
            }

Attachments are not showing in popup.

tmcgee commented 9 years ago

@kcarrier, I don't believe this is a CMV issue. It is my understanding that showAttachments is only available in the ArcGIS JavaScript API for feature layers, not for dynamic layers. CMV doesn't do anything with the identify template you provide other than pass it along to the PopupTemplate. Here's what the docs say about using showAttachments in defining the popup template

DavidSpriggs commented 9 years ago

@kcarrier @tmcgee Yes, it has to be a feature layer when added to the map. Try adding it via the operational layers array in viewer.js as a feature layer using: http://engineer05.gomvo.org/arcgis/rest/services/SP/RoadRecords/MapServer/13 Then the showAttachments should work in your template definition.

kcarrier commented 9 years ago

@tmcgee & @DavidSpriggs - All I agree the documentation says one thing but I think this code might disprove that theory. You will need to zoom all the way in to get the popup to work, but the attachment comes through here, thoughts?

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <!--The viewport meta tag is used to improve the presentation and behavior of the
    samples on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>
        San Francisco
    </title>

    <link rel="stylesheet" href="http://js.arcgis.com/3.10/js/dojo/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="http://js.arcgis.com/3.10/js/esri/css/esri.css">
    <style>
        html, body {
            height: 100%;
            width: 100%;
            margin: 0;
            padding: 0;
        }

        .esriScalebar {
            padding: 20px 20px;
        }

        #map {
            padding: 0;
        }
    </style>

    <script src="http://js.arcgis.com/3.10/"></script>
    <script>
        var map;

        require([
          "esri/config",
          "esri/map",
          "esri/dijit/Popup",
          "esri/dijit/PopupTemplate",
          "esri/layers/ArcGISDynamicMapServiceLayer",
          "esri/symbols/SimpleMarkerSymbol",
          "esri/tasks/GeometryService",
          "dojo/dom-construct",
          "dojo/parser",
          "esri/Color",
          "dijit/layout/BorderContainer",
          "dijit/layout/ContentPane",
          "dojo/domReady!"
        ],
          function (
            esriConfig, Map, Popup, PopupTemplate, ArcGISDynamicMapServiceLayer,
            SimpleMarkerSymbol, GeometryService, domConstruct, parser, Color
          ) {

              parser.parse();

              esriConfig.defaults.geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

              var popupOptions = {
                  markerSymbol: new SimpleMarkerSymbol("circle", 32, null,
                    new Color([0, 0, 0, 0.25])),
                  marginLeft: "20",
                  marginTop: "20"
              };
              //create a popup to replace the map's info window
              var popup = new Popup(popupOptions, domConstruct.create("div"));

              map = new Map("map", {
                  basemap: "topo",
                  center: [-84.259420, 39.750745],
                  zoom: 17,
                  infoWindow: popup
              });

              var popupTemplate = new PopupTemplate({
                  title: "TEST",
                  fieldInfos: [
                    {
                        fieldName: "STR_NAME",
                        visible: true,
                        label: "Type"
                    },
                    {
                        fieldName: "HyperLink",
                        visible: true,
                        label: "Hyperlink"
                    }
                  ],
                  showAttachments: true
              });

              var demographicsLayer = new ArcGISDynamicMapServiceLayer("http://engineer05.gomvo.org/arcgis/rest/services/SP/RoadRecords/MapServer");
              demographicsLayer.setInfoTemplates({
                 13: { infoTemplate: popupTemplate }
              });
              map.addLayer(demographicsLayer);
          });
    </script>
</head>

<body class="claro">
    <div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline'"
         style="width: 100%; height: 100%; margin: 0;">
        <div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'"
             style="border:1px solid #000;padding:0;">
        </div>
    </div>
</body>

</html>
DavidSpriggs commented 9 years ago

@kcarrier The behaviour in CMV is due to the way we set the templates on the features independent of the layer. In your example it is set on the actual layer. I will investigate and see if we can fix this.

tmcgee commented 9 years ago

'setInfoTemplate' was just added to Dynamic and Tile layers at version 3.10 so it sounds like the documentation has some catching up to do. An infoTemplates property for the layer configuration options was added as well.

There has potential to greatly simplify the Identify widget using infoTemplates at the layer level. However, adding the infoTemplate to the dynamic layer like this as opposed to the returned features has an undesirable side effect of interfering with other map tools that use a click (Edit, Draw, Measure, StreetView, Directions). This occurs in some instances today with feature layer infoTemplates (and other graphics such as features returned from a FInd). We addressed it for the Edit widget and feature layer infoTemplates. Alternative strategies have been discussed for a centralized approach instead of custom code for each individual widget.

In the example provided, it is not clear to me what triggers the identify at just the highest zoom level. It will require some investigation to determine when to let the API handle the map click and when to do it the "CMV way". In my opinion, more documentation of this behavior from ESRI is required before we should support this behavior.

Another consideration is that some users of CMV are intentionally not using version 3.10 of the API. I'm not sure of the reasoning for this but it is something that needs to be considered before supporting an api feature that just appeared in the newest version.

kcarrier commented 9 years ago

@tmcgee - What triggers the identify is the layered in this case 13, this is the highest level zoom layerid in the rest endpoint.

var demographicsLayer = new ArcGISDynamicMapServiceLayer("http://engineer05.gomvo.org/arcgis/rest/services/SP/RoadRecords/MapServer");
              demographicsLayer.setInfoTemplates({
                 13: { infoTemplate: popupTemplate }
              });
              map.addLayer(demographicsLayer);
tmcgee commented 9 years ago

I recognize it is the highest zoom level but why would that trigger the identify? Seems somewhat arbitrary. Any documentation on this?

kcarrier commented 9 years ago

@tmcgee - Good point not real sure. I can look around but @DavidSpriggs might be able to answer this better than I can, worth a call to Esri support though to see if they can explain it to a newbie like me, LOL.

tmcgee commented 9 years ago

good luck with ESRI support. LOL

kcarrier commented 9 years ago

Well that was a quick call, looks like it happens on a click event of a graphic, basically was told same thing documentation says so we might have to wait on a better explanation from David in my opinion.

tmcgee commented 9 years ago

There is no graphic involved with a dynamic layer. There is one for a feature layer. So it sounds like the support person's explanation is bit out of date too. ;)

My point is more that the documentation is currently lacking. Even with an explanation from David (or my own exploration of the api's code on this), we may not want to build code to support undocumented behavior that may change in the future.

DavidSpriggs commented 9 years ago

@kcarrier @tmcgee This behaviour is all baked into the map now to be more like AGO (you dont have to wire up identify, just define an pop up template and your good). There is a new prop on the map object to turn this on and off: showInfoWindowOnClick and corresponding method: https://developers.arcgis.com/javascript/jsapi/map-amd.html#setinfowindowonclick

So we can use this new functionality in CMV by turning the feature off when using other tools.

kcarrier commented 9 years ago

"Excellent Smithers!" (Bart Simpson reference), Well hopefully when there is time to work on it in CMV I can help test. We really need that feature as we have many map services with attachments enabled. Cannot replace our Flex stuff until I can get that working. I will wait patiently I promise, thanks for the help!

tmcgee commented 9 years ago

I saw that addition in the "What's New in Version 3.10" ArcGIS. It says `toggle the default behavior of showing the map's infoWindow when clicking a graphic.' which is incorrect since it appears to apply to dynamic and tiled layers as well.

Any idea why the identify is only triggered on the highest zoom level in kcarrier's example? I'm not sure we want to tap into this new feature if identify would only work at the highest zoom.

tmcgee commented 9 years ago

@karrier: you can't use a feature layer? that works already. You could add a feature layer (or layers) that only is visible at the highest zoom to mimic this behavior.

tmcgee commented 9 years ago

Oh I think I now see why it is only triggered on the highest zoom. The sublayer used in the example is only visible at that zoom level.

kcarrier commented 9 years ago

@tmcgee - Feature Layers require SDE and we use file gdb as backend. I prefer to use map services over feature services for performance and file gdb over SDE for performance as well. We replicate the data in WMAS each night via script so there is no performance hit for projecting on the fly. I was told by Esri at UC 2014 that they are working on improving the performance of feature services but in my testing they are slower than map services plus I am not big on having web services hitting my database as we do not do any web editing it is all read only. More a preference, could it be done sure but there are some deeper issues like having to reconfig my entire backend process for pop-ups?

tmcgee commented 9 years ago

Are you talking about Feature Layers or Feature Services? You can have feature layers that point to a single sublayer in a Map Service. It does not have to be a Feature Service. In your Map Service, this is a feature layer: http://engineer05.gomvo.org/arcgis/rest/services/SP/RoadRecords/MapServer/13

Using a Feature Layer may not be your desired outcome. I am just pointing out that it is possible.

pwild commented 9 years ago

Do I understand correctly that currently showAttachments will only work with feature layers and not dynamic layers in the CMV? I have successfully included attachments to a single feature layer, but I lose the labeling as such. I would prefer not to include both feature and dynamic layers for the same object. Hints?

tmcgee commented 9 years ago

That is correct. The ESRI Javascript API did not support showAttachments in the infoTemplate for dynamic layers until the recent version 3.1.0. We do plan to add this capability to CMV - it is balance to ensure we incorporate the newest capabilities while continuing to support older versions of the API that people are still using.

goriliukasbuxton commented 9 years ago

having trouble showing attachments added as feature layer in viewer.js. Is where a example with attachments configured?

tmcgee commented 9 years ago

The SF311 layer in the demo app uses showAttachments. For this particular layer, the infoTemplate is not defined in identify.js and so is created automatically by cmv. The code detects that attachments are available (hasAttachments: true for the layer) and builds the infoTemplate accordingly.

In your own infoTemplate defined in identify.js, you should just need to add showAttachments: true to enable the same functionality.

With either method, you'll need to confirm that your service has attachments. You can do this by examining the properties from the REST end point for the particular sub-layer of the map service/feature service.

goriliukasbuxton commented 9 years ago

Well, tried both methods, no Attachments are visible. Maybe because its a secure service?

tmcgee commented 9 years ago

Do you see the "Attachments:" heading at the bottom of the Info Window with the message "No Attachments Found"? If so, then your infoTemplate is configured correctly in CMV but the ESRI API is not finding the attachments. That's an API issue. You might want to try one of the ESRI sandbox examples with your service to see if it has similar results. I'm not aware of a problem with showAttachments with a secure service.

DavidSpriggs commented 9 years ago

Try this one, it has a sandbox link: https://developers.arcgis.com/javascript/jssamples/ed_attachments.html or just add it on AGO and turn on attachemebts to test: http://www.arcgis.com/home/webmap/viewer.html

goriliukasbuxton commented 9 years ago

The sandbox works with my feature layer. but it doesnt work with CMV snippet: { type: "feature", url: "[server]/rest/services/Panoramio/Trinidad/MapServer/0", title: "Panoramio", options: { id: 'png1', opacity: 1.0, visible: true, outFields: ["*"], mode: 0 }

    },

Thank you guys.

goriliukasbuxton commented 9 years ago

Hello guys, is this attachment problem is resolved in the 1.3.1 version of the viewer?

Thank you,

tmcgee commented 9 years ago

@goriliukasbuxton there has been no additional attention given to the additional showAttachments functionality added recently to the ESRI JS API. I will add this enhancement to the next development milestone for consideration.

kcarrier commented 9 years ago

@tmcgee - I see this was looked at on Nov 25, 2014 wondering if it is still on the radar or if there is a fix I have not found yet. I essentially want to setup popups where the attachment will come across in the popup as mentioned a while back. I know you all are continuing to work hard on this and trust me it is appreciated, just curious on your thoughts about when this might make it in?

tmcgee commented 9 years ago

@kcarrier to my knowledge there's been no further investigation into this even as to whether an enhancement required or a different configuration. I will do some more research on the issue if you or anyone can provide a public url to a MapServer that has attachments?

rkoelpin commented 9 years ago

Here is an arcserver service

https://gis.dhs.in.gov/arcgis/rest/services/OpenAccess/EditParcelsD5_Small/FeatureServer

Do you need the ArcGIS online url with credentials too?


From: Tim McGee notifications@github.com Sent: Friday, February 27, 2015 1:15 AM To: cmv/cmv-app Subject: Re: [cmv-app] showAttachments not honored in Identify.js against MapService (#177)

@kcarrierhttps://github.com/kcarrier to my knowledge there's been no further investigation into this even as to whether an enhancement required or a different configuration. I will do some more research on the issue if you or anyone can provide a public url to a MapServer that has attachments?

Reply to this email directly or view it on GitHubhttps://github.com/cmv/cmv-app/issues/177#issuecomment-76345172.

kcarrier commented 9 years ago

Here is another one, it is a point service

layerIds: [1,3,5,7,9,11,13]

http://engineer.gomvo.org/arcgis/rest/services/WMAS/MCEO_SurveyRecords/MapServer

Here is some code I was using

viewer.js:

operationalLayers: [{
            type: 'dynamic',
            url: 'http://engineer.gomvo.org/arcgis/rest/services/WMAS/MCEO_SurveyRecords/MapServer',
            title: 'Survey Records',
            options: {
                id: 'SurveyRecords',
                opacity: 1.0,
                visible: true,
                imageParameters: imageParameters
            },
            identifyLayerInfos: {
                layerIds: [1,3,5,7,9,11,13]
            }
  },

identify.js:

SurveyRecords: {
            1: {
                title: 'SURVEY_NUMBER',
                showAttachments: true,
                fieldInfos: [{
                    fieldName: 'SURVEY_NUMBER',
                    visible: true
                }]
            },
            3: {
                title: 'SURVEY_NUMBER',
                showAttachments: true,
                fieldInfos: [{
                    fieldName: 'SURVEY_NUMBER',
                    visible: true
                }]
            },
            5: {
                title: 'SURVEY_NUMBER',
                showAttachments: true,
                fieldInfos: [{
                    fieldName: 'SURVEY_NUMBER',
                    visible: true
                }]
            },
            7: {
                title: 'SURVEY_NUMBER',
                showAttachments: true,
                fieldInfos: [{
                    fieldName: 'SURVEY_NUMBER',
                    visible: true
                }]
            },
            9: {
                title: 'SURVEY_NUMBER',
                showAttachments: true,
                fieldInfos: [{
                    fieldName: 'SURVEY_NUMBER',
                    visible: true
                }]
            },
            11: {
                title: 'SURVEY_NUMBER',
                showAttachments: true,
                fieldInfos: [{
                    fieldName: 'SURVEY_NUMBER',
                    visible: true
                }]
            },
            13: {
                title: 'SURVEY_NUMBER',
                showAttachments: true,
                fieldInfos: [{
                    fieldName: 'SURVEY_NUMBER',
                    visible: true
                }]
            }
        },
tmcgee commented 9 years ago

@rkoelpin @kcarrier thank you. I guess if I was paying full attention last night, I would have noticed/remembered that kcarrier provided another example in the initial description of this issue. Now I have 3 examples to investigate. ;)

kcarrier commented 9 years ago

@tmcgee - Thanks for looking into this, let me know if you need anything else.

taran03 commented 9 years ago

Along these lines, I just noticed an issue in my CMV application with opening attachments on a secured service via the attachment link in the feature's ID pop up window. The attachment links display as intended in the pop up window, but when the user clicks on the attachment link the URL is calling for a redirect that requires the user to authenticate with our ArcGIS Server in order to see the attached image. Of course, the attachments work fine if the service is public. I'm already using proxy to auto authenticate user access to secure services, so I'm a little stumped as to why clicking on the attachment link leads to a login redirect page (the standard ArcGIS Server REST API Login page) instead of direct authentication from the functioning proxy. Any thoughts as to whether this is an ESRI thing or a CMV issue? Thanks.

image

image

tmcgee commented 9 years ago

@taran03 All of the logic for displaying the contents within the InfoWindow including the list of attachments and opening those attachments is handled by the ESRI JS API. Sorry if that comes across like I'm passing the buck. ;)

taran03 commented 9 years ago

Ok, that is what I suspected. Thanks for confirming this.

kcarrier commented 9 years ago

@tmcgee - I know you have other things in your life to do but I was just curious what the initial findings were from the examples we were able to provide.

tmcgee commented 9 years ago

@kcarrier Sorry, I have not had the opportunity yet.

kcarrier commented 9 years ago

@tmcgee - Hope you had a good time at DevSummit, just checking in.

tmcgee commented 9 years ago

@kcarrier this is still on my "when I get around to it" list.

tmcgee commented 9 years ago

@kcarrier: I finally spent some time this afternoon to look into this. This default map functionality behind the mapclick is not well documented in the API docs beyond what @DavidSpriggs mentioned about the setInfoWindowOnClick method to turn it on/off. In essence they treat each sublayer in a dynamic layer as if it were a feature layer - that's is why the showAttachments behaves similar to that of a feature layer. They then use multiple QueryTasks per layer (one per sub layer) to get the identify results instead of a single IdentifyTask per layer as we do in CMV.

You can use the built-in functionality within the map in CMV. You will need to not include the identify widget in your app and you will need to define your infoTemplates directly within each operationalLayer like this:

{
        type: 'dynamic',
        url: 'http://engineer.gomvo.org/arcgis/rest/services/WMAS/MCEO_SurveyRecords/MapServer',
        title: 'Survey Records',
        options: {
            id: 'SurveyRecords',
            opacity: 1.0,
            visible: true,
            imageParameters: imageParameters,
            infoTemplates: {
                1: {
                    infoTemplate: new PopupTemplate({
                        title: 'SURVEY_NUMBER',
                        showAttachments: true,
                        fieldInfos: [{
                            fieldName: 'SURVEY_NUMBER',
                            visible: true
                        }]
                    })
                }
            }
        }
}

I have not tested whether this plays nice with other cmv widgets that interact with the map so there may be a can of worms there.

I'm not sure if it a good idea or not to do away with the current Identify widget completely within CMV and rely on this undocumented functionality. That would require more discussion. I'm not a fan of their approach since using QueryTask as ESRI does instead of IdentifyTask is certainly less efficient for the server and the client.

Now that I have a better understanding of what they are doing and why it behaves the way it does, I have a few thoughts to explore how we might incorporate similar showAttachments functionality for dynamic layers within the cmv identify widget.

kcarrier commented 9 years ago

@tmcgee - I just tested the code above and it does not work as expected. Still no attachments coming through in the Popup Window, just the Survey Number comes through in the title and in the field section.

tmcgee commented 9 years ago

Hmm. I used the exact layer config that I posted above and the attachments were there in the InfoWindow. Did you disable the cmv Identify widget? That's an integral step to getting this to work..

kcarrier commented 9 years ago

@tmcgee - Disabling the identify fixed it, sorry glossed over that step. So rather than build the identifies in the identify.js file, I would just build them within viewer.js correct? Thanks for the prompt reply very much appreciated!

kcarrier commented 9 years ago

@tmcgee - Thanks again for all the help!

igover007 commented 9 years ago

@DavidSpriggs , @tmcgee . Hi all, love the work going on here. Just wondering, with regard to the showInfoWindowOnClick functionality, where abouts in CMV do I setInfoWindowOnClick(true); ? Thanks again for working on this.

tmcgee commented 9 years ago

@igover007 There isn't anything to set for this functionality. The default value is true.

kcarrier commented 8 years ago

@tmcgee - It appears I might not be able to use the description method in the viewer.js file, it is like it does not recognize anything except the first field value, all other field values come back blank. The attachments still work as you explained earlier but now the field values are not coming through as they were in the identify.js file. When I use fieldInfos[{}] as specified in the Esri JS API documentation the values come through, any thoughts. My code example can be seen below, the map service is publicly accessible.

https://gist.github.com/kcarrier/d28cec24ebc9a2f4f708

tmcgee commented 8 years ago

@kcarrier the description property in your example looks correct (when used in identify.js). This infoTemplates functionality for dynamic layers is relatively new and not well documented so it could be that the description parameter is not (yet) supported by the API for a dynamic layer's infoTemplates array.