const objectIdField:String = event.featureLayer.tableDetails.objectIdField;
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:esri="http://www.esri.com/2008/ags" pageTitle="Related records"> <s:layout> <s:VerticalLayout gap="0"/> </s:layout> <fx:Script> <![CDATA[ import com.esri.ags.FeatureSet; import com.esri.ags.events.FeatureLayerEvent; import com.esri.ags.events.MapMouseEvent; import com.esri.ags.geometry.Extent; import com.esri.ags.tasks.supportClasses.Query; import com.esri.ags.tasks.supportClasses.RelationshipQuery; import mx.controls.Alert; import mx.rpc.AsyncResponder; [Bindable] private var selectedObjectID:Number; [Bindable] private var relatedRecordsCount:Number; private function findWells(event:MapMouseEvent):void { // find wells near the mouse click var tol:Number = map.extent.width / map.width * 5; var x:Number = event.mapPoint.x; var y:Number = event.mapPoint.y; var queryExtent:Extent = new Extent(x - tol, y - tol, x + tol, y + tol, event.mapPoint.spatialReference); var thisSelectionQuery:Query = new Query(); thisSelectionQuery.geometry = queryExtent; wellsLayer.selectFeatures(thisSelectionQuery, FeatureLayer.SELECTION_NEW); } private function wellsLayer_selectionCompleteHandler(event:FeatureLayerEvent):void { relatedDatagrid.dataProvider = null; // check the first return feature to see if it has any related features if (event.features.length > 0) { relatedTopsQuery.objectIds = [ event.features[0].attributes.OBJECTID ]; selectedObjectID = event.features[0].attributes.OBJECTID; wellsLayer.queryRelatedFeatures(relatedTopsQuery, new AsyncResponder(onResult, onFault)); function onResult(relatedRecords:Object, token:Object = null):void { // get related records for the first feature var fset:FeatureSet = (relatedRecords[event.features[0].attributes.OBJECTID]); if (fset is FeatureSet) { relatedDatagrid.dataProvider = new ArrayCollection(fset.attributes) relatedRecordsCount = fset.attributes.length; } else { Alert.show("No related records for well #" + event.features[0].attributes.OBJECTID, "No related records"); relatedRecordsCount = 0; } } function onFault(info:Object, token:Object = null):void { map.infoWindow.hide(); Alert.show(info.toString(), "queryRelatedFeatures Problem"); } } else { map.infoWindow.hide(); Alert.show("No wells found here, please try somewhere else.", "No features"); } } protected function saveRelatedRecordsForObjectID(event:MouseEvent):void { } protected function deleteRelatedRecordsForObjectID(event:MouseEvent):void { } ]]> </fx:Script> <fx:Declarations> <esri:RelationshipQuery id="relatedTopsQuery" outFields="[OBJECTID,API_NUMBER,ELEVATION,FORMATION,TOP]" relationshipId="3"/> </fx:Declarations> <s:controlBarLayout> <s:VerticalLayout gap="10" paddingBottom="7" paddingLeft="10" paddingRight="10" paddingTop="7"/> </s:controlBarLayout> <s:controlBarContent> <s:Button click="saveRelatedRecordsForObjectID(event)" label="Save" visible="{relatedRecordsCount > 0}"/> <s:Button click="deleteRelatedRecordsForObjectID(event)" label= "Delete Records" visible="{relatedRecordsCount > 0}"/> </s:controlBarContent> <esri:Map id="map" mapClick="findWells(event)"> <esri:extent> <esri:Extent xmin="-10854000" ymin="4502000" xmax="-10829000" ymax="4524000"> <esri:SpatialReference wkid="102100"/> </esri:Extent> </esri:extent> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"/> <esri:ArcGISDynamicMapServiceLayer url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer"> <esri:visibleLayers> <s:ArrayCollection> <fx:Number>0</fx:Number> <fx:Number>1</fx:Number> </s:ArrayCollection> </esri:visibleLayers> </esri:ArcGISDynamicMapServiceLayer> <esri:FeatureLayer id="wellsLayer" mode="selection" outFields="[completion,plug_date]" selectionComplete="wellsLayer_selectionCompleteHandler(event)" url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer/0"> <esri:infoWindowRenderer> <fx:Component> <esri:LabelDataRenderer> <esri:layout> <s:VerticalLayout/> </esri:layout> <esri:label>Well ID {data.OBJECTID}</esri:label> <s:Label text="Plug date: {data.plug_date ? new Date(data.plug_date) : 'No date available'}"/> <s:Label text="Completion: {data.completion ? new Date(data.completion) : 'No date available'}"/> </esri:LabelDataRenderer> </fx:Component> </esri:infoWindowRenderer> </esri:FeatureLayer> </esri:Map> <s:DataGrid id="relatedDatagrid" width="100%" height="45%"> <s:columns> <s:ArrayList> <s:GridColumn dataField="OBJECTID" headerText="ID"/> <s:GridColumn dataField="API_NUMBER" headerText="API Number"/> <s:GridColumn dataField="ELEVATION" headerText="Elevation"/> <s:GridColumn dataField="FORMATION" headerText="Formation"/> <s:GridColumn dataField="TOP" headerText="Top"/> </s:ArrayList> </s:columns> </s:DataGrid> </s:Application>
<s:TextInput id="qText" width="100%" enter="doSearch()" text="AU" toolTip="You may use % as a wildcard, e.g., A%"/> <s:Button click="doSearch()" label="Search"/>
{ var urltable:String = "http://tfsgis-iisd01:6080/arcgis/rest/services/SARS_WILSON/RELATED_TABLES/FeatureServer/1" //or you can use your feature layer layerDetails informations to get the related table Id. var yourTable:FeatureLayer; //Here you're casting the table as a FeatureLayer so it's editable yourTable = new FeatureLayer(urltable, null, null) as FeatureLayer; yourTable.outFields = ["*"]; yourTable.definitionExpression = "Office like '" + qText.text + "'"; myAttributeTable.featureLayer = yourTable }
protected function myFeatureLayer_SelectionCompleteHandler(event:FeatureLayerEvent):void { var query:Query = new Query; query.where = "Office = " + myFeatureLayer.selectedFeatures[0].attributes.NAME_SH; yourTable.selectFeatures(query, FeatureLayer.SELECTION_NEW); }
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:esri="http://www.esri.com/2008/ags" pageTitle="Attribute Table"> <s:layout> <s:VerticalLayout gap="0"/> </s:layout> <fx:Script> <![CDATA[ import com.esri.ags.Graphic; import com.esri.ags.events.AttributeTableEvent; import com.esri.ags.events.FeatureLayerEvent; import com.esri.ags.layers.supportClasses.FeatureEditResult; import com.esri.ags.layers.supportClasses.FeatureEditResults; import com.esri.ags.layers.supportClasses.Field; import com.esri.ags.tasks.supportClasses.Query; import mx.controls.Alert; import mx.events.FlexEvent; import mx.rpc.AsyncResponder; import mx.rpc.Fault; /* [Bindable] private var urltable:String = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/MapServer/1" //or you can use your feature layer layerDetails informations to get the related table Id. private var yourTable:FeatureLayer; //Here you're casting the table as a FeatureLayer so it's editable protected function application1_initializeHandler(event:FlexEvent):void { yourTable = new FeatureLayer(urltable, null, null) as FeatureLayer; }*/ protected function myMap_clickHandler(event:MouseEvent):void { if (event.target is Graphic || event.target.parent is Graphic) { var graphic:Graphic = event.target is Graphic ? Graphic(event.target) : Graphic(event.target.parent); var query:Query = new Query; query.objectIds = [graphic.attributes[myFeatureLayer.layerDetails.objectIdField]]; myFeatureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW); myFeatureLayer.addEventListener(FeatureLayerEvent.SELECTION_COMPLETE,myFeatureLayer_SelectionCompleteHandler); } else { myFeatureLayer.clearSelection(); yourTable.clearSelection(); } } protected function myFeatureLayer_SelectionCompleteHandler(event:FeatureLayerEvent):void { var query:Query = new Query; query.where = "sf_311_serviceoid = " + myFeatureLayer.selectedFeatures[0].attributes.objectid; yourTable.selectFeatures(query, FeatureLayer.SELECTION_NEW); } protected function fdg_updateFeatureHandler(event:AttributeTableEvent):void { const attributes:Object = {}; const objectIdField:String = event.featureLayer.layerDetails.objectIdField; attributes[objectIdField] = event.feature.attributes[objectIdField]; attributes[event.field.name] = event.newValue; // change the attributes on client right away event.feature.attributes[event.field.name] = event.newValue; const feature:Graphic = new Graphic(null, null, attributes); const updates:Array = [ feature ]; event.featureLayer.applyEdits(null, updates, null, false, new AsyncResponder(featureLayer_editsCompleteHandler, featureLayer_faultHandler, { feature: event.feature, field: event.field, oldValue: event.oldValue })); } protected function fdg_deleteFeaturesHandler(event:AttributeTableEvent):void { const deletes:Array = event.features; event.featureLayer.applyEdits(null, null, deletes, false, new AsyncResponder(featureLayer_editsCompleteHandler, featureLayer_faultHandler)); } private function featureLayer_editsCompleteHandler(featureEditResults:FeatureEditResults, token:Object = null):void { var doRefresh:Boolean = false; for each (var deleteResult:FeatureEditResult in featureEditResults.deleteResults) { if (deleteResult.success === false) { Alert.show("Could not delete feature"); doRefresh = true; } } for each (var updateResult:FeatureEditResult in featureEditResults.updateResults) { const feature:Graphic = token.feature; if (updateResult.success === false) { Alert.show("Could not update feature, Restoring old value", "Error"); const field:Field = token.field; feature.attributes[field.name] = token.oldValue; doRefresh = true; } else { feature.refresh(); } } if (doRefresh) { myAttributeTable.refresh(); } } private function featureLayer_faultHandler(fault:Fault, token:Object = null):void { Alert.show(fault.faultString, "Fault"); myAttributeTable.refresh(); } ]]> </fx:Script> <fx:Declarations> <esri:FeatureLayer id="yourTable" outFields="*" url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/1"/> </fx:Declarations> <s:controlBarContent> <s:RichText width="100%"> This sample demonstrates how to use the AttributeTable component which allows viewing and editing feature atttributes. The component uses a data grid where the columns correspond to the fields of a feature layer. The application also allows user to click on a feature and select it. The AttributeTable then displays the selection by highlighting the corresponding row in the grid. </s:RichText> </s:controlBarContent> <esri:Map id="myMap" width="100%" height="60%" click="myMap_clickHandler(event)"> <esri:extent> <esri:Extent id="sheepfire" xmin="-13638587" ymin="4543797" xmax="-13620242" ymax="4549912"> <esri:SpatialReference wkid="102100"/> </esri:Extent> </esri:extent> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/> <esri:FeatureLayer id="myFeatureLayer" mode="onDemand" outFields="*" url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0"/> </esri:Map> <s:Line width="100%"> <s:stroke> <s:SolidColorStroke color="0x000000" weight="1"/> </s:stroke> </s:Line> <s:BorderContainer width="100%" height="40%" backgroundColor="0xEEEEEE" borderVisible="false"> <s:layout> <s:HorizontalLayout paddingLeft="5" paddingRight="5" paddingTop="2"/> </s:layout> <esri:AttributeTable id="myAttributeTable" width="100%" height="100%" deleteFeatures="fdg_deleteFeaturesHandler(event)" featureLayer="{yourTable}" updateFeature="fdg_updateFeatureHandler(event)"> </esri:AttributeTable> </s:BorderContainer> </s:Application>
<fx:Declarations> <esri:FeatureLayer id="yourTable" outFields="*" url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/1"/> </fx:Declarations>
<?xml version="1.0" encoding="utf-8"?><s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:esri="http://www.esri.com/2008/ags" pageTitle="Attribute Table"> <s:layout> <s:VerticalLayout gap="0"/> </s:layout> <fx:Script> <![CDATA[ import com.esri.ags.Graphic; import com.esri.ags.events.AttributeTableEvent; import com.esri.ags.events.FeatureLayerEvent; import com.esri.ags.layers.supportClasses.FeatureEditResult; import com.esri.ags.layers.supportClasses.FeatureEditResults; import com.esri.ags.layers.supportClasses.Field; import com.esri.ags.tasks.supportClasses.Query; import mx.controls.Alert; import mx.events.FlexEvent; import mx.rpc.AsyncResponder; import mx.rpc.Fault; /* [Bindable] private var urltable:String = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/MapServer/1" //or you can use your feature layer layerDetails informations to get the related table Id. private var yourTable:FeatureLayer; //Here you're casting the table as a FeatureLayer so it's editable protected function application1_initializeHandler(event:FlexEvent):void { yourTable = new FeatureLayer(urltable, null, null) as FeatureLayer; }*/ protected function myMap_clickHandler(event:MouseEvent):void { if (event.target is Graphic || event.target.parent is Graphic) { var graphic:Graphic = event.target is Graphic ? Graphic(event.target) : Graphic(event.target.parent); var query:Query = new Query; query.objectIds = [graphic.attributes[myFeatureLayer.layerDetails.objectIdField]]; myFeatureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW); myFeatureLayer.addEventListener(FeatureLayerEvent.SELECTION_COMPLETE,myFeatureLayer_SelectionCompleteHandler); } else { myFeatureLayer.clearSelection(); yourTable.clearSelection(); } } protected function myFeatureLayer_SelectionCompleteHandler(event:FeatureLayerEvent):void { var query:Query = new Query; query.where = "sf_311_serviceoid = " + myFeatureLayer.selectedFeatures[0].attributes.objectid; yourTable.selectFeatures(query, FeatureLayer.SELECTION_NEW); } protected function fdg_updateFeatureHandler(event:AttributeTableEvent):void { //TODO } protected function fdg_deleteFeaturesHandler(event:AttributeTableEvent):void { //TODO } private function featureLayer_editsCompleteHandler(featureEditResults:FeatureEditResults, token:Object = null):void { //TODO } private function featureLayer_faultHandler(fault:Fault, token:Object = null):void { Alert.show(fault.faultString, "Fault"); myAttributeTable.refresh(); } ]]> </fx:Script> <fx:Declarations> <esri:FeatureLayer id="yourTable" outFields="*" url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/1"/> </fx:Declarations> <s:controlBarContent> <s:RichText width="100%"> This sample demonstrates how to use the AttributeTable component which allows viewing and editing feature atttributes. The component uses a data grid where the columns correspond to the fields of a feature layer. The application also allows user to click on a feature and select it. The AttributeTable then displays the selection by highlighting the corresponding row in the grid. </s:RichText> </s:controlBarContent> <esri:Map id="myMap" width="100%" height="60%" click="myMap_clickHandler(event)"> <esri:extent> <esri:Extent id="sheepfire" xmin="-13638587" ymin="4543797" xmax="-13620242" ymax="4549912"> <esri:SpatialReference wkid="102100"/> </esri:Extent> </esri:extent> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/> <esri:FeatureLayer id="myFeatureLayer" mode="onDemand" outFields="*" url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0"/> </esri:Map> <s:Line width="100%"> <s:stroke> <s:SolidColorStroke color="0x000000" weight="1"/> </s:stroke> </s:Line> <s:BorderContainer width="100%" height="40%" backgroundColor="0xEEEEEE" borderVisible="false"> <s:layout> <s:HorizontalLayout paddingLeft="5" paddingRight="5" paddingTop="2"/> </s:layout> <esri:AttributeTable id="myAttributeTable" width="100%" height="100%" deleteFeatures="fdg_deleteFeaturesHandler(event)" featureLayer="{yourTable}" updateFeature="fdg_updateFeatureHandler(event)"> </esri:AttributeTable> </s:BorderContainer> </s:Application>
var url:String = "theURLpathToYourStandaloneTable" //or you can use your feature layer layerDetails informations to get the related table Id. var yourTable:FeatureLayer = new FeatureLayer(url, null, null) as FeatureLayer ; //Here you're casting the table as a FeatureLayer so it's editable
query.where = "yourTable_displayFeatureLayerID = yourDisplayedFeatureLayerID";
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.