Zoom to Feature from grid button

788
1
Jump to solution
08-29-2013 11:34 AM
KennethRichards
New Contributor III
I'm trying to zoom to the feature on my map when the user selects a button built into my grid. I have experimented with a couple of different functions to accomplish this.

This makes a button in my grid.
function makeZoomButton(id){//id is objectid         var zBtn = "<div data-dojo-type='dijit.form.Button'><img src='photos/bg_magnify.png'";         zBtn = zBtn + " width='18' height='18'";         zBtn = zBtn + " onClick=\"zoomRow('"+id+"')\"></div>"; //activates zoomRow function         return zBtn;       }


These are two different functions that have tried calling when the button is clicked.

function zoomRow(id){         var grid = dijit.byId('grid');         var clickedWell = grid.getItem(id);         var selectedWell;           dojo.forEach(map.graphics.graphics,function(graphic){           if((graphic.attributes) && graphic.attributes.BUILDING === clickedWell){             selectedWell = graphic;             return;           }         });         var wellExtent = selectedWell.geometry.getExtent();         map.setExtent(wellExtent);         selectionLayer.clear();        // var wellExtent = featureLayer[0].geometry.getExtent().expand(5.0);         //map.setExtent(wellExtent);     }      function zoomRow(id) {         //console.log(id);       dojo.some(wellFeatureLayer.graphic,function(graphic){         if (graphic.attributes.ObjectID.toString() === id) {         console.log(graphic.attributes);           var selectedWell = new esri.Graphic(graphic.geometry).setAttributes(               graphic.attributes);           selectionLayer.add(selectedWell);           var wellExtent = selectedWell.geometry.getExtent().expand(5.0);           map.setExtent(wellExtent);           return true;         }       });     }


Do any of you have any ideas on how I can get this to work?

I attached a screen grab of what the map looks like.

[ATTACH=CONFIG]27089[/ATTACH]
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
I think the problem might be that you're trying to get the extent of a point. Take a look at this thread for one way to do your zoom.

View solution in original post

0 Kudos
1 Reply
KenBuja
MVP Esteemed Contributor
I think the problem might be that you're trying to get the extent of a point. Take a look at this thread for one way to do your zoom.
0 Kudos