Select by URL Parameters - zoom to point?

903
5
02-29-2012 09:29 AM
LizDaRos
Occasional Contributor
I'm trying to use the code sample here to use URL parameters to select one or more POINT features and zoom the map to those features. I have configured it using one of my polygon features and it works but I'm trying to use it for a point feature.
When I try passing this URL parameter the symbol appears around the point but the map does not zoom in or display the points information. Also I get this error- TypeError: query.geometry is null
Does anyone know what I need to add to my code to allow this to work properly? I've tried a few different ways but not having much luck.
0 Kudos
5 Replies
HemingZhu
Occasional Contributor III
I'm trying to use the code sample here to use URL parameters to select one or more POINT features and zoom the map to those features. I have configured it using one of my polygon features and it works but I'm trying to use it for a point feature.
When I try passing this URL parameter the symbol appears around the point but the map does not zoom in or display the points information. Also I get this error- TypeError: query.geometry is null
Does anyone know what I need to add to my code to allow this to work properly? I've tried a few different ways but not having much luck.


From the error message, I think the problem lies in the queryExtent in your executeQueryTask(evt) function. Try this to see if it works:
function executeQueryTask(evt)
{

    query.where = "";
    var centerPoint = evt.mapPoint;
    var mapWidth = theMap.extent.getWidth();
    var pixelWidth = mapWidth/theMap.width;
    //Calculate a 10 pixel envelope width (5 pixel tolerance on each side)
     var tolerance = 5 * pixelWidth;    
     var queryExtent = new esri.geometry.Extent(centerPoint.x -tolerance, centerPoint.y -tolerance, centerPoint.x +tolerance, centerPoint.y +tolerance, theMap.spatialReference);
     query.geometry = queryExtent;

    queryTask.execute(query, showResults);
}

0 Kudos
LizDaRos
Occasional Contributor
Thanks for taking a look at it, unfortunately I still get the same error. Could the issue also be in-
var ResultEnv = query.geometry.getExtent().expand(10.0);

??
0 Kudos
HemingZhu
Occasional Contributor III
Thanks for taking a look at it, unfortunately I still get the same error. Could the issue also be in-
var ResultEnv = query.geometry.getExtent().expand(10.0);

??


Yes, you need to change make similiar changes on you showResults function.
0 Kudos
LizDaRos
Occasional Contributor
I tried-
     function showResults(featureSet)

//Zoom to the extent of the graphics
query.where = "";
    var centerPoint = evt.mapPoint;
    var mapWidth = theMap.extent.getWidth();
    var pixelWidth = mapWidth/theMap.width;
    //Calculate a 10 pixel envelope width (5 pixel tolerance on each side)
     var tolerance = 5 * pixelWidth;   
     var queryExtent = new esri.geometry.Extent(centerPoint.x -tolerance, centerPoint.y -tolerance, centerPoint.x +tolerance, centerPoint.y +tolerance, theMap.spatialReference);
     query.geometry = queryExtent;
var ResultEnv = query.geometry.getExtent().expand(10.0);
theMap.setExtent(ResultEnv);

but I get an error: ReferenceError: evt is not defined
0 Kudos
HemingZhu
Occasional Contributor III
I tried-
     function showResults(featureSet)

//Zoom to the extent of the graphics
query.where = "";
    var centerPoint = evt.mapPoint;
    var mapWidth = theMap.extent.getWidth();
    var pixelWidth = mapWidth/theMap.width;
    //Calculate a 10 pixel envelope width (5 pixel tolerance on each side)
     var tolerance = 5 * pixelWidth;   
     var queryExtent = new esri.geometry.Extent(centerPoint.x -tolerance, centerPoint.y -tolerance, centerPoint.x +tolerance, centerPoint.y +tolerance, theMap.spatialReference);
     query.geometry = queryExtent;
var ResultEnv = query.geometry.getExtent().expand(10.0);
theMap.setExtent(ResultEnv);

but I get an error: ReferenceError: evt is not defined


You will have to use the featureSet's extent not evt. Like this:
 
var ResultEnv =esri.graphicsExtent(featureSet.features);
theMap.setExtent(ResultEnv);
0 Kudos