/// <summary>
        /// Renders a Polygon feature layer using a single symbol.
        /// </summary>
        /// <remarks>
        /// ![Simple Renderer for Polygon features](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/simple-polygon.png)
        /// </remarks>
        /// <returns>
        /// </returns>
        internal static Task SimpleRendererPolygon()
        {
            //Check feature layer name
            //Code works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data
            var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(f => f.Name == "USDemographics");

            if (featureLayer == null)
            {
                MessageBox.Show("This renderer works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data", "Data missing");
                return(Task.FromResult(0));
            }
            return(QueuedTask.Run(() =>
            {
                //Creating a polygon with a red fill and blue outline.
                CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
                    ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.Solid);
                CIMPolygonSymbol fillWithOutline = SymbolFactory.Instance.ConstructPolygonSymbol(
                    ColorFactory.Instance.CreateRGBColor(255, 190, 190), SimpleFillStyle.Solid, outline);
                //Get the layer's current renderer
                CIMSimpleRenderer renderer = featureLayer.GetRenderer() as CIMSimpleRenderer;

                //Update the symbol of the current simple renderer
                renderer.Symbol = fillWithOutline.MakeSymbolReference();

                //Update the feature layer renderer
                featureLayer.SetRenderer(renderer);
            }));
        }
Example #2
0
        private Task <CIMSymbolReference> OverlaySymbolX(GeometryType gt)
        {
            return(QueuedTask.Run(() =>
            {
                CIMSymbolReference retval = null;

                switch (gt)
                {
                case GeometryType.Polygon:
                case GeometryType.Envelope:
                    CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.RedRGB, 2.0, SimpleLineStyle.Solid);
                    CIMPolygonSymbol fillWithOutline =
                        SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Null, outline);
                    retval = fillWithOutline.MakeSymbolReference();
                    break;

                case GeometryType.Point:
                case GeometryType.Multipoint:
                    CIMPointSymbol ps = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 5.0, SimpleMarkerStyle.Circle);
                    retval = ps.MakeSymbolReference();
                    break;

                case GeometryType.Polyline:
                    CIMLineSymbol ls = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.RedRGB, 2.0, SimpleLineStyle.Solid);
                    retval = ls.MakeSymbolReference();
                    break;

                default:
                    break;
                }

                return retval;
            }));
        }
Example #3
0
 private Task AddStyleItemToStyle(StyleProjectItem styleProjectItem, CIMPolygonSymbol cimPolygonSymbol)
 {
     return(QueuedTask.Run(() =>
     {
         if (styleProjectItem == null || cimPolygonSymbol == null)
         {
             throw new System.ArgumentNullException();
         }
         SymbolStyleItem symbolStyleItem = new SymbolStyleItem()//define the symbol
         {
             Symbol = cimPolygonSymbol,
             ItemType = StyleItemType.PolygonSymbol,
             Category = "BuildingFacade",
             Name = SelectedRulePackage.Name,
             Key = SelectedRulePackage.Name,
             Tags = $"BuildingStyle, {SelectedRulePackage.Title}"
         };
         //Does style already contain the styleItem?
         SymbolStyleItem item = (SymbolStyleItem)_styleProjectItem?.LookupItem(symbolStyleItem.ItemType, symbolStyleItem.Key);
         if (item == null)
         {
             styleProjectItem.AddItem(symbolStyleItem);
         }
     }));
 }
Example #4
0
        public PickerViewModel(List <IPickableItem> pickingCandidates,
                               bool isSingleMode)
        {
            FlashItemCmd = new RelayCommand(FlashItem, () => true, false);

            CloseCommand = new RelayCommand(Close, () => true, false);

            PickableItems =
                new ObservableCollection <IPickableItem>(pickingCandidates);

            _isSingleMode = isSingleMode;

            CIMColor magenta = ColorFactory.Instance.CreateRGBColor(255, 0, 255);

            CIMStroke outline =
                SymbolFactory.Instance.ConstructStroke(
                    magenta, 4, SimpleLineStyle.Solid);

            _highlightLineSymbol =
                SymbolFactory.Instance.ConstructLineSymbol(magenta, 4);

            _highlightPolygonSymbol =
                SymbolFactory.Instance.ConstructPolygonSymbol(
                    magenta, SimpleFillStyle.Null, outline);

            _highlightPointSymbol =
                SymbolFactory.Instance.ConstructPointSymbol(magenta, 6);
        }
Example #5
0
        public AdvancedReshapeFeedback()
        {
            _openJawReplaceEndSymbol = CreateHollowCircle(0, 0, 200);

            _addAreaSymbol    = SymbolUtils.CreateHatchFillSymbol(0, 255, 0, 90);
            _removeAreaSymbol = SymbolUtils.CreateHatchFillSymbol(255, 0, 0);
        }
        public RemoveOverlapsFeedback()
        {
            _overlapLineSymbol =
                SymbolUtils.CreateLineSymbol(255, 0, 0, 2);

            _overlapPolygonSymbol = SymbolUtils.CreateHatchFillSymbol(255, 0, 0);
        }
        //construct polygon symbol
        public void ConstructPolygonSymbol_1()
        {
            #region How to construct a polygon symbol of specific color and fill style

            CIMPolygonSymbol polygonSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid);

            #endregion
        }
        public void ConstructPolygonSymbol_3()
        {
            #region How to construct a polygon symbol without an outline

            CIMPolygonSymbol fillWithoutOutline = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid, null);

            #endregion
        }
        public void ConstructPolygonSymbol_2()
        {
            #region How to construct a polygon symbol of specific color, fill style and outline

            CIMStroke        outline         = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.Solid);
            CIMPolygonSymbol fillWithOutline = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid, outline);

            #endregion
        }
        protected override Task OnToolActivateAsync(bool active)
        {
            QueuedTask.Run(() =>
            {
                _polygonSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(CIMColor.CreateRGBColor(255, 255, 0, 40));
                _textSymbol    = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 9.5, "Corbel", "Bold");
            });

            return(base.OnToolActivateAsync(active));
        }
        //symbol reference
        public void GetSymbolReference()
        {
            #region How to get symbol reference from a symbol

            CIMPolygonSymbol symbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB);

            //Get symbol reference from the symbol
            CIMSymbolReference symbolReference = symbol.MakeSymbolReference();

            #endregion
        }
        public void setFootprintSymbol()
        {
            CIMColor  outlineColor = ColorFactory.Instance.CreateRGBColor(0, 157, 165, 100);
            CIMColor  fillColor    = ColorFactory.Instance.CreateRGBColor(0, 157, 165, 25);
            CIMStroke outline      = SymbolFactory.Instance.ConstructStroke(
                outlineColor, 2.0, SimpleLineStyle.Solid);
            CIMPolygonSymbol polygonSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(
                fillColor, SimpleFillStyle.Solid, outline);

            footprintSymbol = polygonSymbol.MakeSymbolReference();
        }
Example #13
0
        internal async void ApplyRulePackage()
        {
            await DownloadRulePackage(SelectedRulePackage);  //Download the rule package selected.

            await QueuedTask.Run(async() =>
            {
                //Get the build footprint layer's current renderer.
                CIMSimpleRenderer renderer = (CIMSimpleRenderer)Module1.BuildingFootprintLayer.GetRenderer();

                if (renderer == null)
                {
                    return;
                }
                //Get the rule package attributes and mapping to Feature layer from the dictionary
                var attributeExpressionMapping =
                    SelectedRulePackage.RpkAttributeExpressionMapping[SelectedRulePackage.Title];

                //Create the array of CIMPrimitiveOverrides. This is where the field\attribute mapping for the rulepackage is done.
                var primitiveOverrides = attributeExpressionMapping.Select(kvp => new CIMPrimitiveOverride
                {
                    PrimitiveName = SelectedRulePackage.Title,
                    PropertyName  = kvp.Key,
                    Expression    = kvp.Value
                }).ToArray();

                //Full path of the rule package path
                var rulePkgPath = Path.Combine(_rulePkgPath, SelectedRulePackage.Name);

                //Creating a procedural symbol using the rulepackage
                var symbolReference = SymbolFactory.Instance.ConstructProceduralSymbol(rulePkgPath,
                                                                                       Module1.BuildingFootprintLayer, primitiveOverrides);

                //CIMPolygonSymbol needed to create a style item.
                CIMPolygonSymbol polygonSymbol = symbolReference.Symbol as CIMPolygonSymbol;

                //Set symbol's real world setting to be the same as that of the feature layer
                polygonSymbol.SetRealWorldUnits(Module1.BuildingFootprintLayer.UsesRealWorldSymbolSizes);

                //Set the current renderer to the new procedural symbol's CIMSymbolReference
                renderer.Symbol = polygonSymbol.MakeSymbolReference();

                //Set the Building footprint layer's render.
                Module1.BuildingFootprintLayer.SetRenderer(renderer);

                //Create a style project item.
                await CreateStyleItem();

                if (BuildingStyleProjectItem != null && !BuildingStyleProjectItem.IsReadOnly)
                {
                    await AddStyleItemToStyle(BuildingStyleProjectItem, polygonSymbol); //Building footprint's procedural symbol is added to the BuildingStyle
                }
            });
        }
Example #14
0
        private CIMPolygonSymbol CreatePolygonSymbol()
        {
            CIMColor magenta = ColorFactory.Instance.CreateRGBColor(255, 0, 255);

            CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
                magenta, 2, SimpleLineStyle.Solid);

            CIMPolygonSymbol highlightPolygonSymbol =
                SymbolFactory.Instance.ConstructPolygonSymbol(
                    magenta, SimpleFillStyle.Null, outline);

            return(highlightPolygonSymbol);
        }
Example #15
0
        /// <summary>
        /// Renders a Polygon feature layer using a single symbol.
        /// </summary>
        /// <remarks>
        /// ![Simple Renderer for Polygon features](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/simple-polygon.png)
        /// </remarks>
        /// <param name="featureLayer"></param>
        /// <returns>
        /// </returns>
        internal async static Task SimpleRendererPolygon(FeatureLayer featureLayer)
        {
            await QueuedTask.Run(() =>
            {
                //Creating a polygon with a red fill and blue outline.
                CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
                    ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.Solid);
                CIMPolygonSymbol fillWithOutline = SymbolFactory.Instance.ConstructPolygonSymbol(
                    ColorFactory.Instance.CreateRGBColor(255, 190, 190), SimpleFillStyle.Solid, outline);
                //Get the layer's current renderer
                CIMSimpleRenderer renderer = featureLayer.GetRenderer() as CIMSimpleRenderer;

                //Update the symbol of the current simple renderer
                renderer.Symbol = fillWithOutline.MakeSymbolReference();

                //Update the feature layer renderer
                featureLayer.SetRenderer(renderer);
            });
        }
