QueryTask AS 쓰기

2424 단어 query
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());
                }
            }

좋은 웹페이지 즐겨찾기