public override void FinalizeRun()
        {
            TotalProcessTime.Start();
            //generate map HTML
            string html = Utils.ResourceHelper.GetEmbeddedTextFile("/Resources/ActionShowOnlineMap.html");

            //icons
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(string.Format("var foundIcon = new google.maps.MarkerImage(\"{0}\");", Utils.ResourceHelper.GetEmbeddedHtmlImageData("/Resources/Map/found.png")));
            sb.AppendLine(string.Format("var unknownIcon = new google.maps.MarkerImage(\"{0}\");", Utils.ResourceHelper.GetEmbeddedHtmlImageData("/Resources/Map/0.png")));
            sb.AppendLine(string.Format("var myownIcon = new google.maps.MarkerImage(\"{0}\");", Utils.ResourceHelper.GetEmbeddedHtmlImageData("/Resources/Map/myown.png")));
            foreach (var gctype in ApplicationData.Instance.GeocacheTypes)
            {
                sb.AppendLine(string.Format("var gct{0}Icon = new google.maps.MarkerImage(\"{1}\");", gctype.ID.ToString().Replace("-", "_"), Utils.ResourceHelper.GetEmbeddedHtmlImageData(string.Format("/Resources/Map/{0}.png", gctype.ID))));
                sb.AppendLine(string.Format("var gct{0}IconC = new google.maps.MarkerImage(\"{1}\");", gctype.ID.ToString().Replace("-", "_"), Utils.ResourceHelper.GetEmbeddedHtmlImageData(string.Format("/Resources/Map/c{0}.png", gctype.ID))));
            }
            foreach (var wptype in ApplicationData.Instance.WaypointTypes)
            {
                sb.AppendLine(string.Format("var wpt{0}Icon = new google.maps.MarkerImage(\"{1}\");", wptype.ID.ToString().Replace("-", "_"), Utils.ResourceHelper.GetEmbeddedHtmlImageData(string.Format("/Resources/Map/{0}.gif", wptype.ID))));
            }
            html = html.Replace("//icons", sb.ToString());

            sb.Length = 0;
            using (var db = new NPoco.Database(DatabaseConnection.Connection, NPoco.DatabaseType.SQLite))
            {
                var gcl = db.Fetch<GeocachePoco>(string.Format("select Code, Name, CacheType, Found, IsOwner, Latitude, Longitude, kAfterLat, kAfterLon from Caches inner join {0} on Caches.Code={0}.gccode left join Corrected on Caches.Code=Corrected.kCode", ActionInputTableName));
                foreach (var gc in gcl)
                {
                    var gcicon = "gct0Icon";
                    if (gc.IsOwner != 0)
                    {
                        gcicon = "myownIcon";
                    }
                    else if (gc.Found != 0)
                    {
                        gcicon = "foundIcon";
                    }
                    else
                    {
                        var gctype = (from a in ApplicationData.Instance.GeocacheTypes where a.GSAK == gc.CacheType select a).FirstOrDefault();
                        if (gctype != null)
                        {
                            if (gc.kAfterLat != null)
                            {
                                gcicon = string.Format("gct{0}IconC", gctype.ID);
                            }
                            else
                            {
                                gcicon = string.Format("gct{0}Icon", gctype.ID);
                            }
                        }
                    }
                    sb.AppendFormat("markers.push(addClickListener(new MarkerWithLabel({{position: new google.maps.LatLng({1},{2}),icon:{3},title:'{0}',labelContent:'{0}',labelAnchor: new google.maps.Point(10, 0),labelClass:'labels'}})));", string.Format("{0}-{1}", gc.Code, gc.Name.Replace("'", "").Replace("\\", "")), gc.kAfterLat == null ? gc.Latitude : gc.kAfterLat, gc.kAfterLon == null ? gc.Longitude : gc.kAfterLon, gcicon);
                }
                sb.AppendLine();
                sb.AppendLine("markerClusterer = new MarkerClusterer(map, markers, clusterOptions);");
                if (gcl.Count > 0)
                {
                    var dr = DatabaseConnection.ExecuteReader(string.Format("select AVG(Latitude), AVG(Longitude) from Caches inner join {0} on Caches.Code={0}.gccode left join Corrected on Caches.Code=Corrected.kCode", ActionInputTableName));
                    if (dr.Read())
                    {
                        var lat = dr.GetDouble(0);
                        var lon = dr.GetDouble(1);
                        sb.AppendLine(string.Format("map.setCenter(new google.maps.LatLng({0}, {1}));", lat.ToString(CultureInfo.InvariantCulture), lon.ToString(CultureInfo.InvariantCulture)));
                    }
                }
            }
            html = html.Replace("//geocachelist", sb.ToString());

            _context.Send(new SendOrPostCallback(delegate(object state)
            {
                var wnd = new Dialogs.WindowWebBrowser(html, new WebBrowserControl.JSCallback() { Name = "bound", Instance = new JSCallBack() });
                wnd.Show();
            }), null);

            TotalProcessTime.Stop();
            base.FinalizeRun();
        }
