Ejemplo n.º 1
0
        private string ProcessClubs()
        {
            StringBuilder szClubs = new StringBuilder("[");

            if (Clubs != null)
            {
                List <string> lstClubs = new List <string>();
                foreach (Club c in Clubs)
                {
                    if (c.HomeAirport != null && !String.IsNullOrEmpty(c.HomeAirport.Code))
                    {
                        lstClubs.Add(String.Format(CultureInfo.InvariantCulture, "new MFBClubMarker({0}, {1}, '{2}', {3}, '{4}')", c.HomeAirport.LatLong.Latitude, c.HomeAirport.LatLong.Longitude, c.Name.JavascriptEncode(), c.ID, ClubClickHandler));
                        if (BoundingBox == null)
                        {
                            BoundingBox = new LatLongBox(c.HomeAirport.LatLong);
                        }
                        else
                        {
                            BoundingBox.ExpandToInclude(c.HomeAirport.LatLong);
                        }
                    }
                }
                szClubs.AppendFormat(CultureInfo.InvariantCulture, "{0}", String.Join(",\r\n", lstClubs.ToArray()));
            }
            szClubs.Append("]");
            return(szClubs.ToString());
        }
Ejemplo n.º 2
0
 private void UpdateBoundingBox(MFBGMapLatLon gll)
 {
     if (BoundingBox == null)
     {
         BoundingBox = new LatLongBox(gll.latlong);
     }
     else
     {
         BoundingBox.ExpandToInclude(gll.latlong);
     }
 }
