this.addEventListener(GraphicEvent.GRAPHIC_ADD, onGraphicAdd); this.addEventListener(GraphicEvent.GRAPHIC_REMOVE, onGraphicRemove); this.addEventListener(GraphicsLayerEvent.GRAPHICS_CLEAR, onGraphicsClear);
package org.lacsd.layers { import com.esri.ags.Graphic; import com.esri.ags.events.GraphicEvent; import com.esri.ags.events.GraphicsLayerEvent; import com.esri.ags.layers.FeatureLayer; import flash.events.MouseEvent; import mx.utils.ObjectUtil; public class TestFeatureLayer extends FeatureLayer { public function TestFeatureLayer(url:String=null, proxyURL:String=null, token:String=null) { super(url, proxyURL, token); this.addEventListener(GraphicEvent.GRAPHIC_ADD, onGraphicAdd); this.addEventListener(GraphicEvent.GRAPHIC_REMOVE, onGraphicRemove); this.addEventListener(GraphicsLayerEvent.GRAPHICS_CLEAR, onGraphicsClear); } private function addListener(graphic:Graphic):void { graphic.addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent):void { graphic.useHandCursor = true; graphic.buttonMode = true; map.openHandCursorVisible = false; trace("mouse over"); }); graphic.addEventListener(MouseEvent.MOUSE_OUT, function(event:MouseEvent):void { graphic.useHandCursor = false; graphic.buttonMode = false; map.openHandCursorVisible = true; trace("mouse out"); }); graphic.addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void { trace("Click"); }) } private function onGraphicAdd(event:GraphicEvent):void { trace("graphic has been added", ObjectUtil.toString(event.graphic.attributes)); this.addListener(event.graphic); // add listeners here } private function onGraphicRemove(event:GraphicEvent):void { trace("graphic has been removed", ObjectUtil.toString(event.graphic.attributes)); // remove listeners here } private function onGraphicsClear(event:GraphicsLayerEvent):void { // may want to find a way to remove listeners here or add them with a weak reference } } }
public class BuildingFeatureLayer extends FeatureLayer { private var defaultSymbol:SimpleFillSymbol = new SimpleFillSymbol(); private var mouseOverSymbol:SimpleFillSymbol = new SimpleFillSymbol(); public function BuildingFeatureLayer() { super(); setLoaded(true); defaultSymbol.color = 0xFFFFFF; defaultSymbol.alpha = 0.1; mouseOverSymbol.color = 0xFF0000; mouseOverSymbol.alpha = 0.5; this.mode = "snapshot"; this.symbol=defaultSymbol; this.outFields = []; this.url="http://<server>/ArcGIS/rest/services/layers/<layername>/MapServer/0" this.useAMF=false; this.visible=true; } override protected function updateLayer():void { super.updateLayer(); } // OVERRIDING THIS METHOD IS NOT PERMITTED BY THE API override public function add(graphic:Graphic):void { graphic.toolTip = graphic.attributes.BUILDING_NAME; graphic.addEventListener( MouseEvent.ROLL_OVER, graphic_mouseOverHandler ); graphic.addEventListener( MouseEvent.ROLL_OUT, graphic_mouseOutHandler ); }
queryTask.execute(query, new AsyncResponder(onResult, onFault)); function onResult(featureSet:FeatureSet, token:Object = null):void { for each (var graphic:Graphic in featureSet.features) { graphic.addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent):void { graphic.useHandCursor = true; graphic.buttonMode = true; map.openHandCursorVisible = false; trace("mouse over"); }); graphic.addEventListener(MouseEvent.MOUSE_OUT, function(event:MouseEvent):void { graphic.useHandCursor = false; graphic.buttonMode = false; map.openHandCursorVisible = true; trace("mouse out"); }); graphic.addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void { trace("Click"); }) } }
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.