示例#1
0
        private async Task <ImageSource> TakeSnapshotSend(FunctionType sendType)
        {
            ImageSource outputImg = null;

            if (sendType == FunctionType.TakeSnapshot)
            {
                outputImg = await AutomationAPIHelper.TakeSnapshot();
            }
            return(outputImg);
        }
示例#2
0
        private async void SaveImage()
        {
            try
            {
                // Set save file options.
                SaveFileDialog dialog = new SaveFileDialog
                {
                    Filter           = "Jpeg Files|*.jpg|Png Files|*.png|Tiff Files|*.tif",
                    FileName         = "ArcGIS Earth.jpg",
                    DefaultExt       = "jpg",
                    OverwritePrompt  = true,
                    RestoreDirectory = true
                };
                if (dialog.ShowDialog() == true)
                {
                    // Get screenshot from ArcGIS Earth.
                    var bitmapImage = await AutomationAPIHelper.TakeSnapshot() as BitmapImage;

                    if (bitmapImage == null)
                    {
                        ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed to save image.");
                        return;
                    }
                    using (var outStream = new MemoryStream())
                    {
                        var encoder = new BmpBitmapEncoder();
                        encoder.Frames.Add(BitmapFrame.Create(bitmapImage));
                        encoder.Save(outStream);
                        var bitmap = new Bitmap(outStream);
                        bitmap.Save(dialog.FileName);
                    }
                }
            }
            catch (Exception)
            {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed to save image.");
            }
        }
示例#3
0
        private async void RemoveLayerFromEarth(LayerEventsArgs args)
        {
            try
            {
                // Get removed layer list.
                List <Layer> layerList = args.Layers as List <Layer>;
                if (layerList?.Count != 0)
                {
                    // Use temp list to log the id of removed elevation sources in ArcGIS Pro.
                    List <string> idList = new List <string>();
                    foreach (var layer in layerList)
                    {
                        foreach (var item in ToolHelper.IdInfoDictionary)
                        {
                            // Find and save removed id.
                            if (item.Value?.Length == 3 && item.Value[0] == layer.Name && item.Value[1] == layer.MapLayerType.ToString() && item.Value[2] == null)
                            {
                                idList.Add(item.Key);
                            }
                        }
                    }
                    // Remove elevation sources in ArcGIS Earth and removed id of these sources.
                    foreach (var id in idList)
                    {
                        JObject idJson   = JObject.Parse(id);
                        string  idString = idJson["id"].ToString();
                        await AutomationAPIHelper.RemoveLayer(idString);

                        ToolHelper.IdInfoDictionary.Remove(id);
                    }
                }
            }
            catch
            {
            }
        }
示例#4
0
 private async void SetCameraInEarth(MapViewCameraChangedEventArgs args)
 {
     try
     {
         // Get current camera of ArcGIS Pro.
         MapView mapView = args.MapView;
         if (null != mapView && null != mapView.Camera && mapView.ViewingMode == MapViewingMode.SceneGlobal)
         {
             JObject cameraJObject = new JObject()
             {
                 // Get position.
                 ["position"] = new JObject
                 {
                     ["x"] = mapView.Camera.X,
                     ["y"] = mapView.Camera.Y,
                     ["z"] = mapView.Camera.Z,
                     ["spatialReference"] = new JObject
                     {
                         ["wkid"] = mapView.Camera.SpatialReference?.Wkid
                     }
                 },
                 // Get heading.
                 ["heading"] = mapView.Camera.Heading > 0 ? 360 - mapView.Camera.Heading : -mapView.Camera.Heading,
                 // Get tilt.
                 ["tilt"] = mapView.Camera.Pitch + 90,
                 // Get roll.
                 ["roll"] = mapView.Camera.Roll
             };
             // Set camera in ArcGIS Earth.
             await AutomationAPIHelper.SetCamera(cameraJObject.ToString());
         }
     }
     catch
     {
     }
 }
