<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic ArcGIS Maps SDK for JavaScript example: Previous and Next extent buttons (updated for 4.25) in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-maps-sdk-for-javascript-example-previous/m-p/1247844#M79889</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I like to have my Previous extent and Next extent buttons in a web mapping application. Don't you?&lt;/P&gt;&lt;P&gt;&lt;A href="https://twiav.nl/tutorial/arcgis/javascript/arcgis_javascript_example_previous_next_extent_buttons.htm" target="_blank" rel="noopener"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-right" image-alt="ArcGIS Maps SDK for JavaScript example: Previous and Next extent buttons" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60325iDAADC8E665FB4CD4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="arcgis_javascript_example_previous_next_extent_buttons.png" alt="ArcGIS Maps SDK for JavaScript example: Previous and Next extent buttons" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;ArcGIS Maps SDK for JavaScript example: Previous and Next extent buttons&lt;/span&gt;&lt;/span&gt;&lt;/A&gt;But as far as I know the (new) ArcGIS Maps SDK for JavaScript does not have a default widget for that. Is that correct?&lt;/P&gt;&lt;P&gt;So, I have created an example with my own Previous and Next Buttons - see sample code below or click on the map to get to a working application.&lt;/P&gt;&lt;P&gt;True, my version of these buttons owes a lot to work done by &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1104"&gt;@RobertScheitlin__GISP&lt;/a&gt; (see his app with a navigation toolbar &lt;A href="https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/does-the-class-quot-esri-toolbars-navigation-quot/m-p/567061" target="_self"&gt;in this post&lt;/A&gt;.)&lt;/P&gt;&lt;P&gt;I have updated the code for the two buttons to 4.25, removing dojo and replacing watchUtils with reactiveUtils.&lt;/P&gt;&lt;P&gt;And I managed to group the two buttons together (like the zoom in and zoom out buttons) using esri css classes.&lt;/P&gt;&lt;P&gt;I think it all works, more or less. Can you please test it and tell me what you think?&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Egge-Jan&lt;/P&gt;&lt;P&gt;&lt;A href="https://twiav.nl/tutorial/arcgis/javascript/arcgis_javascript_example_previous_next_extent_buttons.htm" target="_blank" rel="noopener"&gt;TWIAV | ArcGIS JavaScript example - Previous and Next extent buttons&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="utf-8"&amp;gt;
  &amp;lt;meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"&amp;gt;
  &amp;lt;title&amp;gt;TWIAV | ArcGIS JavaScript example - Previous and Next extent buttons&amp;lt;/title&amp;gt;
  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.25/esri/css/main.css"&amp;gt;
  &amp;lt;script src="https://js.arcgis.com/4.25/"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;style&amp;gt;
    html, body {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
      font-family: sans-serif;
    }
    #header {	
    	width: 100%;
        height: 70px;
        background-color: #154273;
        color:#FFFFFF;
        margin: 0;
    }
    #headertext {
        float: left;
        font-size: 35px;
        color: white;
        line-height: 70px;
        padding-left: 15px;
    }
    #viewDiv {
        position: absolute;
        top: 70px;
        bottom: 0;
        right: 0;
        left: 0;
        padding: 0;
        margin: 0;
    }
  &amp;lt;/style&amp;gt;
  &amp;lt;script&amp;gt;
    require([
      "esri/Map",
      "esri/views/MapView",
	  "esri/core/reactiveUtils"
    ], function(Map, MapView, reactiveUtils) {

      var map = new Map({
        basemap: "osm"
      });

      var view = new MapView({
        container: "viewDiv",
        map: map,
        zoom: 10,
        center: [0, 51.5]
      });

      createZoomPrevZoomNextBtns();
      view.ui.add(["zoomPrevNextBtns"], "top-left");

      /*******************************************************************************
       * Start Zoom Previous and Zoom Next buttons
       *******************************************************************************
	   * The solution presented here to add these 2 zoom buttons is based on work by RobertScheitlin__GISP.
	   * See his answer to this question:
	   * https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/does-the-class-quot-esri-toolbars-navigation-quot/m-p/567061
	   * Changes to the original RobertScheitlin__GISP solution: removed dojo and replaced watchUtils with reactiveUtils (to upgrade to 4.25)
       *******************************************************************************/

      _prevExtent = false;
      _preExtent = null;
      _currentExtent = null;
      _extentHistory = [];
      _extentHistoryIndx = 0;
      _nextExtent = false;

      reactiveUtils.when(
        () =&amp;gt; view.stationary === true,
        () =&amp;gt; {
          extentChangeHandler(view.extent);
        }
      );

      function createZoomPrevZoomNextBtns() {
        const zoomPrevNextBtnsDiv = document.createElement('div');
		zoomPrevNextBtnsDiv.innerHTML = `
		  &amp;lt;div id="zoomPrevNextBtns" class="esri-component esri-zoom"&amp;gt;
		    &amp;lt;div id="zoomPrevBtn" class="esri-widget--button esri-widget esri-disabled" role="button"&amp;gt;
              &amp;lt;span title="Previous extent" id="zoomPrev" class="esri-icon esri-icon-left-arrow-circled"&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/div&amp;gt;
		    &amp;lt;div id="zoomNextBtn" class="esri-widget--button esri-widget esri-disabled" role="button"&amp;gt;
              &amp;lt;span title="Next extent" id="zoomNext" class="esri-icon esri-icon-right-arrow-circled"&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/div&amp;gt;
          &amp;lt;/div&amp;gt;`;
        document.body.appendChild(zoomPrevNextBtnsDiv);
      }

      let l_zoomPrevBtn = document.getElementById("zoomPrevBtn");
	  l_zoomPrevBtn.addEventListener("click", zoomPreviousExtent);

      let l_zoomNextBtn = document.getElementById("zoomNextBtn");
	  l_zoomNextBtn.addEventListener("click", zoomNextExtent);
      
      function zoomNextExtent() {
        _nextExtent = true;
        _extentHistoryIndx++;
        if (_extentHistoryIndx &amp;gt; _extentHistory.length - 1) { // this might happen if the user clicks the zoomNext button too often too fast 
          _extentHistoryIndx = _extentHistory.length - 1;
        }
        view.goTo(_extentHistory[_extentHistoryIndx].currentExtent);
      }
		
		function zoomPreviousExtent() {
        if(_extentHistory[_extentHistoryIndx].preExtent){
          _prevExtent = true;
          view.goTo(_extentHistory[_extentHistoryIndx].preExtent);
          _extentHistoryIndx--;
        }
      }

      function extentChangeHandler(evt) {
        if(_prevExtent || _nextExtent){
          _currentExtent = evt;
        }else{
          _preExtent = _currentExtent;
          _currentExtent = evt;
          _extentHistory.push({
            preExtent: _preExtent,
            currentExtent: _currentExtent
          });
          _extentHistoryIndx = _extentHistory.length - 1;
        }
        _prevExtent = _nextExtent = false;
        extentHistoryChange();
      }

      function extentHistoryChange() {
        if(_extentHistory.length === 0 || _extentHistoryIndx === 0 ){
		  l_zoomPrevBtn.classList.add("esri-disabled");
        } else {
		  l_zoomPrevBtn.classList.remove("esri-disabled");
        }
        if(_extentHistory.length === 0 || _extentHistoryIndx === _extentHistory.length - 1){
		  l_zoomNextBtn.classList.add("esri-disabled");
        } else {
		  l_zoomNextBtn.classList.remove("esri-disabled");
        }
      }

      /*******************************************************************************
       * End Zoom Previous and Zoom Next buttons
       *******************************************************************************/
    });
  &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;div id="header"&amp;gt;
      &amp;lt;div id="headertext" class="stretch"&amp;gt;ArcGIS Maps SDK for JavaScript example: Previous and Next extent buttons&amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Jan 2023 21:49:50 GMT</pubDate>
    <dc:creator>Egge-Jan_Pollé</dc:creator>
    <dc:date>2023-01-12T21:49:50Z</dc:date>
    <item>
      <title>ArcGIS Maps SDK for JavaScript example: Previous and Next extent buttons (updated for 4.25)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-maps-sdk-for-javascript-example-previous/m-p/1247844#M79889</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I like to have my Previous extent and Next extent buttons in a web mapping application. Don't you?&lt;/P&gt;&lt;P&gt;&lt;A href="https://twiav.nl/tutorial/arcgis/javascript/arcgis_javascript_example_previous_next_extent_buttons.htm" target="_blank" rel="noopener"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-right" image-alt="ArcGIS Maps SDK for JavaScript example: Previous and Next extent buttons" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60325iDAADC8E665FB4CD4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="arcgis_javascript_example_previous_next_extent_buttons.png" alt="ArcGIS Maps SDK for JavaScript example: Previous and Next extent buttons" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;ArcGIS Maps SDK for JavaScript example: Previous and Next extent buttons&lt;/span&gt;&lt;/span&gt;&lt;/A&gt;But as far as I know the (new) ArcGIS Maps SDK for JavaScript does not have a default widget for that. Is that correct?&lt;/P&gt;&lt;P&gt;So, I have created an example with my own Previous and Next Buttons - see sample code below or click on the map to get to a working application.&lt;/P&gt;&lt;P&gt;True, my version of these buttons owes a lot to work done by &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1104"&gt;@RobertScheitlin__GISP&lt;/a&gt; (see his app with a navigation toolbar &lt;A href="https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/does-the-class-quot-esri-toolbars-navigation-quot/m-p/567061" target="_self"&gt;in this post&lt;/A&gt;.)&lt;/P&gt;&lt;P&gt;I have updated the code for the two buttons to 4.25, removing dojo and replacing watchUtils with reactiveUtils.&lt;/P&gt;&lt;P&gt;And I managed to group the two buttons together (like the zoom in and zoom out buttons) using esri css classes.&lt;/P&gt;&lt;P&gt;I think it all works, more or less. Can you please test it and tell me what you think?&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Egge-Jan&lt;/P&gt;&lt;P&gt;&lt;A href="https://twiav.nl/tutorial/arcgis/javascript/arcgis_javascript_example_previous_next_extent_buttons.htm" target="_blank" rel="noopener"&gt;TWIAV | ArcGIS JavaScript example - Previous and Next extent buttons&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="utf-8"&amp;gt;
  &amp;lt;meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"&amp;gt;
  &amp;lt;title&amp;gt;TWIAV | ArcGIS JavaScript example - Previous and Next extent buttons&amp;lt;/title&amp;gt;
  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.25/esri/css/main.css"&amp;gt;
  &amp;lt;script src="https://js.arcgis.com/4.25/"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;style&amp;gt;
    html, body {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
      font-family: sans-serif;
    }
    #header {	
    	width: 100%;
        height: 70px;
        background-color: #154273;
        color:#FFFFFF;
        margin: 0;
    }
    #headertext {
        float: left;
        font-size: 35px;
        color: white;
        line-height: 70px;
        padding-left: 15px;
    }
    #viewDiv {
        position: absolute;
        top: 70px;
        bottom: 0;
        right: 0;
        left: 0;
        padding: 0;
        margin: 0;
    }
  &amp;lt;/style&amp;gt;
  &amp;lt;script&amp;gt;
    require([
      "esri/Map",
      "esri/views/MapView",
	  "esri/core/reactiveUtils"
    ], function(Map, MapView, reactiveUtils) {

      var map = new Map({
        basemap: "osm"
      });

      var view = new MapView({
        container: "viewDiv",
        map: map,
        zoom: 10,
        center: [0, 51.5]
      });

      createZoomPrevZoomNextBtns();
      view.ui.add(["zoomPrevNextBtns"], "top-left");

      /*******************************************************************************
       * Start Zoom Previous and Zoom Next buttons
       *******************************************************************************
	   * The solution presented here to add these 2 zoom buttons is based on work by RobertScheitlin__GISP.
	   * See his answer to this question:
	   * https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/does-the-class-quot-esri-toolbars-navigation-quot/m-p/567061
	   * Changes to the original RobertScheitlin__GISP solution: removed dojo and replaced watchUtils with reactiveUtils (to upgrade to 4.25)
       *******************************************************************************/

      _prevExtent = false;
      _preExtent = null;
      _currentExtent = null;
      _extentHistory = [];
      _extentHistoryIndx = 0;
      _nextExtent = false;

      reactiveUtils.when(
        () =&amp;gt; view.stationary === true,
        () =&amp;gt; {
          extentChangeHandler(view.extent);
        }
      );

      function createZoomPrevZoomNextBtns() {
        const zoomPrevNextBtnsDiv = document.createElement('div');
		zoomPrevNextBtnsDiv.innerHTML = `
		  &amp;lt;div id="zoomPrevNextBtns" class="esri-component esri-zoom"&amp;gt;
		    &amp;lt;div id="zoomPrevBtn" class="esri-widget--button esri-widget esri-disabled" role="button"&amp;gt;
              &amp;lt;span title="Previous extent" id="zoomPrev" class="esri-icon esri-icon-left-arrow-circled"&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/div&amp;gt;
		    &amp;lt;div id="zoomNextBtn" class="esri-widget--button esri-widget esri-disabled" role="button"&amp;gt;
              &amp;lt;span title="Next extent" id="zoomNext" class="esri-icon esri-icon-right-arrow-circled"&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/div&amp;gt;
          &amp;lt;/div&amp;gt;`;
        document.body.appendChild(zoomPrevNextBtnsDiv);
      }

      let l_zoomPrevBtn = document.getElementById("zoomPrevBtn");
	  l_zoomPrevBtn.addEventListener("click", zoomPreviousExtent);

      let l_zoomNextBtn = document.getElementById("zoomNextBtn");
	  l_zoomNextBtn.addEventListener("click", zoomNextExtent);
      
      function zoomNextExtent() {
        _nextExtent = true;
        _extentHistoryIndx++;
        if (_extentHistoryIndx &amp;gt; _extentHistory.length - 1) { // this might happen if the user clicks the zoomNext button too often too fast 
          _extentHistoryIndx = _extentHistory.length - 1;
        }
        view.goTo(_extentHistory[_extentHistoryIndx].currentExtent);
      }
		
		function zoomPreviousExtent() {
        if(_extentHistory[_extentHistoryIndx].preExtent){
          _prevExtent = true;
          view.goTo(_extentHistory[_extentHistoryIndx].preExtent);
          _extentHistoryIndx--;
        }
      }

      function extentChangeHandler(evt) {
        if(_prevExtent || _nextExtent){
          _currentExtent = evt;
        }else{
          _preExtent = _currentExtent;
          _currentExtent = evt;
          _extentHistory.push({
            preExtent: _preExtent,
            currentExtent: _currentExtent
          });
          _extentHistoryIndx = _extentHistory.length - 1;
        }
        _prevExtent = _nextExtent = false;
        extentHistoryChange();
      }

      function extentHistoryChange() {
        if(_extentHistory.length === 0 || _extentHistoryIndx === 0 ){
		  l_zoomPrevBtn.classList.add("esri-disabled");
        } else {
		  l_zoomPrevBtn.classList.remove("esri-disabled");
        }
        if(_extentHistory.length === 0 || _extentHistoryIndx === _extentHistory.length - 1){
		  l_zoomNextBtn.classList.add("esri-disabled");
        } else {
		  l_zoomNextBtn.classList.remove("esri-disabled");
        }
      }

      /*******************************************************************************
       * End Zoom Previous and Zoom Next buttons
       *******************************************************************************/
    });
  &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;div id="header"&amp;gt;
      &amp;lt;div id="headertext" class="stretch"&amp;gt;ArcGIS Maps SDK for JavaScript example: Previous and Next extent buttons&amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 21:49:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-maps-sdk-for-javascript-example-previous/m-p/1247844#M79889</guid>
      <dc:creator>Egge-Jan_Pollé</dc:creator>
      <dc:date>2023-01-12T21:49:50Z</dc:date>
    </item>
  </channel>
</rss>

