Remove "segment-select" event in Directions dijit js api

466
3
Jump to solution
12-19-2017 01:37 AM
AlbertoLópez
New Contributor III

Hello;

 

I have to insert some td html elements in the results table of the Directions dijit (version 3.22) and I need to remove  the "segment-select" event of  the Direction dijit.

What I want is that when I click on any of the segments of the direction table results, the map view does not move to the selected segment in the map

 

I have tried to do this in the direction finish event  function and in the startup function of the widget  but without results.

 

1-

var buttonHandler = on.pausable(this._dijitDirections, "segment-select");

buttonHandler.pause();

2-

var buttonHandler = on(this._dijitDirections,'segment-select', lang.hitch(this, function (evt) {

}));

buttonHandler.remove();

3-

    var buttonHandler = on(this._dijitDirections,'segment-select', lang.hitch(this, function (evt) {
            buttonHandler.remove();
            }));
            

4-

this.own(on(this._dijitDirections, 'segment-select', lang.hitch(this, function (event) {

event.stopPropagation();//and event.target.stopPropagation()

})));

Any suggestions?

Best Regard.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Alberto,

  OK that is quite a bit more complicated. You have to override the Directions dijits centerAtSegmentStart function:

Add the new require to your require array:

require([
...
  "dojo/Deferred",
...
], function(
...
  Deferred,
...
) {

set the dijits centerAtSegmentStart override function:

directions.startup();
directions.centerAtSegmentStart = _centerAtSegmentStart;

Here is the override function:

        function _centerAtSegmentStart(a) {
          var b, d = new Deferred;
          if (directions.directions && directions.directions.features) {
              b = Math.max(0, Math.min(directions.directions.features.length - 1, a || 0));
              var e = directions.directions.features[b];
              directions.highlightSegment(b, !0);
              directions._showSegmentPopup(e, b);
              d.resolve()
          } else
              d.reject(Error("No directions."));
          return d.promise
        }

View solution in original post

3 Replies
RobertScheitlin__GISP
MVP Emeritus

Alberto,

   You can remove the listeners this way:

        directions.on('directions-finish', function(){
          query('.esriRoute', this._dijitDirections.domNode).forEach(function(item){
            item.outerHTML = item.outerHTML;
          });
        });
AlbertoLópez
New Contributor III

Thank you very much Robert.

Your code works fine , but in addition to remove  the segment-select event, it also removes the segment-highlight event (Fired when you hover over a route segment in the directions display.). I need to remove only the segment-select event but not the segment-highlight .

It's possible?.

Regards.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Alberto,

  OK that is quite a bit more complicated. You have to override the Directions dijits centerAtSegmentStart function:

Add the new require to your require array:

require([
...
  "dojo/Deferred",
...
], function(
...
  Deferred,
...
) {

set the dijits centerAtSegmentStart override function:

directions.startup();
directions.centerAtSegmentStart = _centerAtSegmentStart;

Here is the override function:

        function _centerAtSegmentStart(a) {
          var b, d = new Deferred;
          if (directions.directions && directions.directions.features) {
              b = Math.max(0, Math.min(directions.directions.features.length - 1, a || 0));
              var e = directions.directions.features[b];
              directions.highlightSegment(b, !0);
              directions._showSegmentPopup(e, b);
              d.resolve()
          } else
              d.reject(Error("No directions."));
          return d.promise
        }