Reusable Accessible Mapping Platform

API Docs for: 3.0.0
Show:

File: src\js\RAMP\Utils\tmplUtil.js

  1. /* global define */
  2.  
  3. /**
  4. * Utility module containing useful static classes.
  5. *
  6. * @module Utils
  7. */
  8.  
  9. /**
  10. * A set of functions that can be accessed within templates
  11. *
  12. *
  13. * @class TmplUtil
  14. * @static
  15. */
  16.  
  17. define(["ramp/globalStorage"],
  18. function (GlobalStorage) {
  19. "use strict";
  20.  
  21. return {
  22. /**
  23. * Given a feature object or a graphic object (or any object that has a getLayer method and an
  24. * attributes field) return the image URL for that feature/graphic object.
  25. *
  26. * NOTE: all dependent functions should be written as nested functions inside the caller function, otherwise TmplEx templating library won't identify
  27. *
  28. * @method getGraphicIcon
  29. * @param {Graphic} graphic
  30. * @param {Object} layerConfig
  31. * @return {String} imageUrl Url to the features symbology image
  32. */
  33. getGraphicIcon: function (graphic, layerConfig) {
  34. var symbolConfig = layerConfig.symbology;
  35.  
  36. //TODO expand logic. Need to handle up to 3 keys in unique renderer. Need to handle Ranged renderer
  37. switch (symbolConfig.renderer.type) {
  38. case "unique":
  39. var key = graphic.attributes[symbolConfig.renderer.key1];
  40. return symbolConfig.icons[key].imageUrl;
  41.  
  42. case "simple":
  43. return symbolConfig.icons["default"].imageUrl;
  44. default:
  45. return symbolConfig.icons["default"].imageUrl;
  46. }
  47. },
  48.  
  49. /**
  50. * Given a feature object or a graphic object (or any object that has a getLayer method and an
  51. * attributes field) return the attribute value for its designed "name" field
  52. *
  53. * NOTE: all dependent functions should be written as nested functions inside the caller function, otherwise TmplEx templating library won't identify
  54. *
  55. * @method getFeatureName
  56. * @param {Graphic} graphic
  57. * @param {Object} layerConfig
  58. * @return {String} imageUrl Url to the features symbology image
  59. */
  60. getFeatureName: function (graphic, layerConfig) {
  61. return graphic.attributes[layerConfig.nameField];
  62. },
  63.  
  64. /**
  65. * Given a feature object return the objectid for that item.
  66. * This will likely fail on a non-feature object (e.g. a plain graphic)
  67. *
  68. * NOTE: all dependent functions should be written as nested functions inside the caller function, otherwise TmplEx templating library won't identify
  69. *
  70. * @method getObjectId
  71. * @param {Graphic} graphic
  72. * @return {Integer} objectId
  73. */
  74. getObjectId: function (graphic) {
  75. return graphic.attributes[graphic.getLayer().objectIdField];
  76. },
  77. /*
  78. * Helper function, get attribute value by field name
  79. *
  80. * @method getAttributeValueByName
  81. * @param {Object} graphic ?
  82. * @param {String} fieldName ?
  83. */
  84. getAttributeValueByName: function (graphic, fieldName) {
  85. return graphic.attributes[fieldName];
  86. },
  87.  
  88. /* Helper function used by filterManager.*/
  89. /*
  90. * generate visibility legend object
  91. * @param o
  92. */
  93. generateVisibilityLegend: function (o) {
  94. var attr = "",
  95. visibilityLegendLabel = {
  96. for: "filterGroup_" + o.data[o.idx].id,
  97. attr: attr,
  98. value: o.data[o.idx].id,
  99. checked: "checked",
  100. label: o.data[o.idx].layerConfig.displayName,
  101. class: "eye checked",
  102. layerId: o.data[o.idx].id
  103. };
  104. return visibilityLegendLabel;
  105. },
  106. /*
  107. * generate visibility legend object
  108. * @param o
  109. */
  110. generateBoundingBoxLegend: function (o) {
  111. // adding flag for the generated o object
  112. // o.disabled will indicate the bounding checkbox is to be disabled.
  113. var checkboxDisabled = false,
  114. attr = "",
  115. boundingLegendLabel;
  116.  
  117. // determine if given layer is static or WMS
  118. checkboxDisabled = Boolean(o.data[o.idx].ramp.type === GlobalStorage.layerType.Static ||
  119. o.data[o.idx].ramp.type === GlobalStorage.layerType.WMS);
  120.  
  121. boundingLegendLabel = {
  122. for: "filterGroup_" + o.data[o.idx].id + "1",
  123. attr: attr + "1",
  124. value: o.data[o.idx].id,
  125. checked: "checked",
  126. label: o.data[o.idx].layerConfig.displayName,
  127. class: "box checked",
  128. disabled: checkboxDisabled,
  129. layerId: o.data[o.idx].id
  130. };
  131.  
  132. return boundingLegendLabel;
  133. },
  134.  
  135. /*
  136. * Generate settings toggle object.
  137. *
  138. * @method generateSettingsToggle
  139. * @param o
  140. */
  141. generateSettingsToggle: function (o) {
  142. var //attr = "",
  143. boundingLegendLabel = {
  144. str: o.str,
  145. layerId: o.data[o.idx].id,
  146. settings: o.data[o.idx].layerConfig.settings
  147. };
  148.  
  149. return boundingLegendLabel;
  150. }
  151. };
  152. });