Reusable Accessible Mapping Platform

API Docs for: 3.0.0
Show:

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

  1. /*global define */
  2.  
  3. /**
  4. *
  5. *
  6. * @module RAMP
  7. */
  8.  
  9. /**
  10. * RAMP class.
  11. *
  12. * Module for shared code that need the global configuration object.
  13. * For code that can be of use to any javascript program and do not
  14. * require the global configuration object, place the code in
  15. * util.js
  16. *
  17. * @class RAMP
  18. * @uses dojo/_base/declare
  19. * @uses dojo/query
  20. * @uses dojo/_base/array
  21. * @uses dojo/dom
  22. * @uses dojo/dom-class
  23. * @uses dojo/dom-style
  24. * @uses dojo/dom-construct
  25. * @uses dojo/request/script
  26. * @uses GlobalStorage
  27. * @uses Array
  28. * @uses Dictionary
  29. * @uses Util
  30. * @uses TmplUtil
  31. */
  32.  
  33. define([
  34. // Dojo
  35. "dojo/_base/declare", "dojo/query", "dojo/_base/array", "dojo/dom", "dojo/dom-class", "dojo/dom-style",
  36. "dojo/dom-construct", "dojo/request/script",
  37.  
  38. // RAMP
  39. "ramp/globalStorage", "ramp/map",
  40.  
  41. // Utils
  42. "utils/array", "utils/dictionary", "utils/util", "utils/tmplUtil"],
  43.  
  44. function (
  45. // Dojo
  46. declare, dojoQuery, dojoArray, dom, domClass, domStyle, domConstruct, requestScript,
  47.  
  48. // RAMP
  49. GlobalStorage, RampMap,
  50.  
  51. // Utils,
  52. UtilArray, UtilDict, UtilMisc, UtilTmpl) {
  53. "use strict";
  54. return {
  55. /**
  56. * Updates some of the Strings on the HTML page using the config string resources
  57. *
  58. * @method loadStrings
  59. */
  60. loadStrings: function () {
  61. // doesn't seem to be doing a lot, this function
  62. },
  63.  
  64. /**
  65. * Returns the feature layer config for the given url
  66. *
  67. * @param {String} url
  68. * @param {String} wmsName WMS Layer name. Optional. Should only be provided if attempting to get a WMS layer.
  69. * @method getLayerConfig
  70. */
  71. getLayerConfig: function (url, wmsName) {
  72. if (!GlobalStorage.urlCfg) {
  73. GlobalStorage.urlCfg = {};
  74. }
  75.  
  76. var res = UtilArray.find(GlobalStorage.config.wmsLayers.concat(GlobalStorage.config.featureLayers), function (layerConfig) {
  77. if (wmsName == null) {
  78. return layerConfig.url === url;
  79. } else {
  80. return (layerConfig.url.indexOf(url) >= 0 && layerConfig.layerInfo.name === wmsName);
  81. }
  82. });
  83.  
  84. GlobalStorage.urlCfg[url] = res;
  85.  
  86. return GlobalStorage.urlCfg[url];
  87. },
  88.  
  89. getLayerConfigwithGuid: function (uuid) {
  90. return UtilArray.find(GlobalStorage.config.wmsLayers.concat(GlobalStorage.config.featureLayers),
  91. function (layerConfig) {
  92. return layerConfig.uuid === uuid;
  93. });
  94. },
  95.  
  96. getLayerConfigWithId: function (id) {
  97. return UtilArray.find(GlobalStorage.config.wmsLayers.concat(GlobalStorage.config.featureLayers),
  98. function (layerConfig) {
  99. return layerConfig.id === id;
  100. });
  101. },
  102.  
  103. /**
  104. * Gets the defined symbology from a layer's web service
  105. * @method _getSymbolConfig
  106. * @param {String} layerUrl A URL to the feature layer service
  107. * @param {String} wmsName WMS Layer name. Optional. Should only be provided if attempting to get a WMS layer.
  108. * @returns {esri/layer/symbology} The defined symbology from the layer definition
  109. */
  110. _getSymbolConfig: function (layerUrl, wmsName) {
  111. return this.getLayerConfig(layerUrl, wmsName).symbology;
  112. },
  113.  
  114. /**
  115. * Gets the default symbology icon from a layer's web service
  116. * @method getSymbolForLayer
  117. * @param {Object} layer A feature layer
  118. * @param {String} wmsName WMS Layer name. Optional. Should only be provided if attempting to get a WMS layer.
  119. * @returns {icon} The default icon from the layer's symbology
  120. */
  121. getSymbolForLayer: function (layer, wmsName) {
  122. var symbolConfig = this._getSymbolConfig(layer.url, wmsName);
  123. return symbolConfig.icons["default"];
  124. },
  125.  
  126. /**
  127. * Given a feature object or a graphic object (or any object that has a getLayer method and an
  128. * attributes field) return the object containing the image URL and legend text for that
  129. * feature/graphic object.
  130. *
  131. * @param {Object} feature
  132. * @return {icon} The default icon used to represent the feature layer
  133. * @method getSymbolForFeature
  134. */
  135. getSymbolForFeature: function (feature) {
  136. var layerConfig = this.getLayerConfig(feature.getLayer().url);
  137.  
  138. //as this function is used by templating, we piggyback the logic here
  139. return UtilTmpl.getGraphicIcon(feature, layerConfig);
  140. },
  141. /*
  142. * This method builds a complete service URL callout for a map configuration. The URL is built using a base URL and map ID, and a language culture code.
  143. * @method getServiceURL
  144. * @param {String} rampService The base URL for a web service that provide's valid map JSON configuration data
  145. * @param {Number} mapID a unique identifier for a group of map configuration
  146. * @param {String} language culture code either 'en' or 'fr'
  147. *
  148. */
  149. getServiceURL: function (rampService, mapID, language) {
  150. var serviceURL = rampService + "configservice/map?mapid=" + mapID + "&lang=" + language;
  151. return serviceURL;
  152. }
  153. };
  154. });