官术网_书友最值得收藏!

InfoTemplates

InfoTemplates, as we mentioned in Chapter 1, Your First Mapping Application, describe how you want to display data in a popup. The InfoTemplate can be constructed using two strings, the title and the content. The title and content strings represent HTML templates, and you can substitute graphic attributes in the template. For a graphic's infoTemplate, if you wanted to display the graphic's total attribute, you would insert the value in the template with a ${total}, which shows the field name inserted inside the brackets of the substitution string ${}.

If you want to display a popup containing all the name/value pairs in the graphic's attributes, you can use a wildcard ${*} in the content value, as follows:

graphic.infoTemplate = new InfoTemplate("Attributes", "${*}");

For the content, you can add HTML content to the string, including tables, lists, images, and links. For example, you might use something like the following to describe a marine habitat:

graphic.infoTemplate = new InfoTemplate("Marine Habitat 
  (${name})", "<table><tbody><tr><th>Type: 
  </th><td>${type}</td></tr><tr><th>Ocean 
  zone:</th><td>${zone}</td></tr><tr><td colspan='2'><img 
  src='${imageSrc}' alt='${name}' /></td></tr></tbody></table>");

In the preceding example, we added the name attribute of the graphic to the title, and created a two-column table that displays the type of the graphic, the zone where the graphic resides, and a two-column wide image connected to the map graphic.

主站蜘蛛池模板: 洞口县| 南昌县| 丹阳市| 定西市| 富蕴县| 独山县| 兴业县| 鄢陵县| 龙游县| 农安县| 孟连| 汉阴县| 丹棱县| 四平市| 天峻县| 陆河县| 昌图县| 中山市| 青浦区| 喜德县| 四子王旗| 岗巴县| 上饶市| 图们市| 连平县| 合川市| 文安县| 梁平县| 望江县| 凤台县| 海丰县| 日土县| 甘谷县| 鄂托克前旗| 大理市| 盐亭县| 宝鸡市| 大足县| 修水县| 宜章县| 岱山县|