コード例 #1
0
ファイル: Default.aspx.cs プロジェクト: windcatcher/MapServer
        public void TestGetLayer()
        {
            IEnumerable funs = Map1.GetFunctionalities();

            foreach (IGISFunctionality gisFun in funs)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("gisFun.name={0}", gisFun.Name));
                IGISResource gisRes = gisFun.Resource;
                System.Diagnostics.Debug.WriteLine(string.Format("gisRes.name={0}  gisRes.ResourceDefinition={1}", gisRes.Name, gisRes.ResourceDefinition));
                IGISDataSource gisDs = gisRes.DataSource;
                System.Diagnostics.Debug.WriteLine(string.Format("gisDs.name={0}  gisDs.ResourceDefinition={1} gisDs.Identity={2}", gisDs.Name, gisDs.DataSourceDefinition, gisDs.Identity));
            }
        }
コード例 #2
0
 /// <summary>
 /// 获取GISResource
 /// </summary>
 /// <param name="map"></param>
 /// <param name="resourceName"></param>
 /// <returns></returns>
 public static IGISResource GetGISResourceByName(ESRI.ArcGIS.ADF.Web.UI.WebControls.Map map, string resourceName)
 {
     if (map == null)
     {
         return(null);
     }
     try
     {
         foreach (IGISFunctionality gisFun in map.GetFunctionalities())
         {
             IGISResource gisRes = gisFun.Resource;
             if (gisRes.Name.Equals(resourceName))
             {
                 return(gisRes);
             }
         }
     }
     catch (Exception)
     {
         return(null);
     }
     return(null);
 }
コード例 #3
0
ファイル: Default.aspx.cs プロジェクト: windcatcher/MapServer
        public void TestQuery()
        {
            IGISResource gisRes = ServerUtility.GetGISResourceByName(Map1, PublicConst.Lbl_WmsSvr_China);

            ESRI.ArcGIS.ADF.Web.DataSources.OGCWMSService.MapResource mapRes = gisRes as ESRI.ArcGIS.ADF.Web.DataSources.OGCWMSService.MapResource;
            IQueryFunctionality QueryFun;

            string[] layerIds  = null, layerNames = null;
            bool     isSupport = false;

            if (mapRes.SupportsFunctionality(typeof(IQueryFunctionality)))
            {
                QueryFun = mapRes.CreateFunctionality(typeof(IQueryFunctionality), "query") as IQueryFunctionality;
                QueryFun.GetQueryableLayers(null, out layerIds, out layerNames);
            }
            if (layerNames == null || layerNames.Length == 0)
            {
                return;
            }
            for (int i = 0; i < layerNames.Length; i++)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("图层:{0}", layerNames[i]));
            }
        }
コード例 #4
0
    public void ServerAction(ToolEventArgs args)
    {
        Map mapCtrl = null;

        mapCtrl = (Map)args.Control;
        string         strName = "";
        PointEventArgs ptArgs  = null;

        ptArgs = (PointEventArgs)args;
        System.Drawing.Point pt = ptArgs.ScreenPoint;
        //转换为地图上的点
        ESRI.ArcGIS.ADF.Web.Geometry.Point adfPt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(pt.X, pt.Y, mapCtrl.Extent
                                                                                                 , (int)mapCtrl.Width.Value, (int)mapCtrl.Height.Value);

        //查找图层
        System.Collections.IEnumerable func_enum = null;
        func_enum = mapCtrl.GetFunctionalities();
        ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource grahpResource = null;

        System.Data.DataTable dt;
        foreach (IGISFunctionality gisfunction in func_enum)
        {
            IGISResource gisRes = null;
            gisRes = gisfunction.Resource;
            if (gisfunction.Resource.Name == "graph")
            {
                grahpResource = (MapResource)gisfunction.Resource;//找到内存图像资源
            }
            bool bIsSupported = false;
            //地理资源是否支持查询
            bIsSupported = gisRes.SupportsFunctionality((typeof(IQueryFunctionality)));
            if (!bIsSupported)
            {
                continue;
            }
            IQueryFunctionality qFunc = null;
            qFunc = (IQueryFunctionality)gisRes.CreateFunctionality((typeof(IQueryFunctionality)), null);
            string[] strIds;
            string[] strNames;
            qFunc.GetQueryableLayers(null, out strIds, out strNames);
            if (strIds == null)
            {
                continue;                //如果是遥感影像不支持查询
            }
            int layerIndex = -1;
            for (int i = 0; i < strNames.Length; i++)
            {
                if (strNames[i] == "bou2_4p")
                {
                    layerIndex = i;
                    break;
                }
            }
            if (layerIndex < 0)
            {
                continue;
            }
            //找到该图层
            SpatialFilter sFilter = new SpatialFilter();
            sFilter.ReturnADFGeometries = true;
            sFilter.Geometry            = adfPt;
            sFilter.MaxRecords          = 100;


            dt = qFunc.Query(null, strIds[layerIndex], sFilter);
            if (dt == null || dt.Rows.Count == 0)
            {
                continue;
            }
            for (int jj = 0; jj < dt.Columns.Count; jj++)
            {
                strName = dt.Rows[0]["name"].ToString();
                if (dt.Columns[jj].DataType == typeof(ESRI.ArcGIS.ADF.Web.Geometry.Geometry))
                {
                    //找到该集合对象
                    ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = (ESRI.ArcGIS.ADF.Web.Geometry.Geometry)dt.Rows[0][jj];
                    ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer glayer = null;
                    foreach (System.Data.DataTable dt1 in grahpResource.Graphics.Tables)
                    {
                        if (dt1 is ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)
                        {
                            glayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dt1;
                            break;
                        }
                    }
                    if (glayer == null)
                    {
                        glayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();
                        grahpResource.Graphics.Tables.Add(glayer);
                    }
                    glayer.Clear();
                    ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement ge = null;

                    ge = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(geom, System.Drawing.Color.Red);
                    ge.Symbol.Transparency = 50;
                    glayer.Add(ge);
                }
            }
        }



        //
        if (mapCtrl.ImageBlendingMode == ImageBlendingMode.WebTier)
        {
            mapCtrl.Refresh();
        }
        else if (mapCtrl.ImageBlendingMode == ImageBlendingMode.Browser)
        {
            mapCtrl.RefreshResource(grahpResource.Name);
        }
        object[] oa = new object[1];
        string   sa = "alert('" + strName + "');";

        oa[0] = sa;
        CallbackResult crl = new CallbackResult(null, null, "javascript", oa);

        mapCtrl.CallbackResults.Add(crl);
    }
