Select to view content in your preferred language

minimize widget after getting results

1317
10
Jump to solution
01-10-2012 08:32 AM
PeterHoffman
Deactivated User
I am looking for a way to automatically minimize a widget after clicking
on a button in a custom locate widget.
The user wants to locate an item and then automatically minimize the widget.
I have searched but not found any code that would do this.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Peter,

   Glad you got it working. Don't forget to click the top arrow (promote) and to click the Mark as answer check as shown below:

View solution in original post

0 Kudos
10 Replies
RobertScheitlin__GISP
MVP Emeritus
Peter,

   Sure just dispatch the right AppEvent:

This code goes in the LocateWidget.mxml

Add this Import:

import com.esri.viewer.AppEvent;


            private function showLocation(data:Object):void
            {
                hideInfoWindow();
                graphicsLayer.clear();

                var ptGraphic:Graphic = new Graphic();
                ptGraphic.geometry = data.point;
                graphicsLayer.add(ptGraphic);

                var popUpInfo:PopUpInfo = new PopUpInfo();
                popUpInfo.title = data.title;
                popUpInfo.description = data.content;

                var infoWindowRenderer:ClassFactory = new ClassFactory(PopUpRenderer);
                infoWindowRenderer.properties = { popUpInfo: popUpInfo };
                graphicsLayer.infoWindowRenderer = infoWindowRenderer;

                popUpRenderer.popUpInfo = popUpInfo;
                popUpRenderer.graphic = ptGraphic;

                if (map.scale > zoomScale)
                {
                    map.scale = zoomScale;
                }
                map.centerAt(data.point);

                infoWindowShow();
//Added Code
                var data:Object = {
                    id: widgetId,
                    state: "minimized"
                }
                AppEvent.dispatch(AppEvent.WIDGET_CHANGE_STATE, data);
//End Added Code
            }
0 Kudos
PeterHoffman
Deactivated User
Robert,

The code I have has been highly modified by a consultant and this is the closest I could find to the showLocation function I have,
it is passing in a data of type array and not object.

Website:  http://gis.co.suffolk.ny.us/shelters4/index.html and widget is the "Find Closest Shelter".

function locateResult(data:Array, token:Object = null):void
    {
     if (data.length > 0)
     {
      var addrCandidate:AddressCandidate = data[0];
     
      locPoint = addrCandidate.location;
      locationGraphicsLayer.add(new Graphic(locPoint, pmsLocation));
     
      map.centerAt(locPoint);
      while(map.scale > 50000)
      {
       map.zoomIn();
      }
     
      gButtons.visible = true;
      gFacilities.visible = true;
     
      qryStormSurge.geometry = locPoint as Geometry;
      qryStormSurge.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;
     
      qtStormSurgeTask.execute(qryStormSurge, new AsyncResponder(queryStormSurgeResult, genericError));    
     
     }
     else
     {
      showMessage("Could not locate an address using on the Street, City, and Zip values.", false);
     }
    }
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Peter,

   OK, So you just need to put the comment code I provided in the last function that gets called. Maybe queryStormSurgeResult (not sure without seeing the whole code).
0 Kudos
PeterHoffman
Deactivated User
Robert,

Thnaks for the quick replys.

Now I get this error message:

Multiple markers at this line:
-1061: Call to a possibly undefined method dispatch through a reference with static type Class.

Line of code:
AppEvent.dispatch(AppEvent.WIDGET_CHANGE_STATE, data2);
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Peter,

   Yep that code is for Flex Viewer 2.5 not 2.2. Try this line instead

ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_CHANGE_STATE, data2));
0 Kudos
PeterHoffman
Deactivated User
Now I get:
1120: Access of undefined property ViewerContainer. FindClosestWidget.mxml /SuffolkSheltersEric/src/widgets/Locate line 598 Flex Problem
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Peter,

   I keep forgetting your not a developer:

Add this import at the top with the others

import com.esri.viewer.ViewerContainer;
0 Kudos
PeterHoffman
Deactivated User
No, I am not a developer, I am not supposed to be even doing any programming according to my job title but I do anyhow to get the job done.
I did try typing in the import com.esri.viewer. and did not get the intellisense to show me ViewContainer as an option.

The minimize feature works great!

Thanks for your help again.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Peter,

   Glad you got it working. Don't forget to click the top arrow (promote) and to click the Mark as answer check as shown below:
0 Kudos