FeatureLayer的用法

當加載FeatureLayer時爲每個Feature增加監聽

            protected function fLayer_graphicAddHandler(event:GraphicEvent):void
            {
                // just so we can add tool tips
                event.graphic.toolTip = event.graphic.attributes.Name + "\n";
                event.graphic.toolTip += "Magnitude " + myOneDecimalFormatter.format(event.graphic.attributes.Magnitude) + " earthquake";
                if (event.graphic.attributes.Num_Deaths)
                {
                    event.graphic.toolTip += "\n(" + event.graphic.attributes.Num_Deaths + " people died)";
                }
            }


            protected function fLayer_graphicAddHandler(event:GraphicEvent):void
            {
                // just so we can add tool tips
                event.graphic.toolTip = event.graphic.attributes.Name + "\n";
                event.graphic.toolTip += "Magnitude " + myOneDecimalFormatter.format(event.graphic.attributes.Magnitude) + " earthquake";
                if (event.graphic.attributes.Num_Deaths)
                {
                    event.graphic.toolTip += "\n(" + event.graphic.attributes.Num_Deaths + " people died)";
                }
            }

查詢時,增加篩選的事件

            private function doSearch():void
            {
                // fLayer.layerDetails.displayField
                fLayer.definitionExpression = "STATE_NAME like '" + qText.text + "'";
            }

            // the following four functions are 'just' error handling and showing/hiding the busy cursor
            protected function fLayer_updateStartHandler(event:LayerEvent):void
            {
                this.cursorManager.setBusyCursor();
            }

            protected function fLayer_updateEndHandler(event:LayerEvent):void
            {
                if (event.fault)
                {
                    trace("updateEnd: " + event.fault); // maybe a badly formatted query?
                }
                else if (event.updateSuccess == false)
                {
                    trace(event.type + ": " + event.updateSuccess + " ... unexpected failure");
                }
                else // things seem OK
                {
                    if (FeatureLayer(event.layer).numGraphics < 1)
                    {
                        Alert.show("Sorry, found no such features, please try something else");
                    }
                }
                this.cursorManager.removeBusyCursor();
            }

            protected function fLayer_faultHandler(event:FaultEvent):void
            {
                Alert.show(event.fault.faultString + "\n\n" + event.fault.faultDetail, "FeatureLayer Fault " + event.fault.faultCode);
            }

            protected function fLayer_loadErrorHandler(event:LayerEvent):void
            {
                Alert.show(event.fault.faultString + "\n\n" + event.fault.faultDetail, "FeatureLayer Load Error " + event.fault.faultCode);
            }


爲Feature增加監聽

        <esri:FeatureLayer id="fLayer"
                           definitionExpression="STATE_NAME='South Carolina'"
                           graphicAdd="fLayer_graphicAddHandler(event)"
                           mode="snapshot"
                           outFields="*"
                           symbol="{defaultsym}"
                           url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3"/>


         protected function fLayer_graphicAddHandler(event:GraphicEvent):void
            {
                event.graphic.addEventListener(MouseEvent.MOUSE_OVER, onMouseOverHandler);
                event.graphic.addEventListener(MouseEvent.MOUSE_OUT, onMouseOutHandler);
            }

            private function onMouseOverHandler(event:MouseEvent):void
            {
                var gr:Graphic = Graphic(event.target);
                gr.symbol = mouseOverSymbol;
                myTextArea.textFlow = TextFlowUtil.importFromString("<span fontWeight='bold'>2000 Population: </span>" + gr.attributes.POP2000.toString() + "<br/>"
                                                                    + "<span fontWeight='bold'>2000 Population per Sq. Mi.: </span>" + gr.attributes.POP00_SQMI.toString() + "<br/>"
                                                                    + "<span fontWeight='bold'>2007 Population: </span>" + gr.attributes.POP2007 + "<br/>"
                                                                    + "<span fontWeight='bold'>2007 Population per Sq. Mi.: </span>" + gr.attributes.POP07_SQMI);
                myMap.infoWindow.label = gr.attributes.NAME;
                myMap.infoWindow.closeButtonVisible = false;
                myMap.infoWindow.show(myMap.toMapFromStage(event.stageX, event.stageY));
            }

            private function onMouseOutHandler(event:MouseEvent):void
            {
                var gr:Graphic = Graphic(event.target);
                gr.symbol = defaultsym;
                myMap.infoWindow.hide();
            }


FeatureLayer選擇要素使之高亮顯示

			protected function button2_clickHandler(event:MouseEvent):void
			{
				var query:Query=new Query();
				query.where="RainYN like '0'";
				fLayer.selectFeatures(query,"new");
			}
			


獲取所有feature


			protected function button2_clickHandler(event:MouseEvent):void
			{
				var arr:ArrayCollection=fLayer.graphicProvider as ArrayCollection;
				Alert.show(arr.length.toString());
				
			}

feature 具有event.graphic.visible=false;屬性。

在權限控制的時候,帥選顯示要素

            protected function button3_clickHandler(event:MouseEvent):void
            {
                fLayer.definitionExpression = "NOT (Name IN('徐圖港西閘站','田大港閘站'))" ;               
            }

FeatureLayer的update_end事件,當更新時,包括地圖放大、縮小、漫遊、重新過濾篩選feature。

				featureLayer.addEventListener(LayerEvent.UPDATE_END,updateEndHandler);

				function updateEndHandler(event:LayerEvent):void{
					var arr:ArrayCollection=featureLayer.graphicProvider as ArrayCollection;
					Alert.show(arr.length.toString());
				}


-------------------------------------------------------------------------------------------------------------------


發佈了16 篇原創文章 · 獲贊 5 · 訪問量 32萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章