Select to view content in your preferred language

Custom map's infoTemplate

426
1
04-01-2022 03:48 PM
GeoGarage
New Contributor

Hello all.

I am developping with API 3.35 and wab 2.19. It is not possible for me to change of versions for client requeriments.

I need customize the map's default infoTemplate, and it's not possible customized for a particular layer or several layers. If I were to customize the infoTemplate of several layers, then I would be forced to preload them, and the workflow doesn'y allow this.

I need to reached the default infoTemplate of the map for customize its infoTemplate.content property in such a way when I click on a feature, if an of its fields has a certain value type, then the value is reclaculated, showing the new value in the infoWindow. If the feature (or layer) doesn't have this field type, then infoTemplate is without customization.

The service is a DynamicMapServiceLayer, consecuently it is not possible to customize infoTemplate in portal, as in the case of a FeatureService.

Is it possible to reached the map's default infoTemplate for customize it?

0 Kudos
1 Reply
GeoGarage
New Contributor

OK. I will answer myself. If anyone has a better answer and wants to add it, thanks in advance:

My solution will be to modify the Splash widget, which is a widget that starts at the beginning of the app, in such a way that in the "start" event of the widget I will do the following:

 

 

var url = "captured url of the service of interest"
        this.map.on("layer-add-result", function(evt){
          if(evt.layer.url == url){
            var titulo = "Información de " + evt.layer.name;
            var infoTemplate = new InfoTemplate(titulo, function(graphic){
              var content = "";
              for(var i=0; i<evt.layer.fields.length; i++){
                if(evt.layer.fields[i].name == "URL"){
                  content = content + "<br><a href="+ graphic.attributes[evt.layer.fields[i].name] + graphic.attributes["sesion"] target='_blank'>Más información del objeto</a>"
                }
                else{
                  content = content + "<br><b>" + evt.layer.fields[i].name + "</b>: " + graphic.attributes[evt.layer.fields[i].name]
                }
              }
              return content;
            });
            evt.layer.setInfoTemplate(infoTemplate);
          }
        });

 

0 Kudos