<?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;turns out very important. I added to every showBookmark function and it works pretty well. Also, in your codes I found that , e.g., in loadBookmark2 function, you used
bookmarkSO2.data[BOOKMARKS] = bookmarkSOAL;, but it actually should be
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>