Exemple #1
0
        public GoogleMapsForm(int width, int height, bool googleMap)
        {
            InitializeComponent();

            this.GoogleMap                  = googleMap;
            this.buttonSave.Enabled         = false;
            this.buttonSaveToDevice.Enabled = false;

            this.setMobileSize(width, height);

            if (googleMap)
            {
                webBrowserMap.AllowWebBrowserDrop            = false;
                webBrowserMap.IsWebBrowserContextMenuEnabled = false;
                webBrowserMap.WebBrowserShortcutsEnabled     = false;
                webBrowserMap.ObjectForScripting             = this;
                try
                {
                    rapi = new RAPI();

                    if (rapi.DevicePresent)
                    {
                        this.setMobileSize(rapi.GetDeviceCapabilities(DeviceCaps.HorizontalResolution), rapi.GetDeviceCapabilities(DeviceCaps.VerticalResolution));
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Device Size couldn't be automatically retrieved. Default values will be used.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    this.setMobileSize(width, height);
                }

                String fullPath = Environment.CurrentDirectory + @"\Ressources\GoogleMap.html";

                try
                {
                    if (File.Exists(fullPath))
                    {
                        System.Uri u = new Uri(fullPath);
                        webBrowserMap.Navigate(u);
                        showOverlay();
                        webBrowserMap.Visible            = true;
                        pictureBoxMap.Visible            = false;
                        this.groupBoxGoogleMap.Enabled   = true;
                        this.groupBoxMap.Enabled         = false;
                        showToolStripMenuItem.Enabled    = true;
                        openMapToolStripMenuItem.Enabled = false;
                    }
                    else
                    {
                        throw new ConnectionCorruptedException("GoogleMaps Script couldn't be located. Please ensure that there is a directory named 'Ressources' and a HTML-File 'GoogleMaps.html' within.");
                    }
                }
                catch (Exception)
                {
                    throw new DataFunctionsException("Exception while opening GoogleMaps Script.");
                }
            }
            else
            {
                try
                {
                    OpenFileDialog dlg = new OpenFileDialog();
                    dlg.Title  = "Choose map to be shown";
                    dlg.Filter = "JPEG (*.JPEG, *.JPG)|*.jpg;*.jpeg|GIF (*.gif)|*.gif|PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp";
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        pictureBoxMap.Image = zoomImage(new Bitmap(dlg.FileName));
                        readSettingsFromXML(Path.GetDirectoryName(dlg.FileName), Path.GetFileNameWithoutExtension(dlg.FileName));

                        deltaX = (pictureBoxMap.Width - pictureBoxMap.Image.Width) / 2;
                        deltaY = (pictureBoxMap.Height - pictureBoxMap.Image.Height) / 2;
                        showOverlay();
                    }

                    webBrowserMap.Visible            = false;
                    pictureBoxMap.Visible            = true;
                    this.groupBoxGoogleMap.Enabled   = false;
                    this.groupBoxMap.Enabled         = true;
                    showToolStripMenuItem.Enabled    = false;
                    openMapToolStripMenuItem.Enabled = true;
                }
                catch (Exception)
                {
                    throw new DataFunctionsException("Exception while opening map and reading settings from XML file.");
                }
            }
        }