Example #16
0
        public RemoveOverlapsFeedback()
        {
            CIMColor color = ColorFactory.Instance.CreateRGBColor(255, 0, 0);

            _overlapLineSymbol = SymbolFactory.Instance.ConstructLineSymbol(color, 2);

            var hatchFill = new CIMHatchFill
            {
                Enable     = true,
                Rotation   = 0.0,
                Separation = 2.5,
                LineSymbol = _overlapLineSymbol
            };

            var symbolLayers = new List <CIMSymbolLayer>();

            symbolLayers.AddRange(_overlapLineSymbol.SymbolLayers);
            symbolLayers.Add(hatchFill);

            _overlapPolygonSymbol = new CIMPolygonSymbol {
                SymbolLayers = symbolLayers.ToArray()
            };
        }
Example #17
0
        protected override Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            if (Module1.Current.SelectedGraphicsLayerTOC == null)
            {
                MessageBox.Show("Select a graphics layer in the TOC", "No graphics layer selected",
                                System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
                return(Task.FromResult(true));
            }
            if (_polygonSymbol == null)
            {
                return(Task.FromResult(true));
            }
            return(QueuedTask.Run(() =>
            {
                var selectedElements = Module1.Current.SelectedGraphicsLayerTOC.GetSelectedElements().
                                       OfType <GraphicElement>();

                //If only one element is selected, is it of type Polygon?
                if (selectedElements.Count() == 1)
                {
                    if (selectedElements.FirstOrDefault().GetGraphic() is CIMPolygonGraphic) //It is a polygon
                    {
                        //So we use it
                        var polySymbol = selectedElements.FirstOrDefault().GetGraphic() as CIMPolygonGraphic;
                        _polygonSymbol = polySymbol.Symbol.Symbol as CIMPolygonSymbol;
                    }
                }
                var cimGraphicElement = new CIMPolygonGraphic
                {
                    Polygon = geometry as Polygon,
                    Symbol = _polygonSymbol.MakeSymbolReference()
                };
                Module1.Current.SelectedGraphicsLayerTOC.AddElement(cimGraphicElement);
                return true;
            }));
        }
        /// <summary>
        /// Create a label for the weather feature layer.
        /// </summary>
        /// <param name="weatherLayer"></param>
        public static void SetLabeling(FeatureLayer weatherLayer)
        {
            // Get the CIMFeatureLayer definition.
            CIMFeatureLayer weatherLayerDefinition = weatherLayer.GetDefinition() as CIMFeatureLayer;

            // Get the label classes - we need the first one
            CIMLabelClass weatherLabelClass = weatherLayerDefinition.LabelClasses.FirstOrDefault();

            if (weatherLabelClass != null)
            {
                // Create a new Arcade label expression.
                if (DamlSettings.Default.Celius)
                {
                    weatherLabelClass.Expression = "$feature.Temperature + \" c \\r\" +$feature.Humidity + \" % \"";
                }
                else
                {
                    weatherLabelClass.Expression = "(($feature.Temperature * 1.8) + 32)+ \" F \\r\" +$feature.Humidity + \" % \"";
                }

                // Create a polygon symbol for the halo
                CIMPolygonSymbol textHalo = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.WhiteRGB, SimpleFillStyle.Solid);

                // Create text symbol using the halo polygon
                CIMTextSymbol weatherTextSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 14, "Corbel", "Regular");
                weatherTextSymbol.HaloSymbol = textHalo;
                weatherTextSymbol.HaloSize   = 1;
                weatherTextSymbol.HaloSymbol.SetOutlineColor(ColorFactory.Instance.WhiteRGB);

                // Set the text symbol
                weatherLabelClass.TextSymbol.Symbol = weatherTextSymbol;

                // Update the layer definition
                weatherLayer.SetDefinition(weatherLayerDefinition);
            }
        }
Example #19
0
        /// <summary>
        /// Renders a polygon feature layer with Dot Density symbols to represent quantities.
        /// ![Dot Density renderer](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/dotDensity-renderer.png)
        /// </summary>
        /// <remarks></remarks>
        /// <returns></returns>
        internal static Task DotDensityRendererAsync()
        {
            //Check feature layer name
            //Code works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data
            var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(f => f.Name == "USDemographics");

            if (featureLayer == null)
            {
                MessageBox.Show("This renderer works with the USDemographics feature layer available with the ArcGIS Pro SDK Sample data", "Data missing");
                return(Task.FromResult(0));
            }
            return(QueuedTask.Run(() =>
            {
                //Define size of the dot to use for the renderer
                int dotSize = 3;
                //Check if the TOTPOP10 field exists
                int idxField = -1;
                using (var table = featureLayer.GetTable())
                {
                    var def = table.GetDefinition();
                    idxField = def.FindField("TOTPOP10");
                }
                // "TOTPOP10" field was not found
                if (idxField == -1)
                {
                    return;
                }

                //array of fields to be represented in the renderer
                string[] valueFields = new string[] { "TOTPOP10" };
                //Create the DotDensityRendererDefinition object
                var dotDensityDef = new DotDensityRendererDefinition(valueFields, SDKHelpers.GetColorRamp(),
                                                                     dotSize, 30000, "Dot", "people");
                //Create the renderer using the DotDensityRendererDefinition
                CIMDotDensityRenderer dotDensityRndr = (CIMDotDensityRenderer)featureLayer.CreateRenderer(dotDensityDef);

                //if you want to customize the dot symbol for the renderer, create a "DotDensitySymbol" which is an
                //Amalgamation of 3 symbol layers: CIMVectorMarker, CIMSolidFill and CIMSolidStroke
                //Define CIMVectorMarker layer
                var cimMarker = SymbolFactory.Instance.ConstructMarker(ColorFactory.Instance.RedRGB, dotSize);
                var dotDensityMarker = cimMarker as CIMVectorMarker;
                //Definte the placement
                CIMMarkerPlacementInsidePolygon markerPlacement = new CIMMarkerPlacementInsidePolygon {
                    Randomness = 100, GridType = PlacementGridType.RandomFixedQuantity, Clipping = PlacementClip.RemoveIfCenterOutsideBoundary
                };
                dotDensityMarker.MarkerPlacement = markerPlacement;

                //Define CIMSolidFill layer
                CIMSolidFill solidFill = new CIMSolidFill {
                    Color = new CIMRGBColor {
                        R = 249, G = 232, B = 189, Alpha = 50
                    }
                };

                //Define CIMSolidStroke
                CIMSolidStroke solidStroke = new CIMSolidStroke {
                    Color = ColorFactory.Instance.GreyRGB, Width = .5
                };

                //Create the amalgamated CIMPolygonSymbol that includes the 3 layers
                var dotDensitySymbol = new CIMPolygonSymbol
                {
                    SymbolLayers = new CIMSymbolLayer[] { dotDensityMarker, solidFill, solidStroke }
                };

                //Apply the dotDensitySymbol to the CIMDotDenstityRenderer's DotDensitySymbol property.
                dotDensityRndr.DotDensitySymbol = dotDensitySymbol.MakeSymbolReference();

                //Apply the renderer to the polygon Feature Layer.
                featureLayer.SetRenderer(dotDensityRndr);
            }));
        }
        protected override Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            if (Module1.Current.SelectedGraphicsLayerTOC == null)
            {
                MessageBox.Show("Select a graphics layer in the TOC", "No graphics layer selected",
                                System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
                return(Task.FromResult(true));
            }

            if (_polygonSymbol == null)
            {
                return(Task.FromResult(true));
            }
            return(QueuedTask.Run(() =>
            {
                var selectedElements = Module1.Current.SelectedGraphicsLayerTOC.GetSelectedElements().
                                       OfType <GraphicElement>();

                if (selectedElements.Count() == 1)
                {
                    if (selectedElements.FirstOrDefault().GetGraphic() is CIMPolygonGraphic)
                    {
                        var polySymbol = selectedElements.FirstOrDefault().GetGraphic() as CIMPolygonGraphic;
                        _polygonSymbol = polySymbol.Symbol.Symbol as CIMPolygonSymbol;
                    }
                }
                var cimGraphicElement = new CIMPolygonGraphic
                {
                    Polygon = geometry as Polygon,
                    Symbol = _polygonSymbol.MakeSymbolReference()
                };

                Module1.Current.SelectedGraphicsLayerTOC.AddElement(cimGraphicElement);

                MapPoint pntPolygon = null;
                pntPolygon = GeometryEngine.Instance.LabelPoint(geometry);

                if (selectedElements.Count() == 1)
                {
                    if (selectedElements.FirstOrDefault().GetGraphic() is CIMTextGraphic)
                    {
                        //So we use it
                        var textSymbol = selectedElements.FirstOrDefault().GetGraphic() as CIMTextGraphic;
                        _textSymbol = textSymbol.Symbol.Symbol as CIMTextSymbol;
                    }
                }

                // Get the ribbon or the dockpane text values
                string txtBoxString = null;
                string queryTxtBoxString = null;
                if (Module1.Current.blnDockpaneOpenStatus == false)
                {
                    // Use value in the edit boxes
                    txtBoxString = Module1.Current.TextValueEditBox.Text;
                    queryTxtBoxString = Module1.Current.QueryValueEditBox.Text;
                    if (txtBoxString == null || txtBoxString == "")
                    {
                        txtBoxString = "    Default Text";
                    }
                    else
                    {
                        txtBoxString = "   " + txtBoxString;
                    }
                    if (queryTxtBoxString != null && queryTxtBoxString != "")
                    {
                        txtBoxString = txtBoxString + "\r\n    " + queryTxtBoxString;
                    }
                }
                if (Module1.Current.blnDockpaneOpenStatus == true)
                {
                    _dockpane = FrameworkApplication.DockPaneManager.Find("GraphicTools_TextPane") as TextPaneViewModel;
                    txtBoxString = _dockpane.TxtBoxDoc;
                    queryTxtBoxString = _dockpane.QueryTxtBoxDoc;
                    if (txtBoxString == null || txtBoxString == "")
                    {
                        txtBoxString = "    Default Text";
                    }
                    else
                    {
                        txtBoxString = "   " + txtBoxString;
                    }
                    if (queryTxtBoxString != null && queryTxtBoxString != "")
                    {
                        txtBoxString = txtBoxString + "\r\n    " + queryTxtBoxString;
                    }
                }

                var textGraphic = new CIMParagraphTextGraphic
                {
                    Symbol = _textSymbol.MakeSymbolReference(),
                    Shape = geometry as Polygon,
                    Text = txtBoxString
                };

                Module1.Current.SelectedGraphicsLayerTOC.AddElement(textGraphic);
                Module1.Current.SelectedGraphicsLayerTOC.ClearSelection();

                return true;
            }));
        }
