samlarsen

Cannot change webmap feature layer popup title

Discussion created by samlarsen on Oct 4, 2012
Latest reply on Sep 17, 2013 by JasonJFitzsimmons
Hi,

I am having trouble changing the popup title of a webmap feature layer as shown here.

The code below demonstrates creation of a new infoTemplate, setting a title function (or string for that matter) and applying the infoTemplate to the feature layer results in an empty title.  Setting the popup content works, but not the title.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" /> 
    <!--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"/>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/dojo/dijit/themes/claro/claro.css">
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/esri/css/esri.css" />
    <style type="text/css">
      html,body { height:100%; width:100%; margin:0; padding:0; }
      body{ background-color:#777; overflow:hidden; font-family:"Trebuchet MS"; }
      #map { overflow:hidden; padding:0; }
    </style>
    <script type="text/javascript">var dojoConfig={parseOnLoad: true};</script>
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.2">
    </script>
    <script type="text/javascript">
      dojo.require("dijit.dijit"); // optimize: load dijit layer
      dojo.require("dijit.layout.BorderContainer");
      dojo.require("dijit.layout.ContentPane");
      dojo.require("esri.map");
      dojo.require("esri.arcgis.utils");   
      var map;
      function init() {
        var webmap = "1a40fa5cc1ab4569b79f45444d728067";
        var mapDeferred = esri.arcgis.utils.createMap(webmap, "map", {
          mapOptions: {
            slider: false,
            nav:false
          }
        });
        mapDeferred.addCallback(function(response) {
          map = response.map;
          //resize the map when the browser resizes
          dojo.connect(dijit.byId('map'), 'resize', map,map.resize);

          template = new esri.InfoTemplate();
          template.setTitle(function(){ return "i set the title" });
          template.setContent(function(){ return "i can set the content, but not the title :(" });   
          var layer = map.getLayer(map.graphicsLayerIds[0]);
          layer.setInfoTemplate(template)                    
        
        });
        mapDeferred.addErrback(function(error) {
          console.log("Map creation failed: ", dojo.toJson(error));
        });
      }
      function resizeMap() {
        var resizeTimer;
        clearTimeout(resizeTimer);
        resizeTimer = setTimeout(function() {
          map.resize();
          map.reposition();
        }, 500);
      }
      //show map on load
      dojo.addOnLoad(init);
    </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'">
        <div id="bingLogo" style="position: absolute;bottom: 2px;left: 3px;display:none;z-index:49;">
          <img src="images/bing_logo.png" border="0" />
        </div>
      </div>
    </div>
  </body>
</html>�??

Outcomes