Reusable Accessible Mapping Platform

API Docs for: 5.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. * Returns the oid of the given graphic object
  50. *
  51. * @param {esri/Graphic} graphic
  52. * @method getOid
  53. */
  54. getOid: function (graphic) {
  55. var objectIdField = graphic.getLayer().objectIdField;
  56. return graphic.attributes[objectIdField];
  57. },
  58.  
  59. /**
  60. * Get popup content for a graphic (i.e. a point)
  61. * This logic is customized per project
  62. *
  63. *
  64. * @method getTextContent
  65. * @private
  66. * @param {Object} graphic
  67. * @return {Object} found graphic object
  68. */
  69. getTextContent: function (graphic) {
  70. var templateName = graphic.getLayer().ramp.config.templates.detail;
  71.  
  72. function fillTemplate(graphic) {
  73. tmpl.cache = {};
  74. tmpl.templates = JSON.parse(
  75. TmplHelper.stringifyTemplate(feature_details_template));
  76.  
  77. var datawrapper = TmplHelper.dataBuilder(graphic, graphic.getLayer().ramp.config),
  78. result = tmpl(templateName, datawrapper);
  79.  
  80. return result;
  81. }
  82.  
  83. //return generateHtml(graphic.attributes);
  84. return fillTemplate(graphic);
  85. },
  86.  
  87. /**
  88. * Returns the content of the name field of the provided graphic object
  89. *
  90. * @method getGraphicTitle
  91. * @param {esri/Graphic} graphic a graphic object or a feature object
  92. * @return {}
  93. */
  94. getGraphicTitle: function (graphic) {
  95. return graphic.attributes[graphic.getLayer().ramp.config.nameField];
  96. }
  97. };
  98. });