selectFeatures Query always returning 0 length

698
5
Jump to solution
01-18-2012 04:25 AM
MichaelCooper
New Contributor
I have spent 2 days on what i think is something simple.  My Query is not working in the onclick function and i think it has something to do with my extents being defined wrong, but i'm not sure - i have checked the forums and have not seen similar issues.  I was hoping one of you might see something simple in the attached file:

Here is my extent definition:

var startExtent = new esri.geometry.Extent({"xmin":-74.487856,"ymin":40.849173,"xmax":-73.487856,"ymax":40.649173,"spatialReference":{"wkid":2263}});


Here is the onclick block - feature,length always comes back as 0.

        dojo.connect(map, "onClick", function(evt) {
  
          selectQuery.geometry = evt.mapPoint;
          waterHydrantsFL.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW, function(features) {
   
            if (features.length > 0) {
             //store the current feature
              updateFeature = features[0];
              map.infoWindow.setTitle(features[0].getLayer().name);
              map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint));
            } else {
              map.infoWindow.hide();
            }
          });

        });


thanks
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Frequent Contributor
I'm not able to get your your REST endpoints, are they supposed to be public?

I put some code on jsfiddle a while back showing how to build a small extent from a point and do a selection:  http://jsfiddle.net/swingley/Bkswj/ And talked a bit about it here:  http://forums.arcgis.com/threads/36210-popup-widget-for-ArcGISDynamicMapServiceLayer?p=147007&viewfu...

For your extent, it looks like you're specifying lat, long values but your spatial reference specifies a projected coordinate system (Long Island State Plane). Use the SRID for WGS84 in your extent, which is 4326.

View solution in original post

0 Kudos
5 Replies
JeffPace
MVP Alum
I have spent 2 days on what i think is something simple.  My Query is not working in the onclick function and i think it has something to do with my extents being defined wrong, but i'm not sure - i have checked the forums and have not seen similar issues.  I was hoping one of you might see something simple in the attached file:

Here is my extent definition:

var startExtent = new esri.geometry.Extent({"xmin":-74.487856,"ymin":40.849173,"xmax":-73.487856,"ymax":40.649173,"spatialReference":{"wkid":2263}});


Here is the onclick block - feature,length always comes back as 0.

        dojo.connect(map, "onClick", function(evt) {
  
          selectQuery.geometry = evt.mapPoint;
          waterHydrantsFL.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW, function(features) {
   
            if (features.length > 0) {
             //store the current feature
              updateFeature = features[0];
              map.infoWindow.setTitle(features[0].getLayer().name);
              map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint));
            } else {
              map.infoWindow.hide();
            }
          });

        });


thanks



I see you are using a point to select.  Remember if you are clicking on a point or a line (basically anything but in a poly) it would have to be PERFECT to satisfy the query. 

I recommend buffering the point a couple units.
0 Kudos
derekswingley1
Frequent Contributor
I'm not able to get your your REST endpoints, are they supposed to be public?

I put some code on jsfiddle a while back showing how to build a small extent from a point and do a selection:  http://jsfiddle.net/swingley/Bkswj/ And talked a bit about it here:  http://forums.arcgis.com/threads/36210-popup-widget-for-ArcGISDynamicMapServiceLayer?p=147007&viewfu...

For your extent, it looks like you're specifying lat, long values but your spatial reference specifies a projected coordinate system (Long Island State Plane). Use the SRID for WGS84 in your extent, which is 4326.
0 Kudos
MichaelCooper
New Contributor
Thank you very much.  I changed to he SRID and added the following code from your sample for buffering:

var pad = map.extent.getWidth() / map.width * 3;
        var queryGeom = new esri.geometry.Extent(e.mapPoint.x - pad, e.mapPoint.y - pad, e.mapPoint.x + pad, e.mapPoint.y + pad, map.spatialReference);

        selectQuery.geometry = queryGeom;
        waterHydrantsFL.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW, function(features) {

Which works perfectly.

Sorry my maps and features are behind a firewall =(
0 Kudos
derekswingley1
Frequent Contributor
Glad to help! Can you mark my post as answer?
0 Kudos
SmaranHarihar
New Contributor III
I'm not able to get your your REST endpoints, are they supposed to be public?

I put some code on jsfiddle a while back showing how to build a small extent from a point and do a selection:  http://jsfiddle.net/swingley/Bkswj/ And talked a bit about it here:  http://forums.arcgis.com/threads/36210-popup-widget-for-ArcGISDynamicMapServiceLayer?p=147007&viewfu...

For your extent, it looks like you're specifying lat, long values but your spatial reference specifies a projected coordinate system (Long Island State Plane). Use the SRID for WGS84 in your extent, which is 4326.


Hi @swingley, I used your code and the popups are coming great, but the only problem is that, when I click on the Zoom to hyperlink in the popup window. It zooms into the map, displays the county and if I pan or zoom out, I am losing the layer. In the sense, the layer disappears. Any idea why? Should I post a new question?
0 Kudos