Reusable Accessible Mapping Platform

API Docs for: 3.0.0
Show:

File: src\js\RAMP\bootstrapper.js

  1. /*global require, window, esri, dojoConfig, i18n, document, $, console */
  2.  
  3. /**
  4. * Ramp module
  5. *
  6. * @module RAMP
  7. * @main RAMP
  8. */
  9.  
  10. /**
  11. * Bootstrapper class.
  12. * Starting point of RAMP, RAMP modules are loaded here and mapped to a function parameter
  13. * Phase X?: For mobile support, there can be a different mobileBootstrapper with only the mobile modules loaded
  14. *
  15. * @class Bootstrapper
  16. * @static
  17. *
  18. * @uses dojo/parser
  19. * @uses dojo/on
  20. * @uses dojo/topic
  21. * @uses dojo/request/script
  22. * @uses dojo/request/xhr
  23. *
  24. * @uses Map
  25. * @uses Basemapselector
  26. * @uses Maptips
  27. * @uses Datagrid
  28. * @uses Navigation
  29. * @uses FilterManager
  30. * @uses BookmarkLink
  31. * @uses Url
  32. * @uses FeatureHighlighter
  33. * @uses Ramp
  34. * @uses GlobalStorage
  35. * @uses GUI
  36. * @uses EventManager
  37. * @uses AdvancedToolbar
  38. * @uses Util
  39. * @uses Prototype
  40. * @uses FunctionMangler
  41. */
  42.  
  43. require([
  44. /* Dojo */
  45. "dojo/parser", "dojo/on", "dojo/topic",
  46. "dojo/request/script",
  47. "dojo/request/xhr", "dojo/_base/array",
  48.  
  49. /* RAMP */
  50. "ramp/map", "ramp/basemapSelector", "ramp/maptips", "ramp/datagrid",
  51. "ramp/navigation", "ramp/filterManager", "ramp/bookmarkLink",
  52. "utils/url", "ramp/featureHighlighter",
  53. "ramp/ramp", "ramp/globalStorage", "ramp/gui", "ramp/eventManager",
  54. "ramp/advancedToolbar",
  55. "ramp/theme",
  56.  
  57. /* Utils */
  58. "utils/util",
  59.  
  60. /* Plugins */
  61. "utils/prototype!", "utils/functionMangler!"],
  62.  
  63. //"dojo/domReady!"],
  64.  
  65. function (
  66. /* Dojo */
  67. parser, dojoOn, topic, requestScript, xhr, dojoArray,
  68.  
  69. /* RAMP */
  70. RampMap, BasemapSelector, Maptips, Datagrid, NavWidget, FilterManager,
  71. BookmarkLink, Url, FeatureHighlighter,
  72. Ramp, globalStorage, gui, EventManager, AdvancedToolbar, theme,
  73.  
  74. /* Utils */
  75. UtilMisc
  76. ) {
  77. "use strict";
  78.  
  79. /**
  80. * loadPlugin takes a plugin file and loads it into the DOM.
  81. * Creates a dynamic script tag to load the script at runtime.
  82. *
  83. * @method loadPlugin
  84. * @private
  85. * @param {String} pluginName, the file name of the plugin to be loaded (should be in the plugins folder)
  86. */
  87. function loadPlugin(pluginName) {
  88. var head = document.getElementsByTagName('head')[0],
  89. script = document.createElement('script');
  90. script.type = 'text/javascript';
  91. script.src = dojoConfig.fullPluginPath + pluginName;
  92. console.log('loading plugin: ' + script.src);
  93. head.appendChild(script);
  94. }
  95.  
  96. function initializeMap() {
  97. /* Start - RAMP Events, after map is loaded */
  98.  
  99. topic.subscribe(EventManager.Map.ALL_LAYERS_LOADED, function () {
  100. console.log("map - >> first update-end; init the rest");
  101.  
  102. // Only initialize the bookmark link after all the UI events of all other modules have
  103. // finished loading
  104. // IMPORTANT: for now, only basemapselector and filtermanager have a UI complete event
  105. // but in the future, if other modules start publishing their own UI complete events, it needs
  106. // to be subscribe to here so BookmarkLink will not attempt to call the module before its GUI
  107. // has finished rendering
  108. UtilMisc.subscribeAll(
  109. [
  110. EventManager.BasemapSelector.UI_COMPLETE,
  111. EventManager.FilterManager.UI_COMPLETE
  112. ], function () {
  113. BookmarkLink.subscribeAndUpdate();
  114. });
  115. // Added current level so slider will know how to adjust the position
  116. var currentLevel = (RampMap.getMap().__LOD.level) ? RampMap.getMap().__LOD.level : 0;
  117.  
  118. NavWidget.init(currentLevel);
  119. FeatureHighlighter.init();
  120.  
  121. Maptips.init();
  122.  
  123. //Apply listeners for basemap gallery
  124. BasemapSelector.init();
  125.  
  126. //initialize the filter
  127. FilterManager.init();
  128.  
  129. // Initialize the advanced toolbar and tools.
  130. if (globalStorage.config.advancedToolbar.enabled) {
  131. AdvancedToolbar.init();
  132. }
  133.  
  134. Datagrid.init();
  135.  
  136. theme.tooltipster();
  137. });
  138. RampMap.init();
  139. NavWidget.construct();
  140.  
  141. // a workaround for bug#3460; ideally each module's ui component would call tooltipster on its own; probably a good idea would to implement this when working on mobile view
  142. theme.tooltipster();
  143.  
  144. /* End - RAMP Events */
  145. }
  146. /* End - Bootstrapper functions */
  147.  
  148. // Check to make sure the console exists, redefines it to the no-op function
  149. // if it does not (e.g. in IE when the debugger is not on)
  150. UtilMisc.checkConsole();
  151.  
  152. // Once all of our modules are loaded and the DOM is ready:
  153.  
  154. // call the parser to create the dijit layout dijits
  155. parser.parse();
  156.  
  157. //turn off cors detection to stop cross domain error from happening.
  158. esri.config.defaults.io.corsDetection = false;
  159.  
  160. //To hold values from RAMP service
  161.  
  162. var lang = $("html").attr("lang"),
  163. configFile,
  164. defJson;
  165.  
  166. if (lang !== "en" && lang !== "fr") {
  167. lang = "en";
  168. }
  169.  
  170. i18n.init(
  171. {
  172. lng: lang + "-CA",
  173. load: "current",
  174. fallbackLng: false
  175. });
  176.  
  177. //loading config object from JSON file
  178. configFile = (lang === "fr") ? "config.fr.json" : "config.en.json";
  179.  
  180. // Request the JSON config file
  181. defJson = xhr(configFile, {
  182. handleAs: "json"
  183. });
  184.  
  185. defJson.then(
  186. function (fileContent) {
  187. var pluginConfig,
  188. advancedToolbarToggle = $("li.map-toolbar-item #advanced-toggle").parent();
  189. //there is no need to convert the result to an object. it comes through pre-parsed
  190.  
  191. console.log("Bootstrapper: config loaded");
  192.  
  193. globalStorage.config = fileContent;
  194.  
  195. // Show or remove advanced toolbar toggle based on the config value
  196. if (globalStorage.config.advancedToolbar.enabled) {
  197. advancedToolbarToggle.removeClass("wb-invisible");
  198. } else {
  199. advancedToolbarToggle.remove();
  200. }
  201.  
  202. pluginConfig = globalStorage.config.plugins;
  203. if (pluginConfig) {
  204. dojoArray.map(pluginConfig, function (pName) {
  205. loadPlugin(pName);
  206. });
  207. }
  208. // Modify the config based on the url
  209. // needs to do this before the gui loads because the gui module
  210. // also reads from the config
  211. BookmarkLink.updateConfig(window.location.pathname.split("/").last());
  212.  
  213. // Initialize the map only after the gui loads
  214. // if we do it beforehand, the map extent may get messed up since
  215. // the available screen size may still be changing (e.g. due to fullscreen
  216. // or subpanel closing)
  217. topic.subscribe(EventManager.GUI.UPDATE_COMPLETE, function () {
  218. initializeMap();
  219. });
  220.  
  221. gui.load(null, null, function () { });
  222.  
  223. // Create the panel that the bookmark link sits in
  224. // can only do this after the gui loads
  225. BookmarkLink.createUI();
  226.  
  227. Ramp.loadStrings();
  228. },
  229. function (error) {
  230. console.log("An error occurred when retrieving the JSON Config: " + error);
  231. }
  232. );
  233. });