Reusable Accessible Mapping Platform

API Docs for: 3.0.0
Show:

File: src\js\RAMP\Modules\graphicExtension.js

  1. /*global define, tmpl */
  2.  
  3. //the "use strict" forces the ECMA Script 5 interpretation of the code
  4.  
  5. /**
  6. *
  7. *
  8. * @module RAMP
  9. * @submodule Map
  10. */
  11.  
  12. /**
  13. * GraphicExtension class containing helper functions for graphic objects.
  14. * Note this class requires the config object.
  15. *
  16. * @class GraphicExtension
  17. * @static
  18. * @uses RAMP
  19. * @uses Array
  20. * @uses Dictionary
  21. * @uses Util
  22. * @uses templates/point_details_list_Template.html
  23. * @uses templates/point_details_list_item_Template.html
  24. */
  25.  
  26. define([
  27. // RAMP
  28. "ramp/ramp",
  29.  
  30. // Utils
  31. "utils/array", "utils/dictionary", "utils/util", "utils/tmplHelper",
  32.  
  33. //details template
  34. "dojo/text!./templates/feature_details_template.json"],
  35.  
  36. function (
  37. // RAMP
  38. Ramp,
  39.  
  40. // Utils
  41. UtilArray, UtilDict, UtilMisc, TmplHelper,
  42.  
  43. //json details template
  44. feature_details_template) {
  45. "use strict";
  46.  
  47. return {
  48. /**
  49. * Given a graphic object, returns the config object associated with the graphic's layer.
  50. *
  51. * @method getLayerConfig
  52. * @param {esri/Graphic} graphic a graphic object or a feature object
  53. * @return {esri/Graphic}
  54. */
  55. getLayerConfig: function (graphic) {
  56. return Ramp.getLayerConfig(graphic.getLayer().url);
  57. },
  58.  
  59. /**
  60. * Returns the oid of the given graphic object
  61. *
  62. * @param {esri/Graphic} graphic
  63. * @method getOid
  64. */
  65. getOid: function (graphic) {
  66. var objectIdField = graphic.getLayer().objectIdField;
  67. return graphic.attributes[objectIdField];
  68. },
  69.  
  70. /**
  71. * Get popup content for a graphic (i.e. a point)
  72. * This logic is customized per project
  73. *
  74. *
  75. * @method getTextContent
  76. * @private
  77. * @param {Object} graphic
  78. * @return {Object} found graphic object
  79. */
  80. getTextContent: function (graphic) {
  81. var templateName = Ramp.getLayerConfig(graphic.getLayer().url).detailTemplate;
  82.  
  83. function fillTemplate(graphic) {
  84. tmpl.cache = {};
  85. tmpl.templates = JSON.parse(
  86. TmplHelper.stringifyTemplate(feature_details_template));
  87.  
  88. var datawrapper = TmplHelper.dataBuilder(graphic, graphic.getLayer().url),
  89. result = tmpl(templateName, datawrapper);
  90.  
  91. return result;
  92. }
  93.  
  94. //return generateHtml(graphic.attributes);
  95. return fillTemplate(graphic);
  96. },
  97.  
  98. /**
  99. * Returns the content of the name field of the provided graphic object
  100. *
  101. * @method getGraphicTitle
  102. * @param {esri/Graphic} graphic a graphic object or a feature object
  103. * @return {}
  104. */
  105. getGraphicTitle: function (graphic) {
  106. return graphic.attributes[this.getLayerConfig(graphic).nameField];
  107. }
  108. };
  109. });