コード例 #5
0
ファイル: Default.aspx.cs プロジェクト: windcatcher/MapServer
        /// <summary>
        /// 根据属性定位
        /// </summary>
        private void LocalByAttribute(string eventArgs)
        {
            if (string.IsNullOrEmpty(eventArgs))
            {
                return;
            }

            try
            {
                IEnumerable func_enum = null;
                DataTable   table     = null;
                //获取当前map的所有functionlity  图层名BOUNT_poly
                func_enum = Map1.GetFunctionalities();
                //d对所有的functionlity遍历
                foreach (IGISFunctionality gisFunclity in func_enum)
                {
                    IGISResource        gisResr = null;
                    IQueryFunctionality qFunc;
                    gisResr = gisFunclity.Resource;
                    if (gisResr == null)
                    {
                        continue;
                    }
                    //判断是否支持IQueryFunctionality
                    bool isSurport = false;
                    isSurport = gisResr.SupportsFunctionality(typeof(IQueryFunctionality));
                    if (!isSurport)
                    {
                        continue;
                    }
                    qFunc = gisResr.CreateFunctionality(typeof(IQueryFunctionality), null) as IQueryFunctionality;
                    if (qFunc == null)
                    {
                        continue;
                    }
                    //获取图层layerid和layerName
                    string[] layerIds, layerNames;
                    qFunc.GetQueryableLayers(null, out layerIds, out layerNames);
                    if (layerIds == null || layerIds.Length == 0)
                    {
                        continue;
                    }
                    int layerId = -1;
                    for (int i = 0; i < layerIds.Length; i++)
                    {
                        if (layerNames[i] == "res2_4m")
                        {
                            layerId = i;
                            break;
                        }
                    }
                    if (layerId == -1)
                    {
                        continue;
                    }
                    //设置过滤器的过滤条件
                    ESRI.ArcGIS.ADF.Web.SpatialFilter sf = new ESRI.ArcGIS.ADF.Web.SpatialFilter();
                    sf.ReturnADFGeometries = true;
                    sf.MaxRecords          = 100;

                    string name = CallbackUtility.ParseStringIntoNameValueCollection(eventArgs)["attr"];
                    sf.WhereClause = string.Format("NAME='{0}'", name);
                    //对指定图层进行查询,查询结果保存为
                    table = qFunc.Query(null, layerIds[layerId], sf);
                    if (table == null || table.Rows.Count == 0)
                    {
                        sCallBackFuncStr = JsMesage.ShowMessage(Map1, "没有找到该城市");
                        continue;
                    }
                    for (int i = 0; i < table.Columns.Count; i++)
                    {
                        DataColumn column = table.Columns[i];
                        if (column.DataType == typeof(Geometry))
                        {
                            ESRI.ArcGIS.ADF.Web.Geometry.Point adfPt = table.Rows[0][i] as ESRI.ArcGIS.ADF.Web.Geometry.Point;
                            try
                            {
                                Map1.CenterAt(adfPt);
                            }
                            catch (Exception ex)
                            {
                                System.Diagnostics.Debug.WriteLine(ex);
                            }
                            try
                            {
                                DrawBufferByPoint(adfPt);
                            }
                            catch (Exception ex)
                            {
                                System.Diagnostics.Debug.WriteLine(ex);
                            }
                            sCallBackFuncStr = Map1.CallbackResults.ToString();
                            return;
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }