Exemplo n.º 1
0
        public async static Task UpdateLegendAsync(Layout layout, BA_Objects.MapDefinition mapDefinition)
        {
            await QueuedTask.Run(() =>
            {
                //Get LayoutCIM and iterate through its elements
                var layoutDef = layout.GetDefinition();

                foreach (var elem in layoutDef.Elements)
                {
                    if (elem is CIMLegend)
                    {
                        var legend = elem as CIMLegend;
                        foreach (var legendItem in legend.Items)
                        {
                            if (mapDefinition.LegendLayerList.Contains(legendItem.Name))
                            {
                                legendItem.IsVisible = true;
                            }
                            else
                            {
                                legendItem.IsVisible = false;
                            }
                        }
                    }
                }
                //Apply the changes back to the layout
                layout.SetDefinition(layoutDef);
            });
        }
Exemplo n.º 2
0
        public static BA_Objects.MapDefinition LoadMapDefinition(BagisMapType mapType)
        {
            BA_Objects.MapDefinition mapDefinition   = null;
            IList <string>           lstLayers       = new List <string>();
            IList <string>           lstLegendLayers = new List <string>();

            switch (mapType)
            {
            case BagisMapType.ELEVATION:
                lstLayers = new List <string> {
                    Constants.MAPS_AOI_BOUNDARY, Constants.MAPS_STREAMS,
                    Constants.MAPS_HILLSHADE, Constants.MAPS_ELEV_ZONE
                };
                lstLegendLayers = new List <string> {
                    Constants.MAPS_ELEV_ZONE
                };
                if (Module1.Current.AoiHasSnotel == true)
                {
                    lstLayers.Add(Constants.MAPS_SNOTEL);
                    lstLegendLayers.Add(Constants.MAPS_SNOTEL);
                }
                if (Module1.Current.AoiHasSnowCourse == true)
                {
                    lstLayers.Add(Constants.MAPS_SNOW_COURSE);
                    lstLegendLayers.Add(Constants.MAPS_SNOW_COURSE);
                }
                // @ToDo: manage elevation units better
                mapDefinition = new BA_Objects.MapDefinition("ELEVATION DISTRIBUTION",
                                                             "Elevation Units = Feet", Constants.FILE_EXPORT_MAP_ELEV_PDF);
                mapDefinition.LayerList       = lstLayers;
                mapDefinition.LegendLayerList = lstLegendLayers;
                break;

            case BagisMapType.SLOPE:
                lstLayers = new List <string> {
                    Constants.MAPS_AOI_BOUNDARY, Constants.MAPS_STREAMS,
                    Constants.MAPS_HILLSHADE, Constants.MAPS_SLOPE_ZONE
                };
                lstLegendLayers = new List <string> {
                    Constants.MAPS_SLOPE_ZONE
                };
                if (Module1.Current.AoiHasSnotel == true)
                {
                    lstLayers.Add(Constants.MAPS_SNOTEL);
                    lstLegendLayers.Add(Constants.MAPS_SNOTEL);
                }
                if (Module1.Current.AoiHasSnowCourse == true)
                {
                    lstLayers.Add(Constants.MAPS_SNOW_COURSE);
                    lstLegendLayers.Add(Constants.MAPS_SNOW_COURSE);
                }
                mapDefinition = new BA_Objects.MapDefinition("SLOPE DISTRIBUTION",
                                                             " ", Constants.FILE_EXPORT_MAP_SLOPE_PDF);
                mapDefinition.LayerList       = lstLayers;
                mapDefinition.LegendLayerList = lstLegendLayers;
                break;

            case BagisMapType.ASPECT:
                lstLayers = new List <string> {
                    Constants.MAPS_AOI_BOUNDARY, Constants.MAPS_STREAMS,
                    Constants.MAPS_HILLSHADE, Constants.MAPS_ASPECT_ZONE
                };
                lstLegendLayers = new List <string> {
                    Constants.MAPS_ASPECT_ZONE
                };
                if (Module1.Current.AoiHasSnotel == true)
                {
                    lstLayers.Add(Constants.MAPS_SNOTEL);
                    lstLegendLayers.Add(Constants.MAPS_SNOTEL);
                }
                if (Module1.Current.AoiHasSnowCourse == true)
                {
                    lstLayers.Add(Constants.MAPS_SNOW_COURSE);
                    lstLegendLayers.Add(Constants.MAPS_SNOW_COURSE);
                }
                mapDefinition = new BA_Objects.MapDefinition("ASPECT DISTRIBUTION",
                                                             " ", Constants.FILE_EXPORT_MAP_ASPECT_PDF);
                mapDefinition.LayerList       = lstLayers;
                mapDefinition.LegendLayerList = lstLegendLayers;
                break;

            case BagisMapType.SNOTEL:
                lstLayers = new List <string> {
                    Constants.MAPS_AOI_BOUNDARY, Constants.MAPS_STREAMS,
                    Constants.MAPS_HILLSHADE, Constants.MAPS_ELEV_ZONE,
                    Constants.MAPS_SNOTEL_REPRESENTED
                };
                lstLegendLayers = new List <string> {
                    Constants.MAPS_SNOTEL_REPRESENTED
                };
                if (Module1.Current.AoiHasSnotel == true)
                {
                    lstLayers.Add(Constants.MAPS_SNOTEL);
                    lstLegendLayers.Add(Constants.MAPS_SNOTEL);
                }
                mapDefinition = new BA_Objects.MapDefinition("SNOTEL SITES REPRESENTATION",
                                                             " ", Constants.FILE_EXPORT_MAP_SNOTEL_PDF);
                mapDefinition.LayerList       = lstLayers;
                mapDefinition.LegendLayerList = lstLegendLayers;
                break;
            }
            return(mapDefinition);
        }
