private void ShowMap(LogbookEntry le)
    {
        double distance = 0.0;
        bool   fHasPath = le.Telemetry != null && le.Telemetry.HasPath;
        ListsFromRoutesResults result = null;

        if (le.Route.Length > 0 || fHasPath) // show a map.
        {
            result = AirportList.ListsFromRoutes(le.Route);
            MfbGoogleMap1.Map.Airports          = result.Result;
            MfbGoogleMap1.Map.ShowRoute         = ckShowRoute.Checked;
            MfbGoogleMap1.Map.AutofillOnPanZoom = (result.Result.Count() == 0);
            MfbGoogleMap1.Map.AllowDupeMarkers  = false;
            lnkZoomOut.NavigateUrl = MfbGoogleMap1.ZoomToFitScript;
            lnkZoomOut.Visible     = !result.MasterList.LatLongBox().IsEmpty;

            // display flight path, if available.
            if (ckShowPath.Checked && le.Telemetry.HasPath)
            {
                MfbGoogleMap1.Map.Path = le.Telemetry.Path();
                distance           = le.Telemetry.Distance();
                lnkViewKML.Visible = true;
            }

            string szURL = Request.Url.PathAndQuery;
            lnkShowMapOnly.NavigateUrl = String.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", szURL, szURL.Contains("?") ? "&" : "?", "show=map");
        }

        MfbGoogleMap1.Map.Images = ckShowImages.Checked ? mfbIlFlight.Images.ImageArray.ToArray() : new MFBImageInfo[0];

        bool fForceDynamicMap    = util.GetIntParam(Request, "dm", 0) != 0;
        bool fHasGeotaggedImages = false;

        if (le.FlightImages != null)
        {
            Array.ForEach <MFBImageInfo>(le.FlightImages, (mfbii) => { fHasGeotaggedImages = fHasGeotaggedImages || mfbii.Location != null; });
        }

        // By default, show only a static map (cut down on dynamic map hits)
        if (fForceDynamicMap || fHasGeotaggedImages || fHasPath)
        {
            MfbGoogleMap1.Mode = MyFlightbook.Mapping.GMap_Mode.Dynamic;
        }
        else
        {
            MfbGoogleMap1.Mode = MyFlightbook.Mapping.GMap_Mode.Static;
            popmenu.Visible    = false;
            lnkZoomOut.Visible = mfbAirportServices1.Visible = false;
        }

        if (result != null)
        {
            mfbAirportServices1.GoogleMapID = MfbGoogleMap1.MapID;
            mfbAirportServices1.AddZoomLink = (MfbGoogleMap1.Mode == MyFlightbook.Mapping.GMap_Mode.Dynamic);
            mfbAirportServices1.SetAirports(result.MasterList.GetNormalizedAirports());
        }

        lblDistance.Text    = le.GetPathDistanceDescription(distance);
        pnlDistance.Visible = lblDistance.Text.Length > 0;
    }
