query.where = queryAttribute + "='" + dropDownList1.selectedItem.name + "'";
Georgianna, Your issue is that you are not dealing with a custom itemRenderer any more like the bookmark widget was so you need to do something like this:query.where = queryAttribute + "='" + dropDownList1.selectedItem.name + "'";
Georgianna, What is the other dropdown list going to do when someone choose a value?
Look at the toolbar above the box you type in it will be the # button.
<?xml version="1.0" encoding="utf-8"?> <viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:viewer="com.esri.viewer.*" xmlns:esri="http://www.esri.com/2008/ags" x="600" y="300" layout="absolute" widgetConfigLoaded="init()" > <fx:Script> <![CDATA[ import com.esri.ags.FeatureSet; import com.esri.ags.utils.GraphicUtil; import com.esri.ags.geometry.Extent; import mx.collections.ArrayList; import mx.controls.Alert; import mx.rpc.AsyncResponder; import mx.events.EffectEvent; import spark.components.supportClasses.ItemRenderer; import spark.core.NavigationUnit; private const BOOKMARKS:String = "bookmarks"; private const BOOKMARKS2:String = "bookmarks2"; private const ICON_URL:String = "assets/images/"; //labels private var bookmarksLabel:String; [Bindable] //query info private var featureURL:String; private var queryAttribute:String; private var featureURL2:String; private var queryAttribute2:String; [Bindable] private var bookmarkAL:ArrayList; // used by BookmarkDataGroup private var bookmarkSO:SharedObject; private var bookmarkSOAL:ArrayList; // stored in bookmarkSO [Bindable] private var bookmarkAL2:ArrayList; // used by BookmarkDataGroup private var bookmarkSO2:SharedObject; private var bookmarkSOAL2:ArrayList; // stored in bookmarkSO private var selectedindex:int = 0; private function init():void { if (configXML) { //labels bookmarksLabel = configXML.labels.bookmarkslabel || "Bookmarks"; //query information featureURL = configXML.queryinfo.featureURL; queryAttribute = configXML.queryinfo.attribute; featureURL2 = configXML.queryinfo2.featureURL; queryAttribute2 = configXML.queryinfo2.attribute; } bookmarkAL = new ArrayList(); try { bookmarkSO = SharedObject.getLocal(BOOKMARKS); } catch (err:Error) { trace(err); } loadBookmarks(); bookmarkAL2 = new ArrayList(); try { bookmarkSO2 = SharedObject.getLocal(BOOKMARKS2); } catch (err:Error) { trace(err); } loadBookmarks2(); } private function loadBookmarks():void { if (configXML) { var bookmarkList:XMLList = configXML..bookmark; for (var i:int = 0; i < bookmarkList.length(); i++) { var name:String = bookmarkList.@name; var icon:String = bookmarkList.@icon; var bookmark:Object = new Object(); bookmark.name = name; bookmark.icon = icon; bookmarkAL.addItem(bookmark); } } if (bookmarkSO) { bookmarkSOAL = bookmarkSO.data[BOOKMARKS] as ArrayList; if (!bookmarkSOAL) { bookmarkSOAL = new ArrayList(); bookmarkSO.data[BOOKMARKS] = bookmarkSOAL; } else { bookmarkAL.addAll(bookmarkSOAL); } } } private function showBookmark(event:Event):void { //var bookmark:Bookmark = ItemRenderer(event.target).data as Bookmark; query.where = queryAttribute + "='" + dropDownList1.selectedItem.name + "'"; queryTask.execute(query, new AsyncResponder(onResult, onFault)); function onResult(featureSet:FeatureSet, token:Object = null):void { if (featureSet.features.length == 0) { Alert.show("Not found."); } else { map.extent = GraphicUtil.getGraphicsExtent(featureSet.features) ; } } function onFault(info:Object, token:Object = null):void { Alert.show(info.toString()); } } private function loadBookmarks2():void { if (configXML) { var bookmarkList:XMLList = configXML..bookmark2; for (var i:int = 0; i < bookmarkList.length(); i++) { var name:String = bookmarkList.@name; var icon:String = bookmarkList.@icon; var bookmark2:Object = new Object(); bookmark2.name = name; bookmark2.icon = icon; bookmarkAL2.addItem(bookmark2); } } if (bookmarkSO2) { bookmarkSOAL2 = bookmarkSO2.data[BOOKMARKS] as ArrayList; if (!bookmarkSOAL2) { bookmarkSOAL2 = new ArrayList(); bookmarkSO2.data[BOOKMARKS] = bookmarkSOAL; } else { bookmarkAL2.addAll(bookmarkSOAL2); } } } private function showBookmark2(event:Event):void { query.where = queryAttribute + "='" + dropDownList2.selectedItem.name + "'"; queryTask.execute(query, new AsyncResponder(onResult, onFault)); function onResult(featureSet:FeatureSet, token:Object = null):void { if (featureSet.features.length == 0) { Alert.show("Not found."); } else { map.extent = GraphicUtil.getGraphicsExtent(featureSet.features) ; } } function onFault(info:Object, token:Object = null):void { Alert.show(info.toString()); } } ]]> </fx:Script> <fx:Declarations> <esri:QueryTask id="queryTask" url="{featureURL}" useAMF="false"/> <esri:Query id="query" outSpatialReference="{map.spatialReference}" returnGeometry="true"/> </fx:Declarations> <viewer:WidgetTemplate id="helloWorld" width="300" height="300"> <viewer:layout> <s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/> </viewer:layout> <s:Label text="Choose a county from the droplist" /> <s:DropDownList id="dropDownList1" labelField="name" change="showBookmark(event)" dataProvider="{bookmarkAL}"/> <s:Label text="Choose a quad from the droplist" /> <s:DropDownList id="dropDownList2" labelField="name" change="showBookmark2(event)" dataProvider="{bookmarkAL2}"/> <s:Label id="lbl" fontSize="21" fontStyle="italic" fontWeight="bold"/> </viewer:WidgetTemplate> </viewer:BaseWidget>
<?xml version="1.0" ?> <configuration> <queryinfo> <!-- URL of map service feature layer to query --> <featureURL>http://labinsw2010.freac.fsu.edu/ArcGIS/rest/services/swfwmd/control2/MapServer/10</featureURL> <!-- name of attribute in map service layer to query --> <attribute>ctyname</attribute> </queryinfo> <!-- bookmark names are checked against the specified attribute --> <bookmarks> <bookmark name="Alachua"></bookmark> <bookmark name="Baker"></bookmark> <bookmark name="Bay"></bookmark> <bookmark name="Leon"></bookmark> </bookmarks> <queryinfo2> <!-- URL of map service feature layer to query --> <featureURL>http://labinsw2010.freac.fsu.edu/ArcGIS/rest/services/swfwmd/control2/MapServer/12</featureURL> <!-- name of attribute in map service layer to query --> <attribute>quad</attribute> </queryinfo2> <!-- bookmark names are checked against the specified attribute --> <bookmarks2> <bookmark2 name="Leon"></bookmark2> <bookmark2 name="Orange"></bookmark2> </bookmarks2> </configuration>
<?xml version="1.0" ?> <configuration> <queryinfo> <!-- URL of map service feature layer to query --> <featureURL>http://labinsw2010.freac.fsu.edu/ArcGIS/rest/services/swfwmd/control2/MapServer/10</featureURL> <!-- name of attribute in map service layer to query --> <attribute>ctyname</attribute> </queryinfo> <!-- bookmark names are checked against the specified attribute --> <bookmarks> <bookmark name="Alachua"></bookmark> <bookmark name="Baker"></bookmark> <bookmark name="Bay"></bookmark> </bookmarks> <queryinfo2> <!-- URL of map service feature layer to query --> <featureURL>http://labinsw2010.freac.fsu.edu/ArcGIS/rest/services/swfwmd/control2/MapServer/12</featureURL> <!-- name of attribute in map service layer to query --> <attribute>quad</attribute> </queryinfo2> <!-- bookmark names are checked against the specified attribute --> <bookmarks2> <bookmark2 name="5237"></bookmark2> </bookmarks2> </configuration>
private function showBookmark2(event:Event):void { query.where = queryAttribute2 + "='" + dropDownList2.selectedItem.name + "'"; queryTask.url = featureURL2; queryTask.execute(query, new AsyncResponder(onResult, onFault)); function onResult(featureSet:FeatureSet, token:Object = null):void { if (featureSet.features.length == 0) { Alert.show("Not found."); } else { map.extent = GraphicUtil.getGraphicsExtent(featureSet.features) ; } } function onFault(info:Object, token:Object = null):void { Alert.show(info.toString()); } }
queryTask.url = featureURL2;
bookmarkSO2.data[BOOKMARKS] = bookmarkSOAL;
bookmarkSO2.data[BOOKMARKS] = bookmarkSOAL2;
base_and_survey.sde.SWFWMD_CONTROL_09_28_2010.swfwmd_hyd (Type: esriFieldTypeString, Alias: swfwmd_hyd, Length: 254 )
base_and_survey.sde.SWFWMD_CONTROL_09_28_2010.freacid (Type: esriFieldTypeDouble, Alias: FREACID99)
ctyname (Type: esriFieldTypeString, Alias: ctyname, Length: 15 )
<queryinfo2> <!-- URL of map service feature layer to query --> <featureURL>http://labinsw2010.freac.fsu.edu/ArcGIS/rest/services/swfwmd/control2/MapServer/3</featureURL> <!-- name of attribute in map service layer to query --> <attribute>swfwmd_hyd</attribute> </queryinfo2> <!-- bookmark names are checked against the specified attribute --> <bookmarks2> <bookmark2 name="CYP043"></bookmark2> <bookmark2 name="900012"></bookmark2> <bookmark2 name="19966"></bookmark2> <bookmark2 name="17500"></bookmark2> </bookmarks2>
<queryinfo2> <!-- URL of map service feature layer to query --> <featureURL>http://labinsw2010.freac.fsu.edu/ArcGIS/rest/services/swfwmd/control2/MapServer/3</featureURL> <!-- name of attribute in map service layer to query --> <attribute>base_and_survey.sde.SWFWMD_CONTROL_09_28_2010.swfwmd_hyd</attribute> </queryinfo2> <!-- bookmark names are checked against the specified attribute --> <bookmarks2> <bookmark2 name="CYP043"></bookmark2> <bookmark2 name="900012"></bookmark2> <bookmark2 name="19966"></bookmark2> <bookmark2 name="17500"></bookmark2> </bookmarks2>
private function showBookmark2(event:Event):void { query.where = queryAttribute2 + "='" + dropDownList2.selectedItem.name + "'"; queryTask.url = featureURL2; queryTask.execute(query, new AsyncResponder(onResult, onFault)); function onResult(featureSet:FeatureSet, token:Object = null):void { if (featureSet.features.length == 0) { Alert.show("Not found."); }else if(featureSet.features.length == 1){ if(featureSet.features[0].geometry is MapPoint) { map.scale = 24000; map.centerAt(featureSet.features[0].geometry as MapPoint); }else{ map.extent = GraphicUtil.getGraphicsExtent(featureSet.features); } } else { map.extent = GraphicUtil.getGraphicsExtent(featureSet.features); } } function onFault(info:Object, token:Object = null):void { Alert.show(info.toString()); } }
private function loadBookmarks2():void { if (configXML) { var bookmarkList:XMLList = configXML..bookmark2; for (var i:int = 0; i < bookmarkList.length(); i++) { var name:String = bookmarkList.@name; var icon:String = bookmarkList.@icon; var bookmark2:Object = new Object(); bookmark2.name = name; bookmark2.icon = icon; bookmarkAL2.addItem(bookmark2); } } if (bookmarkSO2) { bookmarkSOAL2 = bookmarkSO2.data[BOOKMARKS2] as ArrayList; if (!bookmarkSOAL2) { bookmarkSOAL2 = new ArrayList(); bookmarkSO2.data[BOOKMARKS2] = bookmarkSOAL2; } else { bookmarkAL2.addAll(bookmarkSOAL2); } } }
<?xml version="1.0" encoding="utf-8"?> <viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:viewer="com.esri.viewer.*" xmlns:esri="http://www.esri.com/2008/ags" x="600" y="300" layout="absolute" widgetConfigLoaded="init()" > <fx:Script> <![CDATA[ import com.esri.ags.FeatureSet; import com.esri.ags.geometry.Extent; import com.esri.ags.geometry.MapPoint; import com.esri.ags.utils.GraphicUtil; import mx.collections.ArrayList; import mx.controls.Alert; import mx.rpc.AsyncResponder; private const ICON_URL:String = "assets/images/"; //labels [Bindable] private var bookmarksLabel:String; [Bindable] private var bookmarksLabel2:String; //query info [Bindable] private var featureURL:String; private var queryAttribute:String; private var featureURL2:String; private var queryAttribute2:String; [Bindable] private var bookmarkAL:ArrayList; [Bindable] private var bookmarkAL2:ArrayList; private var selectedindex:int = 0; private function init():void { if (configXML) { //labels bookmarksLabel = configXML.labels.bookmarkslabel || "Option 1"; bookmarksLabel2 = configXML.labels.bookmarkslabel2 || "Option 2"; //query information featureURL = configXML.queryinfo.featureURL; queryAttribute = configXML.queryinfo.attribute; featureURL2 = configXML.queryinfo2.featureURL; queryAttribute2 = configXML.queryinfo2.attribute; } bookmarkAL = new ArrayList(); loadBookmarks(); bookmarkAL2 = new ArrayList(); loadBookmarks2(); } private function loadBookmarks():void { if (configXML) { var bookmarkList:XMLList = configXML..bookmark; for (var i:int = 0; i < bookmarkList.length(); i++) { var name:String = bookmarkList.@name; var icon:String = bookmarkList.@icon; var bookmark:Object = new Object(); bookmark.name = name; bookmark.icon = icon; bookmarkAL.addItem(bookmark); } } } private function showBookmark(event:Event):void { query.where = queryAttribute + "='" + dropDownList1.selectedItem.name + "'"; queryTask.execute(query, new AsyncResponder(onResult, onFault)); function onResult(featureSet:FeatureSet, token:Object = null):void { if (featureSet.features.length == 0){ Alert.show("Not found."); }else if(featureSet.features.length == 1){ if(featureSet.features[0].geometry is MapPoint) { map.scale = 24000; map.centerAt(featureSet.features[0].geometry as MapPoint); }else{ map.extent = GraphicUtil.getGraphicsExtent(featureSet.features); } }else{ map.extent = GraphicUtil.getGraphicsExtent(featureSet.features); } } function onFault(info:Object, token:Object = null):void { Alert.show(info.toString()); } } private function loadBookmarks2():void { if (configXML) { var bookmarkList:XMLList = configXML..bookmark2; for (var i:int = 0; i < bookmarkList.length(); i++) { var name:String = bookmarkList.@name; var icon:String = bookmarkList.@icon; var bookmark2:Object = new Object(); bookmark2.name = name; bookmark2.icon = icon; bookmarkAL2.addItem(bookmark2); } } } private function showBookmark2(event:Event):void { query.where = queryAttribute2 + "='" + dropDownList2.selectedItem.name + "'"; queryTask.url = featureURL2; queryTask.execute(query, new AsyncResponder(onResult, onFault)); function onResult(featureSet:FeatureSet, token:Object = null):void { if (featureSet.features.length == 0){ Alert.show("Not found."); }else if(featureSet.features.length == 1){ if(featureSet.features[0].geometry is MapPoint) { map.scale = 24000; map.centerAt(featureSet.features[0].geometry as MapPoint); }else{ map.extent = GraphicUtil.getGraphicsExtent(featureSet.features); } }else{ map.extent = GraphicUtil.getGraphicsExtent(featureSet.features); } } function onFault(info:Object, token:Object = null):void { Alert.show(info.toString()); } } ]]> </fx:Script> <fx:Declarations> <esri:QueryTask id="queryTask" url="{featureURL}" useAMF="false"/> <esri:Query id="query" outSpatialReference="{map.spatialReference}" returnGeometry="true"/> </fx:Declarations> <viewer:WidgetTemplate width="300" height="180"> <viewer:layout> <s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/> </viewer:layout> <s:Label text="{bookmarksLabel}" /> <s:DropDownList id="dropDownList1" labelField="name" change="showBookmark(event)" dataProvider="{bookmarkAL}"/> <s:Label text="{bookmarksLabel2}" /> <s:DropDownList id="dropDownList2" labelField="name" change="showBookmark2(event)" dataProvider="{bookmarkAL2}"/> <s:Label id="lbl" fontSize="21" fontStyle="italic" fontWeight="bold"/> </viewer:WidgetTemplate> </viewer:BaseWidget>
<?xml version="1.0" ?> <configuration> <queryinfo> <!-- URL of map service feature layer to query --> <featureURL>http://labinsw2010.freac.fsu.edu/ArcGIS/rest/services/swfwmd/control2/MapServer/10</featureURL> <!-- name of attribute in map service layer to query --> <attribute>ctyname</attribute> </queryinfo> <!-- bookmark names are checked against the specified attribute --> <bookmarks> <bookmark name="Alachua"/> <bookmark name="Baker"/> <bookmark name="Bay"/> <bookmark name="Leon"/> </bookmarks> <queryinfo2> <!-- URL of map service feature layer to query --> <featureURL>http://labinsw2010.freac.fsu.edu/ArcGIS/rest/services/swfwmd/control2/MapServer/3</featureURL> <!-- name of attribute in map service layer to query --> <attribute>base_and_survey.sde.SWFWMD_CONTROL_09_28_2010.swfwmd_hyd</attribute> </queryinfo2> <!-- bookmark names are checked against the specified attribute --> <bookmarks2> <bookmark2 name="CYP043"/> <bookmark2 name="900012"/> <bookmark2 name="19966"/> <bookmark2 name="17500"/> </bookmarks2> <labels> <bookmarkslabel>Choose a county from the droplist</bookmarkslabel> <bookmarkslabel2>Choose a quad from the droplist</bookmarkslabel2> </labels> </configuration>
if(featureSet.features[0].geometry is MapPoint)
map.centerAt(featureSet.features[0].geometry as MapPoint);
<queryinfo2> <!-- URL of map service feature layer to query --> <featureURL>http://labinsw2010/ArcGIS/rest/services/swfwmd/control2/MapServer/14</featureURL> <!-- name of attribute in map service layer to query --> <attribute>swfwmd_hyd</attribute> </queryinfo2> <bookmarks2> <bookmark2 name="17500"></bookmark2> </bookmarks2>
<queryinfo2> <!-- URL of map service feature layer to query --> <featureURL>http://labinsw2010.freac.fsu.edu/ArcGIS/rest/services/swfwmd/control2/MapServer/14</featureURL> <!-- name of attribute in map service layer to query --> <attribute>swfwmd_hyd</attribute> </queryinfo2> <bookmarks2> <bookmark2 name="17500"/> </bookmarks2>
Robert:The only problem with the cleaned up codes that u posted above is that u r using point layer codes for showBookmark1 as well. Actually it should be using codes for polygon layers, just as what u posted the first time. All other things work very well! And the fully qualified url does not really make a difference. I used to think it matters too. Thank you!
Georgianna, That is because the code will work with all geometry types the way it is written (not just points). The fully qualified url name does matter when you are not on your network. So for me to access your rest services I have to use the full url.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.