zoukankan      html  css  js  c++  java
  • C# 动态生成Html地图文件

       public void GPSModel(string x, string y, string ss)//动态地图文件
            {
                if (x.Contains("-") && y.Contains("-")) return;
                if (x=="" ||y=="") return;
                StringBuilder IndexHTMLBuilder = new StringBuilder();
                IndexHTMLBuilder.Append("<!DOCTYPE html>" + Environment.NewLine);
                IndexHTMLBuilder.Append("<html>" + Environment.NewLine);
                IndexHTMLBuilder.Append("<head>" + Environment.NewLine);
                IndexHTMLBuilder.Append("<meta http-equiv="Content-Type" content="text/html;charset=gb2312"/>" + Environment.NewLine);
                IndexHTMLBuilder.Append("<title>baidumap</title> " + Environment.NewLine);
                IndexHTMLBuilder.Append("<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>" + Environment.NewLine);
                IndexHTMLBuilder.Append("</head>" + Environment.NewLine);
                IndexHTMLBuilder.Append("<body>" + Environment.NewLine);
                IndexHTMLBuilder.Append("<div style=" 600px; height:1000px; border:1px solid gray" id="container"></div>" + Environment.NewLine);
                IndexHTMLBuilder.Append("</body>" + Environment.NewLine);
                IndexHTMLBuilder.Append("</html>" + Environment.NewLine);
                IndexHTMLBuilder.Append("<script type="text/javascript">" + Environment.NewLine);
                IndexHTMLBuilder.Append("var map = new BMap.Map("container");" + Environment.NewLine);
                IndexHTMLBuilder.Append("var point = new BMap.Point(" + y + "," + x + ");" + Environment.NewLine);
                IndexHTMLBuilder.Append("map.centerAndZoom(point, 15);" + Environment.NewLine);
                IndexHTMLBuilder.Append("map.enableScrollWheelZoom(); " + Environment.NewLine);
                IndexHTMLBuilder.Append("map.enableKeyboard(); " + Environment.NewLine);
                IndexHTMLBuilder.Append("var point2 = new BMap.Point(" + y + "," + x + ");" + Environment.NewLine);
                IndexHTMLBuilder.Append("var marker2 = new BMap.Marker(point2);" + Environment.NewLine);
                IndexHTMLBuilder.Append("map.addOverlay(marker2);" + Environment.NewLine);
                IndexHTMLBuilder.Append("var label2 = new BMap.Label("" + ss + "",{offset:new BMap.Size(20,-10)});" + Environment.NewLine);
                IndexHTMLBuilder.Append("marker2.setLabel(label2);" + Environment.NewLine);
                IndexHTMLBuilder.Append("</script>" + Environment.NewLine);
                string Htmltext = IndexHTMLBuilder.ToString();
                System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory , Htmltext, Encoding.UTF8);            
            }

    使用方法:x,y,ss  分别对应经纬度,Mark点名称,动态生成Html文件,可以在浏览器预览。

    每天进步一点点。
  • 相关阅读:
    用Repeater控件显示主从关系数据表
    transactsql高级查询(上)
    利用动态加载模板,配合ajax实现无刷新操作
    如何使用Repeater控件的模板
    总结一下DataGrid,DataList,Repeater
    ajax实现dropdownlist与datagrid或Repeater无联动刷新
    Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)
    SQLSERVER存储过程
    我的java 的实用代码
    各种数据库对应的jar包、驱动类名和URL格式
  • 原文地址:https://www.cnblogs.com/snow-zhang/p/10113586.html
Copyright © 2011-2022 走看看