⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zoomtoresults.cs

📁 C#开发的ArcGIS Server9.2查询地物居中高亮显示控件
💻 CS
📖 第 1 页 / 共 2 页
字号:
                            foreach (DataTable dt in ds.Tables)
                            {
                                processDataTable(doSelect, doZoom, dt, ref pEnv);
                            }
                        }
                    }
                }
            }

            //Zoom the map if the results set is equal to or less then the MaxResultsForZoom
            if (doZoom && pEnv != null)
            {
                //resize the envelope if it is smaller than the minimum extent size
                if (pEnv.Width < MinWidthOfZoom && pEnv.Height < MinWidthOfZoom)
                {
                    double dblExpandX = (MinWidthOfZoom - pEnv.Width) / 2;
                    double dblExpandY = (MinWidthOfZoom - pEnv.Height) / 2;
                    pEnv = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(pEnv.XMin - dblExpandX, pEnv.YMin - dblExpandY,
                        pEnv.XMax + dblExpandX, pEnv.YMax + dblExpandY);
                }
                else if (pEnv.Width < MinWidthOfZoom)
                {
                    double dblExpandX = (MinWidthOfZoom - pEnv.Width) / 2;
                    pEnv = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(pEnv.XMin - dblExpandX, pEnv.YMin,
                        pEnv.XMax + dblExpandX, pEnv.YMax);
                }
                else if (pEnv.Height < MinWidthOfZoom)
                {
                    double dblExpandY = (MinWidthOfZoom - pEnv.Height) / 2;
                    pEnv = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(pEnv.XMin, pEnv.YMin - dblExpandY,
                        pEnv.XMax, pEnv.YMax + dblExpandY);
                }

                //Zoom out a little when you set the extent so you can see the features.
                if (ZoomExtentExpansionPercent > 0)
                {
                    pEnv = pEnv.Expand(ZoomExtentExpansionPercent);
                }

                //Hold onto the old extent to test with later
                ESRI.ArcGIS.ADF.Web.Geometry.Envelope pOldEnv =
                    (ESRI.ArcGIS.ADF.Web.Geometry.Envelope)MapInstance.Extent.Clone();

                //Find the scale of the new envlope
                double dEnvelopeScale = 0;
                if (MapInstance.Extent.Width / pEnv.Width < MapInstance.Extent.Height / pEnv.Height)
                { dEnvelopeScale = MapInstance.Scale * (pEnv.Width / MapInstance.Extent.Width); }
                else
                { dEnvelopeScale = MapInstance.Scale * (pEnv.Height / MapInstance.Extent.Height); }

                RemoveAllMapCallbacks(MapInstance);

                //zoom out to the next cache level if the data source is cached
                ESRI.ArcGIS.ADF.Web.DataSources.TileCacheInfo tci = MapInstance.PrimaryMapResourceInstance.MapInformation.TileCacheInfo;
                if (tci != null)
                {
                    //Find the next largest (smaller map scale) tile scale
                    LodInfo[] lodInfo = tci.LodInfos;
                    for (int i = tci.LodInfos.GetUpperBound(0); i > -1; i--)
                    {
                        if (lodInfo[i].Scale > dEnvelopeScale)
                        {
                            //If we just need to pan then center the map. If we set the extent when the scale / map dimensions 
                            //are the same we can get artifacts in the graphics layer in IE6
                            if (MapInstance.Extent.Width >= pEnv.Width &&
                                MapInstance.Extent.Height >= pEnv.Height &&
                                MapInstance.Level == i)
                            {
                                MapInstance.CenterAt(new ESRI.ArcGIS.ADF.Web.Geometry.Point(
                                    pEnv.XMin + (pEnv.Width / 2),
                                    pEnv.YMin + (pEnv.Height / 2)));
                            }
                            else
                            {
                                //If we need to zoom to the feature set the extent first
                                MapInstance.Extent = pEnv;
                                //remove the callback generated by changing the extent.  If we don't do this we will 
                                //get artifacts in the graphics layer in IE6.
                                RemoveAllMapCallbacks(MapInstance);
                                //Set the level for the map.  This will add the callback to the map that will
                                //include the extent change.
                                MapInstance.Level = i;
                            }
                            break;
                        }
                    }
                }
                else  //This data is not cached so we don't need to worry about tile level.
                {
                    //Set the extent of the map to the new extent
                    bool isGoodWidth = Math.Round(MapInstance.Extent.Width, 10) >= Math.Round(pEnv.Width, 10);
                    bool isGoodHeight = Math.Round(MapInstance.Extent.Height, 10) >= Math.Round(pEnv.Height, 10);
                    bool isGoodScale = Math.Round(MapInstance.Scale, 0) == Math.Round(dEnvelopeScale, 0);
                    //If we just need to pan then center the map. If we set the extent when the scale / map dimensions 
                    //are the same we can get artifacts in the graphics layer in IE6
                    if (isGoodHeight && isGoodWidth && isGoodScale)
                    {
                        MapInstance.CenterAt(new ESRI.ArcGIS.ADF.Web.Geometry.Point(
                                    pEnv.XMin + (pEnv.Width / 2),
                                    pEnv.YMin + (pEnv.Height / 2)));
                    }
                    else
                    {
                        MapInstance.Extent = pEnv;
                    }
                }
            }
            if (DisplayTaskResults)
                base.DisplayResults(task, taskJobID, taskInputs, taskResults);
        }

        private void RemoveAllMapCallbacks(Map pMap)
        {
            List<CallbackResult> mapCallbacks = new List<CallbackResult>();
            foreach (CallbackResult cr in pMap.CallbackResults)
            {
                if (cr.Control == pMap)
                {
                    mapCallbacks.Add(cr);
                }
            }
            foreach (CallbackResult mapCr in mapCallbacks)
            {
                pMap.CallbackResults.Remove(mapCr);
            }
        }

        private int countAllResultsInNode(TreeViewPlusNode pNode)
        {
            int iCounter = 0;
            GraphicsLayerNode glNode = pNode as GraphicsLayerNode;
            if (glNode != null)
            {
                iCounter += ((DataTable)glNode.Layer).Rows.Count;
            }
            glNode = null;
            foreach (TreeViewPlusNode childNode in pNode.Nodes)
            {
                iCounter += countAllResultsInNode(childNode);
            }
            return iCounter;
        }

        private void processNode(TreeViewPlusNode pNode, bool doSelect, bool doZoom, ref ESRI.ArcGIS.ADF.Web.Geometry.Envelope pEnv)
        {
            GraphicsLayerNode glNode = pNode as GraphicsLayerNode;
            if (glNode != null && glNode.Value != "Input Features")
            {
                processDataTable(doSelect, doZoom, (DataTable)glNode.Layer, ref pEnv);
            }
            glNode = null;
            foreach (TreeViewPlusNode childNode in pNode.Nodes)
            {
                processNode(childNode, doSelect, doZoom, ref pEnv);
            }
        }

        private void processDataTable(bool doSelect, bool doZoom, DataTable dt, ref ESRI.ArcGIS.ADF.Web.Geometry.Envelope pEnv)
        {
            if (dt.Rows.Count > 0)
            {
                //copy the data table before creating a graphics layer so the features don't get added to the map.
                GraphicsLayer gl = ESRI.ArcGIS.ADF.Web.Converter.ToGraphicsLayer(dt.Copy());

                //Expand the new extent to include the extent of the graphics layer
                if (doZoom)
                {
                    //Create a new envleope if this is the first table to process
                    if (pEnv == null)
                    { pEnv = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(); }
                    pEnv.Union(gl.FullExtent);
                }

                //Select the features if their total number is less then or equal to the maxResultsForAutoSelect property
                if (doSelect)
                {
                    int intSelCol = dt.Columns.IndexOf(gl.IsSelectedColumn.ColumnName);
                    foreach (DataRow dr in dt.Rows)
                    {
                        dr[intSelCol] = true;
                    }
                    dt.AcceptChanges();
                }
            }
        }

        // Override to add design-time warning
        protected override void RenderContents(HtmlTextWriter writer)
        {
            if (DesignMode)
            {
                RenderDesignTimeHtml(writer);
            }
            else
            {
                base.RenderContents(writer);
            }
        }

        // Display warning at design-time, developer must set the Map property
        private void RenderDesignTimeHtml(HtmlTextWriter writer)
        {
            writer.WriteLine("<tr>");
            writer.WriteLine("<td nowrap>");
            writer.WriteLine("&nbsp;" + ClientID + "<br>");
            writer.WriteLine("</td>");
            writer.WriteLine("</tr>");

            System.Text.StringBuilder sbMess = new System.Text.StringBuilder(512);
            if (Map.Equals("(none)") || string.IsNullOrEmpty(Map))
            {
                sbMess.Append("<br><br>&nbsp;<font color=\"#FF0000\">Warning</font>: You must set the Map property. ");
            }

            writer.WriteLine("<tr>");
            writer.WriteLine("<td>&nbsp;ZoomToResults WebControl<br>");
            writer.WriteLine(sbMess.ToString());
            writer.WriteLine("</td>");
            writer.WriteLine("</tr>");
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -