NavToobar Deactivate in WAB question

4056
16
Jump to solution
11-12-2015 09:47 AM
StephenSchmidt2
New Contributor II

Hi All!

I have a quick question about deactivating the navtoolbar (navToolbar.deactivate();) on a panel close in webapp builder. I can seem to tweak the attached widget to work.  The functionality is all there, but it stays live when I exit out of the widget.  I've looked at how the draw widget deactivates with no luck.  Any suggestions would be greatly appreacited!!

Best as always,

Stephen

0 Kudos
16 Replies
StephenSchmidt2
New Contributor II

Thank you!  Got it, match in order of listing!  Now I remember that rule from the pre-webapp builder use of ArcGIS JavaScript API.  I should have known that! 

I'll take a shot at navToolbar.deactivate() onClose next.

Thank you!

Stephen

0 Kudos
StephenSchmidt2
New Contributor II

Hi Robert!

I'm 99 percent of the way there with the Navigation widget.  It now deactivates onclose, and I added in the remaining navigation functions.  The last thing I'm trying to accomplish is to have the buttons change color when selected.  I figured that jQuery was the best approach.  What I have below works in JSFiddle, but not in WAB Developer.  If you have a second, do you see what I'm missing or doing wrong?  Also, once this is done, I'd like to post this widget to the custom widget resource section of GeoNet if that's OK.  Thanks again!!!

JS:

define([

  'dojo/_base/declare',

  'dojo/_base/lang',

  'jimu/BaseWidget',

  'dojo/on',

  'esri/toolbars/navigation',

  'jimu/loaderplugins/jquery-loader!https://code.jquery.com/jquery-git1.min.js'

],

function(declare, lang, BaseWidget, on, Navigation, $) {

    var clazz = declare([BaseWidget], {

  name: 'Navigation',

  baseClass: 'widget-Navigation',

  navToolbar: null,

  startup: function() {

  this.navToolbar = new Navigation(this.map);

  this.own(on(this.zoomIn, 'click', lang.hitch(this, function() {

  this.navToolbar.activate(Navigation.ZOOM_IN);

  })));

  this.own(on(this.zoomOut, 'click', lang.hitch(this, function() {

  this.navToolbar.activate(Navigation.ZOOM_OUT);

  })));

  this.own(on(this.zoomPrevious, 'click', lang.hitch(this, function() {

  this.navToolbar.zoomToPrevExtent();

  })));

  this.own(on(this.zoomNext, 'click', lang.hitch(this, function() {

  this.navToolbar.zoomToNextExtent();

  })));

  $('.main .btn').click(function (evt) {

  $('.selected').not(this).removeClass('selected');

  $(this).toggleClass('selected');

  });

  $(document).click(function () {

  $('.main .btn').removeClass('selected');

  });

  },

      onClose: function() {

   this.navToolbar.deactivate(); 

      }

  });

  return clazz;

});

HTML:

<div class='main'>           

     <label><b>${nls.selectNavigation}</b></label>

     <br/><br/>

     <div data-dojo-attach-point="zoomIn" class='btn'>

     <img src='widgets/sNavigation/images/zoom-in.png' style='width:35px; height:35px;      margin:5px;'>     </img>

     </div>

     <br/>

     <div data-dojo-attach-point="zoomOut" class='btn'>

     <img src='widgets/sNavigation/images/zoom-out.png' style='width:35px; height:35px;      margin:5px;'>     </img>

     </div>

     <br/>

     <div data-dojo-attach-point="zoomPrevious" class='btn'>

     <img src='widgets/sNavigation/images/zoom-previous.png' style='width:35px; height:35px;      margin:5px;'>    </img>

     </div>

     <br/>

     <div data-dojo-attach-point="zoomNext" class='btn'>

     <img src='widgets/sNavigation/images/zoom-next.png' style='width:35px; height:35px;      margin:5px;'>     </img>

     </div>

</div>

CSS:

.widget-Navigation .selected {

  color: rgba(255, 255, 255);

  background-color: #999;

  background-color: rgba(0, 0, 0, 0.4);

  width: 45px;

  height: 45px;

}

.widget-Navigation {

  font-size:medium;

}

.widget-Navigation .btn{

  background-color: #ccc;

  background-color: rgba(0, 0, 0, 0.2);

  border: 1px solid #000000;

  border: 1px solid rgba(0, 0, 0, 0.4);

  width: 45px;

  height: 45px;

}

.widget-Navigation .btn:hover{

  color: rgba(255, 255, 255);

  background-color: #999;

  background-color: rgba(0, 0, 0, 0.4);

  width: 45px;

  height: 45px;

}

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Stephen,

  I don't like using a third party library when you already have dojo that can do the style and class stuff. I will update the code to show you how to do it with dojo.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Stephen,

  Here is the widget using pure dojo. I don't think you should have a select state on the previous and next buttons as they are only monetary buttons not toggles like the zoom-in and out, so that is how my code works.

StephenSchmidt2
New Contributor II

Wow!  Thanks Robert!!  I was able to get a jquery version working as well, but it's really messy!  Your version is much more straight forward.

I really appreciate your help!  I learned a bunch about the internal workings of WAB.

Thanks again!!!

Stephen

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Stephen,

   You have marked this as "Assumed Answered". What "Assumed Answered" is for is when you have answered your own question or just feel that one particular reply is appropriate to mark as the answer to your question.

You should mark one of the many replies as the correct answer. To do this you have to open the thread (you can not see the correct answer link from inside your inbox) and then you will see the green star with correct answer link on each reply in the thread. Just click that link on the thread that best answered your question.

StephenSchmidt2
New Contributor II

Here's some small tweaks, but still not there.

0 Kudos