Example #21
0
 protected override Task OnToolActivateAsync(bool active)
 {
     _polygonSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(CIMColor.CreateRGBColor(255, 255, 0));
     return(base.OnToolActivateAsync(active));
 }
        private async Task RedrawConeAsync()
        {
            await QueuedTask.Run(() =>
            {
                GlobeSpotter globeSpotter = GlobeSpotter.Current;

                if ((globeSpotter.InsideScale()) && (!_mapPoint.IsEmpty) && (Color != null))
                {
                    var thisColor                       = (SystCol)Color;
                    MapView thisView                    = MapView.Active;
                    Map map                             = thisView.Map;
                    SpatialReference mapSpat            = map.SpatialReference;
                    SpatialReference mapPointSpat       = _mapPoint.SpatialReference;
                    ProjectionTransformation projection = ProjectionTransformation.Create(mapPointSpat, mapSpat);
                    _mapPoint                           = GeometryEngine.Instance.ProjectEx(_mapPoint, projection) as MapPoint;

                    WinPoint point = thisView.MapToScreen(_mapPoint);
                    double angleh  = (_hFov *Math.PI) / 360;
                    double angle   = (((270 + _angle) % 360) * Math.PI) / 180;
                    double angle1  = angle - angleh;
                    double angle2  = angle + angleh;
                    double x       = point.X;
                    double y       = point.Y;
                    double size    = Size / 2;

                    WinPoint screenPoint1 = new WinPoint((x + (size * Math.Cos(angle1))), (y + (size * Math.Sin(angle1))));
                    WinPoint screenPoint2 = new WinPoint((x + (size * Math.Cos(angle2))), (y + (size * Math.Sin(angle2))));
                    MapPoint point1       = thisView.ScreenToMap(screenPoint1);
                    MapPoint point2       = thisView.ScreenToMap(screenPoint2);

                    IList <MapPoint> polygonPointList = new List <MapPoint>();
                    polygonPointList.Add(_mapPoint);
                    polygonPointList.Add(point1);
                    polygonPointList.Add(point2);
                    polygonPointList.Add(_mapPoint);
                    Polygon polygon = PolygonBuilder.CreatePolygon(polygonPointList);

                    Color colorPolygon             = SystCol.FromArgb(_blinking ? BlinkAlpha : NormalAlpha, thisColor);
                    CIMColor cimColorPolygon       = ColorFactory.Instance.CreateColor(colorPolygon);
                    CIMPolygonSymbol polygonSymbol = SymbolFactory.Instance.DefaultPolygonSymbol;
                    polygonSymbol.SetColor(cimColorPolygon);
                    polygonSymbol.SetOutlineColor(null);
                    CIMSymbolReference polygonSymbolReference = polygonSymbol.MakeSymbolReference();
                    IDisposable disposePolygon = thisView.AddOverlay(polygon, polygonSymbolReference);

                    IList <MapPoint> linePointList = new List <MapPoint>();
                    linePointList.Add(point1);
                    linePointList.Add(_mapPoint);
                    linePointList.Add(point2);
                    Polyline polyline = PolylineBuilder.CreatePolyline(linePointList);

                    Color colorLine             = _active ? SystCol.Yellow : SystCol.Gray;
                    CIMColor cimColorLine       = ColorFactory.Instance.CreateColor(colorLine);
                    CIMLineSymbol cimLineSymbol = SymbolFactory.Instance.DefaultLineSymbol;
                    cimLineSymbol.SetColor(cimColorLine);
                    cimLineSymbol.SetSize(_blinking ? BorderSizeBlinking : BorderSize);
                    CIMSymbolReference lineSymbolReference = cimLineSymbol.MakeSymbolReference();
                    IDisposable disposePolyLine            = thisView.AddOverlay(polyline, lineSymbolReference);

                    _disposePolygon?.Dispose();
                    _disposePolygon = disposePolygon;
                    _disposePolyLine?.Dispose();
                    _disposePolyLine = disposePolyLine;

                    if (_blinking)
                    {
                        var blinkEvent         = new AutoResetEvent(true);
                        var blinkTimerCallBack = new TimerCallback(ResetBlinking);
                        _blinkTimer            = new Timer(blinkTimerCallBack, blinkEvent, BlinkTime, -1);
                    }
                }
                else
                {
                    _disposePolygon?.Dispose();
                    _disposePolyLine?.Dispose();
                }
            });
        }
Example #23
0
        public void btnChangeRoomSymbology(object sender, EventArgs e)
        {
            var polygonSymbology = ((RadioButton)sender).Tag;

            QueuedTask.Run(() =>
            {
                //Get the active map's definition - CIMMap.

                if (polygonSymbology.ToString() == "None")
                {
                    var cimMap = MapView.Active.Map.GetDefinition();
                    //FeatureLayer a = MapView.Active.Map.Layers[1] as FeatureLayer;
                    var lyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(s => s.ShapeType == esriGeometryType.esriGeometryPolygon);
                    CIMSimpleRenderer renderer = lyr.GetRenderer() as CIMSimpleRenderer;
                    CIMStroke outline          = SymbolFactory.Instance.ConstructStroke(
                        ColorFactory.Instance.GreyRGB, 0.5, SimpleLineStyle.Solid);
                    CIMPolygonSymbol fillWithOutline = SymbolFactory.Instance.ConstructPolygonSymbol(
                        ColorFactory.Instance.CreateRGBColor(255, 255, 255), SimpleFillStyle.Solid, outline);
                    //Update the symbol of the current simple renderer
                    renderer.Symbol = fillWithOutline.MakeSymbolReference();
                    //Update the feature layer renderer
                    lyr.SetRenderer(renderer);
                }
                if (polygonSymbology.ToString() == "Multicolor1")
                {
                    Debug.WriteLine("Multicolor1");
                    var cimMap = MapView.Active.Map.GetDefinition();
                    //FeatureLayer a = MapView.Active.Map.Layers[1] as FeatureLayer;
                    var lyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(s => s.ShapeType == esriGeometryType.esriGeometryPolygon);
                    CIMUniqueValueRenderer renderer = lyr.GetRenderer() as CIMUniqueValueRenderer;

                    // color ramp
                    CIMICCColorSpace colorSpace = new CIMICCColorSpace()
                    {
                        URL = "Default RGB"
                    };

                    CIMRandomHSVColorRamp randomHSVColorRamp = new CIMRandomHSVColorRamp()
                    {
                        ColorSpace = colorSpace,
                        MinAlpha   = 100,
                        MaxAlpha   = 100,
                        MinH       = 0,
                        MaxH       = 360,
                        MinS       = 15,
                        MaxS       = 30,
                        MinV       = 99,
                        MaxV       = 100,
                        Seed       = 0
                    };

                    UniqueValueRendererDefinition uvr = new UniqueValueRendererDefinition()
                    {
                        ValueFields = new string[] { "RMAREA" }, //multiple fields in the array if needed.
                        ColorRamp   = randomHSVColorRamp         //Specify color ramp
                    };

                    var r = lyr.CreateRenderer(uvr);
                    lyr.SetRenderer(r);
                }
                if (polygonSymbology.ToString() == "Beige")
                {
                    var cimMap = MapView.Active.Map.GetDefinition();
                    //FeatureLayer a = MapView.Active.Map.Layers[1] as FeatureLayer;
                    var lyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(s => s.ShapeType == esriGeometryType.esriGeometryPolygon);
                    //CIMSimpleRenderer renderer = lyr.GetRenderer() as CIMSimpleRenderer;
                    CIMSimpleRenderer renderer = new CIMSimpleRenderer()
                    {
                    };
                    CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
                        ColorFactory.Instance.GreyRGB, 0.5, SimpleLineStyle.Solid);
                    CIMPolygonSymbol fillWithOutline = SymbolFactory.Instance.ConstructPolygonSymbol(
                        ColorFactory.Instance.CreateRGBColor(255, 222, 173), SimpleFillStyle.Solid, outline);

                    //Update the symbol of the current simple renderer
                    renderer.Symbol = fillWithOutline.MakeSymbolReference();
                    //Update the feature layer renderer
                    lyr.SetRenderer(renderer);

                    /*
                     *
                     * unique value rendere
                     * internal static Task UniqueValueRenderer(FeatureLayer featureLayer)
                     * {
                     * return QueuedTask.Run(() =>
                     * {
                     * //construct unique value renderer definition
                     * UniqueValueRendererDefinition uvr = new
                     * UniqueValueRendererDefinition()
                     * {
                     * ValueFields = new string[] { SDKHelpers.GetDisplayField(featureLayer) }, //multiple fields in the array if needed.
                     * ColorRamp = SDKHelpers.GetColorRamp(), //Specify color ramp
                     * };
                     *
                     * //Creates a "Renderer"
                     * var cimRenderer = featureLayer.CreateRenderer(uvr);
                     *
                     * //Sets the renderer to the feature layer
                     * featureLayer.SetRenderer(cimRenderer);
                     * });
                     *
                     * }
                     *
                     *
                     * diagonal cross hatch example
                     * public static Task<CIMPolygonSymbol> CreateDiagonalCrossPolygonAsync()
                     * {
                     * return QueuedTask.Run<CIMPolygonSymbol>(() =>
                     * {
                     * var trans = 50.0;//semi transparent
                     * CIMStroke outline = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(0, 0, 0, trans), 2.0, SimpleLineStyle.Solid);
                     *
                     * //Stroke for the fill
                     * var solid = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(255, 0, 0, trans), 1.0, SimpleLineStyle.Solid);
                     *
                     * //Mimic cross hatch
                     * CIMFill[] diagonalCross =
                     * {
                     * new CIMHatchFill() {
                     * Enable = true,
                     * Rotation = 45.0,
                     * Separation = 5.0,
                     * LineSymbol = new CIMLineSymbol() { SymbolLayers = new CIMSymbolLayer[1] { solid } }
                     * },
                     * new CIMHatchFill() {
                     * Enable = true,
                     * Rotation = -45.0,
                     * Separation = 5.0,
                     * LineSymbol = new CIMLineSymbol() { SymbolLayers = new CIMSymbolLayer[1] { solid } }
                     * }
                     * };
                     * List<CIMSymbolLayer> symbolLayers = new List<CIMSymbolLayer>();
                     * symbolLayers.Add(outline);
                     * foreach (var fill in diagonalCross)
                     * symbolLayers.Add(fill);
                     * return new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() };
                     * });
                     * }
                     */
                }
            });

            Debug.WriteLine(MapView.Active.Map.Layers[0].Name); // .SetLabelVisibility(true);
            Debug.WriteLine(MapView.Active.Map.Layers[1].Name); // .SetLabelVisibility(true);
            //Debug.WriteLine(MapView.Active.Map.SetLabelEngine
        }
