QueryTask AS写法

本文详细介绍了如何使用ArcGIS API查询特定州(如阿拉斯加)的城市数据,并通过自定义图形对象将其可视化在地图上。重点在于实现数据查询、属性解析以及在地图中展示城市信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

protected function myMap_initializeHandler(event:MapEvent):void
{
// Query to get the cities under the specified state
var queryTask:QueryTask = new QueryTask();
queryTask.url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0";
queryTask.useAMF = false;
var query:Query = new Query();
query.outSpatialReference = myMap.spatialReference;
query.outFields = [ "CITY_NAME", "AGE_UNDER5", "AGE_5_17", "AGE_18_64", "AGE_65_UP" ];
query.returnGeometry = true;
query.where = "STATE_NAME = 'Alaska' AND TYPE = 'city'";
queryTask.execute(query, new AsyncResponder(onResult, onFault));
// add the graphic on the map
function onResult(featureSet:FeatureSet, token:Object = null):void
{
for each (var myGraphic:Graphic in featureSet.features)
{
myGraphicsLayer.add(myGraphic);
// creating an arraycollection from the graphic attriobutes
var object:ArrayCollection = new ArrayCollection(
[
{ CITY_NAME: myGraphic.attributes.CITY_NAME, AGE: "Under 5", VALUE: myGraphic.attributes.AGE_UNDER5 },
{ CITY_NAME: myGraphic.attributes.CITY_NAME, AGE: "Age 5-17", VALUE: myGraphic.attributes.AGE_5_17 },
{ CITY_NAME: myGraphic.attributes.CITY_NAME, AGE: "Age 18-64", VALUE: myGraphic.attributes.AGE_18_64 },
{ CITY_NAME: myGraphic.attributes.CITY_NAME, AGE: "65 and up", VALUE: myGraphic.attributes.AGE_65_UP }
]);
myGraphic.attributes = object;
}
}
function onFault(info:Object, token:Object = null):void
{
Alert.show(info.toString());
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值