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

📄 demo.aspx.cs

📁 使用ASP.NET 2.0 (c#) 实现的gis 的地图系统
💻 CS
📖 第 1 页 / 共 5 页
字号:
            }
            else
            {
                ShowQueryResultInCurrentWindow(resultSet, maxLength);
                btnClearQueryResult.Visible = true;
            }
        }

        /// <summary>
        /// 在当前窗口中显示查询结果。注意:暂时不考虑ReturnFields中的引号。
        /// </summary>
        /// <param name="resultSet"></param>
        /// <param name="maxLength"></param>
        private void ShowQueryResultInCurrentWindow(SuperMap.IS.Utility.ResultSet resultSet, int maxLength)
        {
            if (resultSet == null || resultSet.Recordsets == null || resultSet.Recordsets.Length == 0 || resultSet.TotalCount <= 0)
            {
                DisplayResult(null);
                return;
            }
            if (Page.IsStartupScriptRegistered("jsResult"))
            {
                return;
            }

            int currentRecordIndex = 0;

            int tableCount = resultSet.Recordsets.Length;

            if (resultSet.MapResult != null)
            {
                Session["Result_MapName"] = resultSet.MapResult.ReturnMapParam.MapName;
            }

            StringBuilder sbQueryResult = new StringBuilder();
            sbQueryResult.Append("<input type=\"hidden\" name=\"Result_MapName\" value=\"" + Session["Result_MapName"] + "\">");
            sbQueryResult.Append("<input type=\"hidden\" name=\"Result_X\" id=\"Result_X\">");
            sbQueryResult.Append("<input type=\"hidden\" name=\"Result_Y\" id=\"Result_Y\">");
            sbQueryResult.Append("<input type=\"hidden\" name=\"Result_Name\" id=\"Result_Name\">");

            string displayField = ConfigurationManager.AppSettings["QueryDisplayField"].ToLower();
            if (string.IsNullOrEmpty(displayField))
            {
                displayField = "smid";
            }

            Recordset curRecordset;
            for (int i = 0; i < tableCount; i++)
            {
                curRecordset = resultSet.Recordsets[i];

                sbQueryResult.Append(@"<table border=\'1pt\' bordercolorlight=\'#eeeeee\' cellspacing=\'1pt\' bordercolordark=\'#eeeeee\' bgcolor=\'#FFFFFF\' width=\'100%\'>");
                int headerCount = curRecordset.ReturnFields.Length;
                int index = 0;
                int smidIndex = 0;
                for (int j = 0; j < headerCount; j++)
                {
                    if (curRecordset.ReturnFields[j].ToLower() == "smid")
                    {
                        index = j;
                        smidIndex = j;
                    }
                    if (curRecordset.ReturnFields[j].ToLower() == displayField)
                    {
                        index = j;
                        break;
                    }
                }

                int recordCount = curRecordset.Records.Length;
                for (int j = 0; j < recordCount; j++)
                {
                    currentRecordIndex++;
                    if (maxLength > 0 && currentRecordIndex > maxLength)
                    {
                        break;
                    }

                    Record curRecord = curRecordset.Records[j];

                    string curRecordText = curRecord.FieldValues[index];
                    if (curRecordText == null || curRecordText.Length == 0 || curRecordText.Trim().Length == 0)
                    {
                        curRecordText = curRecord.FieldValues[smidIndex];
                    }
                    else
                    {
                        curRecordText = curRecordText.Replace("'", "\'").Replace("<","&lt;").Replace(">","&gt;").Replace("\"","&quot;");
                    }

                    sbQueryResult.Append("<tr><td>");
                    if (curRecord.Center != null)   //如果没有返回中心点,那就啥也不干。
                    {
                        //显示标题。
                        int recordIndex = i * recordCount + j;
                        string recordID = "Record_" + recordIndex;
                        sbQueryResult.Append("<table style=\"font-size: 12px; color:blue;\" ><tr>");
                        sbQueryResult.AppendFormat("<td width=\"170\" style=\"cursor:pointer\" onclick=\"SwitchResultVisible({0}, \\'{1}\\')\">", recordIndex, "Record_");
                        sbQueryResult.AppendFormat("<a onclick=\"SetFieldValue(\\'Result_X\\',{0}); SetFieldValue(\\'Result_Y\\',{1}); SetFieldValue(\\'Result_Name\\',\\'{2}\\'); {3}_DoPostBack(); return false;\">&nbsp; {2}</a>",
                            curRecord.Center.X, curRecord.Center.Y, curRecordText.Replace("'","\\\'"), this.MapControl1.ClientID);
                        sbQueryResult.Append("</td>");
                        sbQueryResult.AppendFormat("<td style=\"cursor:pointer\" onclick=\"SwitchResultVisible({0}, \\'{1}\\')\">◇</td>", recordIndex, "Record_");
                        sbQueryResult.Append("</tr></table>");

                        //显示详细信息。
						string curFiledNameText, curFieldValueText;
                        sbQueryResult.AppendFormat("<table id=\"{0}\" style=\"display:none\">", recordID);
                        for (int k = 0; k < headerCount; k++)
                        {
							curFiledNameText=curRecordset.ReturnFields[k];
							if(curFiledNameText==null){curFiledNameText=string.Empty;}
							else{curFiledNameText=curFiledNameText.Replace("'",@"\'");}
							curFieldValueText=curRecord.FieldValues[k];
							if(curFieldValueText==null){curFieldValueText=string.Empty;}
							else{curFieldValueText=curFieldValueText.Replace("'",@"\'");}
                            sbQueryResult.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", curFiledNameText, curFieldValueText);
                        }
                        sbQueryResult.Append("</table>");
                    }
                    sbQueryResult.Append("</td></tr>");

                }
                sbQueryResult.Append("</table>");
            }

            string jsResult = "<script type='text/javascript'>";
            jsResult += "var strTable = '" + sbQueryResult.ToString() + "';";
            jsResult += "var divQueryResult = document.getElementById('DivQueryResult');";
            jsResult += "if(divQueryResult != null)";
            jsResult += "{";
            jsResult += "	divQueryResult.innerHTML = strTable";
            jsResult += "}";
            jsResult += "</script>";
            if (!Page.IsStartupScriptRegistered("jsResult"))
            {
                Page.RegisterStartupScript("jsResultInCurrentWindow", jsResult);
            }
        }

        /// <summary>
        /// 在新窗口中显示查询结果
        /// </summary>
        /// <param name="resultSet"></param>
        /// <param name="maxLength"></param>
        private void ShowQueryResultInNewWindow(SuperMap.IS.Utility.ResultSet resultSet, int maxLength)
        {
            if (resultSet == null || resultSet.Recordsets == null || resultSet.Recordsets.Length <= 0 || resultSet.TotalCount <= 0)
            {
                DisplayResult(null);
                return;
            }

            Session.Remove("ResultSet");	//下次不再弹出。

            int currentRecordIndex = 0;

            int tableCount = resultSet.Recordsets.Length;
            string strQueryResult = string.Empty;
            Recordset curRecordset;
            int headerCount;
            int recordCount;
            for (int i = 0; i < tableCount; i++)
            {
                curRecordset = resultSet.Recordsets[i];

                strQueryResult += "<table style=\"font-size: 9pt\" border=1pt bordercolorlight=#C0C0C0 cellspacing=1pt bordercolordark=#FFFFFF bgcolor=#ceccc1 width=100%><tr>";
                headerCount = curRecordset.ReturnFields.Length;
                for (int j = 0; j < headerCount; j++)
                {
                    strQueryResult += string.Format("<td>{0}</td>", curRecordset.ReturnFields[j]);
                }
                strQueryResult += "</tr>";

                recordCount = curRecordset.Records.Length;
                Record curRecord;
                int valueCount;
                for (int j = 0; j < recordCount; j++)
                {
                    currentRecordIndex++;
                    if (maxLength > 0 && currentRecordIndex > maxLength)
                    {
                        break;
                    }

                    curRecord = curRecordset.Records[j];
                    valueCount = curRecord.FieldValues.Length;
                    strQueryResult += "<tr>";
                    for (int k = 0; k < valueCount; k++)
                    {
                        strQueryResult += string.Format("<td>{0}</td>", curRecord.FieldValues[k]);
                    }
                    strQueryResult += "</tr>";
                }
                strQueryResult += "</table>";
            }
            string jsResult = "<script language='javascript'>";
            jsResult += "var strTable = '" + strQueryResult + "';";
            jsResult += "var strFeature='height=360,width=500,status=no,toolbar=no,resizable=no,menubar=no,location=no,scrollbars=yes';";
            jsResult += "var aWin = window.open('','QueryResult',strFeature);";
            jsResult += "aWin.document.open();";
            jsResult += "aWin.document.write(\"<html>\");";
            jsResult += "aWin.document.write(\"<head>\");";
            jsResult += "aWin.document.write(\"<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>\");";
            jsResult += "aWin.document.write(\"<title>SuperMap IS Query Result</title>\");";
            jsResult += "aWin.document.write(\"</head>\");";
            jsResult += "aWin.document.write(\"<BODY style='font-size: 9pt' bgcolor=#eeccE1>\");";
            jsResult += "aWin.document.write(strTable);";
            jsResult += "aWin.document.write(\"</BODY>\");";
            jsResult += "aWin.document.write(\"</html>\");";
            jsResult += "aWin.document.close();";
            jsResult += "function focusResultWindow(){";
            jsResult += "aWin.focus();";
            jsResult += "}";
            jsResult += "setTimeout(focusResultWindow, 1500);";
            jsResult += "</script>";
            if (!Page.IsStartupScriptRegistered("jsResult"))
            {
                Page.RegisterStartupScript("jsResultInNewWindow", jsResult);
            }
        }
        #endregion

        #region 切换地图
        /// <summary>
        /// 切换地图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lstMaps_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            string selectedMapName = this.lstMaps.SelectedItem.Text;
            if (!this.MapControl1.MapName.Equals(selectedMapName))
            {
                this.MapControl1.MapName = selectedMapName;
                this.MapControl1.Update();
            }
        }
        #endregion

        #region 切换地图后的事件
        /// <summary>
        /// 当切换地图后的事件,重新设置 地图列表下拉框 里的默认选定值。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MapControl1_MapSwitched(object sender, SuperMap.IS.WebControls.EventArguments.MapSwitchedEventArgs e)
        {
            FillMapList(lstMaps, true);
            LayerType[] editableLayers = new LayerType[3];
            editableLayers[0] = LayerType.Point;
            editableLayers[1] = LayerType.Line;
            editableLayers[2] = LayerType.Polygon;
            // editableLayers[3] = LayerType.Text;
            FillLayerList(lstEditLayers, editableLayers);
            FillLayerList(lstPointLayers, new LayerType[1] { LayerType.Point });
        }
        #endregion

        #region 显示地图列表, 刷新地图列表
        /// <summary>
        /// 把地图名显示在下拉框中,当前地图为默认选中项
        /// </summary>
        /// <param name="list">要显示地图名的下拉框</param>
        /// <param name="onlyRefreshSelected">是否仅刷新当前地图选项</param>
        private void FillMapList(DropDownList list, bool onlyRefreshSelected)
        {
            string currentMapName = this.MapControl1.MapName;

            if (list == null)
            {
                return;
            }

            if (!onlyRefreshSelected)
            {
                string[] mapNames = this.MapControl1.MapNames;

                if (mapNames == null || mapNames.Length < 1)
                {
                    return;
                }

                list.Items.Clear();

                for (int i = 0; i < mapNames.Length; i++)
                {
                    string mapName = mapNames[i];
                    list.Items.Add(mapName);
                    if (currentMapName != null && currentMapName.Equals(mapName))
                    {
                        list.Items[i].Selected = true;
                    }
                }
            }
            else
            {
                for (int i = 0; i < list.Items.Count; i++)
                {
                    if (list.Items[i].Text.Equals(currentMapName))
                    {
                        list.SelectedItem.Selected = false;
                        list.Items[i].Selected = true;
                        break;
                    }
                }

⌨️ 快捷键说明

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