Example #24
0
        public void snippets_CreateLayoutElements()
        {
            LayoutView layoutView = LayoutView.Active;
            Layout     layout     = layoutView.Layout;

            #region Create point graphic with symbology

            //Create a simple 2D point graphic and apply an existing point style item as the symbology.
            //An alternative simple symbol is also provided below.  This would completely elminate the 4 lines of code that reference a style.

            QueuedTask.Run(() =>
            {
                //Build 2D point geometry
                Coordinate2D coord2D = new Coordinate2D(2.0, 10.0);

                //Reference a point symbol in a style
                StyleProjectItem ptStylePrjItm = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D");
                SymbolStyleItem ptSymStyleItm  = ptStylePrjItm.SearchSymbols(StyleItemType.PointSymbol, "City Hall")[0];
                CIMPointSymbol pointSym        = ptSymStyleItm.Symbol as CIMPointSymbol;
                pointSym.SetSize(50);

                //Set symbolology, create and add element to layout
                //CIMPointSymbol pointSym = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 25.0, SimpleMarkerStyle.Star);  //Alternative simple symbol
                GraphicElement ptElm = LayoutElementFactory.Instance.CreatePointGraphicElement(layout, coord2D, pointSym);
                ptElm.SetName("New Point");
            });
            #endregion

            #region Create line graphic with symbology

            //Create a simple 2D line graphic and apply an existing line style item as the symbology.
            //An alternative simple symbol is also provided below.  This would completely elminate the 4 lines of code that reference a style.

            QueuedTask.Run(() =>
            {
                //Build 2d line geometry
                List <Coordinate2D> plCoords = new List <Coordinate2D>();
                plCoords.Add(new Coordinate2D(1, 8.5));
                plCoords.Add(new Coordinate2D(1.66, 9));
                plCoords.Add(new Coordinate2D(2.33, 8.1));
                plCoords.Add(new Coordinate2D(3, 8.5));
                Polyline linePl = PolylineBuilder.CreatePolyline(plCoords);

                //Reference a line symbol in a style
                StyleProjectItem lnStylePrjItm = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D");
                SymbolStyleItem lnSymStyleItm  = lnStylePrjItm.SearchSymbols(StyleItemType.LineSymbol, "Line with 2 Markers")[0];
                CIMLineSymbol lineSym          = lnSymStyleItm.Symbol as CIMLineSymbol;
                lineSym.SetSize(20);

                //Set symbolology, create and add element to layout
                //CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 4.0, SimpleLineStyle.Solid);  //Alternative simple symbol
                GraphicElement lineElm = LayoutElementFactory.Instance.CreateLineGraphicElement(layout, linePl, lineSym);
                lineElm.SetName("New Line");
            });
            #endregion

            #region Create rectangle graphic with simple symbology

            //Create a simple 2D rectangle graphic and apply simple fill and outline symbols.

            QueuedTask.Run(() =>
            {
                //Build 2D envelope geometry
                Coordinate2D rec_ll = new Coordinate2D(1.0, 4.75);
                Coordinate2D rec_ur = new Coordinate2D(3.0, 5.75);
                Envelope rec_env    = EnvelopeBuilder.CreateEnvelope(rec_ll, rec_ur);

                //Set symbolology, create and add element to layout
                CIMStroke outline        = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 5.0, SimpleLineStyle.Solid);
                CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.GreenRGB, SimpleFillStyle.DiagonalCross, outline);
                GraphicElement recElm    = LayoutElementFactory.Instance.CreateRectangleGraphicElement(layout, rec_env, polySym);
                recElm.SetName("New Rectangle");
            });
            #endregion

            #region Create text element with basic font properties

            //Create a simple point text element and assign basic symbology as well as basic text settings.

            QueuedTask.Run(() =>
            {
                //Build 2D point geometry
                Coordinate2D coord2D = new Coordinate2D(3.5, 10);

                //Set symbolology, create and add element to layout
                CIMTextSymbol sym       = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.RedRGB, 32, "Arial", "Regular");
                string textString       = "Point text";
                GraphicElement ptTxtElm = LayoutElementFactory.Instance.CreatePointTextGraphicElement(layout, coord2D, textString, sym);
                ptTxtElm.SetName("New Point Text");

                //Change additional text properties
                ptTxtElm.SetAnchor(Anchor.CenterPoint);
                ptTxtElm.SetX(4.5);
                ptTxtElm.SetY(9.5);
                ptTxtElm.SetRotation(45);
            });
            #endregion

            #region Create rectangle text with more advanced symbol settings

            //Create rectangle text with background and border symbology.  Also notice how formatting tags are using within the text string.

            QueuedTask.Run(() =>
            {
                //Build 2D polygon geometry
                List <Coordinate2D> plyCoords = new List <Coordinate2D>();
                plyCoords.Add(new Coordinate2D(3.5, 7));
                plyCoords.Add(new Coordinate2D(4.5, 7));
                plyCoords.Add(new Coordinate2D(4.5, 6.7));
                plyCoords.Add(new Coordinate2D(5.5, 6.7));
                plyCoords.Add(new Coordinate2D(5.5, 6.1));
                plyCoords.Add(new Coordinate2D(3.5, 6.1));
                Polygon poly = PolygonBuilder.CreatePolygon(plyCoords);

                //Set symbolology, create and add element to layout
                CIMTextSymbol sym         = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreyRGB, 10, "Arial", "Regular");
                string text               = "Some Text String that is really long and is <BOL>forced to wrap to other lines</BOL> so that we can see the effects." as String;
                GraphicElement polyTxtElm = LayoutElementFactory.Instance.CreatePolygonParagraphGraphicElement(layout, poly, text, sym);
                polyTxtElm.SetName("New Polygon Text");

                //(Optionally) Modify paragraph border
                CIMGraphic polyTxtGra = polyTxtElm.Graphic;
                CIMParagraphTextGraphic cimPolyTxtGra   = polyTxtGra as CIMParagraphTextGraphic;
                cimPolyTxtGra.Frame.BorderSymbol        = new CIMSymbolReference();
                cimPolyTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
                polyTxtElm.SetGraphic(polyTxtGra);
            });
            #endregion

            #region Create a new picture element with advanced symbol settings

            //Create a picture element and also set background and border symbology.

            QueuedTask.Run(() =>
            {
                //Build 2D envelope geometry
                Coordinate2D pic_ll = new Coordinate2D(6, 1);
                Coordinate2D pic_ur = new Coordinate2D(8, 2);
                Envelope env        = EnvelopeBuilder.CreateEnvelope(pic_ll, pic_ur);

                //Create and add element to layout
                string picPath        = @"C:\Temp\WhitePass.jpg";
                GraphicElement picElm = LayoutElementFactory.Instance.CreatePictureGraphicElement(layout, env, picPath);
                picElm.SetName("New Picture");

                //(Optionally) Modify the border and shadow
                CIMGraphic picGra                   = picElm.Graphic;
                CIMPictureGraphic cimPicGra         = picGra as CIMPictureGraphic;
                cimPicGra.Frame.BorderSymbol        = new CIMSymbolReference();
                cimPicGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.Solid);

                cimPicGra.Frame.ShadowSymbol        = new CIMSymbolReference();
                cimPicGra.Frame.ShadowSymbol.Symbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlackRGB, SimpleFillStyle.Solid);

                picElm.SetGraphic(picGra);
            });
            #endregion

            #region Create a map frame and zoom to a bookmark

            //Create a map frame and also sets its extent by zooming the the extent of an existing bookmark.

            QueuedTask.Run(() =>
            {
                //Build 2D envelope geometry
                Coordinate2D mf_ll = new Coordinate2D(6.0, 8.5);
                Coordinate2D mf_ur = new Coordinate2D(8.0, 10.5);
                Envelope mf_env    = EnvelopeBuilder.CreateEnvelope(mf_ll, mf_ur);

                //Reference map, create MF and add to layout
                MapProjectItem mapPrjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name.Equals("Map"));
                Map mfMap      = mapPrjItem.GetMap();
                MapFrame mfElm = LayoutElementFactory.Instance.CreateMapFrame(layout, mf_env, mfMap);
                mfElm.SetName("New Map Frame");

                //Zoom to bookmark
                Bookmark bookmark = mfElm.Map.GetBookmarks().FirstOrDefault(b => b.Name == "Great Lakes");
                mfElm.SetCamera(bookmark);
            });
            #endregion

            #region Create a legend for a specifc map frame

            //Create a legend for an associated map frame.

            QueuedTask.Run(() =>
            {
                //Build 2D envelope geometry
                Coordinate2D leg_ll = new Coordinate2D(6, 2.5);
                Coordinate2D leg_ur = new Coordinate2D(8, 4.5);
                Envelope leg_env    = EnvelopeBuilder.CreateEnvelope(leg_ll, leg_ur);

                //Reference MF, create legend and add to layout
                MapFrame mapFrame = layout.FindElement("New Map Frame") as MapFrame;
                if (mapFrame == null)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING");
                    return;
                }
                Legend legendElm = LayoutElementFactory.Instance.CreateLegend(layout, leg_env, mapFrame);
                legendElm.SetName("New Legend");
            });
            #endregion

            #region Creating group elements
            //Create an empty group element at the root level of the contents pane
            //Note: call within QueuedTask.Run()
            GroupElement grp1 = LayoutElementFactory.Instance.CreateGroupElement(layout);
            grp1.SetName("Group");

            //Create a group element inside another group element
            //Note: call within QueuedTask.Run()
            GroupElement grp2 = LayoutElementFactory.Instance.CreateGroupElement(grp1);
            grp2.SetName("Group in Group");
            #endregion Creating group elements

            {
                #region Create scale bar
                Coordinate2D llScalebar = new Coordinate2D(6, 2.5);
                MapFrame     mapframe   = layout.FindElement("New Map Frame") as MapFrame;
                //Note: call within QueuedTask.Run()
                LayoutElementFactory.Instance.CreateScaleBar(layout, llScalebar, mapframe);
                #endregion
            }
            #region How to search for scale bars in a style
            var arcgis_2d = Project.Current.GetItems <StyleProjectItem>().First(si => si.Name == "ArcGIS 2D");
            QueuedTask.Run(() => {
                var scaleBarItems = arcgis_2d.SearchScaleBars("Double Alternating Scale Bar");
            });

            #endregion

            #region How to add a scale bar from a style to a layout
            var arcgis_2dStyle = Project.Current.GetItems <StyleProjectItem>().First(si => si.Name == "ArcGIS 2D");
            QueuedTask.Run(() =>
            {
                //Imperial Double Alternating Scale Bar
                //Metric Double Alternating Scale Bar
                //or just use empty string to list them all...
                var scaleBarItem     = arcgis_2d.SearchScaleBars("Double Alternating Scale Bar").FirstOrDefault();
                Coordinate2D coord2D = new Coordinate2D(10.0, 7.0);
                MapFrame myMapFrame  = layout.FindElement("Map Frame") as MapFrame;
                LayoutElementFactory.Instance.CreateScaleBar(layout, coord2D, myMapFrame, scaleBarItem);
            });
            #endregion

            #region Create NorthArrow
            Coordinate2D llNorthArrow = new Coordinate2D(6, 2.5);
            MapFrame     mf           = layout.FindElement("New Map Frame") as MapFrame;
            //Note: call within QueuedTask.Run()
            var northArrow = LayoutElementFactory.Instance.CreateNorthArrow(layout, llNorthArrow, mf);
            #endregion

            #region How to search for North Arrows in a style
            var arcgis_2dStyles = Project.Current.GetItems <StyleProjectItem>().First(si => si.Name == "ArcGIS 2D");
            QueuedTask.Run(() => {
                var scaleBarItems = arcgis_2dStyles.SearchNorthArrows("ArcGIS North 13");
            });
            #endregion

            #region How to add a North Arrow from a style to a layout
            var arcgis2dStyles = Project.Current.GetItems <StyleProjectItem>().First(si => si.Name == "ArcGIS 2D");
            QueuedTask.Run(() => {
                var northArrowStyleItem = arcgis2dStyles.SearchNorthArrows("ArcGIS North 13").FirstOrDefault();
                Coordinate2D nArrow     = new Coordinate2D(6, 2.5);
                MapFrame newFrame       = layout.FindElement("New Map Frame") as MapFrame;
                //Note: call within QueuedTask.Run()
                var newNorthArrow = LayoutElementFactory.Instance.CreateNorthArrow(layout, nArrow, newFrame, northArrowStyleItem);
            });

            #endregion

            #region Create dynamic text
            var          title   = @"<dyn type = ""page"" property = ""name"" />";
            Coordinate2D llTitle = new Coordinate2D(6, 2.5);
            //Note: call within QueuedTask.Run()
            var titleGraphics = LayoutElementFactory.Instance.CreatePointTextGraphicElement(layout, llTitle, null) as TextElement;
            titleGraphics.SetTextProperties(new TextProperties(title, "Arial", 24, "Bold"));
            #endregion


            #region Create dynamic table

            QueuedTask.Run(() =>
            {
                //Build 2D envelope geometry
                Coordinate2D tab_ll = new Coordinate2D(6, 2.5);
                Coordinate2D tab_ur = new Coordinate2D(12, 6.5);
                Envelope tab_env    = EnvelopeBuilder.CreateEnvelope(tab_ll, tab_ur);
                MapFrame mapFrame   = layout.FindElement("New Map Frame") as MapFrame;
                // get the layer
                MapProjectItem mapPrjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name.Equals("Map"));
                Map theMap = mapPrjItem?.GetMap();
                var lyrs   = theMap?.FindLayers("Inspection Point Layer", true);
                if (lyrs?.Count > 0)
                {
                    Layer lyr  = lyrs[0];
                    var table1 = LayoutElementFactory.Instance.CreateTableFrame(layout, tab_env, mapFrame, lyr, new string[] { "No", "Type", "Description" });
                }
            });
            #endregion
        }
