How to add a new attribute to infowindow of a dynamic map service or add additional content to the infowindow (PopupTemplate)?

840
6
Jump to solution
11-08-2016 06:09 AM
Vara_PrasadM_S
Occasional Contributor II

Hi,

I am trying to add a new attribute at the end of the list of actual attributes in infowindow of a dynamic map service added to web map which is used in Web AppBuilder.

My workflow is -

1. Based on some operations, I would get a list of graphics from various layers of a dynamic map service. I need to add all these result graphics to a graphic layer

2. On click of this graphic layer, the infoWindow of dynamic map service shows the actual attributes

3. In this infoWindow it self, I need to add an additional attribute name and value (which is not in the data base) at the end or top of the actual attributes

4. Also, need to add a new link beside "zoom to" and on click of this new link, need to perform some action.

For point 3 above, I tried, appending content of the infoWindow, but it is not working.

For point 4 above, I am planning to implement a new "PopupAction"

Could some one please suggest me how to implement point 3?

And is it correct way to create a new "PopupAction" to implement point 4 or any other best approach?

Thanks in advance!

With Regards,

Vara Prasad.

0 Kudos
1 Solution

Accepted Solutions
Vara_PrasadM_S
Occasional Contributor II

Hi Robert,

I have achieved the first task by implementing, "selection-change" event of PopUp. Implemented the other one too.

Thank you

With Regards,

Vara Prasad.

View solution in original post

0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Vara,

I tried, appending content of the infoWindow, but it is not working

What did you try? Can you share the code you attempted and where you placed it?

For the new action in the popup you need to create a new FeatureAction:

Create a feature action in your widget—Web AppBuilder for ArcGIS (Developer Edition) | ArcGIS for De... 

Or look at existing FeatureActions like: [install dir]\server\apps\[app#]\jimu.js\featureActions\Flash.js

Vara_PrasadM_S
Occasional Contributor II

Hi Robert,

Thanks a lot for the reply. Here is the code that I have tried.

What did you try? Can you share the code you attempted and where you placed it?

on(graphicsLayer, "click", lang.hitch(this, function(evt) {
    LayerInfos.getInstance(this.map, this.map.itemInfo).then(lang.hitch(this, function(operLayerInfos) {
        arrayUtils.forEach(operLayerInfos._layerInfos, lang.hitch(this, function(layerInfo, index) {
            //<<Code to identify the mapservice and layer id based on the graphic from graphic layer which has been clicked by executing some identify task >>
            this._updatePopupContent(graphicObj, layerInfo, layerIndex);
        }));
    }));
}));

_updatePopupContent: function(graphic, layerInfo, subId) {
    var mapServiceLayer = layerInfo.layerObject;

    if (mapServiceLayer.infoTemplates && mapServiceLayer.infoTemplates[subId] && mapServiceLayer.infoTemplates[subId].infoTemplate) {

        var contentdiv = mapServiceLayer.infoTemplates[subId].infoTemplate.content;

        var newContent = domConstruct.create("div", null, contentdiv);

        //<<code to create new elements and add to newContent div

        //If title to be changed
        mapServiceLayer.infoTemplates[subId].infoTemplate.setTitle("Information");


        //approach 1 tried - no luck
        mapServiceLayer.infoTemplates[subId].infoTemplate.setContent(contentdiv.innerHTML);
        //approach 2 tried - no luck
        mapServiceLayer.infoTemplates[subId].infoTemplate.content += contentBody.innerHTML;

    }

}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks for the suggestion for the other issue. I will try it tomorrow as soon as I reach office.

With Regards,

Vara Prasad.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Vara,

  And where did you place this code? Setting the info template for the layer after the graphic has already been clicked would only effect the next click as the click event has already been dispatched to the graphic and the default infoTemplate already shown. Why not prevent default on the event and just set the content of the map.infoWindow _updatePopupContent method?

0 Kudos
Vara_PrasadM_S
Occasional Contributor II

Hi Robert,

We need to append information (related to the graphic from graphic layer where user clicks) to the default content. So, I am fetching the graphic details on click of graphic layer and trying to append content to the default infoWindow.

I am doing this in one of my custom widgets.

Please let me know if I am not clear.

Thanks & Regards,

Vara Prasad.

0 Kudos
Vara_PrasadM_S
Occasional Contributor II

Hi Robert,

I have achieved the first task by implementing, "selection-change" event of PopUp. Implemented the other one too.

Thank you

With Regards,

Vara Prasad.

View solution in original post

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Vara,

  Great. Don't forget to mark this question as answered by clicking on the "Correct Answer" link on the reply that answered your question.

0 Kudos