Hello.
Im doing a widget that has a grid with the result of a query that i did previously.
My question is. When i click on the grid i can get one of the attributes in the grid with the "event.currentTarget.selectedItem.ATTRIBUTETOCHOOSE"
and then i do another query asking the geometry of that attribute to make a zoom in the map when its selected.
The thing is, i dont wanna make another query to get the featureSet of that attribute, because in the previous query i have them all. So how i can search just for the "selected" attribute in the previous featureSet that i used already?
Thanks.
My code is this one, and it works but i want to change it for not to do the second query.
This is the code for the query to ask some routes on the arcgis srv and put the data in a grid:
public function searchRoute():void
{
var queryTaskRuta:QueryTask = new QueryTask();
queryTaskRuta.showBusyCursor = true;
queryTaskRuta.url = "XXXXXXXXXXX";
queryTaskRuta.useAMF = false;
var queryRutaSelected:Query = new Query();
queryRutaSelected.returnGeometry = true;
queryRutaSelected.outFields = ["*"];
//queryRutaSelected.where = "ARCGIS.dbo.CLIENTES_DATA_DATOS_006.nis IN (118936, 118934)";
queryRutaSelected.where = "ARCGIS.dbo.CLIENTES_DATA_DATOS_006.cd_sector =" + CboSector.selectedIndex + " and ARCGIS.dbo.CLIENTES_DATA_DATOS_006.cd_area= " + TxtArea.text
queryTaskRuta.execute(queryRutaSelected, new AsyncResponder(onResult, onFault));
function onResult(featureSet:FeatureSet, token:Object = null):void
{
if (featureSet.features.length == 0){
Alert.show("Ruta no encontrada","Busqueda de Rutas");
}
else{
try{
setBusyCursor();
for (var x:Number=0; x < featureSet.features.length; x++)
{
//agregar a variables y luego al objeto que se muestra en la tabla...
var nis:Number = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.nis"]; var nm_estado_suministro:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.nm_estado_suministro"]; var zona:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.zona"]; var nm_tarifa:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.nm_tarifa"]; var categoria:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.categoria"]; var oficina:String=featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.oficina"]; var empalme:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.empalme"]; var cd_area_tipica:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.cd_area_tipica"]; var cd_sector:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.cd_sector"]; var cd_area:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.cd_area"]; var consumidor:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.consumidor"]; var nm_tipo_suministro:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.nm_tipo_suministro"]; var resp_tipo_cliente:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.resp_tipo_cliente"]; var res_tipo_nodo:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.res_tipo_nodo"]; var resp_rotulo_nodo:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.resp_rotulo_nodo"]; var resp_id_nodo:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.resp_id_nodo"]; var resp_id_sed:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.resp_id_sed"]; var direccion_resu:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.direccion_resu"]; var id_dir_dmps:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.id_dir_dmps"]; var cliente_bt:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.cliente_bt"]; var cliente_mt:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.cliente_mt"]; var tipo_cliente:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.tipo_cliente"]; var estado_direccion:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.estado_direccion"]; var estado_poste:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.estado_poste"]; var estado_comuna:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.estado_comuna"]; var tipo_cnx:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.tipo_cnx"]; var estado_final:String = featureSet.features
.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.estado_final"]; featureSet.features
.attributes["nis"] = nis; featureSet.features
.attributes["nm_estado_suministro"] = nm_estado_suministro; featureSet.features
.attributes["zona"] = zona; featureSet.features
.attributes["nm_tarifa"] = nm_tarifa; featureSet.features
.attributes["categoria"] = categoria; featureSet.features
.attributes["oficina"] = oficina; featureSet.features
.attributes["empalme"] = empalme; featureSet.features
.attributes["cd_area_tipica"] = cd_area_tipica; featureSet.features
.attributes["cd_sector"] = cd_sector; featureSet.features
.attributes["cd_area"] = cd_area; featureSet.features
.attributes["consumidor"] = consumidor; featureSet.features
.attributes["resp_tipo_cliente"] = resp_tipo_cliente; featureSet.features
.attributes["res_tipo_nodo"] = res_tipo_nodo; featureSet.features
.attributes["resp_rotulo_nodo"] = resp_rotulo_nodo; featureSet.features
.attributes["resp_id_nodo"] = resp_id_nodo; featureSet.features
.attributes["resp_id_sed"] = resp_id_sed; featureSet.features
.attributes["direccion_resu"] = direccion_resu; featureSet.features
.attributes["id_dir_dmps"] = id_dir_dmps; featureSet.features
.attributes["cliente_bt"] = cliente_bt; featureSet.features
.attributes["cliente_mt"] = cliente_mt; featureSet.features
.attributes["tipo_cliente"] = tipo_cliente; featureSet.features
.attributes["estado_direccion"] = estado_direccion; featureSet.features
.attributes["estado_poste"] = estado_poste; featureSet.features
.attributes["estado_comuna"] = estado_comuna; featureSet.features
.attributes["tipo_cnx"] = tipo_cnx; featureSet.features
.attributes["estado_final"] = estado_final; coleccion.addItem(featureSet.features
.attributes); fset=featureSet;
var mp:MapPoint=featureSet.features
.geometry as MapPoint; var myGraphic:Graphic = new Graphic(new MapPoint(mp.x,mp.y, new SpatialReference (102100)));
myGraphic.symbol=new SimpleMarkerSymbol("circle",8,0xFF3300)
graphicsLayer.add(myGraphic);
map.zoomTo(featureSet.features
.geometry); map.level = 15;
map.addLayer(graphicsLayer);
}
}catch(err:Error){
Alert.show("Error al graficar","Route Search");
}
myViewStack.selectedIndex = 1;
removeBusyCursor();
}
}
function onFault(info:Object, token:Object = null):void
{
Alert.show("Ruta No existe","Route Search");
removeBusyCursor();
}
}
This is the code when the user click on the grid and extracts the "nis" attribute to search again in another query to get the geometry to zoom it on the map, also put the InfoWindow with some of the data of the clicked field on the grid. (i want to change this for using the featureSet that i have in the other query and search the clicked from there)
protected function gridTest_clickHandler(event:MouseEvent):void
{
var seleccionado:String = new String(event.currentTarget.selectedItem.nis);
//Configuración ventana infoWindow datos
var popUpInfo:PopUpInfo = new PopUpInfo;
popUpInfo.title = seleccionado;
popUpInfo.description = String(event.currentTarget.selectedItem.zona) + "<br>" + String(event.currentTarget.selectedItem.direccion_resu);
var q:QueryTask = new QueryTask();
q.showBusyCursor = true;
q.url = "xxxxxxxxxxxxx";
q.useAMF = false;
var r:Query = new Query();
r.returnGeometry = true;
r.where = "ARCGIS.dbo.CLIENTES_DATA_DATOS_006.nis =" + seleccionado;
q.execute(r, new AsyncResponder(onResult, onFault));
function onResult(featureSet:FeatureSet, token:Object = null):void
{
try{
for each (var myGraphic:Graphic in featureSet.features)
{
myGraphic.symbol=new SimpleMarkerSymbol("diamond",10,0x00FF00)
var mp:MapPoint=featureSet.features[0].geometry as MapPoint;
graphicsLayer.add(myGraphic);
map.zoomTo(featureSet.features[0].geometry);
map.level = 16;
//Configuración ventana infoWindow con graphic
popUpRenderer.popUpInfo = popUpInfo;
popUpRenderer.graphic = myGraphic;
map.infoWindow.content = popUpRenderer;
map.infoWindow.contentOwner = popUpRenderer.graphic;
map.infoWindow.show(mp);
}
}catch(err:Error){
Alert.show("no se pudo hacer zoom al equipo seleccionado");
}
}
function onFault(info:Object, token:Object = null):void
{
Alert.show("nis no encontrado");
}
}
Solved! Go to Solution.
Evelyn,
Here is a sample that works with joined data.
<?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">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import com.esri.ags.FeatureSet;
import com.esri.ags.Graphic;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.symbols.SimpleMarkerSymbol;
import com.esri.ags.tasks.QueryTask;
import com.esri.ags.tasks.supportClasses.Query;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.rpc.AsyncResponder;
[Bindable]
private var listBridges:ArrayCollection;
protected function equiposAP_clickHandler(event:MouseEvent):void
{
var queryTaskEquipo:QueryTask = new QueryTask();
queryTaskEquipo.url = "http://gislap183/arcgis/rest/services/ParcelTest/MapServer/1";
queryTaskEquipo.useAMF = true;
var queryEquipo:Query = new Query();
queryEquipo.outFields = ["*"];
queryEquipo.returnGeometry = true;
queryEquipo.where = "1=1";
queryEquipo.outSpatialReference = map.spatialReference;
queryTaskEquipo.execute(queryEquipo, new AsyncResponder(onResult, onFault));
function onResult(featureSet:FeatureSet, token:Object = null):void
{
for (var x:Number=0; x < featureSet.features.length; x++){
//var mp:MapPoint=featureSet.features
.geometry as MapPoint; //var myGraphic:Graphic = new Graphic(new MapPoint(mp.x,mp.y, new SpatialReference (102100)), new SimpleMarkerSymbol("circle",8,0xFF3300), featureSet.features
.attributes); graphicsLayer.add(featureSet.features
); }
listBridges = new ArrayCollection(featureSet.attributes);
}
function onFault(info:Object, token:Object = null):void
{
Alert.show("Error "+ info.toString());
}
}
protected function gridEquipos_clickHandler(event:MouseEvent):void
{
var seleccionado:String = new String(event.currentTarget.selectedItem["Parcels3.PPIN"]);
for (var g:int = 0; g < graphicsLayer.numGraphics; g++){
var tGra:Graphic = graphicsLayer.graphicProvider
as Graphic; if (tGra.attributes["Parcels3.PPIN"] == seleccionado){
map.zoomTo(tGra.geometry);
break;
}
}
}
private function getLabel(item:Object,column:DataGridColumn):String
{
return item[column.dataField];
}
]]>
</fx:Script>
<s:controlBarLayout>
<s:VerticalLayout gap="10"
paddingBottom="7"
paddingLeft="10"
paddingRight="10"
paddingTop="7"/>
</s:controlBarLayout>
<s:controlBarContent>
<s:RichText width="100%">
This sample demonstrates how to populate a datagrid with the results of a querytask
</s:RichText>
<s:Button id="popButton"
click="equiposAP_clickHandler(event)"
label="execute query..."/>
</s:controlBarContent>
<esri:Map id="map" height="100%" width="100%">
<esri:extent>
<esri:Extent xmax="-9518156.843666727" ymax="4029927.412560757"
xmin="-9592690.117733276" ymin="3963966.655639243">
<esri:SpatialReference wkid="102100" >
</esri:SpatialReference>
</esri:Extent>
</esri:extent>
<esri:ArcGISTiledMapServiceLayer url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" />
<esri:GraphicsLayer id="graphicsLayer" />
</esri:Map>
<mx:DataGrid id="gridEquipos" width="100%" height="30%" visible="true" editable="false" dragEnabled="true"
dropEnabled="true" dataProvider="{listBridges}"
click="gridEquipos_clickHandler(event)">
<mx:columns>
<mx:DataGridColumn headerText="PIN" dataField="Parcels3.PPIN" labelFunction="getLabel" />
<mx:DataGridColumn headerText="Name" dataField="Parcels3.NAME" labelFunction="getLabel"/>
<mx:DataGridColumn headerText="Neighborhood" dataField="Parcels3.NEIGHBORHOOD" labelFunction="getLabel"/>
<mx:DataGridColumn headerText="Value" dataField="Parcels3.TOTAL_TRUE" labelFunction="getLabel"/>
</mx:columns>
</mx:DataGrid>
</s:Application>
The labelFunction getLabel allow you to just add your data that is nested to the datagrid without all your steps of simplifying the field name.
Evelyn,
Since you already have the graphics added to the map all you need to do is add the attributes from the first query to the graphics you are creating.
var myGraphic:Graphic = new Graphic(new MapPoint(mp.x,mp.y, new SpatialReference (102100)), new SimpleMarkerSymbol("circle",8,0xFF3300), featureSet.features
.attributes);
Then instead of a query you just loop through your graphicsLayers graphics attributes for a matching attribute (of course the attribute has to be unique, that is why I normally use the ObjectID).
I did not understand .
In the seconf function i wanna replace this part of the code
var q:QueryTask = new QueryTask();
q.showBusyCursor = true;
q.url = "http://gisred.chilquinta/arcgis/rest/services/Chilquinta_006/ClientesV2/MapServer/0";
q.useAMF = false;
var r:Query = new Query();
r.returnGeometry = true;
r.where = "ARCGIS.dbo.CLIENTES_DATA_DATOS_006.nis =" + seleccionado;
q.execute(r, new AsyncResponder(onResult, onFault));
function onResult(featureSet:FeatureSet, token:Object = null):void
{
try{
for each (var myGraphic:Graphic in featureSet.features)
{
myGraphic.symbol=new SimpleMarkerSymbol("diamond",10,0x00FF00)
var mp:MapPoint=featureSet.features[0].geometry as MapPoint;
graphicsLayer.add(myGraphic);
map.zoomTo(featureSet.features[0].geometry);
map.level = 16;
//Configuración ventana infoWindow con graphic
popUpRenderer.popUpInfo = popUpInfo;
popUpRenderer.graphic = myGraphic;
map.infoWindow.content = popUpRenderer;
map.infoWindow.contentOwner = popUpRenderer.graphic;
map.infoWindow.show(mp);
}
}catch(err:Error){
Alert.show("no se pudo hacer zoom al equipo seleccionado");
}
}
function onFault(info:Object, token:Object = null):void
{
Alert.show("nis no encontrado");
}
I wanna make a loop how u said , searching the result of the other featureSet that i have before with the "nis" parameter, because in this case that is unique.
Its something like
if featureset.nis = seleccionado
draw the point where it is and zoom
else
do nothing or error msg
But i dont know how to do it .
Thanks in adv
Evelyn,
I don't have time to write the code for you so I will try and explain a little better. You need to search the Graphics layer not the featureset. The GraphicsLayer that you populated in the first query with all the individual graphics from the query results now will contain attributes like your nis attribute. So you do a standard loop though your GraphicsLayer and check each graphics attribute of nis and see if it is equal to the nis your are looking for.
for (var g:int = 0; g < graphicsLayer.numGraphics; g++){
var tGra:Graphic = graphicsLayer.graphicProvider
as Graphic; if (tGra.attributes["nis"] == seleccionado){
map.zoomTo(tGra.geometry);
break;
}
}
Robert,
Im sorry, i tried to do the same what u said but it still doesnt do any zoom to the specified nis that i clicked on the grid.
I dont know what is happening. I understand now what i have to do but it doesnt work idk why.
If u have any example that seems that i want to do will be useful.
Thx you
Evelyn,
Did you remember to add the attributes to the graphic when you create it like I mention a couple of posts ago?
Evelyn,
Here is a whole working example.
<?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">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import com.esri.ags.FeatureSet;
import com.esri.ags.Graphic;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.symbols.SimpleMarkerSymbol;
import com.esri.ags.tasks.QueryTask;
import com.esri.ags.tasks.supportClasses.Query;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.rpc.AsyncResponder;
[Bindable]
private var listBridges:ArrayCollection;
protected function equiposAP_clickHandler(event:MouseEvent):void
{
var queryTaskEquipo:QueryTask = new QueryTask();
queryTaskEquipo.url = "http://gis.calhouncounty.org/arcgis/rest/services/Highway/MapServer/0";
queryTaskEquipo.useAMF = true;
var queryEquipo:Query = new Query();
queryEquipo.outFields = ["*"];
queryEquipo.returnGeometry = true;
queryEquipo.where = "1=1";
queryEquipo.outSpatialReference = map.spatialReference;
queryTaskEquipo.execute(queryEquipo, new AsyncResponder(onResult, onFault));
function onResult(featureSet:FeatureSet, token:Object = null):void
{
for (var x:Number=0; x < featureSet.features.length; x++){
var mp:MapPoint=featureSet.features
.geometry as MapPoint; var myGraphic:Graphic = new Graphic(new MapPoint(mp.x,mp.y, new SpatialReference (102100)), new SimpleMarkerSymbol("circle",8,0xFF3300), featureSet.features
.attributes); graphicsLayer.add(myGraphic);
}
listBridges = new ArrayCollection(featureSet.attributes);
}
function onFault(info:Object, token:Object = null):void
{
Alert.show("Error "+ info.toString());
}
}
protected function gridEquipos_clickHandler(event:MouseEvent):void
{
var seleccionado:String = new String(event.currentTarget.selectedItem.Local_ID);
for (var g:int = 0; g < graphicsLayer.numGraphics; g++){
var tGra:Graphic = graphicsLayer.graphicProvider
as Graphic; if (tGra.attributes["Local_ID"] == seleccionado){
map.zoomTo(tGra.geometry);
break;
}
}
}
]]>
</fx:Script>
<s:controlBarLayout>
<s:VerticalLayout gap="10"
paddingBottom="7"
paddingLeft="10"
paddingRight="10"
paddingTop="7"/>
</s:controlBarLayout>
<s:controlBarContent>
<s:RichText width="100%">
This sample demonstrates how to populate a datagrid with the results of a querytask
</s:RichText>
<s:Button id="popButton"
click="equiposAP_clickHandler(event)"
label="execute query..."/>
</s:controlBarContent>
<esri:Map id="map" height="100%" width="100%">
<esri:extent>
<esri:Extent xmax="-9518156.843666727" ymax="4029927.412560757"
xmin="-9592690.117733276" ymin="3963966.655639243">
<esri:SpatialReference wkid="102100" >
</esri:SpatialReference>
</esri:Extent>
</esri:extent>
<esri:ArcGISTiledMapServiceLayer url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" />
<esri:GraphicsLayer id="graphicsLayer" />
</esri:Map>
<mx:DataGrid id="gridEquipos" width="100%" height="30%" visible="true" editable="false" dragEnabled="true"
dropEnabled="true" dataProvider="{listBridges}"
click="gridEquipos_clickHandler(event)">
<mx:columns>
<mx:DataGridColumn headerText="Local ID" dataField="Local_ID" />
<mx:DataGridColumn headerText="Bridge Inventory Number" dataField="BIN"/>
<mx:DataGridColumn headerText="Road ID" dataField="Road_Id"/>
<mx:DataGridColumn headerText="Intersected Feature" dataField="Feat_Intersect"/>
</mx:columns>
</mx:DataGrid>
</s:Application>
Evelyn,
Did my full sample app help?
Ur example works perfectly, but the issue that we are having is this:
In the arcgis srv, the layer we have the "nis" parameter as nested parameter in the BD like this "ARCGIS.dbo.CLIENTES_DATA_DATOS_006.nis" using points between each word.
You use Local_ID because in ur arcgis srv u have the layer configured like a single word.
When we try to use some nested parameters and we try to get any information from the service to put it in a datagrid we have the issue that it doesnt show anything because flex kinda get crazy with the "." between each word.
So, in the example of the function that i showed u before, we "parse" the nested attributes to not have the issue with the datagrid.
Then when i use the example that u showed me before it will not work because the nested parameters in our arcgis srv (something that really we cannot change)
So, in this line on ur code :
if (tGra.attributes["Local_ID"] == seleccionado){
Then when we put this:
tGra.attributes["nis"] == seleccionado
it doesnt compare anything, and also if we put the entire parameter how in our srv is:
tGra.attributes["ARCGIS.dbo.CLIENTES_DATA_DATOS_006.nis"] == seleccionado
also it doesnt compare.
So, we dont really know how to compare the parameter when it is nested.
Evelyn,
I am able to use joined data fields in my eSearch in the datagrid. Let me look into this some more.