Пример #1
0
        public static SiteStructs.LatLong GetLatLongForCountryPostal(string countryCode, string postalCode)
        {
            SiteStructs.LatLong latlong = new SiteStructs.LatLong();

            if (string.IsNullOrWhiteSpace(countryCode) || string.IsNullOrWhiteSpace(postalCode)) return latlong;

            if (countryCode == SiteEnums.CountryCodeISO.UK.ToString())
            {
                // they call it GB not UK or the other ones made for flags

                string cocode = "GB";

                switch ((SiteEnums.CountryCodeISO)Enum.Parse(typeof(SiteEnums.CountryCodeISO), countryCode))
                {
                    case SiteEnums.CountryCodeISO.UK:
                        countryCode = countryCode.Replace(SiteEnums.CountryCodeISO.UK.ToString(), cocode);
                        break;
                    default:
                        break;
                }

                if (postalCode.Length > 3)
                {
                    // they use only the beginning
                    postalCode = postalCode.Substring(0, 4);
                }
            }
            else if (countryCode == SiteEnums.CountryCodeISO.CR.ToString())
            {
                // they don't have the postal codes in Costa Rica
                postalCode = string.Empty;
            }
            else if (countryCode == SiteEnums.CountryCodeISO.NL.ToString())
            {
                if (postalCode.Length > 3)
                {
                    // they use only the beginning
                    postalCode = postalCode.Substring(0, 4);
                }
            }
            else if (countryCode == SiteEnums.CountryCodeISO.CA.ToString())
            {
                if (postalCode.Length > 2)
                {
                    // they use only the beginning
                    postalCode = postalCode.Substring(0, 3);
                }
            }
            else if (countryCode == SiteEnums.CountryCodeISO.JP.ToString())
            {
                postalCode = postalCode.Replace("-", string.Empty);
            }
            else if (countryCode == SiteEnums.CountryCodeISO.BR.ToString())
            {
                postalCode = postalCode.Replace(" ", string.Empty);

                if (postalCode.Contains("-"))
                {
                    postalCode = postalCode.Split('-')[0];
                    postalCode = postalCode + "-000";
                }
                //if (postalCode.Length == 8)
                //{
                //    // they need a dash
                //    postalCode = postalCode.Insert(5, "-");
                //}
            }
            else
            {
                // not sure why
            }

               // get a configured DbCommand object
            DbCommand comm = DbAct.CreateCommand();
            // set the stored procedure name
            comm.CommandText = "up_GetLatLongForCountryPostal";

            ADOExtenstion.AddParameter(comm, "postalCode",  postalCode.Replace(" ", string.Empty));
            ADOExtenstion.AddParameter(comm, "countryCode", countryCode);

            // execute the stored procedure
            DataTable dt = DbAct.ExecuteSelectCommand(comm);

            if (dt != null && dt.Rows.Count > 0)
            {
                latlong.latitude = FromObj.DoubleFromObj(dt.Rows[0]["latitude"]);
                latlong.longitude = FromObj.DoubleFromObj(dt.Rows[0]["longitude"]);
            }

            return latlong;
        }
