API Docs for: 0.0.8-0
Show:

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

/*global define, tmpl */

//the "use strict" forces the ECMA Script 5 interpretation of the code

/**
*
*
* @module RAMP
* @submodule Map
*/

/**
* GraphicExtension class containing helper functions for graphic objects.
* Note this class requires the config object.
*
* @class GraphicExtension
* @static
* @uses RAMP
* @uses Array
* @uses Dictionary
* @uses Util
* @uses templates/point_details_list_Template.html
* @uses templates/point_details_list_item_Template.html
*/

define([
// RAMP
    "ramp/ramp",

// Utils
    "utils/array", "utils/dictionary", "utils/util", "utils/tmplHelper",

//details template
    "dojo/text!./templates/feature_details_template.json"],

    function (
    // RAMP
    Ramp,

    // Utils
    utilArray, utilDict, utilMisc, tmplHelper,

    //json details template
    feature_details_template) {
        "use strict";

        return {
            /**
            * Given a graphic object, returns the config object associated with the graphic's layer.
            *
            * @param graphic a graphic object or a feature object
            * @return {esri/Graphic}
            * @method getLayerConfig
            */
            getLayerConfig: function (graphic) {
                return Ramp.getLayerConfig(graphic.getLayer().url);
            },

            /**
            * Returns the oid of the given graphic object
            *
            * @param graphic
            * @method getOid
            */
            getOid: function (graphic) {
                var objectIdField = graphic.getLayer().objectIdField;
                return graphic.attributes[objectIdField];
            },

            /**
            * Get popup content for a graphic (i.e. a point)
            * This logic is customized per project
            *
            *
            * @method getTextContent
            * @private
            * @param {Object} graphic
            * @return {Object} found graphic object
            */
            getTextContent: function (graphic) {
                var templateName = Ramp.getLayerConfig(graphic.getLayer().url).detailTemplate;

                function fillTemplate(graphic) {
                    tmpl.cache = {};
                    tmpl.templates = JSON.parse(
                        tmplHelper.stringifyTemplate(feature_details_template));

                    var datawrapper = tmplHelper.dataBuilder(graphic, graphic.getLayer().url);
                    var result = tmpl(templateName, datawrapper);

                    return result;
                }

                //return generateHtml(graphic.attributes);
                return fillTemplate(graphic);
            },

            /**
            *
            *
            * @param graphic a graphic object or a feature object
            * @return {}
            * @method getGraphicTitle
            */
            getGraphicTitle: function (graphic) {
                var fieldnames = this.getLayerConfig(graphic).mapTipSettings.hoverTipTemplateFields;

                return graphic.attributes[fieldnames[0]];

                // based on datagrid featureSources
                // return graphic.attributes[this.getLayerConfig(graphic.getLayer().url).datagrid.featureSources[0]];
            }
        };
    });