Exemplo n.º 3
0
 public static async Task UpdateMapElementsAsync(Layout layout, string titleText, BA_Objects.MapDefinition mapDefinition)
 {
     if (layout != null)
     {
         if (!String.IsNullOrEmpty(titleText))
         {
             if (titleText != null)
             {
                 GraphicElement textBox = layout.FindElement(Constants.MAPS_TITLE) as GraphicElement;
                 if (textBox != null)
                 {
                     await QueuedTask.Run(() =>
                     {
                         CIMTextGraphic graphic = (CIMTextGraphic )textBox.Graphic;
                         graphic.Text           = titleText;
                         textBox.SetGraphic(graphic);
                     });
                 }
             }
             if (mapDefinition.SubTitle != null)
             {
                 GraphicElement textBox = layout.FindElement(Constants.MAPS_SUBTITLE) as GraphicElement;
                 if (textBox != null)
                 {
                     await QueuedTask.Run(() =>
                     {
                         CIMTextGraphic graphic = (CIMTextGraphic)textBox.Graphic;
                         graphic.Text           = mapDefinition.SubTitle;
                         textBox.SetGraphic(graphic);
                     });
                 }
             }
             if (mapDefinition.UnitsText != null)
             {
                 GraphicElement textBox = layout.FindElement(Constants.MAPS_TEXTBOX1) as GraphicElement;
                 if (textBox != null)
                 {
                     await QueuedTask.Run(() =>
                     {
                         CIMTextGraphic graphic = (CIMTextGraphic)textBox.Graphic;
                         graphic.Text           = mapDefinition.UnitsText;
                         textBox.SetGraphic(graphic);
                     });
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
        public static async Task DisplayMaps(string strAoiPath)
        {
            BA_Objects.Aoi oAoi = Module1.Current.Aoi;
            if (String.IsNullOrEmpty(oAoi.Name))
            {
                if (System.IO.Directory.Exists(strAoiPath))
                {
                    // Initialize AOI object
                    oAoi = new BA_Objects.Aoi("animas_AOI_prms", strAoiPath);
                    // Store current AOI in Module1
                    Module1.Current.Aoi = oAoi;
                }
                else
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("!!Please set an AOI before testing the maps", "BAGIS Pro");
                }
            }

            Map oMap = await MapTools.SetDefaultMapNameAsync(Constants.MAPS_DEFAULT_MAP_NAME);

            if (oMap != null)
            {
                if (oMap.Layers.Count() > 0)
                {
                    string strMessage = "Adding the maps to the display will overwrite the current arrangement of data layers. " +
                                        "This action cannot be undone." + System.Environment.NewLine + "Do you wish to continue ?";
                    MessageBoxResult oRes = ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(strMessage, "BAGIS", MessageBoxButton.YesNo);
                    if (oRes != MessageBoxResult.Yes)
                    {
                        return;
                    }
                }

                Layout layout = await MapTools.GetDefaultLayoutAsync(Constants.MAPS_DEFAULT_LAYOUT_NAME);

                if (layout != null)
                {
                    bool bFoundIt = false;
                    //A layout view may exist but it may not be active
                    //Iterate through each pane in the application and check to see if the layout is already open and if so, activate it
                    foreach (var pane in ProApp.Panes)
                    {
                        if (!(pane is ILayoutPane layoutPane))  //if not a layout view, continue to the next pane
                        {
                            continue;
                        }
                        if (layoutPane.LayoutView.Layout == layout) //if there is a match, activate the view
                        {
                            (layoutPane as Pane).Activate();
                            bFoundIt = true;
                        }
                    }
                    if (!bFoundIt)
                    {
                        ILayoutPane iNewLayoutPane = await ProApp.Panes.CreateLayoutPaneAsync(layout); //GUI thread
                    }
                    await MapTools.SetDefaultMapFrameDimensionAsync(Constants.MAPS_DEFAULT_MAP_FRAME_NAME, layout, oMap,
                                                                    1.0, 2.0, 7.5, 9.0);

                    //remove existing layers from map frame
                    await MapTools.RemoveLayersfromMapFrame();

                    //add aoi boundary to map and zoom to layer
                    string strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Aoi, true) +
                                     Constants.FILE_AOI_VECTOR;
                    Uri aoiUri = new Uri(strPath);
                    await MapTools.AddAoiBoundaryToMapAsync(aoiUri, Constants.MAPS_AOI_BOUNDARY);

                    //add Snotel Represented Area Layer
                    strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Analysis, true) +
                              Constants.FILE_SNOTEL_REPRESENTED;
                    Uri           uri       = new Uri(strPath);
                    CIMColor      fillColor = CIMColor.CreateRGBColor(255, 0, 0, 50); //Red with 30% transparency
                    BA_ReturnCode success   = await MapTools.AddPolygonLayerAsync(uri, fillColor, false, Constants.MAPS_SNOTEL_REPRESENTED);

                    if (success.Equals(BA_ReturnCode.Success))
                    {
                        Module1.ToggleState("MapButtonPalette_BtnSnotel_State");
                    }

                    // add aoi streams layer
                    strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Layers, true) +
                              Constants.FILE_STREAMS;
                    uri = new Uri(strPath);
                    await MapTools.AddLineLayerAsync(uri, Constants.MAPS_STREAMS, ColorFactory.Instance.BlueRGB);

                    // add Snotel Layer
                    strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Layers, true) +
                              Constants.FILE_SNOTEL;
                    uri     = new Uri(strPath);
                    success = await MapTools.AddPointMarkersAsync(uri, Constants.MAPS_SNOTEL, ColorFactory.Instance.BlueRGB,
                                                                  SimpleMarkerStyle.X, 16);

                    if (success == BA_ReturnCode.Success)
                    {
                        Module1.Current.AoiHasSnotel = true;
                    }

                    // add Snow Course Layer
                    strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Layers, true) +
                              Constants.FILE_SNOW_COURSE;
                    uri     = new Uri(strPath);
                    success = await MapTools.AddPointMarkersAsync(uri, Constants.MAPS_SNOW_COURSE, CIMColor.CreateRGBColor(0, 255, 255),
                                                                  SimpleMarkerStyle.Star, 16);

                    if (success == BA_ReturnCode.Success)
                    {
                        Module1.Current.AoiHasSnowCourse = true;
                    }

                    // add hillshade layer
                    strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Surfaces, true) +
                              Constants.FILE_HILLSHADE;
                    uri = new Uri(strPath);
                    await MapTools.DisplayRasterAsync(uri, Constants.MAPS_HILLSHADE, 0);

                    // add elev zones layer
                    strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Analysis, true) +
                              Constants.FILE_ELEV_ZONE;
                    uri = new Uri(strPath);
                    await MapTools.DisplayRasterWithSymbolAsync(uri, Constants.MAPS_ELEV_ZONE, "ArcGIS Colors",
                                                                "Elevation #2", "NAME", 30, true);

                    Module1.ToggleState("MapButtonPalette_BtnElevation_State");

                    // add slope zones layer
                    strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Analysis, true) +
                              Constants.FILE_SLOPE_ZONE;
                    uri = new Uri(strPath);
                    await MapTools.DisplayRasterWithSymbolAsync(uri, Constants.MAPS_SLOPE_ZONE, "ArcGIS Colors",
                                                                "Slope", "NAME", 30, false);

                    Module1.ToggleState("MapButtonPalette_BtnSlope_State");

                    // add aspect zones layer
                    strPath = GeodatabaseTools.GetGeodatabasePath(oAoi.FilePath, GeodatabaseNames.Analysis, true) +
                              Constants.FILE_ASPECT_ZONE;
                    uri = new Uri(strPath);
                    await MapTools.DisplayRasterWithSymbolAsync(uri, Constants.MAPS_ASPECT_ZONE, "ArcGIS Colors",
                                                                "Aspect", "NAME", 30, false);

                    Module1.ToggleState("MapButtonPalette_BtnAspect_State");


                    // create map elements
                    await MapTools.AddMapElements(Constants.MAPS_DEFAULT_LAYOUT_NAME, "ArcGIS Colors", "1.5 Point");

                    await MapTools.DisplayNorthArrowAsync(layout, Constants.MAPS_DEFAULT_MAP_FRAME_NAME);

                    await MapTools.DisplayScaleBarAsync(layout, Constants.MAPS_DEFAULT_MAP_FRAME_NAME);

                    // update map elements for default map (elevation)
                    BA_Objects.MapDefinition defaultMap = MapTools.LoadMapDefinition(BagisMapType.ELEVATION);
                    await MapTools.UpdateMapElementsAsync(layout, Module1.Current.Aoi.Name.ToUpper(), defaultMap);

                    await MapTools.UpdateLegendAsync(layout, defaultMap);


                    //zoom to aoi boundary layer
                    double bufferFactor = 1.1;
                    bool   bZoomed      = await MapTools.ZoomToExtentAsync(aoiUri, bufferFactor);
                }
            }
        }