Beispiel #1
0
        protected override void OnClick()
        {
            log.Debug("User has clicked the authentication button.");

            try
            {
                // check to make sure the button is not checked (i.e. user has an auth code)
                log.Debug("Verifying the button is checked or not.");
                log.Debug("this.Checked: " + this.Checked);
                if (!this.Checked)
                {
                    // establish a new OAuth2 form
                    log.Debug("Creating a new OAuth2 authorization form.");
                    Extension.Dialogs.Auth.OAuth2AuthForm oauthForm = new Extension.Dialogs.Auth.OAuth2AuthForm(ext);

                    // show the dialog
                    log.Debug("Showing new dialog window.");
                    oauthForm.Show();
                }
                else
                {
                    // sign the user out of the toolbar
                    log.Debug("Sign the user out of the Google Earth Builder tools by removing all token references.");
                    ext.clearToken();
                }
            }
            catch (System.Exception ex)
            {
                log.Debug(ex);
                ext.displayErrorDialog("Unable to change user authentication state.");
            }
        }
 protected override void OnClick()
 {
     try
     {
         // verify there is a valid
         if (ext.isAuthorizationAvailable())
         {
             Extension.Dialogs.Directory.GoogleMapsEngineDirectoryListing directory = new Extension.Dialogs.Directory.GoogleMapsEngineDirectoryListing();
             //Extension.Dialogs.Directory.MapDirectory directory = new Extension.Dialogs.Directory.MapDirectory(ext);
             directory.Show();
         }
         else
         {
             // no token exists
         }
     }
     catch (System.Exception ex)
     {
         ext.displayErrorDialog("Unable to display Google Earth Builder directory.  " + ex.Message);
     }
 }
        /*
         * A function to handle the click event after the user clicks 'Add'
         */
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // disable the button immediately
            this.btnAdd.Enabled = false;

            // create a download progress dialog and show it
            Dialogs.Processing.ProgressDialog downloadProgress = new Processing.ProgressDialog();
            downloadProgress.Show(this);

            // attempt to add the selected map to the user ArcGIS instance
            log.Debug("Attempting to create a new feature class and add it to the map.");
            try
            {
                // get the key out of the key/value pair object
                log.Debug("Fetching the user selected MapId from the DataGridView.");
                string MapId = ((MapsEngine.DataModel.gme.Map) this.dataGridGlobeDirectory.SelectedRows[0].DataBoundItem).id;
                log.Debug("MapId: " + MapId);

                // create a new empty Feature Class to hold the Google Maps Engine catalog results
                log.Debug("Creating a new empty feature class to hold the Google Maps Enigne catalog results");
                IFeatureClass fc = Extension.Data.GeodatabaseUtilities.createGoogleMapsEngineCatalogFeatureClass(ref log, ref ext);

                // publish a new download event to the extension
                ext.publishRaiseDownloadProgressChangeEvent(false, "Preparing to download map '" + MapId + "'.", 1, 0);

                // create a new reference to the Google Maps API.
                log.Debug("Creating a new instance of the Google Maps Engine API object.");
                MapsEngine.API.GoogleMapsEngineAPI api = new MapsEngine.API.GoogleMapsEngineAPI(ref log);

                // create a new map object to be defined by the API or MapRoot
                log.Debug("Creating a new empty Map object.");
                MapsEngine.DataModel.gme.Map map;

                // query Google Maps Engine for the layers within this map
                log.Debug("Fetching the Google Maps Engine layers for this map.");
                map = api.getMapById(ext.getToken(), MapId);

                // publish a new download event to the extension
                ext.publishRaiseDownloadProgressChangeEvent(false, "Building local geodatabase for map '" + MapId + "'.", 1, 0);

                // create a new Feature Class Management object
                Data.GoogleMapsEngineFeatureClassManagement fcMngmt = new Data.GoogleMapsEngineFeatureClassManagement(api);

                // populate a feature for every Google Maps Engine Map
                log.Debug("Populate the feature class with the specific MapId");
                fcMngmt.populateFCWithGoogleMapsEngineMap(ref fc, ref map);

                // publish a new download event to the extension
                ext.publishRaiseDownloadProgressChangeEvent(true, "Adding '" + MapId + "' layer to your map.", 1, 1);

                // add the new feature class to the map (auto selecting type "map")
                ext.addFeatureClassToMapAsLayer(ref fc, Properties.Resources.GeodatabaseUtilities_schema_LayerName
                                                , "" + Properties.Resources.GeodatabaseUtilities_schema_AssetType_Name + " = 'map'");

                // retrieve the Google Maps Engine WMS URL
                string url = Properties.Settings.Default.gme_wms_GetCapabilities;

                // replace the map identifier and auth token
                url = url.Replace("{mapId}", MapId);
                url = url.Replace("{authTokenPlusSlash}", ext.getToken().access_token + "/");

                // proactively add the viewable layer (WMS or WMTS) to the map
                ext.addWebMappingServiceToMap(new Uri(url));
            }
            catch (System.Exception ex)
            {
                // log error and warn user
                log.Error(ex);

                // hide the download progress, if it is visible
                downloadProgress.Hide();

                // warn the user of the error
                ext.displayErrorDialog(Properties.Resources.dialog_GoogleMapsEngineDirectoryListing_btnAdd_Click_unknownerror + "\n" + ex.Message);
            }

            // close the dialog immediately
            this.Close();
        }