示例#1
0
        public ActionResult PanoXml(string uid, string view)
        {
            //PanoItem item;
            SQLiteConnection conn = new SQLiteConnection(_connstr);

            conn.Open();
            string sql1 = "select * from panosscene where uid=@uid";
            string sql2 = "select * from panos where uid=@uid";

            //
            ViewData["scene"] = "";
            try {
                SceneItem sceneItem = conn.QueryFirst <SceneItem>(sql1, new { uid = uid });
                PanoItem  panoItem  = conn.QueryFirst <PanoItem>(sql2, new { uid = uid });

                //<layer name="map" keep="true"
                //       url="bingmaps.swf" alturl="../panorama/plugins/leafletmaps.js"
                //       align="rightbottom" x="0" y="0" width="270" height="300"
                //       lat="24.30522" lng="109.429847" zoom="15">

                //    <spot name="stpeterssquare" active="true"
                //          lat="24.30522" lng="109.429847" heading="64.5"
                //          onclick="" />

                //    <radar visible="true" zoomwithmap="true" size="50" />
                //</layer>

                if (sceneItem != null && panoItem != null)
                {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(sceneItem.scene);
                    doc.SelectSingleNode("/scene").Attributes["name"].Value  = "_" + uid;                       // 全景名称
                    doc.SelectSingleNode("/scene").Attributes["title"].Value = panoItem.name;                   // 全景标题
                    string thumburl = doc.SelectSingleNode("/scene").Attributes["thumburl"].Value;
                    thumburl = "../_tiles/" + thumburl.Substring(5);
                    doc.SelectSingleNode("/scene").Attributes["thumburl"].Value = thumburl;                     // 全景预览图
                    doc.SelectSingleNode("/scene").Attributes["lat"].Value      = panoItem.lat.ToString();      // 纬度
                    doc.SelectSingleNode("/scene").Attributes["lng"].Value      = panoItem.lng.ToString();      // 经度
                    doc.SelectSingleNode("/scene").Attributes["heading"].Value  = panoItem.heading.ToString();  // 朝向
                    string text = doc.SelectSingleNode("/scene").InnerXml;
                    text = text.Replace("\"panos/", "\"../_tiles/");
                    doc.SelectSingleNode("/scene").InnerXml = text;


                    string radar = @"
<layer name=`map` keep=`true`
       url=`bingmaps.swf` alturl=`../panorama/plugins/leafletmaps.js`
       align=`rightbottom` x=`0` y=`0` width=`270` height=`300`
       lat=`{0}` lng=`{1}` zoom=`14`>
    <spot name=`stpeterssquare` active=`true`
          lat=`{0}` lng=`{1}` heading=`{2}`
          onclick=`` />
    <radar visible=`true` zoomwithmap=`true` size=`40` />
</layer>";
                    radar = radar.Replace("`", "\"");
                    radar = string.Format(radar, panoItem.lat, panoItem.lng, panoItem.heading);


                    ViewData["scene"] = doc.OuterXml + radar;
                }
            }
            catch (Exception ex) {
                throw;
            }


            return(View());
        }
示例#2
0
        public JsonResult Build(string uid, string name, string category, long date, int heading, double lat, double lng, string author, string remark)
        {
            try {
                //
                string imagefile = string.Format("{0}\\{1}.JPG", Server.MapPath(PANO_TEMP_PATH), uid);
                if (System.IO.File.Exists(imagefile) == false)
                {
                    throw new Exception("无效的UID: " + uid);
                }
                string toolfile = Server.MapPath(PANO_TOOL_EXE);
                // 切图
                string    message  = "";
                string    scenexml = "";
                string    root     = "";
                string[]  tiles    = new string[0];
                PanoMaker maker    = new PanoMaker();
                bool      success  = maker.MakeNormal(toolfile, imagefile, 100, out message, out scenexml, out tiles, out root);
                if (success == false)
                {
                    throw new Exception(message);
                }
                // 时间戳转换
                DateTime start = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
                DateTime time  = start.Add(new TimeSpan(date * 10000000));
                // epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000

                // 入库
                PanoItem panoItem = new PanoItem()
                {
                    uid      = uid,
                    name     = name,
                    category = category,
                    shottime = time,
                    heading  = heading,
                    lat      = lat,
                    lng      = lng,
                    author   = author,
                    remark   = remark,
                    maketime = DateTime.Now
                };
                SceneItem sceneItem = new SceneItem()
                {
                    uid   = uid,
                    scene = scenexml
                };

                string sql1 = "insert into PANOS(uid, name, category, shottime, heading, lat, lng, author, remark, maketime) " +
                              "values(@uid, @name, @category, @shottime, @heading, @lat, @lng, @author, @remark, @maketime)";
                string sql2 = "insert into PANOSSCENE(uid, scene) " +
                              "values(@uid, @scene)";
                SQLiteConnection conn = new SQLiteConnection(_connstr);
                conn.Open();
                int result1 = conn.Execute(sql1, panoItem);             // 插入
                int result2 = conn.Execute(sql2, sceneItem);            // 插入
                conn.Close();

                // 存储瓦片数据 碎片直接放磁盘上 放数据库访问起来会有点慢
                foreach (string tile in tiles)
                {
                    string tileroot = Server.MapPath(PANO_TILE_PATH);
                    string tilename = System.IO.Path.GetFileName(tile);
                    string tilepath = System.IO.Path.GetDirectoryName(tile).ToLower().Replace(root.ToLower(), "");
                    string tilesave = tileroot + "//" + tilepath;
                    string tilefile = tilesave + "//" + tilename;
                    if (System.IO.Directory.Exists(tilesave) == false)
                    {
                        System.IO.Directory.CreateDirectory(tilesave);
                    }
                    System.IO.File.Move(tile, tilefile);
                }

                // 保存图片 和 基本信息
                string imagesave = string.Format("{0}\\{1}.JPG", Server.MapPath(PANO_SAVE_PATH), uid);
                System.IO.File.Move(imagefile, imagesave);
                StreamWriter writer = new StreamWriter(string.Format("{0}\\{1}.TXT", Server.MapPath(PANO_SAVE_PATH), uid));
                writer.WriteLine("uid:" + panoItem.uid.Replace("\r\n", "\\r\\n"));
                writer.WriteLine("name:" + panoItem.name.Replace("\r\n", "\\r\\n"));
                writer.WriteLine("category:" + panoItem.category.Replace("\r\n", "\\r\\n"));
                writer.WriteLine("shottime:" + panoItem.shottime.ToString("yyyy/MM/dd HH:mm:ss"));
                writer.WriteLine("heading:" + panoItem.heading.ToString());
                writer.WriteLine("lat:" + panoItem.lat.ToString());
                writer.WriteLine("lng:" + panoItem.lng);
                writer.WriteLine("author:" + panoItem.author.Replace("\r\n", "\\r\\n"));
                writer.WriteLine("remark:" + panoItem.remark.Replace("\r\n", "\\r\\n"));
                writer.WriteLine("maketime:" + panoItem.maketime.ToString("yyyy/MM/dd HH:mm:ss"));
                writer.Flush();
                writer.Close();

                // 删除成图临时目录
                string outputdir = string.Format("{0}\\{1}", Server.MapPath(PANO_TEMP_PATH), uid);
                System.IO.Directory.Delete(outputdir, true);

                return(Json(new { code = 0, success = true, uid = uid, message = "" }));
            }
            catch (Exception ex) {
                return(Json(new { code = 101, success = false, uid = "", message = ex.Message }));
            }
        }