Example #25
0
        async public static void CreateElementSnippets()
        {
            //There are already many Create element snippets in the PRO snippets section.  This section will only contain examples that are NOT in the Pro snippets section
            //Pro snippets region names includes:
            //    Create point graphic with symbology
            //    Create line graphic with symbology
            //    Create rectangle graphic with simple symbology
            //    Create text element with basic font properties
            //    Create rectangle text with more advanced symbol settings
            //    Create a new picture element with advanced symbol settings
            //    Create a map frame and zoom to a bookmark
            //    Create a legend for a specifc map frame
            //    Creating group elements

            LayoutView lytView = LayoutView.Active;
            Layout     layout  = lytView.Layout;

            #region Create_BeizierCurve
            await QueuedTask.Run(() =>
            {
                //Build geometry
                Coordinate2D pt1          = new Coordinate2D(1, 7.5);
                Coordinate2D pt2          = new Coordinate2D(1.66, 8);
                Coordinate2D pt3          = new Coordinate2D(2.33, 7.1);
                Coordinate2D pt4          = new Coordinate2D(3, 7.5);
                CubicBezierBuilder bez    = new CubicBezierBuilder(pt1, pt2, pt3, pt4);
                CubicBezierSegment bezSeg = bez.ToSegment();
                Polyline bezPl            = PolylineBuilder.CreatePolyline(bezSeg);

                //Set symbology, create and add element to layout
                CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.RedRGB, 4.0, SimpleLineStyle.DashDot);
                GraphicElement bezElm = LayoutElementFactory.Instance.CreateLineGraphicElement(layout, bezPl, lineSym);
                bezElm.SetName("New Bezier Curve");
            });

            #endregion Create_BeizierCurve

            #region Create_freehand
            await QueuedTask.Run(() =>
            {
                //Build geometry
                List <Coordinate2D> plCoords = new List <Coordinate2D>();
                plCoords.Add(new Coordinate2D(1.5, 10.5));
                plCoords.Add(new Coordinate2D(1.25, 9.5));
                plCoords.Add(new Coordinate2D(1, 10.5));
                plCoords.Add(new Coordinate2D(0.75, 9.5));
                plCoords.Add(new Coordinate2D(0.5, 10.5));
                plCoords.Add(new Coordinate2D(0.5, 1));
                plCoords.Add(new Coordinate2D(0.75, 2));
                plCoords.Add(new Coordinate2D(1, 1));
                Polyline linePl = PolylineBuilder.CreatePolyline(plCoords);

                //Set symbolology, create and add element to layout
                CIMLineSymbol lineSym  = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid);
                GraphicElement lineElm = LayoutElementFactory.Instance.CreateLineGraphicElement(layout, linePl, lineSym);
                lineElm.SetName("New Freehand");
            });

            #endregion Create_freehand

            #region Create_polygon
            await QueuedTask.Run(() =>
            {
                //Build geometry
                List <Coordinate2D> plyCoords = new List <Coordinate2D>();
                plyCoords.Add(new Coordinate2D(1, 7));
                plyCoords.Add(new Coordinate2D(2, 7));
                plyCoords.Add(new Coordinate2D(2, 6.7));
                plyCoords.Add(new Coordinate2D(3, 6.7));
                plyCoords.Add(new Coordinate2D(3, 6.1));
                plyCoords.Add(new Coordinate2D(1, 6.1));
                Polygon poly = PolygonBuilder.CreatePolygon(plyCoords);

                //Set symbolology, create and add element to layout
                CIMStroke outline        = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.DashDotDot);
                CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline);
                GraphicElement polyElm   = LayoutElementFactory.Instance.CreatePolygonGraphicElement(layout, poly, polySym);
                polyElm.SetName("New Polygon");
            });

            #endregion Create_polygon

            #region Create_circle
            await QueuedTask.Run(() =>
            {
                //Build geometry
                Coordinate2D center       = new Coordinate2D(2, 4);
                EllipticArcBuilder eabCir = new EllipticArcBuilder(center, 0.5, esriArcOrientation.esriArcClockwise);
                EllipticArcSegment cir    = eabCir.ToSegment();

                //Set symbolology, create and add element to layout
                CIMStroke outline          = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Dash);
                CIMPolygonSymbol circleSym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid, outline);
                GraphicElement cirElm      = LayoutElementFactory.Instance.CreateCircleGraphicElement(layout, cir, circleSym);
                cirElm.SetName("New Circle");
            });

            #endregion Create_circle

            #region Create_ellipse
            await QueuedTask.Run(() =>
            {
                //Build geometry
                Coordinate2D center        = new Coordinate2D(2, 2.75);
                EllipticArcBuilder eabElp  = new EllipticArcBuilder(center, 0, 1, 0.45, esriArcOrientation.esriArcClockwise);
                EllipticArcSegment ellipse = eabElp.ToSegment();

                //Set symbolology, create and add element to layout
                CIMStroke outline           = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.GreenRGB, 2.0, SimpleLineStyle.Dot);
                CIMPolygonSymbol ellipseSym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.GreyRGB, SimpleFillStyle.Vertical, outline);
                GraphicElement elpElm       = LayoutElementFactory.Instance.CreateEllipseGraphicElement(layout, ellipse, ellipseSym);
                elpElm.SetName("New Ellipse");
            });

            #endregion Create_ellipse

            #region Create_lasso
            await QueuedTask.Run(() =>
            {
                //Build geometry
                List <Coordinate2D> plyCoords = new List <Coordinate2D>();
                plyCoords.Add(new Coordinate2D(1, 1));
                plyCoords.Add(new Coordinate2D(1.25, 2));
                plyCoords.Add(new Coordinate2D(1.5, 1.1));
                plyCoords.Add(new Coordinate2D(1.75, 2));
                plyCoords.Add(new Coordinate2D(2, 1.1));
                plyCoords.Add(new Coordinate2D(2.25, 2));
                plyCoords.Add(new Coordinate2D(2.5, 1.1));
                plyCoords.Add(new Coordinate2D(2.75, 2));
                plyCoords.Add(new Coordinate2D(3, 1));
                Polygon poly = PolygonBuilder.CreatePolygon(plyCoords);

                //Set symbolology, create and add element to layout
                CIMStroke outline        = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid);
                CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline);
                GraphicElement polyElm   = LayoutElementFactory.Instance.CreatePolygonGraphicElement(layout, poly, polySym);
                polyElm.SetName("New Lasso");
            });

            #endregion Create_lasso

            #region Create_CurveText
            await QueuedTask.Run(() =>
            {
                //Build geometry
                Coordinate2D pt1          = new Coordinate2D(3.6, 7.5);
                Coordinate2D pt2          = new Coordinate2D(4.26, 8);
                Coordinate2D pt3          = new Coordinate2D(4.93, 7.1);
                Coordinate2D pt4          = new Coordinate2D(5.6, 7.5);
                CubicBezierBuilder bez    = new CubicBezierBuilder(pt1, pt2, pt3, pt4);
                CubicBezierSegment bezSeg = bez.ToSegment();
                Polyline bezPl            = PolylineBuilder.CreatePolyline(bezSeg);

                //Set symbolology, create and add element to layout
                CIMTextSymbol sym        = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 24, "Comic Sans MS", "Regular");
                GraphicElement bezTxtElm = LayoutElementFactory.Instance.CreateCurvedTextGraphicElement(layout, bezPl, "Curved Text", sym);
                bezTxtElm.SetName("New Splinned Text");
            });

            #endregion Create_CurveText

            #region Create_PolygonText
            await QueuedTask.Run(() =>
            {
                //Build geometry
                List <Coordinate2D> plyCoords = new List <Coordinate2D>();
                plyCoords.Add(new Coordinate2D(3.5, 7));
                plyCoords.Add(new Coordinate2D(4.5, 7));
                plyCoords.Add(new Coordinate2D(4.5, 6.7));
                plyCoords.Add(new Coordinate2D(5.5, 6.7));
                plyCoords.Add(new Coordinate2D(5.5, 6.1));
                plyCoords.Add(new Coordinate2D(3.5, 6.1));
                Polygon poly = PolygonBuilder.CreatePolygon(plyCoords);

                //Set symbolology, create and add element to layout
                CIMTextSymbol sym         = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreyRGB, 10, "Arial", "Regular");
                string text               = "Some Text String that is really long and is <BOL>forced to wrap to other lines</BOL> so that we can see the effects." as String;
                GraphicElement polyTxtElm = LayoutElementFactory.Instance.CreatePolygonParagraphGraphicElement(layout, poly, text, sym);
                polyTxtElm.SetName("New Polygon Text");

                //(Optionally) Modify paragraph border
                CIMGraphic polyTxtGra = polyTxtElm.Graphic;
                CIMParagraphTextGraphic cimPolyTxtGra   = polyTxtGra as CIMParagraphTextGraphic;
                cimPolyTxtGra.Frame.BorderSymbol        = new CIMSymbolReference();
                cimPolyTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
                polyTxtElm.SetGraphic(polyTxtGra);
            });

            #endregion Create_PolygonText

            #region Create_CircleText
            await QueuedTask.Run(() =>
            {
                //Build geometry
                Coordinate2D center       = new Coordinate2D(4.5, 4);
                EllipticArcBuilder eabCir = new EllipticArcBuilder(center, 0.5, esriArcOrientation.esriArcClockwise);
                EllipticArcSegment cir    = eabCir.ToSegment();

                //Set symbolology, create and add element to layout
                CIMTextSymbol sym        = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreenRGB, 10, "Arial", "Regular");
                string text              = "Circle, circle, circle, circle, circle, circle, circle, circle, circle, circle, circle";
                GraphicElement cirTxtElm = LayoutElementFactory.Instance.CreateCircleParagraphGraphicElement(layout, cir, text, sym);
                cirTxtElm.SetName("New Circle Text");

                //(Optionally) Modify paragraph border
                CIMGraphic cirTxtGra = cirTxtElm.Graphic;
                CIMParagraphTextGraphic cimCirTxtGra   = cirTxtGra as CIMParagraphTextGraphic;
                cimCirTxtGra.Frame.BorderSymbol        = new CIMSymbolReference();
                cimCirTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
                cirTxtElm.SetGraphic(cirTxtGra);
            });

            #endregion Create_CircleText

            #region Create_EllipseText
            await QueuedTask.Run(() =>
            {
                //Build geometry
                Coordinate2D center        = new Coordinate2D(4.5, 2.75);
                EllipticArcBuilder eabElp  = new EllipticArcBuilder(center, 0, 1, 0.45, esriArcOrientation.esriArcClockwise);
                EllipticArcSegment ellipse = eabElp.ToSegment();

                //Set symbolology, create and add element to layout
                CIMTextSymbol sym        = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlueRGB, 10, "Arial", "Regular");
                string text              = "Ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse";
                GraphicElement elpTxtElm = LayoutElementFactory.Instance.CreateEllipseParagraphGraphicElement(layout, ellipse, text, sym);
                elpTxtElm.SetName("New Ellipse Text");

                //(Optionally) Modify paragraph border
                CIMGraphic elpTxtGra = elpTxtElm.Graphic;
                CIMParagraphTextGraphic cimElpTxtGra   = elpTxtGra as CIMParagraphTextGraphic;
                cimElpTxtGra.Frame.BorderSymbol        = new CIMSymbolReference();
                cimElpTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
                elpTxtElm.SetGraphic(elpTxtGra);
            });

            #endregion Create_EllipseText

            MapFrame mfElm = null;
            #region Create_MapFrame
            //This example creates a new map frame and changes the camera scale.
            await QueuedTask.Run(() =>
            {
                //Build geometry
                Coordinate2D ll = new Coordinate2D(6.0, 8.5);
                Coordinate2D ur = new Coordinate2D(8.0, 10.5);
                Envelope env    = EnvelopeBuilder.CreateEnvelope(ll, ur);

                //Reference map, create MF and add to layout
                MapProjectItem mapPrjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name.Equals("Map"));
                Map mfMap = mapPrjItem.GetMap();
                mfElm     = LayoutElementFactory.Instance.CreateMapFrame(layout, env, mfMap);
                mfElm.SetName("New Map Frame");

                //Set the camera
                Camera camera = mfElm.Camera;
                camera.Scale  = 24000;
                mfElm.SetCamera(camera);
            });

            #endregion Create_MapFrame


            #region Create_ScaleBar
            await QueuedTask.Run(() =>
            {
                //Reference a North Arrow in a style
                StyleProjectItem stylePrjItm = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D");
                ScaleBarStyleItem sbStyleItm = stylePrjItm.SearchScaleBars("Double Alternating Scale Bar 1")[0];

                //Build geometry
                Coordinate2D center = new Coordinate2D(7, 8);

                //Reference MF, create north arrow and add to layout
                MapFrame mf = layout.FindElement("New Map Frame") as MapFrame;
                if (mf == null)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING");
                    return;
                }
                ScaleBar sbElm = LayoutElementFactory.Instance.CreateScaleBar(layout, center, mf, sbStyleItm);
                sbElm.SetName("New Scale Bar");
                sbElm.SetWidth(2);
                sbElm.SetX(6);
                sbElm.SetY(7.5);
            });

            #endregion Create_ScaleBar

            #region Create_NorthArrow
            await QueuedTask.Run(() =>
            {
                //Reference a North Arrow in a style
                StyleProjectItem stylePrjItm   = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D");
                NorthArrowStyleItem naStyleItm = stylePrjItm.SearchNorthArrows("ArcGIS North 10")[0];

                //Build geometry
                Coordinate2D center = new Coordinate2D(7, 5.5);

                //Reference MF, create north arrow and add to layout
                MapFrame mf = layout.FindElement("New Map Frame") as MapFrame;
                if (mf == null)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING");
                    return;
                }
                NorthArrow arrowElm = LayoutElementFactory.Instance.CreateNorthArrow(layout, center, mf, naStyleItm);
                arrowElm.SetName("New North Arrow");
                arrowElm.SetHeight(1.75);
                arrowElm.SetX(7);
                arrowElm.SetY(6);
            });

            #endregion Create_NorthArrow
        }
