Select to view content in your preferred language

FlexViewer2 Search Widget with point layer

659
5
07-09-2010 06:03 AM
JoshuaKalov
New Contributor III
I have the new flexviewer and search widget set up with a point layer.  With the graphical search tools, if I draw a polygon around a point, the search finds it.  If I try to just use the "Search by point" and click on my point, the Search can't seem to find it.  Anyone know what could be wrong?  I'm thinking its a click tolerance thing?
Tags (2)
0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus
Joshua,

   There is not tolerance built in for the point graphical search so you have to add one on your own like this:
private function searchDrawEnd(event:DrawEvent):void
   {
    event.target.deactivate();
    var geom:Geometry = event.graphic.geometry;
    if(geom.type == Geometry.MAPPOINT)
    {
     //Expand the point by 5 pixels
     var point:MapPoint = geom as MapPoint;
     var xMin:Number = map.toScreen(point).x - 2.5;
     var yMin:Number = map.toScreen(point).y - 2.5;
     var xMax:Number = map.toScreen(point).x + 2.5;
     var yMax:Number = map.toScreen(point).y + 2.5;
     var mp1:MapPoint = map.toMap(new Point(xMin,yMin));
     var mp2:MapPoint = map.toMap(new Point(xMax,yMax));
     var ext:Extent = new Extent(mp1.x, mp1.y, mp2.x, mp2.y);
     var pA:Array = [];
                 var pPoly:Polygon = new Polygon(null,geom.spatialReference);
              pA.push(new MapPoint(ext.xmin,ext.ymin,geom.spatialReference));
              pA.push(new MapPoint(ext.xmin,ext.ymax,geom.spatialReference));
              pA.push(new MapPoint(ext.xmax,ext.ymax,geom.spatialReference));
              pA.push(new MapPoint(ext.xmax,ext.ymin,geom.spatialReference));
              pA.push(new MapPoint(ext.xmin,ext.ymin,geom.spatialReference));
     pPoly.addRing(pA);
     queryFeaturesGraphical(pPoly);
    } else {
     queryFeaturesGraphical(geom);
    }
   }
0 Kudos
JoshuaKalov
New Contributor III
Thanks. I'll have to take a look at editing widgets.
0 Kudos
JoshuaKalov
New Contributor III
Joshua,

   There is not tolerance built in for the point graphical search so you have to add one on your own like this:
private function searchDrawEnd(event:DrawEvent):void
   {
    event.target.deactivate();
    var geom:Geometry = event.graphic.geometry;
    if(geom.type == Geometry.MAPPOINT)
    {
     //Expand the point by 5 pixels
     var point:MapPoint = geom as MapPoint;
     var xMin:Number = map.toScreen(point).x - 2.5;
     var yMin:Number = map.toScreen(point).y - 2.5;
     var xMax:Number = map.toScreen(point).x + 2.5;
     var yMax:Number = map.toScreen(point).y + 2.5;
     var mp1:MapPoint = map.toMap(new Point(xMin,yMin));
     var mp2:MapPoint = map.toMap(new Point(xMax,yMax));
     var ext:Extent = new Extent(mp1.x, mp1.y, mp2.x, mp2.y);
     var pA:Array = [];
                 var pPoly:Polygon = new Polygon(null,geom.spatialReference);
              pA.push(new MapPoint(ext.xmin,ext.ymin,geom.spatialReference));
              pA.push(new MapPoint(ext.xmin,ext.ymax,geom.spatialReference));
              pA.push(new MapPoint(ext.xmax,ext.ymax,geom.spatialReference));
              pA.push(new MapPoint(ext.xmax,ext.ymin,geom.spatialReference));
              pA.push(new MapPoint(ext.xmin,ext.ymin,geom.spatialReference));
     pPoly.addRing(pA);
     queryFeaturesGraphical(pPoly);
    } else {
     queryFeaturesGraphical(geom);
    }
   }


I am getting compile errors with this line:
var ext:Extent = new Extent(mp1.x, mp1.y, mp2.x, mp2.y);



1046: Type was not found or was not a compile-time constant: Extent. SearchWidget.mxml
1180: Call to a possibly undefined method Extent. SearchWidget.mxml
0 Kudos
JoshuaKalov
New Contributor III
I got the extent error fixed (needed to add an include).

The search still won't recognize a point when clicking on it no matter what I set the tolerance for.  Maybe it is something else that is causing it not to pick up the point?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Joshua,

   That code works fine for me are you sure your map's spatial reference and your map service are the same WKID?
0 Kudos