Ejemplo n.º 3
0
        private string ProcessAirports()
        {
            List <string> lstAllRoutes = new List <string>();

            if (Airports != null)
            {
                int cItems = 0;

                foreach (AirportList airportlist in Airports)
                {
                    airport[] rgap = AllowDupeMarkers ? airportlist.GetAirportList() : airportlist.GetNormalizedAirports();

                    List <string> lstRoute = new List <string>();

                    for (int i = 0; i < rgap.Length; i++)
                    {
                        // Google maps barfs on anything in the high/low latitudes.
                        if (Math.Abs(rgap[i].LatLong.Latitude) > 88)
                        {
                            continue;
                        }

                        lstRoute.Add(String.Format(CultureInfo.InvariantCulture, "new MFBAirportMarker({0}, {1}, '{2}', '{3}', '{4}', {5})", rgap[i].LatLong.Latitude, rgap[i].LatLong.Longitude, rgap[i].Name.JavascriptEncode(), rgap[i].Code, rgap[i].FacilityType, ShowMarkers ? 1 : 0));

                        if (BoundingBox == null)
                        {
                            BoundingBox = new LatLongBox(rgap[i].LatLong);
                        }
                        else
                        {
                            BoundingBox.ExpandToInclude(rgap[i].LatLong);
                        }

                        cItems++;
                    }

                    lstAllRoutes.Add(String.Format(CultureInfo.InvariantCulture, "[{0}]", String.Join(",\r\n", lstRoute.ToArray())));
                }

                if (cItems > 0 && (BoundingBox == null || BoundingBox.IsEmpty))
                {
                    ZoomFactor = GMap_ZoomLevels.Airport;
                }
            }

            return(String.Format(CultureInfo.InvariantCulture, "[{0}]", String.Join(",\r\n", lstAllRoutes.ToArray())));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Pass in an array of airports and get back the latitude/longitude bounding box of all of the airports
        /// </summary>
        /// <returns>A LatLongBox.</returns>
        public LatLongBox LatLongBox(bool fAirportsOnly = false)
        {
            airport[] rgap = fAirportsOnly ? AirportList.RemoveNavaids(m_rgAirports) : m_rgAirports.ToArray();
            if (rgap.Length == 0)
            {
                return(new LatLongBox(new LatLong(0.0, 0.0)));
            }

            LatLongBox llb = new LatLongBox(((airport)rgap[0]).LatLong);

            foreach (airport ap in rgap)
            {
                llb.ExpandToInclude(ap.LatLong);
            }

            return(llb);
        }
        protected void GeoReferenceForPoly(List <LatLong> rgll, string szCountry, string szAdmin)
        {
            if (rgll == null)
            {
                throw new ArgumentNullException(nameof(rgll));
            }
            if (szCountry == null)
            {
                throw new ArgumentNullException(nameof(szCountry));
            }

            if (!rgll.Any())
            {
                throw new InvalidOperationException("No latitude/longitudes in rgll!");
            }


            // Get the bounding box.
            LatLongBox llb = new LatLongBox(rgll.First());

            foreach (LatLong ll in rgll)
            {
                llb.ExpandToInclude(ll);
            }

            IEnumerable <airport> rgap = AdminAirport.UntaggedAirportsInBox(llb);
            GeoRegion             geo  = new GeoRegion(string.Empty, rgll);

            int cAirports = 0;

            foreach (AdminAirport ap in rgap)
            {
                if (geo.ContainsLocation(ap.LatLong))
                {
                    UpdateString.AppendLine(String.Format(CultureInfo.InvariantCulture, "UPDATE airports SET Country='{0}' {1} WHERE type='{2}' AND airportID='{3}';", szCountry, String.IsNullOrWhiteSpace(szAdmin) ? string.Empty : String.Format(CultureInfo.InvariantCulture, ", admin1 = '{0}' ", szAdmin), ap.FacilityTypeCode, ap.Code));
                    ap.SetLocale(szCountry, szAdmin);
                    cAirports++;
                }
            }

            if (cAirports > 0)
            {
                AuditString.AppendLine(String.Format(CultureInfo.CurrentCulture, "Updated {0} airports for country {1}, region {2}", cAirports, szCountry, szAdmin));
            }
        }
Ejemplo n.º 6
0
        private string ProcessPath()
        {
            StringBuilder sbPath = new StringBuilder();

            if (Path != null && Path.Count() > 0)
            {
                if (BoundingBox == null)
                {
                    BoundingBox = new LatLongBox(Path.ElementAt(0));
                }

                foreach (LatLong ll in Path)
                {
                    BoundingBox.ExpandToInclude(ll);
                    sbPath.AppendFormat(CultureInfo.InvariantCulture, "{0} nll({1}, {2})", (sbPath.Length > 0) ? ",\r\n" : "", ll.Latitude, ll.Longitude);
                }
            }
            return(sbPath.ToString());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Registers the script block that includes the data for the airports and the preferences for the map.
        /// <param name="mapID">The ID of the element on the page that holds the map</param>
        /// <param name="containerID">The client ID of the map's container</param>
        /// </summary>
        public string MapJScript(string mapID, string containerID)
        {
            Boolean fAutoZoom = false;

            // Initialize any airports
            BoundingBox = null;
            StringBuilder sbJSAirports = new StringBuilder("function InitAirports() {\r\n", 2000);

            string szAirportMarkers = ProcessAirports();

            string szImages = ProcessImages();

            string szClubs = ProcessClubs();

            fAutoZoom = (BoundingBox != null && !BoundingBox.IsEmpty);

            string szPath = ProcessPath();

            if (!String.IsNullOrEmpty(szPath))
            {
                fAutoZoom = true;
            }

            StringBuilder sbInitMap = new StringBuilder();

            // If there is a path, define a variable to hold it now.
            if (Path != null && Path.Count() > 0)
            {
                sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "var {0} = [{1}];\r\n", PathVarName, szPath);
            }

            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "var {0} = AddMap(MFBNewMapOptions({{", mapID);
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "id: '{0}', ", mapID);
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "rgAirports: {0}, ", szAirportMarkers);
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "rgImages: {0}, ", szImages);
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "rgClubs: {0}, ", szClubs);
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "divContainer: '{0}', ", containerID);
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "fZoom: {0}, ", 1);
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "fAutofillPanZoom: {0}, ", AutofillOnPanZoom ? 1 : 0);
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "fShowMap: {0}, ", MapVisible ? 1 : 0);
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "fShowMarkers: {0}, ", ShowMarkers ? 1 : 0);
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "fShowRoute: {0}, ", ShowRoute ? 1 : 0);
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "fDisableUserManip: {0}, ", 0);
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "defaultZoom: {0}, ", Convert.ToInt32(ZoomFactor, CultureInfo.InvariantCulture));
            sbInitMap.Append(String.Format(CultureInfo.InvariantCulture, "defaultLat: {0}, defaultLong: {1}, ", MapCenter.Latitude, MapCenter.Longitude));
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "MapType: {0}, ", MapTypeToString(MapType));
            if (BoundingBox == null)
            {
                BoundingBox = new LatLongBox(new LatLong(MapCenter.Latitude, MapCenter.Longitude));
            }

            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "minLat: {0}, ", BoundingBox.LatMin);
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "maxLat: {0}, ", BoundingBox.LatMax);
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "minLong: {0}, ", BoundingBox.LongMin);
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "maxLong: {0}, ", BoundingBox.LongMax);

            // pass in the variable that points to the path array (defined above).
            if (Path != null && Path.Count() > 0)
            {
                sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "pathArray: {0}, ", PathVarName);
            }

            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "fAutoZoom: {0}", fAutoZoom ? 1 : 0);
            sbInitMap.Append("}));");
            sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "MFBMapsOnPage.push({0});", mapID);

            if (ClickHandler.Length > 0)
            {
                sbInitMap.AppendFormat(CultureInfo.InvariantCulture, "\r\n{0}.addListenerFunction({1});\r\n", mapID, ClickHandler);
            }

            return(sbInitMap.ToString());
        }