Beispiel #2
0
        private void ShowMap(LogbookEntry le)
        {
            double distance = 0.0;
            bool   fHasPath = le.Telemetry != null && le.Telemetry.HasPath;
            ListsFromRoutesResults result = null;

            if (le.Route.Length > 0 || fHasPath) // show a map.
            {
                result = AirportList.ListsFromRoutes(le.Route);
                MfbGoogleMap1.Map.Airports                 = result.Result;
                MfbGoogleMap1.Map.Options.fShowRoute       = ckShowRoute.Checked;
                MfbGoogleMap1.Map.Options.fAutofillPanZoom = (result.Result.Count == 0);
                MfbGoogleMap1.Map.AllowDupeMarkers         = false;
                lnkZoomOut.NavigateUrl = MfbGoogleMap1.ZoomToFitScript;
                lnkZoomOut.Visible     = !result.MasterList.LatLongBox().IsEmpty;

                // display flight path, if available.
                if (ckShowPath.Checked && le.Telemetry.HasPath)
                {
                    MfbGoogleMap1.Map.Path = le.Telemetry.Path();
                    distance       = le.Telemetry.Distance();
                    rowKML.Visible = true;
                }
            }

            MfbGoogleMap1.Map.Images = ckShowImages.Checked ? mfbIlFlight.Images.ImageArray.ToArray() : Array.Empty <MFBImageInfo>();

            bool fForceDynamicMap    = util.GetIntParam(Request, "dm", 0) != 0;
            bool fHasGeotaggedImages = false;

            if (le.FlightImages != null)
            {
                foreach (MFBImageInfo mfbii in le.FlightImages)
                {
                    fHasGeotaggedImages = fHasGeotaggedImages || mfbii.Location != null;
                }
            }

            // By default, show only a static map (cut down on dynamic map hits)
            if (fForceDynamicMap || fHasGeotaggedImages || fHasPath)
            {
                MfbGoogleMap1.Mode = MyFlightbook.Mapping.GMap_Mode.Dynamic;
            }
            else
            {
                MfbGoogleMap1.Mode = MyFlightbook.Mapping.GMap_Mode.Static;
                popmenu.Visible    = false;
                lnkZoomOut.Visible = mfbAirportServices1.Visible = false;
            }

            if (result != null)
            {
                mfbAirportServices1.GoogleMapID = MfbGoogleMap1.MapID;
                mfbAirportServices1.AddZoomLink = (MfbGoogleMap1.Mode == MyFlightbook.Mapping.GMap_Mode.Dynamic);
                mfbAirportServices1.SetAirports(result.MasterList.GetNormalizedAirports());
            }

            lblDistance.Text    = le.GetPathDistanceDescription(distance);
            pnlDistance.Visible = lblDistance.Text.Length > 0;
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Master.SelectedTab = tabID.mptRoute;
        lblPageHeader.Text      = String.Format(CultureInfo.CurrentCulture, Resources.Airports.MapRouteHeader, Branding.CurrentBrand.AppName);

        bool viewHist = User.Identity.IsAuthenticated && MyFlightbook.Profile.GetUser(User.Identity.Name).CanManageData&& util.GetStringParam(Request, "hist").Length > 0;

        if (!IsPostBack)
        {
            if (!String.IsNullOrEmpty(Request.QueryString["Airports"]))
            {
                txtAirports.Text = Request.QueryString["Airports"].ToString();
                txtAirports.Rows = Math.Min(Math.Max((txtAirports.Text.Length / 70) + 1, 1), 6);
                mfbAirportServices1.GoogleMapID = MfbGoogleMapManager1.MapID;
            }

            if (viewHist)
            {
                pnlRestrictToFlown.Visible = true;

                if (Session[txtAirports.Text] != null)
                {
                    CurrentVisitedRoute = (VisitedRoute)Session[txtAirports.Text];
                }
            }

            btnOptimizeRoute.Visible = (util.GetStringParam(Request, "tsp").Length > 0);
        }


        string szDescription = txtAirports.Text.Length > 0 ? txtAirports.Text : lblPageHeader.Text;

        this.Master.AddMeta("description", szDescription);
        this.Master.Title = szDescription;

        LogbookEntry le = new LogbookEntry()
        {
            Route = txtAirports.Text
        };

        lblDistance.Text    = le.GetPathDistanceDescription(null);
        pnlDistance.Visible = lblDistance.Text.Length > 0;

        ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(btnMapEm);

        MfbGoogleMapManager1.Mode       = (util.GetIntParam(Request, "sm", 0) != 0) ? GMap_Mode.Static : GMap_Mode.Dynamic;
        mfbAirportServices1.AddZoomLink = (MfbGoogleMapManager1.Mode == GMap_Mode.Dynamic);
        if (viewHist && CurrentVisitedRoute != null)
        {
            ViewHistorical();
        }
        else
        {
            MapAirports(txtAirports.Text);
        }

        MfbGoogleMapManager1.Visible = !String.IsNullOrWhiteSpace(txtAirports.Text);    // cut down on pointless mapping.
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        int idFlight = util.GetIntParam(Request, "id", LogbookEntry.idFlightNone);

        if (idFlight == LogbookEntry.idFlightNone)
        {
            throw new MyFlightbookException("No valid ID passed");
        }

        Master.SelectedTab = tabID.tabLogbook;
        Master.Layout      = MasterPage.LayoutMode.Accordion;

        if (!IsPostBack)
        {
            // On a GET request, discard the cache and regenerate it.
            Session[KeyCacheData(idFlight)]   = null;
            Session[KeyCacheFlight(idFlight)] = null;
        }

        // Set up the object, either from cache or from db
        LoadLogbookEntry(idFlight);

        // for debugging, have a download option that skips all the rest
        if (util.GetIntParam(Request, "d", 0) != 0)
        {
            Response.Clear();
            Response.ContentType = "application/octet-stream";
            // Give it a name that is the brand name, user's name, and date.  Convert spaces to dashes, and then strip out ANYTHING that is not alphanumeric or a dash.
            string szFilename    = String.Format(CultureInfo.InvariantCulture, "Data{0}-{1}-{2}", Branding.CurrentBrand.AppName, MyFlightbook.Profile.GetUser(Page.User.Identity.Name).UserFullName, DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).Replace(" ", "-");
            string szDisposition = String.Format(CultureInfo.InvariantCulture, "inline;filename={0}.csv", System.Text.RegularExpressions.Regex.Replace(szFilename, "[^0-9a-zA-Z-]", ""));
            Response.AddHeader("Content-Disposition", szDisposition);
            Response.Write(m_le.FlightData);
            Response.End();
            return;
        }

        LoadData(m_le);

        // Set up any maps.
        mfbGoogleMapManager1.Map.SetAirportList(new AirportList(m_le.Route));
        mfbGoogleMapManager1.ShowMarkers = true;
        if (m_fd.HasLatLongInfo && m_fd.Data.Rows.Count > 1)
        {
            pnlMap.Visible = true;
            mfbGoogleMapManager1.Map.PathVarName             = PathLatLongArrayID;
            mfbGoogleMapManager1.Map.Path                    = m_fd.GetPath();
            cmbFormat.Items[(int)DownloadFormat.KML].Enabled = true;
            cmbFormat.Items[(int)DownloadFormat.GPX].Enabled = true;
        }
        else
        {
            cmbFormat.Items[(int)DownloadFormat.KML].Enabled = false;
            cmbFormat.Items[(int)DownloadFormat.GPX].Enabled = false;
        }
        lnkZoomToFit.NavigateUrl = mfbGoogleMapManager1.ZoomToFitScript;

        // Compute and store the distances, but only the first time since it doesn't change.
        if (!IsPostBack)
        {
            lblDistance.Text    = m_le.GetPathDistanceDescription(m_fd.ComputePathDistance());
            pnlDistance.Visible = lblDistance.Text.Length > 0;
            lblFlightDate.Text  = m_le.Date.ToShortDateString();
            lblFlightDesc.Text  = String.Format(CultureInfo.CurrentCulture, "{0} {1} {2}", m_le.TailNumDisplay ?? string.Empty, m_le.Route, m_le.Comment);
        }

        UpdateChart();
    }