Reusable Accessible Mapping Platform

API Docs for: 5.0.0
Show:

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

  1. /*global define, $, console, RAMP */
  2.  
  3. //the "use strict" forces the ECMA Script 5 interpretation of the code
  4.  
  5. /**
  6. *
  7. *
  8. * @module RAMP
  9. * @submodule GlobalStorage
  10. *
  11. */
  12.  
  13. /**
  14. * GlobalStorage class is used to store variables and exchange them between different modules. Each module has the ability to add variables to the global storage and retrieve them as needed.
  15. *
  16. * @class GlobalStorage
  17. */
  18.  
  19. define(["dojo/_base/array", "utils/util"],
  20. function (dojoArray, util) {
  21. "use strict";
  22.  
  23. var featureLayerDefaults = {
  24. layerAttributes: '*',
  25. minScale: 0,
  26. maxScale: 0,
  27. settings: { panelEnabled: true, opacity: { enabled: true, default: 1 }, visible: true, boundingBoxVisible: false },
  28. datagrid: { rowsPerPage: 50 },
  29. templates: { detail: 'default_feature_details', hover: 'feature_hover_maptip_template', anchor: 'anchored_map_tip', summary: 'default_grid_summary_row' }
  30. },
  31.  
  32. wmsLayerDefaults = {
  33. settings: { panelEnabled: true, opacity: { enabled: true, default: 1 }, visible: true, boundingBoxVisible: true }
  34. },
  35.  
  36. gridColumnDefaults = { orderable: true, type: "string", alignment: 1 },
  37.  
  38. basemapDefaults = { scaleCssClass: "map-scale-dark", type: "Topographic" },
  39.  
  40. configDefaults = {
  41. initialBasemapIndex: 0,
  42. extendedDatagridExtentFilterEnabled: false,
  43. rowsPerPage: 50,
  44. navWidget: { sliderMinVal: 3, sliderMaxVal: 15, debug: false, animate: "fast", cssPath: "ramp-theme/navigation", skin: "white" },
  45. zoomLevels: { min: 1, max: 17 },
  46. templates: { basemap: "default_basemap", globalSelectorToggles: "default_selector_toggles" },
  47. layers: { feature: [], wms: [] },
  48. divNames: { map: "mainMap", navigation: "map-navigation", filter: "searchMapSectionBody", datagrid: "gridpane" },
  49. advancedToolbar: { enabled: false, tools: [] },
  50. mapInitFailUrl: "./error-en.html"
  51. },
  52.  
  53. defaultRenderers = {
  54. circlePoint: {
  55. geometryType: "esriGeometryPoint",
  56. renderer: {
  57. type: "simple",
  58. symbol: {
  59. type: "esriSMS",
  60. style: "esriSMSCircle",
  61. color: [67, 100, 255, 200],
  62. size: 7
  63. }
  64. }
  65. },
  66. solidLine: {
  67. geometryType: "esriGeometryPolyline",
  68. renderer: {
  69. type: "simple",
  70. symbol: {
  71. type: "esriSLS",
  72. style: "esriSLSSolid",
  73. color: [90, 90, 90, 200],
  74. width: 2
  75. }
  76. }
  77. },
  78. outlinedPoly: {
  79. geometryType: "esriGeometryPolygon",
  80. renderer: {
  81. type: "simple",
  82. symbol: {
  83. type: "esriSFS",
  84. style: "esriSFSSolid",
  85. color: [76, 76, 125, 200],
  86. outline: {
  87. type: "esriSLS",
  88. style: "esriSLSSolid",
  89. color: [110, 110, 110, 255],
  90. width: 1
  91. }
  92. }
  93. }
  94. }
  95. };
  96.  
  97. function applyDefaults(defaults, srcObj) {
  98. var defaultClone = $.extend(true, {}, defaults);
  99. return util.mergeRecursive(defaultClone, srcObj);
  100. }
  101.  
  102. function defineProjections(proj4) {
  103. // wgs84 and aux mercator are built in, add Canada Lambert and Canada Atlas Lambert
  104. proj4.defs("EPSG:3978", "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=49 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");
  105. proj4.defs("EPSG:3979", "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=49 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");
  106. proj4.defs("EPSG:102100", proj4.defs('EPSG:3857'));
  107. proj4.defs("EPSG:54004", "+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs");
  108. }
  109.  
  110. function applyConfigDefaults(configObj) {
  111. var result;
  112. console.log(configObj);
  113. result = applyDefaults(configDefaults, configObj);
  114. result.layers.wms = dojoArray.map(result.layers.wms, function (wms) {
  115. return applyDefaults(wmsLayerDefaults, wms);
  116. });
  117. result.basemaps = dojoArray.map(result.basemaps, function (b) {
  118. return applyDefaults(basemapDefaults, b);
  119. });
  120. result.layers.feature = dojoArray.map(result.layers.feature, applyFeatureDefaults);
  121. console.log(result);
  122. return result;
  123. }
  124.  
  125. function applyFeatureDefaults(featureLayer) {
  126. var layer = applyDefaults(featureLayerDefaults, featureLayer);
  127. layer.datagrid.gridColumns = dojoArray.map(layer.datagrid.gridColumns, function (gc) {
  128. return applyDefaults(gridColumnDefaults, gc);
  129. });
  130. return layer;
  131. }
  132.  
  133. function applyWMSDefaults(wmsLayer) {
  134. var layer = applyDefaults(wmsLayerDefaults, wmsLayer);
  135.  
  136. return layer;
  137. }
  138.  
  139. return {
  140. init: function (configObj) {
  141. var config = applyConfigDefaults(configObj);
  142. RAMP.config = config;
  143.  
  144. this.layerSelectorGroups = [
  145. this.layerType.wms,
  146. this.layerType.feature
  147. ];
  148. },
  149.  
  150. defineProjections: defineProjections,
  151. DefaultRenderers: defaultRenderers,
  152. applyFeatureDefaults: applyFeatureDefaults,
  153. applyWMSDefaults: applyWMSDefaults,
  154.  
  155. layerType: {
  156. Basemap: "basemap",
  157. wms: "wms_layer",
  158. BoundingBox: "bounding_box",
  159. feature: "feature_layer",
  160. Static: "static_layer",
  161. Highlight: "highlight_layer",
  162. Hoverlight: "hoverlight_layer",
  163. Zoomlight: "zoomlight_layer"
  164. },
  165.  
  166. // specifies knows layer groups in the reversed order;
  167. layerSelectorGroups: [
  168. ]
  169. };
  170. });