示例#5
0
 private void AddLayerToEarth(LayerEventsArgs args)
 {
     try
     {
         // Get list of added layer.
         List <Layer> layerList = args.Layers as List <Layer>;
         if (layerList?.Count != 0 && !IsCreateNewGroupLayer(layerList))
         {
             foreach (var layer in layerList)
             {
                 QueuedTask.Run(async() =>
                 {
                     // GetDataConnection method must be called within the lambda passed to QueuedTask.Run.
                     CIMDataConnection dataConnection = layer.GetDataConnection();
                     // Get layer url.
                     string url = ToolHelper.GetDataSource(dataConnection);
                     if (!string.IsNullOrWhiteSpace(url))
                     {
                         JObject addLayerJson = new JObject
                         {
                             ["URI"] = url
                         };
                         if (dataConnection is CIMWMSServiceConnection)
                         {
                             // Specify layer type for wms service. API is limited to automatically recognized wms service.
                             addLayerJson["type"] = "WMS";
                         }
                         if (layer.MapLayerType == MapLayerType.Operational)
                         {
                             addLayerJson["target"] = "operationalLayers";
                         }
                         if (layer.MapLayerType == MapLayerType.BasemapBackground)
                         {
                             addLayerJson["target"] = "baseMaps";
                         }
                         string currentJson   = addLayerJson.ToString();
                         string[] nameAndType = new string[3]
                         {
                             layer.Name,
                             layer.MapLayerType.ToString(),
                             null
                         };
                         // Add layer to ArcGIS Earth.
                         // Return layer id when use adding layer, whether it's succeed or failed.
                         string id = await AutomationAPIHelper.AddLayer(currentJson);
                         if (!ToolHelper.IdInfoDictionary.Keys.Contains(id))
                         {
                             // Use IdInfoDictionary to save layer id and layer information.
                             ToolHelper.IdInfoDictionary.Add(id, nameAndType);
                         }
                     }
                     else
                     {
                         ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed to add layer to ArcGIS Earth" + " : " + layer.Name);
                     }
                 });
             }
         }
     }
     catch
     {
         ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed to add layer to ArcGIS Earth.");
     }
 }
示例#6
0
        private async Task <string> SendMessage(FunctionType sendType, string inputStr)
        {
            string outputStr = null;

            switch (sendType)
            {
            case FunctionType.GetCamera:
                outputStr = await AutomationAPIHelper.GetCamera();

                break;

            case FunctionType.SetCamera:
                outputStr = await AutomationAPIHelper.SetCamera(inputStr);

                break;

            case FunctionType.SetFlight:
                outputStr = await AutomationAPIHelper.SetFlight(inputStr);

                break;

            case FunctionType.AddLayer:
                outputStr = await AutomationAPIHelper.AddLayer(inputStr);

                break;

            case FunctionType.GetLayer:
                outputStr = await AutomationAPIHelper.GetLayer(inputStr);

                break;

            case FunctionType.RemoveLayer:
                outputStr = await AutomationAPIHelper.RemoveLayer(inputStr);

                break;

            case FunctionType.ClearLayers:
                outputStr = await AutomationAPIHelper.ClearLayers(inputStr);

                break;

            case FunctionType.AddGraphic:
                outputStr = await AutomationAPIHelper.AddGraphic(inputStr);

                break;

            case FunctionType.GetGraphic:
                outputStr = await AutomationAPIHelper.GetGraphic(inputStr);

                break;

            case FunctionType.UpdateGraphic:
                outputStr = await AutomationAPIHelper.UpdateGraphic(inputStr);

                break;

            case FunctionType.RemoveGraphic:
                outputStr = await AutomationAPIHelper.RemoveGraphic(inputStr);

                break;

            case FunctionType.GetWorkspace:
                outputStr = await AutomationAPIHelper.GetWorkspace();

                break;

            case FunctionType.ImportWorkspace:
                outputStr = await AutomationAPIHelper.ImportWorkspace(inputStr);

                break;

            case FunctionType.ClearWorkspace:
                outputStr = await AutomationAPIHelper.ClearWorkspace();

                break;
            }

            return(outputStr);
        }
示例#7
0
 private async void ClearAll()
 {
     // Clear ArcGIS Earth workspace.
     await AutomationAPIHelper.ClearWorkspace();
 }