Esempio n. 2
0
        public override void FinalizeRun()
        {
            TotalProcessTime.Start();
            //generate map HTML
            string html = Utils.ResourceHelper.GetEmbeddedTextFile("/Resources/ActionShowOnlineMap.html");

            //icons
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(string.Format("var foundIcon = new google.maps.MarkerImage(\"{0}\");", Utils.ResourceHelper.GetEmbeddedHtmlImageData("/Resources/Map/found.png")));
            sb.AppendLine(string.Format("var unknownIcon = new google.maps.MarkerImage(\"{0}\");", Utils.ResourceHelper.GetEmbeddedHtmlImageData("/Resources/Map/0.png")));
            sb.AppendLine(string.Format("var myownIcon = new google.maps.MarkerImage(\"{0}\");", Utils.ResourceHelper.GetEmbeddedHtmlImageData("/Resources/Map/myown.png")));
            foreach (var gctype in ApplicationData.Instance.GeocacheTypes)
            {
                sb.AppendLine(string.Format("var gct{0}Icon = new google.maps.MarkerImage(\"{1}\");", gctype.ID.ToString().Replace("-", "_"), Utils.ResourceHelper.GetEmbeddedHtmlImageData(string.Format("/Resources/Map/{0}.png", gctype.ID))));
                sb.AppendLine(string.Format("var gct{0}IconC = new google.maps.MarkerImage(\"{1}\");", gctype.ID.ToString().Replace("-", "_"), Utils.ResourceHelper.GetEmbeddedHtmlImageData(string.Format("/Resources/Map/c{0}.png", gctype.ID))));
            }
            foreach (var wptype in ApplicationData.Instance.WaypointTypes)
            {
                sb.AppendLine(string.Format("var wpt{0}Icon = new google.maps.MarkerImage(\"{1}\");", wptype.ID.ToString().Replace("-", "_"), Utils.ResourceHelper.GetEmbeddedHtmlImageData(string.Format("/Resources/Map/{0}.gif", wptype.ID))));
            }
            html = html.Replace("//icons", sb.ToString());

            sb.Length = 0;
            using (var db = new NPoco.Database(DatabaseConnection.Connection, NPoco.DatabaseType.SQLite))
            {
                var gcl = db.Fetch <GeocachePoco>(string.Format("select Code, Name, CacheType, Found, IsOwner, Latitude, Longitude, kAfterLat, kAfterLon from Caches inner join {0} on Caches.Code={0}.gccode left join Corrected on Caches.Code=Corrected.kCode", ActionInputTableName));
                foreach (var gc in gcl)
                {
                    var gcicon = "gct0Icon";
                    if (gc.IsOwner != 0)
                    {
                        gcicon = "myownIcon";
                    }
                    else if (gc.Found != 0)
                    {
                        gcicon = "foundIcon";
                    }
                    else
                    {
                        var gctype = (from a in ApplicationData.Instance.GeocacheTypes where a.GSAK == gc.CacheType select a).FirstOrDefault();
                        if (gctype != null)
                        {
                            if (gc.kAfterLat != null)
                            {
                                gcicon = string.Format("gct{0}IconC", gctype.ID);
                            }
                            else
                            {
                                gcicon = string.Format("gct{0}Icon", gctype.ID);
                            }
                        }
                    }
                    sb.AppendFormat("markers.push(addClickListener(new MarkerWithLabel({{position: new google.maps.LatLng({1},{2}),icon:{3},title:'{0}',labelContent:'{0}',labelAnchor: new google.maps.Point(10, 0),labelClass:'labels'}})));", string.Format("{0}-{1}", gc.Code, gc.Name.Replace("'", "").Replace("\\", "")), gc.kAfterLat == null ? gc.Latitude : gc.kAfterLat, gc.kAfterLon == null ? gc.Longitude : gc.kAfterLon, gcicon);
                }
                sb.AppendLine();
                sb.AppendLine("markerClusterer = new MarkerClusterer(map, markers, clusterOptions);");
                if (gcl.Count > 0)
                {
                    var dr = DatabaseConnection.ExecuteReader(string.Format("select AVG(Latitude), AVG(Longitude) from Caches inner join {0} on Caches.Code={0}.gccode left join Corrected on Caches.Code=Corrected.kCode", ActionInputTableName));
                    if (dr.Read())
                    {
                        var lat = dr.GetDouble(0);
                        var lon = dr.GetDouble(1);
                        sb.AppendLine(string.Format("map.setCenter(new google.maps.LatLng({0}, {1}));", lat.ToString(CultureInfo.InvariantCulture), lon.ToString(CultureInfo.InvariantCulture)));
                    }
                }
            }
            html = html.Replace("//geocachelist", sb.ToString());

            _context.Send(new SendOrPostCallback(delegate(object state)
            {
                var wnd = new Dialogs.WindowWebBrowser(html, new WebBrowserControl.JSCallback()
                {
                    Name = "bound", Instance = new JSCallBack()
                });
                wnd.Show();
            }), null);

            TotalProcessTime.Stop();
            base.FinalizeRun();
        }