• 缓冲区点查询(在地图上点击一点,查询一定范围内的信息)


    首先在页面上添加如果代码:

    <esri:MapResourceManager ID="MapResourceManager1" runat="server">
    <ResourceItems>

    <%--高亮显示--%>
    <esri:MapResourceItem Definition="&lt;Definition DataSourceDefinition=&quot;In Memory&quot; DataSourceType=&quot;GraphicsLayer&quot; Identity=&quot;&quot; ResourceDefinition=&quot;&quot; DataSourceShared=&quot;True&quot; /&gt;"
    DisplaySettings="visible=True:transparency=0:mime=True:imgFormat=PNG8:height=100:width=100:dpi=96:color=:transbg=False:displayInToc=True:dynamicTiling="
    LayerDefinitions="" Name="Selection" />

    <%--缓冲区--%>
    <esri:MapResourceItem Definition="&lt;Definition DataSourceDefinition=&quot;In Memory&quot; DataSourceType=&quot;GraphicsLayer&quot; Identity=&quot;&quot; ResourceDefinition=&quot;&quot; DataSourceShared=&quot;True&quot; /&gt;"
    DisplaySettings="visible=True:transparency=0:mime=True:imgFormat=PNG8:height=100:width=100:dpi=96:color=-16711872:transbg=False:displayInToc=True:dynamicTiling="
    LayerDefinitions="" Name="Buffer" />

    <%--查询地图--%>
    <esri:MapResourceItem Definition="&lt;Definition DataSourceDefinition=&quot;http://10.11.204.30/arcgis/services&quot; DataSourceType=&quot;ArcGIS Server Internet&quot; Identity=&quot;XnCuZRa/5MALNPXX0v8+XQbF6yhe9I8j&quot; ResourceDefinition=&quot;(default)@GdGis_2012_Interface&quot; DataSourceShared=&quot;True&quot; /&gt;"
    DisplaySettings="visible=True:transparency=0:mime=True:imgFormat=PNG8:height=100:width=100:dpi=96:color=White:transbg=True:displayInToc=True:dynamicTiling="
    LayerDefinitions="" Name="Portland" />
    </ResourceItems>
    </esri:MapResourceManager>

    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView>
    <div id="griddiv" style="visibility: hidden;">
    </div>

    js 脚本:

    //缓冲区查询
    function fwsz()
    {
    document.getElementById("cxfwsz").style.display="block";
    document.getElementById("BNResult").style.display="block";
    var map = $find('Map1');
    //画点函数
    map.getGeometry(ESRI.ADF.Graphics.ShapeType.Point, usePoint, null, 'red', '#0000FF', 'pointer', true);

    //获取鼠标点击的位置的地图坐标
    function usePoint(clickPoint)
    {
    //地理坐标转到屏幕坐标
    var screenPoint=map.toScreenPoint(clickPoint);
    //获取屏幕坐标的X和Y分量
    var screenX=screenPoint.offsetX;
    var screenY=screenPoint.offsetY;
    ToMapXY(screenX,screenY);
    }
    //屏幕坐标转到地理坐标
    function ToMapXY(screenX,screenY)
    {
    var map = $find('Map1');
    //返回 ESRI.ADF.Geometries.Point 类型的点
    var mapPoint=map.toMapPoint(screenX,screenY);

    var ddlcxfw=document.getElementById("ddlcxfw");

    var cxfw=ddlcxfw.options[ddlcxfw.selectedIndex].text;

    var message='ActiveType=center&EventArg=';
    message+="States";
    message+="&Condtion="+mapPoint+"&cxfw="+cxfw;
    var context="Page1";
    <%=attributeQueryCallBack %>
    }
    }

    后台代码:

    //属性查询
    public string attributeQueryCallBack;

    protected void Page_Load(object sender, EventArgs e)
    {
    attributeQueryCallBack = Page.ClientScript.GetCallbackEventReference(this, "message", "processCallbackResult", "context", "postBackError", true);
    }

    //ICallbackEventHandler先执行RaiseCallbackEvent方法
    void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
    {
    callbackArg = eventArgument;
    }
    string ICallbackEventHandler.GetCallbackResult()
    {
    string v = "";
    //将传入参数依据&分割符分到querystring变量中
    Array keyValuePairs = callbackArg.Split("&".ToCharArray());
    NameValueCollection queryString = new NameValueCollection();
    string[] keyValue;
    if (keyValuePairs.Length > 0)
    {
    for (int i = 0; i < keyValuePairs.Length; i++)
    {
    keyValue = keyValuePairs.GetValue(i).ToString().Split("=".ToCharArray());
    queryString.Add(keyValue[0], keyValue[1]);
    }
    }
    else
    {
    keyValue = callbackArg.Split("=".ToCharArray());
    if (keyValue.Length > 0)
    queryString.Add(keyValue[0], keyValue[1]);
    }
    //针对参数中指定的ActiveType不同执行不同操作
    string controlType = queryString["ActiveType"];
    string eventArg = queryString["EventArg"];

    //地图坐标
    string condition = queryString["Condtion"];
    switch (controlType)
    {
    case "center":

    //查询范围,如1000米
    string ddlcxfw = queryString["cxfw"];
    string cxfw = ddlcxfw.Substring(0, ddlcxfw.Length - 1).ToString();
    testhcq.hqctest(condition, cxfw, Map1);
    v = Map1.CallbackResults.ToString();
    break;
    }

    return v;
    }

    在app_code里添加testhcq类,类中添加hqctest,代码如下:

    /// <summary>
    /// 缓冲区分析
    /// </summary>
    /// <param name="pointPosition">缓冲区查询点的地图坐标 x,y</param>
    /// <param name="map">地图</param>
    public static void hqctest(string pointPosition, string cxfw, Map map)
    {
    int num = pointPosition.IndexOf(',');
    if (num == -1)
    return;
    string[] str = pointPosition.Split(',');
    float centerPointX = float.Parse(str[0]);
    float centerPointY = float.Parse(str[1]);
    float bufferdistance;
    if (!Single.TryParse(cxfw, out bufferdistance))
    {
    bufferdistance = 0.0F;
    }
    //相互连接的直线或曲线
    System.Drawing.Drawing2D.GraphicsPath gpath = new System.Drawing.Drawing2D.GraphicsPath();
    //绘制椭圆
    gpath.AddEllipse(centerPointX - (bufferdistance / 2), centerPointY - (bufferdistance / 2), bufferdistance, bufferdistance);
    //Flatten的参数表示几何变换的3*3仿射矩阵
    System.Drawing.Drawing2D.Matrix translateMatrix = new System.Drawing.Drawing2D.Matrix();

    translateMatrix.Translate(0, 0);
    //误差值,flatten的参数
    float flattening = bufferdistance / 1000; //0.005F; //decimal degrees --- 100F; //meters,feet
    //将gpath曲线转换成相连接的线段序列
    gpath.Flatten(translateMatrix, flattening);
    //点集合
    ESRI.ArcGIS.ADF.Web.Geometry.PointCollection pc = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection();

    foreach (System.Drawing.PointF dpnt in gpath.PathPoints)
    {
    pc.Add(new ESRI.ArcGIS.ADF.Web.Geometry.Point(dpnt.X, dpnt.Y));
    }
    //环形
    ESRI.ArcGIS.ADF.Web.Geometry.Ring ring = new ESRI.ArcGIS.ADF.Web.Geometry.Ring();
    ring.Points = pc;
    ESRI.ArcGIS.ADF.Web.Geometry.RingCollection rings = new ESRI.ArcGIS.ADF.Web.Geometry.RingCollection();
    rings.Add(ring);
    ESRI.ArcGIS.ADF.Web.Geometry.Polygon mappoly = new ESRI.ArcGIS.ADF.Web.Geometry.Polygon();
    mappoly.Rings = rings;
    IdentifyHelper.IdentifyRectangle(map, mappoly);

    #region
    IEnumerable gfc = map.GetFunctionalities();
    ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource gResource = null;
    foreach (IGISFunctionality gfunc in gfc)
    {
    if (gfunc.Resource.Name == "Buffer")
    {
    gResource = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)gfunc.Resource;
    }
    }
    if (gResource == null)

    throw new Exception("Buffer Graphics layer not in MapResourceManager");

    //把缓冲区结果范围进行显示
    ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer glayer = null;
    //查找ElementGraphicsLayer在缓冲区中
    foreach (System.Data.DataTable dt in gResource.Graphics.Tables)
    {
    if (dt is ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)
    {
    glayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dt;
    break;
    }
    }
    //如果缓冲区中没有ElementGraphicsLayer就新增加一个ElementGraphicsLayer
    if (glayer == null)
    {
    glayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();
    gResource.Graphics.Tables.Add(glayer);
    }
    //清除ElementGraphicsLayer中的内容
    glayer.Clear();

    ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = (ESRI.ArcGIS.ADF.Web.Geometry.Geometry)mappoly;
    //设置点显示
    ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement ge = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(geom, System.Drawing.Color.Green);
    //设置透明度
    ge.Symbol.Transparency = 70.0;
    //添加到缓冲区中进行显示
    glayer.Add(ge);

    string targetlayername = "SL_HLGQ_POLYGON ";
    int resource_index = 2;

    int layer_index = 0;
    ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mf = (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality)map.GetFunctionality(resource_index);

    ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = mf.Resource;
    bool supported = gisresource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));
    if (supported)
    {

    ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisresource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);

    string[] lids;

    string[] lnames;

    qfunc.GetQueryableLayers(null, out lids, out lnames);

    for (int i = 0; i < lnames.Length; i++)
    {

    if (lnames[i] == targetlayername)
    {

    layer_index = i;

    break;

    }

    }

    ESRI.ArcGIS.ADF.Web.SpatialFilter spatialfilter = new ESRI.ArcGIS.ADF.Web.SpatialFilter();

    spatialfilter.ReturnADFGeometries = true;

    spatialfilter.MaxRecords = 1000;

    spatialfilter.Geometry = mappoly;

    System.Data.DataSet ds = new DataSet();

    System.Data.DataTable datatable = qfunc.Query(null, lids[layer_index], spatialfilter);

    ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource selresource = null;

    foreach (IGISFunctionality gfunc in gfc)
    {

    if (gfunc.Resource.Name == "Selection")
    {

    selresource = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)gfunc.Resource;

    }

    }

    if (selresource == null)

    return;

    ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer slayer = null;

    foreach (System.Data.DataTable dt in selresource.Graphics.Tables)
    {

    if (dt is ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)
    {

    slayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dt;

    break;

    }

    }

    if (slayer == null)
    {

    slayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();

    selresource.Graphics.Tables.Add(slayer);

    }

    slayer.Clear();

    DataRowCollection drs = datatable.Rows;

    int shpind = -1;

    for (int i = 0; i < datatable.Columns.Count; i++)
    {

    if (datatable.Columns[i].DataType == typeof(ESRI.ArcGIS.ADF.Web.Geometry.Geometry))
    {

    shpind = i;

    break;

    }

    }

    try
    {

    foreach (DataRow dr in drs)
    {

    ESRI.ArcGIS.ADF.Web.Geometry.Geometry sgeom = (ESRI.ArcGIS.ADF.Web.Geometry.Geometry)dr[shpind];

    ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement sge = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(sgeom, System.Drawing.Color.Red);

    sge.Symbol.Transparency = 50.0;

    slayer.Add(sge);

    }

    }

    catch
    {

    throw new Exception("No geometry available in datatable");

    }

    GridView gdview = (GridView)map.Page.FindControl("GridView1");

    object[] oa = new object[1];

    string showtable = "'hidden'";


    gdview.DataSource = dt;

    gdview.DataBind();

    string returnstring = null;

    using (System.IO.StringWriter sw = new System.IO.StringWriter())
    {

    HtmlTextWriter htw = new HtmlTextWriter(sw);

    gdview.RenderControl(htw);

    htw.Flush();

    returnstring = sw.ToString();

    }
    CallbackResult cr = new CallbackResult("div", "griddiv", "innercontent", returnstring);

    map.CallbackResults.Add(cr);

    showtable = "'visible'";

    string sa = "var griddiv = document.getElementById('griddiv');";

    sa += "griddiv.style.visibility = " + showtable + ";";

    oa[0] = sa;

    CallbackResult cr1 = new CallbackResult(null, null, "javascript", oa);

    map.CallbackResults.Add(cr1);

    if (map.ImageBlendingMode == ImageBlendingMode.WebTier)

    { map.Refresh(); }

    else if (map.ImageBlendingMode == ImageBlendingMode.Browser)
    {

    map.RefreshResource(gResource.Name);

    map.RefreshResource(selresource.Name);

    }

    }

    }
    #endregion

    }

  • 相关阅读:
    A. Dreamoon and Stairs(Codeforces Round #272)
    bootstrap之UpdateStrings
    FZU
    IT忍者神龟之 oracle行转列、列转行
    linux find 10天内改动过的文件
    内核调试日志打印宏
    ack-grep 代码全文搜索
    JDK配置 linux
    IDA修改游戏
    curl 访问https问题
  • 原文地址:https://www.cnblogs.com/lff255356/p/2740982.html
Copyright © 2020-2023  润新知