Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Previous/Next Extent</title>
  5. <meta charset="utf-8">
  6. <link rel="stylesheet" href="//js.arcgis.com/3.21/esri/css/esri.css">
  7. <style>
  8. html, body {
  9. margin: 0; padding: 0;
  10. width: 100%; height: 100%;
  11. }
  12.  
  13. #map {
  14. width: 100%; height: 100%;
  15. }
  16.  
  17. #map .buttons {
  18. position: absolute;
  19. top: 1rem;
  20. right: 1rem;
  21. z-index: 999;
  22. }
  23.  
  24. #map .buttons button {
  25. padding: 0.5rem;
  26. border-radius: 0.25rem;
  27. background: white;
  28. border: 1px solid #333;
  29. color: #333;
  30. font-size: 0.8rem;
  31. transition: all 0.6s ease-out;
  32. cursor: pointer;
  33. }
  34.  
  35. #map .buttons button:hover {
  36. background: #333;
  37. color: white;
  38. }
  39.  
  40. #map .buttons button[disabled],
  41. #map .buttons button[disabled]:hover {
  42. background: white;
  43. border: 1px solid #aaa;
  44. color: #aaa;
  45. cursor: not-allowed;
  46. }
  47. </style>
  48. </head>
  49. <body>
  50. <div id="map">
  51. <div class="buttons">
  52. <button id="previousButton" disabled>Previous</button>
  53. <button id="nextButton" disabled>Next</button>
  54. </div>
  55. </div>
  56. <script data-dojo-config="async: true" src="//js.arcgis.com/3.21/init.js"></script>
  57. <script>
  58. require([
  59. 'dojo/_base/declare',
  60. 'dojo/_base/lang',
  61. 'dojo/dom',
  62. 'dojo/dom-attr',
  63. 'dojo/on',
  64. 'esri/map',
  65. 'dojo/domReady!'
  66. ], function (
  67. declare,
  68. lang,
  69. dom,
  70. domAttr,
  71. on,
  72. Map
  73. ) {
  74.  
  75. var PreviousNextExtentManager = declare(null, {
  76.  
  77. _map: null,
  78. _cachedExtent: null,
  79. _previous: null,
  80. _next: null,
  81. _ignoreNext: null,
  82.  
  83. constructor: function(map) {
  84. this._map = map;
  85. this._cachedExtent = map.extent;
  86. this._previous = [];
  87. this._next = [];
  88. this._ignoreNext = false;
  89. this._attachEvents();
  90. },
  91.  
  92. _attachEvents: function() {
  93. this._map.on('extent-change', lang.hitch(this, this._onExtentChange));
  94. },
  95.  
  96. _onExtentChange: function(event) {
  97. if (this._ignoreNext) {
  98. this._ignoreNext = false;
  99. this._cachedExtent = event.extent;
  100. return;
  101. }
  102. this._previous.push(this._cachedExtent);
  103. this._cachedExtent = event.extent;
  104. this._next = [];
  105. },
  106.  
  107. clear: function() {
  108. this._previous = [];
  109. this._next = [];
  110. },
  111.  
  112. canMovePrevious: function() { return !!this._previous.length; },
  113. canMoveNext: function() { return !!this._next.length; },
  114.  
  115. movePrevious: function() {
  116. if (!this.canMovePrevious()) {
  117. return;
  118. }
  119. this._next.push(this._map.extent);
  120. this._ignoreNext = true;
  121. this._map.setExtent(this._previous.pop());
  122. },
  123.  
  124. moveNext: function() {
  125. if (!this.canMoveNext()) {
  126. return;
  127. }
  128. this._previous.push(this._map.extent);
  129. this._ignoreNext = true;
  130. this._map.setExtent(this._next.pop());
  131. }
  132.  
  133. });
  134.  
  135. var map = new Map('map', {
  136. basemap: 'gray',
  137. center: [-77.425461, 39.412327],
  138. zoom: 13
  139. });
  140.  
  141.  
  142.  
  143. map.on('load', function() {
  144. var previousNextMgr = new PreviousNextExtentManager(map);
  145.  
  146. var previousButton = dom.byId('previousButton');
  147. on(previousButton, 'click', function() {
  148. previousNextMgr.movePrevious()
  149. });
  150.  
  151. var nextButton = dom.byId('nextButton');
  152. on(nextButton, 'click', function() {
  153. previousNextMgr.moveNext()
  154. });
  155.  
  156. map.on('extent-change', function() {
  157. if (previousNextMgr.canMovePrevious()) {
  158. domAttr.remove('previousButton', 'disabled');
  159. } else {
  160. domAttr.set('previousButton', 'disabled', 'disabled');
  161. }
  162. if (previousNextMgr.canMoveNext()) {
  163. domAttr.remove('nextButton', 'disabled');
  164. } else {
  165. domAttr.set('nextButton', 'disabled', 'disabled');
  166. }
  167. });
  168. });
  169.  
  170. });
  171. </script>
  172. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement