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=\"width: 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文件,可以在浏览器预览。

转载于:https://www.cnblogs.com/snow-zhang/p/10113586.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值