Example #26
0
        internal async Task PerformAnalysis(MapPoint ptStartLoc, MapView mapView, ProgressorSource ps)
        {
            ps.Progressor.Message = "Running the analysis...";
            ps.Progressor.Status  = "Gathering and verifying parameter data";
            string sReqUrl = Properties.Settings.Default.QryPointToState;
            string sReq    = String.Format("{0}?returnGeometry=false&returnDistinctValues=false&geometry={1}&geometryType=esriGeometryPoint&f=json&outFields=*&spatialRel=esriSpatialRelIntersects",
                                           sReqUrl, ptStartLoc.ToJson());
            // Find out what state the user clicked; or report an error if outside the U.S.
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sReq);
            string         sResp;

            try {
                using (StreamReader sread = new StreamReader(req.GetResponse().GetResponseStream()))
                    sResp = sread.ReadToEnd();
            } catch (Exception e) {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Error mapping the chosen spot to a petroleum area district in the U.S.A.: " + e.Message);
                return;
            }
            dynamic respPADDState = JsonConvert.DeserializeObject(sResp);

            try {
                string sState = respPADDState.features[0].attributes.STATE.ToString();
                // Find out what PADD zone the state is in
                SelectedPADDZone = PaddStateToZone[sState];
            } catch (Exception e) {
                System.Diagnostics.Debug.WriteLine("Exception getting PADD for chosen spot: " + e.Message);
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Please choose a spot within the U.S.A.");
                return /*null*/;
            }

            // Find out the gallons/$1.00 in that PADD zone
            double nFuelCost = PADDZoneToFuelCost[SelectedPADDZone];

            // Find out the miles per dollar each vehicle: (mi / gal) / (dollars / gal)
            // Map is in meters, so convert miles to meters
            Vehicle[]            orderedVehicles        = SelectedVehicles.OrderBy(vehicle => vehicle.Mpg).ToArray <Vehicle>();
            IEnumerable <double> vehicleMetersPerDollar =
                orderedVehicles.Select(vehicle => (vehicle.MetersPerGallon) / nFuelCost);

            string   sDistsParam   = String.Join(" ", vehicleMetersPerDollar.ToArray());
            MapPoint ptStartLocNoZ = await QueuedTask.Run(() => {
                MapPoint ptNoZ = MapPointBuilder.CreateMapPoint(ptStartLoc.X, ptStartLoc.Y, ptStartLoc.SpatialReference);
                return(ptNoZ);
            });

            // No corresponding type for the needed GPFeatureRecordSetLayer parameter
            string sStartGeom     = ptStartLocNoZ.ToJson();
            string sStartLocParam = "{\"geometryType\":\"esriGeometryPoint\",\"features\":[{\"geometry\":" + sStartGeom + "}]}";


            // Run the query
            ps.Progressor.Status = "Executing the analysis";
            string sGPUrl = Properties.Settings.Default.GPFindSA;

            sGPUrl += String.Format("?Distances={0}&Start_Location={1}&f=json", sDistsParam, sStartLocParam);
            HttpWebRequest  reqSA = (HttpWebRequest)WebRequest.Create(sGPUrl);
            HttpWebResponse wr;

            try {
                wr = (HttpWebResponse)reqSA.GetResponse();
                if (wr.StatusCode != HttpStatusCode.OK)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Error running analysis: " + wr.StatusDescription);
                    return;
                }
            } catch (WebException e) {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Error running analysis: " + e.Message);
                return;
            }

            // Show the results
            ps.Progressor.Status = "Processing the results";

            using (StreamReader sread = new StreamReader(wr.GetResponseStream()))
                sResp = sread.ReadToEnd();

            JObject respAnalysis = JObject.Parse(sResp);

            JArray feats = respAnalysis["results"][0]["value"]["features"] as JArray;

            // Rectify results and order so that largest polygon can be added to the map first
            List <JToken> aryResFeats = RectifyResults(feats, orderedVehicles);

            int iSR             = respAnalysis["results"][0]["value"]["spatialReference"]["wkid"].ToObject <Int32>();
            SpatialReference sr = await QueuedTask.Run <SpatialReference>(() => {
                SpatialReference srTemp = SpatialReferenceBuilder.CreateSpatialReference(iSR);
                return(srTemp);
            });

            /*lock (_lockResults)*/
            Results.ClearResults();

            // Iterate backwards to add larger polygons behind smaller ones

            for (int iVeh = orderedVehicles.Count() - 1; iVeh >= 0; iVeh--)
            {
                Result      result  = new Result(orderedVehicles[iVeh]);
                Polygon     poly    = null;
                IDisposable graphic = null;

                // Compute color for this result
                float multiplier = aryResFeats.Count > 1 ? ((float)iVeh) / ((float)(aryResFeats.Count - 1)) : 0;
                byte  red        = (byte)(255 - (255 * multiplier));
                byte  green      = (byte)(255 * multiplier);
                Color color      = Color.FromRgb(red, green, 0);
                result.Color = color.ToString();

                result.PaddZone         = SelectedPADDZone;
                result.DollarsPerGallon = nFuelCost;

                string sGeom = aryResFeats[iVeh]["geometry"].ToString();
                poly = await QueuedTask.Run(() => {
                    Polygon polyNoSR = PolygonBuilder.FromJson(sGeom);
                    return(PolygonBuilder.CreatePolygon(polyNoSR, sr));
                });

                CIMStroke        outline = SymbolFactory.ConstructStroke(ColorFactory.BlackRGB, 1.0, SimpleLineStyle.Solid);
                CIMPolygonSymbol symPoly = SymbolFactory.ConstructPolygonSymbol(
                    ColorFactory.CreateRGBColor(color.R, color.G, color.B, RESULT_OPACITY_PCT),
                    SimpleFillStyle.Solid, outline);
                CIMSymbolReference sym    = symPoly.MakeSymbolReference();
                CIMSymbolReference symDef = SymbolFactory.DefaultPolygonSymbol.MakeSymbolReference();
                graphic = await QueuedTask.Run(() => {
                    return(mapView.AddOverlay(poly, sym));
                });

                result.DriveServiceArea        = poly;
                result.DriveServiceAreaGraphic = graphic;
                result.DriveDistM = aryResFeats[iVeh]["attributes"]["ToBreak"].Value <double>();
                /*lock (_lockResults)*/
                Results.Add(result);
            }
        }
        protected async override void OnClick()
        {
            // To use this utility, you need to add the style that you want to update to your ArcGIS Pro project
            // If necessary and not alreadly listed, update the line below to include the name of the style that
            //    you want to update
            // Note: no ".stylx" extension

            List <string> stylxFiles = new List <string>()
            {
                "mil2525d", "mil2525c", "app6b"
            };

            string stylxUpdatedNames = string.Empty;

            foreach (string stylxToUpdateName in stylxFiles)
            {
                StyleProjectItem projectStyleItem = null;
                try
                {
                    projectStyleItem = Project.Current.GetItems <StyleProjectItem>().First(x => x.Name == stylxToUpdateName);
                }
                catch (Exception ex)
                {
                    projectStyleItem = null;
                }

                if (projectStyleItem == null)
                {
                    continue;
                }

                stylxUpdatedNames += stylxToUpdateName + ";";

                //update point symbols
                var ptSymbols = await projectStyleItem.SearchSymbolsAsync(StyleItemType.PointSymbol, "");

                await QueuedTask.Run(() =>
                {
                    foreach (SymbolStyleItem s in ptSymbols)
                    {
                        CIMPointSymbol symbol = (CIMPointSymbol)s.Symbol;

                        if (symbol == null)
                        {
                            continue;
                        }

                        try
                        {
                            var lyrs = symbol.SymbolLayers;

                            foreach (CIMVectorMarker x in lyrs)
                            {
                                if (x.ScaleSymbolsProportionally == false)
                                {
                                    x.ScaleSymbolsProportionally = true;
                                }
                            }
                            symbol.SymbolLayers = lyrs;
                            s.Symbol            = symbol;
                            projectStyleItem.UpdateItem(s);
                        }
                        catch (Exception ex2)
                        {
                        }
                    }
                });

                //update line symbols
                var lineSymbols = await projectStyleItem.SearchSymbolsAsync(StyleItemType.LineSymbol, "");

                await QueuedTask.Run(() =>
                {
                    foreach (SymbolStyleItem s in lineSymbols)
                    {
                        try
                        {
                            if (s.Symbol is CIMLineSymbol)
                            {
                                CIMLineSymbol symbol = (CIMLineSymbol)s.Symbol;
                                var lyrs             = symbol.SymbolLayers;
                                foreach (CIMSymbolLayer lyr in lyrs)
                                {
                                    CIMVectorMarker x = lyr as CIMVectorMarker;
                                    if (x != null)
                                    {
                                        if (x.ScaleSymbolsProportionally == false)
                                        {
                                            x.ScaleSymbolsProportionally = true;
                                        }
                                    }
                                }
                                symbol.SymbolLayers = lyrs;
                                s.Symbol            = symbol;
                            }
                            else if (s.Symbol is CIMPointSymbol)
                            {
                                CIMPointSymbol symbol = (CIMPointSymbol)s.Symbol;
                                var lyrs = symbol.SymbolLayers;
                                foreach (CIMSymbolLayer lyr in lyrs)
                                {
                                    CIMVectorMarker x = lyr as CIMVectorMarker;
                                    if (x != null)
                                    {
                                        if (x.ScaleSymbolsProportionally == false)
                                        {
                                            x.ScaleSymbolsProportionally = true;
                                        }
                                    }
                                }
                                symbol.SymbolLayers = lyrs;
                                s.Symbol            = symbol;
                                s.ItemType          = StyleItemType.LineSymbol;
                            }

                            projectStyleItem.UpdateItem(s);
                        }
                        catch (Exception ex3)
                        {
                        }
                    }
                });

                //update polygon symbols
                var polygonSymbols = await projectStyleItem.SearchSymbolsAsync(StyleItemType.PolygonSymbol, "");

                await QueuedTask.Run(() =>
                {
                    foreach (SymbolStyleItem s in polygonSymbols)
                    {
                        try
                        {
                            if (s.Symbol is CIMPolygonSymbol)
                            {
                                CIMPolygonSymbol symbol = (CIMPolygonSymbol)s.Symbol;
                                var lyrs = symbol.SymbolLayers;
                                foreach (CIMSymbolLayer lyr in lyrs)
                                {
                                    CIMVectorMarker x = lyr as CIMVectorMarker;
                                    if (x != null)
                                    {
                                        if (x.ScaleSymbolsProportionally == false)
                                        {
                                            x.ScaleSymbolsProportionally = true;
                                        }
                                    }
                                }
                                symbol.SymbolLayers = lyrs;
                                s.Symbol            = symbol;
                            }
                            else if (s.Symbol is CIMPointSymbol)
                            {
                                CIMPointSymbol symbol = (CIMPointSymbol)s.Symbol;
                                var lyrs = symbol.SymbolLayers;
                                foreach (CIMSymbolLayer lyr in lyrs)
                                {
                                    CIMVectorMarker x = lyr as CIMVectorMarker;
                                    if (x != null)
                                    {
                                        if (x.ScaleSymbolsProportionally == false)
                                        {
                                            x.ScaleSymbolsProportionally = true;
                                        }
                                    }
                                }
                                symbol.SymbolLayers = lyrs;
                                s.Symbol            = symbol;
                                s.ItemType          = StyleItemType.PolygonSymbol;
                            }

                            projectStyleItem.UpdateItem(s);
                        }
                        catch (Exception ex3)
                        {
                        }
                    }
                });
            } // end foreach

            if (string.IsNullOrEmpty(stylxUpdatedNames))
            {
                string stylxs = string.Join(";", stylxFiles);
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Could not find any styles: " + stylxs + " in Project");
            }
            else
            {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Stylx Update DONE, styles updated:" + stylxUpdatedNames);
            }
        } // OnClick
        /// <summary>
        /// グラフィックの作成
        /// </summary>
        private void CreateGraphic(FeatureClass featureClass, QueryFilter queryFilter)
        {
            var mapView = MapView.Active;

            using (RowCursor rowCursor = featureClass.Search(queryFilter, true))
            {
                rowCursor.MoveNext();

                //レコードを取得
                using (Row row = rowCursor.Current)
                {
                    Feature  feature = row as Feature;
                    Geometry shape   = feature.GetShape();

                    RemoveFromMapOverlay(); // 既存のグラフィックを削除

                    switch (shape.GeometryType)
                    {
                    // ポイントの場合(マルチには対応していません)
                    case GeometryType.Point:
                        // ポイント作成
                        var      point    = shape as MapPoint;
                        MapPoint mapPoint = MapPointBuilder.CreateMapPoint(point.X, point.Y, shape.SpatialReference);

                        // グラフィック作成
                        var pointGraphic = new CIMPointGraphic();
                        pointGraphic.Location = mapPoint;

                        // シンボル作成
                        CIMPointSymbol pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 5);
                        pointGraphic.Symbol = pointSymbol.MakeSymbolReference();

                        // グラフィックをマップビューに追加
                        _overlayObject = mapView.AddOverlay(pointGraphic);

                        break;

                    case GeometryType.Polygon:

                        // アノテーションの場合
                        if (feature.GetType().Name == "AnnotationFeature")
                        {
                            // グラフィック作成
                            var annoGraphic = new CIMPolygonGraphic();
                            annoGraphic.Polygon = shape as Polygon;

                            // シンボル作成
                            CIMStroke        outline       = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.RedRGB, 2, SimpleLineStyle.Solid);
                            CIMPolygonSymbol polygonSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlueRGB, SimpleFillStyle.Null, outline);
                            annoGraphic.Symbol = polygonSymbol.MakeSymbolReference();

                            // グラフィックをマップビューに追加
                            _overlayObject = mapView.AddOverlay(annoGraphic);
                        }
                        else
                        {
                            // グラフィック作成
                            var polygonGraphic = new CIMPolygonGraphic();
                            polygonGraphic.Polygon = shape as Polygon;

                            // シンボル作成
                            CIMPolygonSymbol polygonSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB);
                            polygonGraphic.Symbol = polygonSymbol.MakeSymbolReference();

                            // グラフィックをマップビューに追加
                            _overlayObject = mapView.AddOverlay(polygonGraphic);
                        }

                        break;

                    case GeometryType.Polyline:

                        // グラフィック作成
                        var lineGraphic = new CIMLineGraphic();
                        lineGraphic.Line = shape as Polyline;

                        // シンボル作成
                        CIMLineSymbol lineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.RedRGB, 5);
                        lineGraphic.Symbol = lineSymbol.MakeSymbolReference();

                        // グラフィックをマップビューに追加
                        _overlayObject = mapView.AddOverlay(lineGraphic);

                        break;

                    default:
                        break;
                    }
                }
            }
        }
