Reusable Accessible Mapping Platform

API Docs for: 3.0.0
Show:

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

  1. /* global define, $ */
  2.  
  3. /**
  4. * Navigation submodule
  5. *
  6. * @module RAMP
  7. * @submodule Navigation
  8. * @main Navigation
  9. */
  10.  
  11. /**
  12. * Navigation class.
  13. *
  14. * This module provide function to initialize navigation widget using settings stored in
  15. * global configuration object.
  16. *
  17. * NOTE: jquery.ui.navigation.js is required to create the object
  18. *
  19. * @class Navigation
  20. * @static
  21. * @uses dojo/_base/declare
  22. * @uses dojo/topic
  23. * @uses GlobalStorage
  24. * @uses EventManager
  25. */
  26.  
  27. define([
  28. //Dojo
  29. "dojo/_base/declare", "dojo/topic",
  30.  
  31. //RAMP
  32. "ramp/globalStorage", "ramp/eventManager"
  33. ],
  34.  
  35. function (
  36. // Dojo
  37. declare, topic,
  38. // RAMP
  39. GlobalStorage, EventManager) {
  40. "use strict";
  41. var nav;
  42.  
  43. /**
  44. * Listen to internal events and republish for other modules' benefit
  45. *
  46. * @method initTopics
  47. * @private
  48. */
  49. function initTopics() {
  50. nav
  51. .on("navigation:panClick", function (e, direction) {
  52. topic.publish(EventManager.Navigation.PAN, {
  53. direction: direction
  54. });
  55. })
  56. .on("navigation:zoomClick", function (e, in_out) {
  57. var newLvl = (in_out === "zoomIn") ? 1 : -1;
  58. topic.publish(EventManager.Navigation.ZOOM_STEP, {
  59. level: newLvl
  60. });
  61. })
  62. .on("navigation:zoomSliderChange", function (e, newVal) {
  63. topic.publish(EventManager.Navigation.ZOOM, {
  64. level: newVal
  65. });
  66. })
  67. .on("navigation:fullExtentClick", function () {
  68. topic.publish(EventManager.Navigation.FULL_EXTENT);
  69. });
  70. }
  71.  
  72. /**
  73. * Listen to map evens and adjust the navigation widget accordingly
  74. *
  75. * @method initListeners
  76. * @private
  77. */
  78. function initListeners() {
  79. function toggleTransition(inTransition) {
  80. nav.navigation("toggleTransition", inTransition);
  81. }
  82.  
  83. topic.subscribe(EventManager.Map.EXTENT_CHANGE, function (event) {
  84. nav.navigation("setSliderVal", event.lod.level);
  85. });
  86.  
  87. /* Keep track of when the map is in transition, the slider will throw
  88. errors if the value is changed during a map transition. */
  89. // explicitly set inTransition true on zoom and pan start
  90. topic.subscribe(EventManager.Map.ZOOM_START, function () { toggleTransition(true); });
  91. topic.subscribe(EventManager.Map.PAN_START, function () { toggleTransition(true); });
  92.  
  93. //topic.subscribe(EventManager.Map.PAN_END, toggleTransition);
  94. //topic.subscribe(EventManager.Map.ZOOM_END, toggleTransition);
  95.  
  96. // only set inTransition false on extent change
  97. topic.subscribe(EventManager.Map.EXTENT_CHANGE, function () { toggleTransition(false); });
  98. }
  99.  
  100. return {
  101. /**
  102. * Initialize navigation widget for pan and zooming using global configuration object
  103. *
  104. * @method init
  105. * @param {Number} currentLevel
  106. */
  107. init: function (currentLevel) {
  108.  
  109. // NOTE: JKW Document the change. Refactor,
  110. nav.navigation("setSliderVal", currentLevel);
  111. initTopics();
  112. initListeners();
  113. },
  114.  
  115. construct: function () {
  116. // Note: JKW added currentlevel
  117. //GlobalStorage.config.navWidget.sliderVal = currentLevel; // reference to line 134 of jquery.ui.navigations.js
  118.  
  119. nav = $("#" + GlobalStorage.config.divNames.navigation).navigation(GlobalStorage.config.navWidget);
  120. }
  121. };
  122. });