2 u012689660 u012689660 于 2016.01.27 11:18 提问

怎么修改操作地图代码,根据地区显示数据而不是显示都是相同数据

图片说明
图片说明
public void ProcessRequest (HttpContext context) {
string codeId = GZSoft.Web.Utility.GZBasic.GetSessionByName("CodeId");//行政代码
string rating = GZSoft.Web.Utility.GZBasic.GetSessionByName("Rating");//权限
switch (rating)
{
case "省级":
codeId = codeId.Substring(0, 2).ToString() + "%";
break;
case "地区级":
codeId = codeId.Substring(0, 4).ToString() + "%";
break;
case "县级":
codeId = codeId.Substring(0, 6).ToString() + "%";
break;
default:
codeId = codeId.Substring(0, 6).ToString() + "%";
break;
}
string tType = context.Request.Params["FType"];
string level = context.Request.Params["level"];//这里取得是地图的比例,源代码没有用到
string Feature = GZSoft.BLL.Map.Feature.GetFeatureGsCharts(codeId, tType);

    context.Response.Write(Feature.Length > 0 ? Feature : "");
}

1个回答

u012689660
u012689660   2016.01.27 11:19

public static string GetFeatureGsCharts(string codeId,string tType)
{
if (codeId == null) throw new ArgumentNullException("codeId");
int total = 0;//古树总数
int totalGsq = 0;//古树群总数

        string strGsInfo = "";
        string strGsqInfo = "";
        string strGsqChart = "";

        try
        {
            var strBdr = new StringBuilder();
            strBdr.Append("select count(isnull(ProtecLevel,'其他')) as C,isnull(ProtecLevel,'其他') as N ");
            strBdr.Append("from Tree_Trees ");
            strBdr.Append("where CodeId like @CodeId group by isnull(ProtecLevel,'其他');");//古树
            strBdr.Append("select count(isnull(ProtecLevel,'其他')) as C,isnull(ProtecLevel,'其他') as N ");
            strBdr.Append("from Tree_GroupTrees ");
            strBdr.Append("where CodeId like @CodeId group by isnull(ProtecLevel,'其他')");//古树群
            string strSql = string.Format("select * from dbo.Basic_Code where CodeId like '{0}'", codeId);

            //获取省下所有的市
            DataTable dt0 = GZSoft.DBUtility.DbHelper.ExecuteDataTableBySql(strSql);
            IList<GZSoft.Model.Map.FeatureCharts> modelsN = new List<GZSoft.Model.Map.FeatureCharts>();
            FeatureCharts modelN;
            double mercatorX = 0, mercatorY = 0;

            for (var i = 0; i < dt0.Rows.Count; i++)
            {
                modelN = new FeatureCharts();
                codeId = dt0.Rows[i]["CodeId"].ToString().Substring(0, 6) + "%";
                SqlParameter[] parameters = {
                                            new SqlParameter("@CodeId", codeId)};
                //把查询的地址放和数据放进DataSetBySql中,并附给dataset
                DataSet ds = GZSoft.DBUtility.DbHelper.ExecuteDataSetBySql(strBdr.ToString(), parameters);
                if (ds == null || ds.Tables.Count < 1)
                    continue;
                DataTable dt = ds.Tables[0];//古树的数据
                DataTable dtgsq = ds.Tables[1];//古树群的数据
                total = 0;
                totalGsq = 0;
                string strChart = ""; strGsInfo = ""; strGsqChart = ""; strGsqInfo = "";

                //古树群不为空,大于0的情况
                if (dt != null && dt.Rows.Count > 0)
                {
                    //循环古树数据
                    for (var k = 0; k < dt.Rows.Count; k++)
                    {
                        //古树总数量
                        total += Int32.Parse(dt.Rows[k]["C"].ToString());
                        //显示古树和数量
                        strChart += LowerToUpperNum(dt.Rows[k]["N"].ToString()) + "级:" + dt.Rows[k]["C"].ToString() +
                                    " ";
                        //显示扇形图中数据,CodeName显示读取地区的地址
                        strGsInfo += "{0}'Name':'" + LowerToUpperNum(dt.Rows[k]["N"].ToString()) + "级','Count':" +
                                     dt.Rows[k]["C"].ToString() + ",'City':'" + dt0.Rows[i]["CodeName"].ToString() +
                                     "','title':'gs',{1}{2},";
                    }
                }
                //古树群不为空,大于0的情况
                if (dtgsq != null && dtgsq.Rows.Count > 0)
                {
                    //循环古树群数据
                    for (var k = 0; k < dtgsq.Rows.Count; k++)
                    {
                        //古树群总数量
                        totalGsq += Int32.Parse(dtgsq.Rows[k]["C"].ToString());
                        //显示地图中图表,古树群中的数据
                        strGsqChart += LowerToUpperNum(dtgsq.Rows[k]["N"].ToString()) + "级:" + dtgsq.Rows[k]["C"].ToString() + " ";
                        //显示显示地图中图表的古树群的扇形图,只有点击古树群才会出现
                        strGsqInfo += "{0}'Name':'" + LowerToUpperNum(dtgsq.Rows[k]["N"].ToString()) + "级','Count':" +
                                      dtgsq.Rows[k]["C"].ToString() + ",'City':'" +
                                      dt0.Rows[i]["CodeName"].ToString() +
                                      "','title':'gsq',{1}{2},";
                    }
                }
                //显示“古树”和“古树群”数据的总条数的就是接strGsqChart这个后面显示数据
                strGsInfo = string.Format(strGsInfo, "{",
                                          "'info':'" + strChart + "共:" + total.ToString() + "株','infoGsq':'" +
                                          strGsqChart + "共:" + totalGsq.ToString() + "株'", "}");
                strGsInfo = (strGsInfo != "" && strGsInfo.Length > 0)
                                ? "[" + strGsInfo.Trim().Substring(0, strGsInfo.Trim().Length - 1).Replace("'","\"") + "]"
                                : "";
                //这个未发现作用
                strGsqInfo = string.Format(strGsqInfo, "{",
                                          "'info':'" + strChart + "共:" + total.ToString() + "株','infoGsq':'" +
                                          strGsqChart + "共:" + totalGsq.ToString() + "株'", "}");
                strGsqInfo = (strGsqInfo != "" && strGsqInfo.Length > 0)
                                ? "[" + strGsqInfo.Trim().Substring(0, strGsqInfo.Trim().Length - 1).Replace("'", "\"") + "]"
                                : "";
                if (strGsInfo == "" && strGsqInfo == "")
                    continue;
                string n = strGsInfo + "|" + strGsqInfo;
                n = (n != "" && n.Length > 0) ? n.Replace("'", "\"") : "";
                modelN.A = dt0.Rows[i]["CodeName"].ToString();
                modelN.N = n;
                double j = 0;//精度
                double w = 0;//纬度
                if(tType=="gs")//统计类型为古树的时候
                {
                   j = double.Parse(dt0.Rows[i]["LONG"].ToString());//使用j来接收dt0所读取到的值
                   w = double.Parse(dt0.Rows[i]["LAT"].ToString());//使用w来接收dt0所读取的值
                }
                else
                {
                    j = double.Parse(dt0.Rows[i]["LONG"].ToString()) + 0.1;//使用j接收dt0读取到的值并加上0.1
                    w = double.Parse(dt0.Rows[i]["LAT"].ToString()) + 0.1;
                }
                ReverserClass.WGS2Mars(ref w, ref j);//调用方法坐标转火星坐标
                Lonlat2Mercator(j, w, ref mercatorX, ref mercatorY);//把转成火星坐标的j和w放入Lonlat2Mercator方法里面,mercatorX和mercatorY返回墨卡托
                modelN.J = decimal.Parse(mercatorX.ToString());
                modelN.W = decimal.Parse(mercatorY.ToString());
                modelsN.Add(modelN);
            }
            if (modelsN.Count > 0)
                return GZSoft.Utility.JsonHelper.Serialize(modelsN);
        }
        catch (Exception ex)
        {
            GZSoft.Utility.LogHelper.Error("GZSoft.BLL.Map.GetFeatureGsCharts(string codeId):" + ex.Message +
                                           "CodeId:" + codeId);
        }
        return string.Empty;
    }
    /// <summary>
    /// 经纬度转墨卡托
    /// author:别晓朋
    /// </summary>
    /// <param name="j">传入经纬度</param>
    /// <param name="w"></param>
    /// <param name="mercatorX">返回墨卡托</param>
    /// <param name="mercatorY"></param>
    public static void Lonlat2Mercator(double j, double w, ref double mercatorX, ref double mercatorY)
    {
        try
        {
            double x = j*20037508.342787/180;
            double y = Math.Log(Math.Tan((90 + w)*Math.PI/360))/(Math.PI/180);
            y = y*20037508.342787/180;
            mercatorX = x;
            mercatorY = y;
        }
        catch (Exception ex)
        {
            GZSoft.Utility.LogHelper.Error("GZSoft.BLL.Map.Lonlat2Mercator:" + ex.Message+j.ToString());
        }
    }
    /// <summary>
    /// 小写等级转换为大写
    /// author:别晓朋
    /// </summary>
    /// <param name="strLower">传入参数小写</param>
    /// <returns>返回大写</returns>
    public static string LowerToUpperNum(string strLower)
    {
        string strUpper = "";
        switch (strLower.Trim())
        {
            case "1":
                strUpper = "一";
                break;
            case "2":
                strUpper = "二";
                break;
            case "3":
                strUpper = "三";
                break;
            case "4":
                strUpper = "四";
                break;
            case "5":
                strUpper = "五";
                break;
            case "6":
                strUpper = "六";
                break;
            case "7":
                strUpper = "七";
                break;
            case "8":
                strUpper = "八";
                break;
            case "9":
                strUpper = "九";
                break;
            default:
                strUpper = "其他";
                break;
        }
        return strUpper;
    }
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!