var OIDArr:Array = new Array; for(anX=0;anX<targetLayer.selectedFeatures.length;anX++){ Alert.show(targetLayer.selectedFeatures[anX].attributes[targetLayer.layerDetails.objectIdField]) }
var OIDArr:Array = new Array; for(anX=0;anX<targetLayer.selectedFeatures.length;anX++){ Alert.show(targetLayer.selectedFeatures[anX].id) }
protected function InvertSelBtn_clickHandler(event:MouseEvent):void{ //reset all three arrays features = []; selected = []; notSelected = []; this.cursorManager.setBusyCursor(); //add features that are currently selected to array selected, then clear selection var i:Number = new Number; for(i=0;i<targetLayer.selectedFeatures.length;i++){ var selFeature:Graphic = targetLayer.selectedFeatures; selected.push(selFeature); } targetLayer.clearSelection(); //this selects all features var query:Query = new Query; query.where = "1=1"; //this.cursorManager.setBusyCursor(); targetLayer.selectFeatures(query,"new",new AsyncResponder(onInvertSelectAllResult, onInvertSelectAllFault)); } //if select all during invert fails private function onInvertSelectAllFault(info:Array, token:FeatureLayer = null):void{ Alert.show("Error During Invert Selection."); } //if select all during invert is successful - continue with invert process private function onInvertSelectAllResult(info:Array, token:FeatureLayer = null):void{ var marker:Boolean = false; //upon result of selecting all features, add all features from targetLayer to array features, then clear selection var i:Number = new Number; for(i=0;i<targetLayer.selectedFeatures.length;i++){ var feature:Graphic = targetLayer.selectedFeatures; features.push(feature); } targetLayer.clearSelection(); //nested for loop to iterate through features (run once for each feature in targetLayer) //then iterate through selected (run once for each feature in selFeatures) //if their objects match, marker set to true - if at the end of the inside loop marker is still false //no match was found and the feature is loaded into notSelected var x1:Number = new Number; var y1:Number = new Number; for(x1=0;x1<features.length;x1++){ marker=false; for(y1=0;y1<selected.length;y1++){ //if there is ever a match, mark boolean as true, and features wont be added to notSelected //i will have to change this to work with line, poly -for now points is fine if(features[x1].geometry.toString() == selected[y1].geometry.toString()){ //this lets us know that there was a match and nothing should be added to notSelected marker=true; } } //if match wasnt found in inside for loop, then the feature wasnt selected and will be added to notSelected if(marker===false){ notSelected.push(features[x1]); } } //pass the array of unselected features into featSet, then pass to unionGeom to get a geometry back var featSet:FeatureSet = new FeatureSet(notSelected); var unionGeom:Geometry = SelectionWidgetUtil.unionGeoms(featSet); //now run query with unionGeom var query1:Query = new Query; query1.geometry=unionGeom; targetLayer.selectFeatures(query1,"new",new AsyncResponder(onInvertResult, onInvertFault, targetLayer)); } //on invert selection result private function onInvertResult(info:Array, token:FeatureLayer = null):void { this.cursorManager.removeBusyCursor(); //this makes the selection results page be displayed upon selection /* var e:Event = new SelectionFeatureLayerEvent(SelectionFeatureLayerEvent.SHOW_RESULTS, null); dispatchEvent(e); */ } //on invert selection fault private function onInvertFault(info:Object, token:Object = null):void { this.cursorManager.removeBusyCursor(); Alert.show("Could not complete Selection. Please try again.\n" + info.toString(), "Selection Error", Alert.OK); }
protected function InvertSelBtn_clickHandler(event:MouseEvent):void{ var i:Number = new Number; var marker:Boolean = false; //holds all features in the targetLayer var features:Array = []; //holds all currently selected features in targetLayer var selected:Array = []; //holds all features that are not currently selected - to be selected var notSelected:Array = []; //add features that are currently selected to array selected, then clear selection for(i=0;i<targetLayer.selectedFeatures.length;i++){ var selFeature:Graphic = targetLayer.selectedFeatures; selected.push(selFeature); } //last query selects all points targetLayer.clearSelection(); //this selects all features var query:Query = new Query; query.where = "1=1"; //this.cursorManager.setBusyCursor(); targetLayer.selectFeatures(query,"new",new AsyncResponder(onResult, onFault)); //if select all fails function onFault(info:Array, token:FeatureLayer = null):void{ Alert.show("Error During Invert Selection."); } //if selection is successful function onResult(info:Array, token:FeatureLayer = null):void{ //upon result of selecting all features, add all features from targetLayer to array features, then clear selection for(i=0;i<targetLayer.selectedFeatures.length;i++){ var feature:Graphic = targetLayer.selectedFeatures; features.push(feature); } //targetLayer.clearSelection(); //nested for loop to iterate through features (run once for each feature in targetLayer) //then iterate through selected (run once for each feature in selFeatures) //if their objects match, marker set to true - if at the end of the inside loop marker is still false //no match was found and for(x=0;x<features.length;x++){ for(y=0;y<selected.length;y++){ //if there is ever a match, mark boolean as true, and features wont be added to notSelected //i will have to change this to work with line, poly -for now points is fine if(features.geometry as MapPoint === selected.geometry as MapPoint){ marker=true; } } //if match wasnt found in inside for loop, then the feature wasnt selected and will be added to notSelected if(marker===false){ notSelected.push(features); } //speed things up and break the loop if all non selected features have been added if(features.length<=(selected.length+notSelected.length)){ break; } } //this alert broke the selection screen for some reason lol //Alert.show("# features selected: " +selected.length.toString()+"+ # features not selected: "+notSelected.length.toString()+"= # features total: "+features.length.toString()); //loop through notSelected, adding each feature in it to selection of targetLayer targetLayer.clearSelection(); Alert.show(notSelected.length.toString()); var query1:Query = new Query; query1.geometry = notSelected.geometry; query1.spatialRelationship=Query.SPATIAL_REL_OVERLAPS; targetLayer.selectFeatures(query1,"new",null); Alert.show(targetLayer.selectedFeatures.length.toString()); } }
protected function InvertSelBtn_clickHandler(event:MouseEvent):void{ var i:Number = new Number; //array to hold selected features (graphics) in target layer var selected:Array = []; for(i=0;i<targetLayer.selectedFeatures.length;i++){ var graphic:Graphic = targetLayer.selectedFeatures; selected.push(graphic); } //clear selected features in targetLayer after selected in loaded with the features that were selected targetLayer.clearSelection(); Alert.show("before loading all features"); //this holds all features in the targetLayer var targetLayerFeatures:ArrayCollection = new ArrayCollection; targetLayerFeatures = targetLayer.graphicProvider as ArrayCollection; Alert.show(targetLayerFeatures.contains(selected[1]).toString());
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.