Пример #2
0
        public ActionResult Frame()
        {
            CultureInfo usa = new CultureInfo("en-US");

            MembershipUser mu = Membership.GetUser();

                    SiteStructs.LatLong userLatLong = new SiteStructs.LatLong();
            userLatLong.latitude = 0;
            userLatLong.longitude = 0;
            UserAccountDetail uad = null;

            if (mu != null)
            {

                UserAccount ua = new UserAccount(mu.UserName);
                uad = new UserAccountDetail();
                uad.GetUserAccountDeailForUser(ua.UserAccountID);
                //if (!string.IsNullOrEmpty(uad.PostalCode))
                //{
                //    userLatLong = GeoData.GetLatLongForCountryPostal(uad.Country, uad.PostalCode);
                //}

                userLatLong.longitude = Convert.ToDouble(uad.Longitude);
                userLatLong.latitude = Convert.ToDouble(uad.Latitude);
            }

            Random rnd = new Random();

            // map

            MapModel mapPoints = new MapModel();

            mapPoints.MapPoints = new List<MapPoint>();
            MapPoint mPoint = null;

            // users
            UserAccounts uas = new UserAccounts();
            uas.GetMappableUsers();
            int offset = 0;

            // because of the foreign cultures, numbers need to stay in the English version unless a javascript encoding could be added
            string currentLang = Utilities.GetCurrentLanguageCode();

            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(SiteEnums.SiteLanguages.EN.ToString());
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(SiteEnums.SiteLanguages.EN.ToString());

            foreach (UserAccount u1 in uas)
            {
                uad = new UserAccountDetail();
                uad.GetUserAccountDeailForUser(u1.UserAccountID);

                if (uad.UserAccountDetailID == 0 || !uad.ShowOnMapLegal) continue;

                if (uad.Longitude == null || uad.Latitude == null || uad.Longitude == 0 || uad.Latitude == 0) continue;

                mPoint = new MapPoint();
                offset = rnd.Next(10, 100);

                // BUG: language adding incorrect
                mPoint.Latitude = Convert.ToDouble(Convert.ToDecimal(uad.Latitude) + Convert.ToDecimal("0.00" + offset));
                mPoint.Longitude = Convert.ToDouble(Convert.ToDecimal(uad.Longitude) + Convert.ToDecimal("0.00" + offset));

                u1.IsProfileLinkNewWindow = true;
                mPoint.Message = string.Format(@"<ul class=""user_list"">{0}</ul>",
               u1.ToUnorderdListItem);// in javascript, escape
                mPoint.Icon = uad.GenderIconLinkDark;
                mapPoints.MapPoints.Add(mPoint);
            }

            // venues

            Venues vnus = new Venues();
            vnus.GetAll();

            foreach (Venue v1 in vnus)
            {
                if (v1.Latitude == 0 || v1.Longitude == 0) continue;

                mPoint = new MapPoint();
                mPoint.Icon = v1.VenueTypeIcon;
                mPoint.Latitude = Convert.ToDouble(v1.Latitude);
                mPoint.Longitude = Convert.ToDouble(v1.Longitude);
                mPoint.Message = v1.MapText ;
                mapPoints.MapPoints.Add(mPoint);
            }

            string longI = userLatLong.longitude.ToString(usa);

            string latI = userLatLong.latitude.ToString(usa);

            StringBuilder sb = new StringBuilder();

            sb.Append(@"
            var map;
            var infowindow;
            function InitializeMap() { ");

            sb.AppendFormat(@"
            var latlng = new google.maps.LatLng({0}, {1});",
            latI, longI);

            if (mu != null && userLatLong.longitude != 0 && userLatLong.latitude != 0)
            {
                // zoom in on user
                sb.Append(@"
            var myOptions =
            {
            zoom: 8,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
            };");
            }
            else
            {
                // zoom out
                sb.Append(@"
            var myOptions =
            {
            zoom: 2,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
            };");
            }

            sb.Append(@"
            map = new google.maps.Map(document.getElementById(""map""), myOptions);
            }
             function markicons() {

            InitializeMap();

            var ltlng = [];
            var details = [];
            var iconType = [];");

            byte[] myarray2 = Encoding.Unicode.GetBytes(string.Empty);

            Encoding iso = Encoding.GetEncoding("ISO-8859-1");
            Encoding utf8 = Encoding.UTF8;

            foreach (DasKlub.Models.MapPoint mp1 in mapPoints.MapPoints)
            {

                if (mp1.Latitude == 0 || mp1.Longitude == 0) continue;

                byte[] utfBytes = utf8.GetBytes(mp1.Message.Replace(@"'", @"\'"));
                byte[] isoBytes = Encoding.Convert(utf8, iso, utfBytes);
                string msg = iso.GetString(isoBytes);

                  longI = mp1.Latitude.ToString(usa);

                  latI = mp1.Longitude.ToString(usa);

            //                sb.AppendFormat(@"
                    //ltlng.push(new google.maps.LatLng({0}, {1}));
                sb.Append(@" ltlng.push(new google.maps.LatLng(");
                sb.Append(longI);
                sb.Append(" , ");
                sb.Append(latI);
                sb.Append(@" )); ");

              //  {0}, {1}));

            sb.AppendFormat(@" details.push('{0}');
                    iconType.push('{1}');
                    " ,
                    msg, mp1.Icon);
            }

            sb.Append(@"
            for (var i = 0; i <= ltlng.length; i++) {

            marker = new google.maps.Marker({
                map: map,
                position: ltlng[i],
                icon: iconType[i]
            });

            (function (i, marker) {

                google.maps.event.addListener(marker, 'click', function () {

                    if (!infowindow) {
                        infowindow = new google.maps.InfoWindow();
                    }

                infowindow.setContent(details[i]);
                    infowindow.open(map, marker);

                });

            })(i, marker);
            }

            }

            window.onload = markicons; ");

            ViewBag.MapScript = sb.ToString( );

            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(currentLang);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(currentLang);

            return View();
        }