Example #29
0
        public void UpdateColor(string colorValue)
        {
            // Update Status Color for Selected Point and Polygon Graphics
            QueuedTask.Run(() =>
            {
                // Take the currently selected text and update it as needed
                // get the first graphics layer in the map's collection of graphics layers
                var graphicsLayer = MapView.Active.Map.GetLayersAsFlattenedList()
                                    .OfType <ArcGIS.Desktop.Mapping.GraphicsLayer>().FirstOrDefault();
                if (graphicsLayer == null)
                {
                    return;
                }

                var selectedGraphicLayers = MapView.Active.GetSelectedLayers().OfType <GraphicsLayer>();
                if (selectedGraphicLayers.Count() == 0)
                { //nothing selected. So clear the selected graphic layer.
                    SelectedGraphicsLayerTOC = null;
                    MessageBox.Show("No graphic layer selected.", "Select layer");
                    return;
                }

                SelectedGraphicsLayerTOC = selectedGraphicLayers.FirstOrDefault();
                var selectedElements     = graphicsLayer.GetSelectedElements().
                                           OfType <GraphicElement>().Where(elem => elem.GetGraphic() is CIMPolygonGraphic || elem.GetGraphic() is CIMPointGraphic);

                if (selectedElements.Count() == 0)
                { //nothing selected. So clear the selected graphic layer.
                    MessageBox.Show("No point or polygon workflow graphics selected.", "Select graphics");
                    return;
                }

                CIMColor myColor = null;
                switch (colorValue)
                {
                case "red":
                    myColor = CIMColor.CreateRGBColor(255, 0, 0, 40);
                    break;

                case "yellow":
                    myColor = CIMColor.CreateRGBColor(255, 255, 0, 40);
                    break;

                case "green":
                    myColor = CIMColor.CreateRGBColor(0, 255, 0, 40);
                    break;
                }

                foreach (var elem in selectedElements)
                {
                    // Get the CIM Graphic and update it
                    if (elem.GetGraphic() is CIMPolygonGraphic)
                    {
                        var newCIMGraphic           = elem.GetGraphic() as CIMPolygonGraphic;
                        CIMPolygonSymbol polySymbol = SymbolFactory.Instance.ConstructPolygonSymbol(myColor);    //  (CIMColor.CreateRGBColor(CreateRGBColor(0, 255, 0, 50));
                        newCIMGraphic.Symbol        = polySymbol.MakeSymbolReference();
                        elem.SetGraphic(newCIMGraphic);
                    }

                    if (elem.GetGraphic() is CIMPointGraphic)
                    {
                        var newCIMGraphic          = elem.GetGraphic() as CIMPointGraphic;
                        CIMPointSymbol pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(myColor);    //  (CIMColor.CreateRGBColor(CreateRGBColor(0, 255, 0, 50));
                        newCIMGraphic.Symbol       = pointSymbol.MakeSymbolReference();
                        elem.SetGraphic(newCIMGraphic);
                    }
                }
            });
        }
