protected override void OnClick() { try { // fetch the most up-to-date auth string auth_token = ext.getToken().access_token; // determine which Maps are selected foreach (string MapAssetId in ext.getSelectedMapAssetIds()) { // 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}", MapAssetId); url = url.Replace("{authTokenPlusSlash}", auth_token + "/"); // add the WMS URL + OAuth to the clipboard System.Windows.Forms.Clipboard.SetText(url); } } catch (System.Exception ex) { // there was an error log.Error(ex); // TODO: Fail gracefully } }
protected override void OnClick() { try { // fetch the most up-to-date auth string auth_token = ext.getToken().access_token; // determine which Maps are selected foreach (string MapAssetId in ext.getSelectedMapAssetIds()) { // 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}", MapAssetId); url = url.Replace("{authTokenPlusSlash}", auth_token + "/"); // add a WMS service to the Map ext.addWebMappingServiceToMap(new Uri(url)); } } catch (System.Exception ex) { // unable to add GEB layer to map log.Error(ex); // TODO: Present user with graceful dialog } }
public ToolsCommand_UploadToGoogleMapsEngine() { // initialize and configure log4net, reading from Xml .config file log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo("log4net.config")); log.Info("ToolsCommand_UploadToGoogleEarthBuilder initializing."); // to check the state of the extension, get the extension log.Info("Retrieving a reference to the extension object to check state."); ext = GoogleMapsEngineToolsExtensionForArcGIS.GetExtension(); // check to see if the extension is enabled log.Debug("Verifying extension is enabled."); if (ext.isExtensionEnabled()) { // the extension is enabled, verify the button is also enabled log.Debug("Extension is enabled, enable button and check to verify the user has an auth token."); this.Enabled = true; // check to see if the user has an auth code log.Debug("Checking to see if the user has an OAuth code"); if (ext.isAuthorizationAvailable() && !ext.getToken().isViewOnly && ext.hasAtLeastOneLayer()) { // the user has an OAuth code available for use log.Debug("User has an OAuth code available. Check the button."); this.Enabled = true; } else { // the user does not have an OAuth code available for use log.Debug("User does not have an OAuth code available. Uncheck the button."); this.Enabled = false; } } else { // disable this button log.Debug("The extension is disabled, disable this button."); this.Enabled = false; } // subscribe to extension state change events through the extension ext.RaiseExtensionStateChangeEvent += HandleExtensionStateChange; // subscribe to Authentication state change events through the extension ext.RaiseAuthenticationStateChangeEvent += HandleAuthenticationStateChangeEvent; // subscribe to map layer selection change events through the extension ext.RaiseMapLayerStateChangeEvent += HandleMapLayerSelectionStateChangeEvent; }
/* * A function to populate a referenced Feature Class (fc) with the contents of a Google Maps Engine map layer */ protected void populateFCWithGoogleMapsEngineLayer(ref IFeatureClass fc, string mapId, string parentId, MapsEngine.DataModel.gme.MapLayer layer) { // create a new feature IFeature feature; log.Debug("Creating a feature for layer " + layer.id); // attempt to process the assets within a the layer try { // fetch the layer asset object from the API log.Debug("Fetching an asset object for the layer."); MapsEngine.DataModel.gme.Asset layerAsset = api.getAssetById(ext.getToken(), layer.id); // create a new feature log.Debug("Creating a new feature."); feature = fc.CreateFeature(); // Update the values for this feature feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_CustomerId_Name), mapId.Split("-".ToCharArray())[0]); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_CustomerId_Name + ": " + mapId.Split("-".ToCharArray())[0]); feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_AssetId_Name), layer.id); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_AssetId_Name + ": " + layer.id); feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_MapAssetId_Name), mapId); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_MapAssetId_Name + ": " + mapId); feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_AssetType_Name), layerAsset.type); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_AssetType_Name + ": " + layerAsset.type); feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_AssetName_Name), layerAsset.name); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_AssetName_Name + ": " + layerAsset.name); feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_ParentAssetId_Name), parentId); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_ParentAssetId_Name + ": " + parentId); // attempt to set the description object try { // set the layer description value (truncate if necessary) feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_AssetDescription_Name) , layerAsset.description.Length > 256 ? layerAsset.description.Substring(0, 252) + "..." : layerAsset.description); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_AssetDescription_Name + ": " + layerAsset.description); } catch (System.Exception ex) { // log warning log.Warn(ex); } // verify the layer has a bbox and has two valid points if (layerAsset.bbox != null && layerAsset.bbox.Count() == 4) { // deterine the maximum and minimum bounds of all layers within this map // 0=West, 1=South, 2=East, 3=North double XMAX = layerAsset.bbox[2]; log.Debug("XMAX: " + XMAX); double YMAX = layerAsset.bbox[3]; log.Debug("YMAX: " + YMAX); double XMIN = layerAsset.bbox[0]; log.Debug("XMIN: " + XMIN); double YMIN = layerAsset.bbox[1]; log.Debug("YMIN: " + YMIN); // determine the map extent based on the layers maximum extent IPoint pExtentNE = new Point(); pExtentNE.X = XMAX; pExtentNE.Y = YMAX; IPoint pExtentSW = new Point(); pExtentSW.X = XMIN; pExtentSW.Y = YMIN; IPoint pExtentNW = new Point(); pExtentNW.X = XMIN; pExtentNW.Y = YMAX; IPoint pExtentSE = new Point(); pExtentSE.X = XMAX; pExtentSE.Y = YMIN; // define the polygon bounding box (NE/SW) as a point collection IPointCollection pExtentPointCol = new Polygon(); pExtentPointCol.AddPoint(pExtentNE, Type.Missing, Type.Missing); pExtentPointCol.AddPoint(pExtentSE, Type.Missing, Type.Missing); pExtentPointCol.AddPoint(pExtentSW, Type.Missing, Type.Missing); pExtentPointCol.AddPoint(pExtentNW, Type.Missing, Type.Missing); // create a polygon, p, from the point collection, then close the polygon IPolygon pExtent = (IPolygon)pExtentPointCol; pExtent.Close(); // add the polygon, p, as the new feature's geometry if (pExtent != null) { // set the shape geometry log.Debug("Setting the feature's geometry as the polygon."); feature.Shape = pExtent; } else { // set the feature's goemetry as the default world log.Debug("Invalid spatial representation, setting feature goemtry as the world."); feature.Shape = worldPolygon; } } else { // the layer does not have spatial information log.Warn("Layer has no bbox information"); //feature.Shape = worldPolygon; } // Commit the new feature to fc log.Debug("Storing feature."); feature.Store(); } catch (Exception ex) { // log the warning log.Warn(ex); } }