Modifying the Zoom To Result in AGO

436
0
03-27-2017 09:08 AM
deleted-user-iwYtitJHBIyn
New Contributor II

Hello,

I posed a question last week concerning the modification of the default AGO zoom in the Search tool.  Specifically, I wanted to know if it was possible to modify the zoom level so that it wasn't so "close" after supplying an address when using the Search tool.  Robert Scheitlin worked feverishly with me on this issue and he was great!  Unfortunately, on my system the code he supplied produced a weird glitch.  Robert tried in vane to reproduce this error on his side to no avail.  I asked Robert if he thought it would be a good idea to repost the question to see if anyone else out there has run into a similar issue and have found a solution...so here I am...again.  The code listed below in bold is what Robert has supplied...which works great but on my system has a "not so good" caveat.  The zoom level is definitely backed off...which is perfect...but if you decide to pan away from the selected parcel and then attempt to use the search tool to go back to the original parcel extent the program cycles and never returns.  At that point you must go all the way out and initialize the search tool again from the default extent.  When you do return to the default extent the parcel is actually still highlighted.  Can anyone offer some assistance?

Thank you.

Jeff

 _onSelectResult: function(e) {
        var result = e.result;
        if (!(result && result.name)) {
          return;
        }
        var dataSourceIndex = e.sourceIndex;
        var sourceResults = this.searchResults[dataSourceIndex];
        var dataIndex = 0;
        var that = this;

        var getGraphics = function(layer, fid) {
          var graphics = layer.graphics;
          var gs = array.filter(graphics, function(g) {
            return g.attributes[layer.objectIdField] === fid;
          });
          return gs;
        };
        var showPopupByFeatures = function(features) {
          var location = null;
          that.map.infoWindow.setFeatures(features);
          if (features[0].geometry.type === "point") {
            location = features[0].geometry;
          } else {
            location = features[0].geometry.getExtent().getCenter();
          }
          that.map.infoWindow.show(location, {
            closetFirst: true
          });
        };

        for (var i = 0, len = sourceResults.length; i < len; i++) {
          if (jimuUtils.isEqual(sourceResults, result)) {
            dataIndex = i;
            break;
          }
        }
        query('li', this.searchResultsNode)
          .forEach(lang.hitch(this, function(li) {
            html.removeClass(li, 'result-item-selected');
            var title = html.getAttr(li, 'title');
            var dIdx = html.getAttr(li, 'data-index');
            var dsIndex = html.getAttr(li, 'data-source-index');

            if (title === result.name &&
              dIdx === dataIndex.toString() &&
              dsIndex === dataSourceIndex.toString()) {
              html.addClass(li, 'result-item-selected');
            }
          }));
  
  var pt = result.feature.geometry.getCentroid();
        if(this.map.getLevel() !== 5){
          this.map.centerAndZoom(pt, 5); //Change this to suit your needs
        }else{
          this.map.centerAt(pt);
        }

        var layer = this.map.getLayer(e.source._featureLayerId);

        if (layer) {
          var gs = getGraphics(layer, e.result.feature.__attributes[layer.objectIdField]);
          if (gs.length > 0) {
            showPopupByFeatures(gs);
          } else {
            var handle = on(layer, 'update-end', lang.hitch(this, function() {
              if (this.domNode) {
                var gs = getGraphics(layer, e.result.feature.__attributes[layer.objectIdField]);
                if (gs.length > 0) {
                  showPopupByFeatures(gs);
                }
              }

              if (handle && handle.remove) {
                handle.remove();
              }
            }));
            this.own(handle);
          }
        }
        // publish select result to other widgets
        this.publishData({
          'selectResult': e
        });
      },

0 Kudos
0 Replies