• 用query实现图层信息的查询和定位功能


    QueryTask和Query是arcgis server端已经封装好的服务,在flex的客户端只需要提供必要的参数即可执行查询,并返回数据以供操作。

    本文主要是根据query的where条件执行查询,并实现图形的定位,高亮显示和属性信息的展示。

    <esri:QueryTask id="queryTask"   url="{queryurl}"   useAMF="false" />
    <esri:Query id="query" returnGeometry="true" where="{whereSql}"/>


    首先查询会用到querytask和query,这2个标签的声明要放在<fx:Declarations>中,因为它只声明不展示。

    protected function openGeometryByKey():void
    {
    if(graphicsLayer!=null)//定位前先清空graphicsLayer
    graphicsLayer.clear();

    //首先取得TreeNode节点SLID信息
    var xml:XML = treeNodeObject as XML;
    var strLabel:String=xml.attribute("lable")==null?"":StringUtil.trim(xml.attribute("lable").toString());
    var slid:String=xml.attribute("slid")==null?"":StringUtil.trim(xml.attribute("slid").toString());

    if(slid=="")
    {
    lablet.data="请检查业务是否上图,暂时无法定位该条信息";
    return;
    };
    lablet.data="";
    queryTask.url=configXML.serviceUrl;
    this.whereSql="slid ='" + slid +"'";
    queryTask.execute(query,new AsyncResponder(onResult, onFault));


    function onResult(featureSet:FeatureSet, token:Object = null):void
    {
    resultCommand(featureSet,token,true);
    }
    function onResultEx(featureSet:FeatureSet, token:Object = null):void
    {
    resultCommand(featureSet,token,false);
    }

    function resultCommand(featureSet:FeatureSet, token:Object = null,isQuery04:Boolean=false):void
    {
    //查询成功,取得返回的图形信息开始定位
    if(featureSet==null || featureSet.features==null ) return;
    var graphic:Graphic=featureSet.features[0];
    if(graphic==null) //若没有查到择到则到serviceUrl04中查询一次
    {
    if(isQuery04==true) //true为第一次查询,false为第二次
    {
    queryTask.url=configXML.serviceUrl04;
    queryTask.execute(query,new AsyncResponder(onResultEx, onFault));
    lablet.data="";
    return;
    }
    lablet.data="请检查业务是否上图,暂时无法定位该条信息";
    return;
    }

    map.infoWindow.hide();//先隐藏map的infowindow
    graphicsLayer.clear();//先清空graphicsLayer

    var mpt:MapPoint=null; //中心点
    var goToExt:Extent=null; //图形的范围
    for each (var myGraphic:Graphic in featureSet.features)//featureSet为查询返回的graphic数组
    {
    graphicsLayer.add(myGraphic); //将返回结果添加到graphicsLayer中
    var geo:Geometry=myGraphic.geometry;//根据graphic的几何形状进行操作

    switch (geo.type)
    {
    case Geometry.MAPPOINT://
    {
    mpt=geo as MapPoint;//绘制简单的点符号用于高亮显示
    myGraphic.symbol=new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CROSS, 15, 0xFF0000, 1);
    break;
    }

    case Geometry.POLYLINE://线
    { //绘制简单的线符号用于高亮显示
    myGraphic.symbol=new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, 0xFF0000, 1.0, 3);
    break;
    }
    case Geometry.POLYGON://
    case Geometry.EXTENT:
    { //绘制简单的面符号用于高亮显示
    var symbol:SimpleFillSymbol=new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, 0xFF0000, 0);
    symbol.outline=new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, 0xFF0000, 1.0, 3);
    myGraphic.symbol=symbol;
    break;
    }
    }

    if(goToExt!=null&&geo.type!=Geometry.MAPPOINT)//若返回多个graphic则将其extent合并
    {
    goToExt=goToExt.union(geo.extent);
    }
    else
    {
    goToExt=geo.extent;
    }
    }
    if (goToExt != null)//
    {
    map.extent=goToExt.expand(2);//实现map的定位
    }
    else//
    {
    var mapPoint:MapPoint=myGraphic.geometry as MapPoint;
    map.centerAt(mapPoint);
    }
    if(goToExt!=null)//获取graphic的中心点mpt
    {
    mpt=goToExt.center;
    }

    map.infoWindow.label=strLabel;//实现属性窗口的展示
    map.infoWindow.show(mpt);

    }
    function onFault(info:Object, token:Object = null):void
    {
    lablet.data="查询定位异常";
    }
    }








    最后如果需要查询到的属性可以到myGraphic.attributes.QLR.toString();中获取

    如下

    map.infoWindow.label="                        宗地信息";
    var vb:VBox=new VBox();
    var qlr:mx.controls.Label=new mx.controls.Label();
    var zdmj:mx.controls.Label=new mx.controls.Label();
    var tdzl:mx.controls.Label=new mx.controls.Label();
    var djh:mx.controls.Label=new mx.controls.Label();
    var frdh:mx.controls.Label=new mx.controls.Label();
    qlr.text="权利人:"+myGraphic.attributes.QLR.toString();
    zdmj.text="宗地面积:"+myGraphic.attributes.QLR.toString();
    tdzl.text="土地坐落:"+myGraphic.attributes.QLR.toString();
    djh.text="地籍号:"+myGraphic.attributes.QLR.toString();
    frdh.text="法人电话号:"+myGraphic.attributes.QLR.toString();
    vb.addElement(qlr);
    vb.addElement(zdmj);
    vb.addElement(tdzl);
    vb.addElement(djh);
    vb.addElement(frdh);
    map.infoWindow.contentGroup.addElement(vb);//组织inforwindow,并展示
    map.infoWindow.show(mpt);
  • 相关阅读:
    Acrobat dose not allow connection to:
    如何备份sqlite数据库
    Linux下Perl的安装
    Sqlserver取分组后的第一条数据
    JS根据占比计算名次范围
    eltable单元格换行显示,超出部分省略号
    二 前端框架引入、结构分配和路由定义
    扩展运算符(...)
    eltable动态合并行列
    解决table中换行符<br>被字符化得问题
  • 原文地址:https://www.cnblogs.com/tiandi/p/2275197.html
Copyright © 2020-2023  润新知