Activate contextual window for some layers only

2883
7
Jump to solution
01-19-2016 03:13 AM
FlorianCADOZ
Occasional Contributor

Hello everyone !

I would like to create a popup (with the infoTemplate) for some of my layers created through ArcGISDynamicMapServiceLayer.

I'm creating a loop that looks like this :

array.forEach(this.config.operationalLayers, function (layer, i) {                   
     var template = new InfoTemplate("Attributs", "${*}");
     var dynamicLayer = new ArcGISDynamicMapServiceLayer(layer.url, {
          "opacity": layer.opacity,
          "visible": layer.visible,
          "id": layer.name,
          "infoTemplate": template
     });
     this.map.addLayer(dynamicLayer);
}, this);

The problem is that I want to create some personnalized template for some layers but not all and I don't know if an ifclause in the infoTemplate is usable...

I don't know if is it clear but I don't know how to explain it clearly...

Thank you by advance for helping me !

0 Kudos
1 Solution

Accepted Solutions
FlorianCADOZ
Occasional Contributor

Woh... I really didn't understood your code but I found my solution ! (forget to answer to my own post, sorry)

That was really stupid, just a syntax error with the .setInfoTemplates ...

The solution I used :

_loadLayers: function () {
     array.forEach(this.config.operationalLayers, function (layer, i) {
          var popeupe = null, bob = ["*"];
          switch (layer.name) {
               case "Densité de population":
                    popeupe = {
                         0: { infoTemplate: new InfoTemplate(layer.name, "Population : ${ind_c}")}
                    };
                    break;
               default:
                    console.log("Défaut");
          }
          var dynamicLayer = new ArcGISDynamicMapServiceLayer(layer.url, {
               "opacity": layer.opacity,
               "visible": layer.visible,
               "id": layer.name
          });
          dynamicLayer.setInfoTemplates(popeupe);
          this.map.addLayer(dynamicLayer);
     }, this);
},

Sorry to have wasted your time Robert !

View solution in original post

0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Emeritus

Florian,

   Based on my understanding of your question. Can you not just check the layer name in your forEach loop and if it is a certain match then create your personalized template?

0 Kudos
FlorianCADOZ
Occasional Contributor

Yeah that's I'm doing right now but my problem is also that in my app, if I want to have the popup, I need to check the "Activate the context window" in the layerList widget...

I would have the popup defined without checking this fonction for each layers in my UI...

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Florain,

   So you are saying that you have to click the "Enable Pop-up" of each layer and that is what are wanting to avoid?

0 Kudos
FlorianCADOZ
Occasional Contributor

yes, it's exactly that !

A strange behavior in my point of view...

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Florian,

   There is actually quite a bit involved in this... In your widget you need to require

'jimu/LayerInfos/LayerInfos' and its var LayerInfos

Then in the startup function:

startup: function() {
        this.inherited(arguments);
        if (this.map.itemId) {
          LayerInfos.getInstance(this.map, this.map.itemInfo)
            .then(lang.hitch(this, function(operLayerInfos) {
              this.operLayerInfos = operLayerInfos;
            }));
        } else {
          var itemInfo = this._obtainMapLayers();
          LayerInfos.getInstance(this.map, itemInfo)
            .then(lang.hitch(this, function(operLayerInfos) {
              this.operLayerInfos = operLayerInfos;
            }));
        }
      },

      _obtainMapLayers: function() {
        // summary:
        //    obtain basemap layers and operational layers if the map is not webmap.
        var basemapLayers = [],
          operLayers = [];
        // emulate a webmapItemInfo.
        var retObj = {
          itemData: {
            baseMap: {
              baseMapLayers: []
            },
            operationalLayers: []
          }
        };
        array.forEach(this.map.graphicsLayerIds, function(layerId) {
          var layer = this.map.getLayer(layerId);
          if (layer.isOperationalLayer) {
            operLayers.push({
              layerObject: layer,
              title: layer.label || layer.title || layer.name || layer.id || " ",
              id: layer.id || " "
            });
          }
        }, this);
        array.forEach(this.map.layerIds, function(layerId) {
          var layer = this.map.getLayer(layerId);
          if (layer.isOperationalLayer) {
            operLayers.push({
              layerObject: layer,
              title: layer.label || layer.title || layer.name || layer.id || " ",
              id: layer.id || " "
            });
          } else {
            basemapLayers.push({
              layerObject: layer,
              id: layer.id || " "
            });
          }
        }, this);

        retObj.itemData.baseMap.baseMapLayers = basemapLayers;
        retObj.itemData.operationalLayers = operLayers;
        return retObj;
      },

Then you can do this:

this.operLayerInfos.getLayerInfoById('Parcel Data_0').enablePopup();
0 Kudos
FlorianCADOZ
Occasional Contributor

Woh... I really didn't understood your code but I found my solution ! (forget to answer to my own post, sorry)

That was really stupid, just a syntax error with the .setInfoTemplates ...

The solution I used :

_loadLayers: function () {
     array.forEach(this.config.operationalLayers, function (layer, i) {
          var popeupe = null, bob = ["*"];
          switch (layer.name) {
               case "Densité de population":
                    popeupe = {
                         0: { infoTemplate: new InfoTemplate(layer.name, "Population : ${ind_c}")}
                    };
                    break;
               default:
                    console.log("Défaut");
          }
          var dynamicLayer = new ArcGISDynamicMapServiceLayer(layer.url, {
               "opacity": layer.opacity,
               "visible": layer.visible,
               "id": layer.name
          });
          dynamicLayer.setInfoTemplates(popeupe);
          this.map.addLayer(dynamicLayer);
     }, this);
},

Sorry to have wasted your time Robert !

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Florian,

   Glad you go it worked out I was having a hard time figuring out why it was not just working automatically when you set the info template to the layer (i didn't notice that you were not no doing that step).

0 Kudos