Select to view content in your preferred language

how to realize a zoom function in the droplist?

2508
25
01-05-2011 05:26 PM
GeorgiannaStrode
Deactivated User
I edited a bookmark widget, replacing the bookmark list with a droplist successfully. The droplist is populated with data from a mapserver(the data from a layer attribute of the mapserver)
Whenever the user makes a selection in the droplist, I wanna it to zoom to the selected record. I have not realized the zoom function yet. If anyone has experience in this function or knows how to do it, please let me know. I would appreciate your help

My codes are as below.Note that the change="showBookmark(event)" does not work. Thats what I think I might be doing wrong.


<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:Bookmark="widgets.QBookmark.*"
x="600" y="300"
layout="absolute"
widgetConfigLoaded="init()" xmlns:esri="http://www.esri.com/2008/ags">

<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 ICON_URL:String = "assets/images/";

//labels
private var bookmarksLabel:String;
[Bindable]

//query info
private var featureURL:String;
private var queryAttribute:String;

[Bindable]
private var bookmarkAL:ArrayList; // used by BookmarkDataGroup
private var bookmarkSO:SharedObject;
private var bookmarkSOAL: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;
}

bookmarkAL = new ArrayList();
try
{
bookmarkSO = SharedObject.getLocal(BOOKMARKS);
}
catch (err:Error)
{
trace(err);
}
loadBookmarks();
}

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:Bookmark = new Bookmark();
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 + "='" + bookmark.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:DropDownList id="dropDownList1"
labelField="name"
change="showBookmark(event)"
dataProvider="{bookmarkAL}"/>

<s:Label id="lbl"
fontSize="21"
fontStyle="italic"
fontWeight="bold"/>
</viewer:WidgetTemplate>

</viewer:BaseWidget>
Tags (2)
0 Kudos
25 Replies
RobertScheitlin__GISP
MVP Emeritus
Georgianna,

For me when I fully qualified your url it worked.

<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>
0 Kudos
GeorgiannaStrode
Deactivated User
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!
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
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.
0 Kudos
GeorgiannaStrode
Deactivated User
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.


Just tried your codes, and yes, they work well for both types. Might be sth else wrong last time. and I get the part of full url too. Thanks
0 Kudos
SamuelLingeman
Occasional Contributor
I've implemented this code and it works great, only the droplist is really narrow, such that the names of the items in my dropdown get cut off quite a bit, is there a way to widen the dropdown list?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Samuel,

   Have you tried adding a width to the dropDownList1 and/or dropDownList2?

Remember if you find a post (any one of them) helpful than click the promote button like below:
0 Kudos