Example #30
0
        async private void   Image_MouseEnter(object sender, MouseEventArgs e)
        {
            Polygon polygon;


            var blackSolidLineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 5, SimpleLineStyle.Solid);

            Geometry geometry = null;
            await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
            {
                SpatialReference inSR   = SpatialReferenceBuilder.CreateSpatialReference(32604);
                SpatialReference sr4326 = SpatialReferences.WGS84;
                SpatialReference sr3857 = SpatialReferences.WebMercator;
                ProjectionTransformation projTransFromSRs = ArcGIS.Core.Geometry.ProjectionTransformation.Create(inSR, sr3857);
                List <Coordinate2D> coordinates           = new List <Coordinate2D>()
                {
                    //new Coordinate2D(-159.20168702818188, 21.876487211082708),
                    //new Coordinate2D(-159.42653907783114, 21.838951660451173),
                    //new Coordinate2D(-159.44077880308507, 21.94718691051718),
                    //new Coordinate2D(-159.21630329750306, 21.94718691051718),
                    //new Coordinate2D(-159.21413990271841, 21.9365008022738),
                    //new Coordinate2D(-159.21383956606297, 21.93655454291286),
                    //new Coordinate2D(-159.20168702818188, 21.876487211082708),
                    new Coordinate2D(-17773406.8675, 2478583.7239999995),
                    new Coordinate2D(-17773406.8675, 2578583.7239999995),
                    new Coordinate2D(-16773406.8675, 2578583.7239999995),
                    new Coordinate2D(-17773406.8675, 2478583.7239999995)
                };
                //MapPoint point = new MapPointBuilder.FromGeoCoordinateString()
                //List<MapPoint> mapPoints = new List<MapPoint>();
                //foreach (Coordinate2D item in coordinates)
                //{
                //    MapPoint point = new MapPointBuilder()
                //}
                //mapPoints.Add( coordinates[0].ToMapPoint());
                MapPointBuilder asas = new MapPointBuilder(new Coordinate2D(-159.20168702818188, 21.876487211082708), MapView.Active.Extent.SpatialReference);
                _polygonSymbol       = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlackRGB, SimpleFillStyle.Null, SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid));
                MapPoint point       = asas.ToGeometry();
                MapPoint point2      = MapPointBuilder.FromGeoCoordinateString(point.ToGeoCoordinateString(new ToGeoCoordinateParameter(GeoCoordinateType.DD)), MapView.Active.Extent.SpatialReference, GeoCoordinateType.DD);
                using (PolygonBuilder polygonBuilder = new PolygonBuilder(coordinates, inSR))
                {
                    polygonBuilder.SpatialReference = inSR;
                    polygon            = polygonBuilder.ToGeometry();
                    geometry           = polygonBuilder.ToGeometry();
                    Geometry geometry2 = GeometryEngine.Instance.ProjectEx(geometry, projTransFromSRs);
                    _graphic           = MapView.Active.AddOverlayAsync(geometry, _polygonSymbol.MakeSymbolReference());
                    //Application.Current.
                }
            });

            //await  QueuedTask.Run(() =>
            //{
            //    MapView.Active.UpdateOverlay(_graphic, point, SymbolFactory.Instance.ConstructPointSymbol(
            //                            ColorFactory.Instance.BlueRGB, 20.0, SimpleMarkerStyle.Circle).MakeSymbolReference());
            //});
            //_graphic = await this.AddOverlayAsync(geometry, _lineSymbol.MakeSymbolReference());
            Console.WriteLine(sender.ToString());
            //_graphic = MapView.Active.AddOverlay(geometry, _lineSymbol.MakeSymbolReference());


            //Geometry geometry = new PolygonBuilder.CreatePolygon(coordinates, inSR); ;
        }