Select to view content in your preferred language

Live Layer Widget - only return records in extent

1069
14
06-10-2010 01:02 PM
SusanMordy1
New Contributor II
I am wanting to modify the Live Layer Widget so only features (points) in the current map extent are queried and have the results shown on the map.  Has anyone done this or does anyone know how to accomplish this?

Thanks!

Susan
Tags (2)
0 Kudos
14 Replies
RobertScheitlin__GISP
MVP Emeritus
Susan,

    In theory (not tested) it should be as simple as adding
query.geometry = map.extent;

to the queryFeatures function in the LiveLayerWidget.mxml
0 Kudos
SusanMordy1
New Contributor II
Robert,

Thanks for your suggestion! I tried it, but the live layer widget still returns all records (not just the records for the map extent).

Any other ideas?

private function queryFeatures():void
   {
    if (queryLayer)
    {
     var queryTask:QueryTask = new QueryTask(queryLayer);
     queryTask.disableClientCaching = true;
     var query:Query = new Query();
     query.outFields = queryFields.split(",");
     query.returnGeometry = true;
     query.where = queryExpr;
     query.outSpatialReference = map.spatialReference;
     queryTask.execute(query, new AsyncResponder(onResult, onFault)); 
     showMessage(loadingLabel, true);
     query.geometry = map.extent;
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Susan,

   You did not put the line in the right spot.
private function queryFeatures():void
{
if (queryLayer)
{
var queryTask:QueryTask = new QueryTask(queryLayer);
queryTask.disableClientCaching = true;
var query:Query = new Query();
query.outFields = queryFields.split(",");
query.returnGeometry = true;
query.where = queryExpr;
query.outSpatialReference = map.spatialReference;
query.geometry = map.extent;
queryTask.execute(query, new AsyncResponder(onResult, onFault));
showMessage(loadingLabel, true);
0 Kudos
SusanMordy1
New Contributor II
Thanks Robert! My mistake 😮

It does work now - thanks - but only in part.

The initial display is correct (eg: zoom to particular area and only those records are displayed - this is great). However, when I pan the map or zoom to another area, the live layer widget is not updated - it still displays the original records.

Any ideas?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Susan,

   Yep, you would have to listen for the map zoomEnd and PanEnd (as Map Extent Change get fired way to often) and have that listener call the queryFeatures function.
0 Kudos
SusanMordy1
New Contributor II
Thanks Robert. Do you know how I can do this?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Susan,

   Add these to the init function.

                      map.addEventListener(PanEvent.PAN_END, fireQuery);
    map.addEventListener(ZoomEvent.ZOOM_END,fireQuery);


Then add this new function

private function fireQuery(Evt:Event):void
   {
    queryFeatures();
   }
0 Kudos
SusanMordy1
New Contributor II
Hi Robert,

I added the below code to livelayerwidget.mxml but then my swf file doesn't build. I am likely putting the code in the wrong place.  I placed the function fireQuery last.

private function init():void
   {
    graphicPointSym = new PictureMarkerSymbol(widgetIcon, 25, 25);
    graphicsLayer = new GraphicsLayer();
    graphicsLayer.symbol = graphicPointSym;
    map.addLayer(graphicsLayer);
    map.addEventListener(PanEvent.PAN_END, fireQuery);
    map.addEventListener(ZoomEvent.ZOOM_END,fireQuery);
    if (configXML)
    {


Would you be able to provide some direction as to where I should place your code?

Thanks for your help,

Susan
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Susan,

   Here is a zip that has the complete LiveLayerWidget.mxml. It has been tried and tested.
0 Kudos