Select to view content in your preferred language

Zoom To Point??

662
2
12-13-2011 07:22 AM
EmilyLaMunyon
Deactivated User
Hello,

I am working on a map that displays data in a dojo grid and when the user selects the row, it zooms to the feature on the map. There are points and polygons and the polygons are zoomed to correctly, however, the points are highlighting on the map, but not zooming in at all. Any help would be greatly appreciated!!:o

} else if (searchType == "PointName") { 
   var clickedTaxLotId = grid4.getItem(evt.rowIndex).POINT_NAME; 
   var selectedTaxLot; 
   dojo.forEach(map.graphics.graphics,function(graphic){ 
     if((graphic.attributes) && graphic.attributes.POINT_NAME === clickedTaxLotId){ 
    selectedTaxLot = graphic; 
    //added this part to build infotemplate
     map.infoWindow.setTitle(graphic.getTitle()); 
     map.infoWindow.setContent(graphic.getContent());
      //
    return; 
     } 
        }); 
  
   if ( selectedTaxLot.geometry.declaredClass == 'esri.geometry.Point' ) {
   //alert("Point");
   map.centerAt(selectedTaxLot.geometry);
   var sp = map.toScreen(selectedTaxLot.geometry);
   map.infoWindow.show(selectedTaxLot.geometry, map.getInfoWindowAnchor(sp));
   } else {
   //alert("Polygon");
   var taxLotExtent = selectedTaxLot.geometry.getExtent(); 
   var screenpoint = map.toScreen(selectedTaxLot.geometry.getExtent().getCenter());
   var mappoint = map.toMap(screenpoint);
    //map.centerAt(mappoint);
    //added by Emily
    map.centerAndZoom(selectedTaxLot.geometry,11);
   
   map.infoWindow.show(taxLotExtent.getCenter(), map.getInfoWindowAnchor(screenpoint));
   }
  }
0 Kudos
2 Replies
JeffPace
MVP Alum
Hello,

I am working on a map that displays data in a dojo grid and when the user selects the row, it zooms to the feature on the map. There are points and polygons and the polygons are zoomed to correctly, however, the points are highlighting on the map, but not zooming in at all. Any help would be greatly appreciated!!:o

} else if (searchType == "PointName") { 
   var clickedTaxLotId = grid4.getItem(evt.rowIndex).POINT_NAME; 
   var selectedTaxLot; 
   dojo.forEach(map.graphics.graphics,function(graphic){ 
     if((graphic.attributes) && graphic.attributes.POINT_NAME === clickedTaxLotId){ 
    selectedTaxLot = graphic; 
    //added this part to build infotemplate
     map.infoWindow.setTitle(graphic.getTitle()); 
     map.infoWindow.setContent(graphic.getContent());
      //
    return; 
     } 
        }); 
  
   if ( selectedTaxLot.geometry.declaredClass == 'esri.geometry.Point' ) {
   //alert("Point");
   map.centerAt(selectedTaxLot.geometry);
   var sp = map.toScreen(selectedTaxLot.geometry);
   map.infoWindow.show(selectedTaxLot.geometry, map.getInfoWindowAnchor(sp));
   } else {
   //alert("Polygon");
   var taxLotExtent = selectedTaxLot.geometry.getExtent(); 
   var screenpoint = map.toScreen(selectedTaxLot.geometry.getExtent().getCenter());
   var mappoint = map.toMap(screenpoint);
    //map.centerAt(mappoint);
    //added by Emily
    map.centerAndZoom(selectedTaxLot.geometry,11);
   
   map.infoWindow.show(taxLotExtent.getCenter(), map.getInfoWindowAnchor(screenpoint));
   }
  }


That is because you are calling "centerAt" so all it does is pan.  Since a point has no Extent, you need to tell it what level to go to

you could try "centerAndZoom" i.e

map.centerAndZoom(pt, level)
0 Kudos
EmilyLaMunyon
Deactivated User
Thanks Jeff, that did the trick!!
0 Kudos