protected async override Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            if (geometry.SpatialReference == null)
            {
                // screen coordinates
                var screenPointAsMapPoint = geometry as MapPoint;
                if (screenPointAsMapPoint != null)
                {
                    var pnt = new System.Windows.Point
                    {
                        X = screenPointAsMapPoint.X,
                        Y = screenPointAsMapPoint.Y
                    };
                    var mapScreenPoint = await QueuedTask.Run <MapPoint>(
                        () => MapView.Active.ClientToMap(pnt));

                    if (mapScreenPoint.IsEmpty)
                    {
                        System.Diagnostics.Debug.WriteLine(@"Screen Point is empty");
                    }
                    else
                    {
                        _graphic = await this.AddOverlayAsync(mapScreenPoint, _pointSymbol.MakeSymbolReference());
                    }
                }
            }
            else
            {
                // map coordinates
                _graphic = await this.AddOverlayAsync(geometry, _pointSymbol.MakeSymbolReference());
            }
            return(true);
        }
        private void Watcher_PositionChanged(object sender, GeoPositionChangedEventArgs <GeoCoordinate> e)
        {
            GeoCoordinate coord   = e.Position.Location;
            var           mapView = MapView.Active;

            if (mapView == null)
            {
                return;
            }
            if (coord.IsUnknown != true)
            {
                System.Diagnostics.Debug.WriteLine("Lat: {0}, Long: {1}",
                                                   coord.Latitude,
                                                   coord.Longitude);
                ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
                {
                    MapPoint zoomToPnt = MapPointBuilder.CreateMapPoint(coord.Longitude, coord.Latitude, SpatialReferences.WGS84);
                    var geoProject     = GeometryEngine.Instance.Project(zoomToPnt, SpatialReferences.WebMercator) as MapPoint;
                    var expandSize     = 200.0;
                    var minPoint       = MapPointBuilder.CreateMapPoint(geoProject.X - expandSize, geoProject.Y - expandSize, SpatialReferences.WebMercator);
                    var maxPoint       = MapPointBuilder.CreateMapPoint(geoProject.X + expandSize, geoProject.Y + expandSize, SpatialReferences.WebMercator);
                    Envelope env       = EnvelopeBuilder.CreateEnvelope(minPoint, maxPoint);
                    mapView.ZoomTo(env, new TimeSpan(0, 0, 3));
                    _graphic = MapView.Active.AddOverlay(zoomToPnt, _pointSymbol.MakeSymbolReference());
                });
            }
            else
            {
                MessageBox.Show("Unknown latitude and longitude.  Check your control panel for Location Privacy settings.");
            }
        }
示例#3
0
        protected override Task HandleMouseDownAsync(MapViewMouseButtonEventArgs e)
        {
            return(QueuedTask.Run(() =>
            {
                // Get the mouse click point
                MapPoint location = MapView.Active.ClientToMap(e.ClientPoint);

                // Create a symbol based on the mouse button.
                CIMPointSymbol pointSymbol = null;
                if (e.ChangedButton == MouseButton.Left)
                {
                    // Specify a symbol
                    pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.CreateRGBColor(150, 0, 0, 60), 80, SimpleMarkerStyle.Circle);
                }
                else if (e.ChangedButton == MouseButton.Right)
                {
                    // Specify a symbol
                    pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.CreateRGBColor(0, 0, 150, 60), 80, SimpleMarkerStyle.Cross);
                }

                // Create a CIMGraphic to show the symbol on the map in the grapicslayer.
                var graphic = new CIMPointGraphic()
                {
                    Symbol = pointSymbol?.MakeSymbolReference(),
                    Location = location
                };

                // Add the graphic to the grapicslayer.
                FieldOfJoy.AddElement(graphic);

                // By default all items are selected, deselect all items
                FieldOfJoy.UnSelectElements();
            }));
        }
示例#4
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;
            }));
        }
示例#5
0
        private Task <Tuple <IDisposable, long> > AddFeatureToOverlay(MapViewMouseEventArgs e)
        {
            return(QueuedTask.Run(() => {
                double llx = e.ClientPoint.X - 3;
                double lly = e.ClientPoint.Y - 3;
                double urx = e.ClientPoint.X + 3;
                double ury = e.ClientPoint.Y + 3;

                EnvelopeBuilder envBuilder = new EnvelopeBuilder(ActiveMapView.ClientToMap(new Point(llx, lly)),
                                                                 ActiveMapView.ClientToMap(new Point(urx, ury)));

                MapPoint mp = ActiveMapView.ClientToMap(e.ClientPoint);
                var cursor = _trees.Search(new SpatialQueryFilter()
                {
                    FilterGeometry = envBuilder.ToGeometry(), SpatialRelationship = SpatialRelationship.Intersects
                });
                if (cursor.MoveNext())
                {
                    return new Tuple <IDisposable, long>(
                        ActiveMapView.AddOverlay(ActiveMapView.ClientToMap(e.ClientPoint),
                                                 _overlaySymbol.MakeSymbolReference()),
                        cursor.Current.GetObjectID());
                }

                //var select = _trees.Select(new SpatialQueryFilter() {
                //    FilterGeometry = envBuilder.ToGeometry(),
                //    SpatialRelationship = SpatialRelationship.Intersects
                //});
                //if (select.GetCount() > 0) {
                //    return ActiveMapView.AddOverlay(ActiveMapView.ClientToMap(e.ClientPoint), _overlaySymbol.MakeSymbolReference());
                //}

                return new Tuple <IDisposable, long>(null, -1);
            }));
        }
示例#6
0
        public static void MakeManholesLayer(Map mapView)
        {
            try
            {
                // Create the "Manholes"  layer object.
                var mh = mapView.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(s => s.Name == "Manholes");

                //Get the selected features from the map.
                var mhOIDList = mh.GetSelection().GetObjectIDs();                 // Gets a list of Object IDs
                var mhOID     = mh.GetTable().GetDefinition().GetObjectIDField(); // Gets the OBJECTID field name for the def query

                // Check to see if there are manhole features selected in the map.
                if (mhOIDList.Count() == 0)
                {
                    MessageBox.Show("There are no manholes selected.");
                }

                else
                {
                    // Create the defenition query
                    string defQuery = $"{mhOID} in ({string.Join(",", mhOIDList)})";
                    string url      = @"O:\SHARE\405 - INFORMATION SERVICES\GIS_Layers\[email protected]\SDE.SEWERMAN.MANHOLES_VIEW";

                    // Create the Uri object create the feature layer.
                    Uri uri            = new Uri(url);
                    var selectionLayer = LayerFactory.Instance.CreateFeatureLayer(uri, mapView, 0, "Manholes SELECTION");

                    // Apply the definition query
                    selectionLayer.SetDefinitionQuery(defQuery);

                    // Create the point symbol renderer.
                    CIMPointSymbol pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(
                        ColorFactory.Instance.GreenRGB,
                        8.0,
                        SimpleMarkerStyle.Circle
                        );
                    CIMSimpleRenderer renderer = selectionLayer.GetRenderer() as CIMSimpleRenderer;
                    // Reference the existing renderer
                    renderer.Symbol = pointSymbol.MakeSymbolReference();
                    // Apply new renderer
                    selectionLayer.SetRenderer(renderer);
                }
            }

            catch (Exception ex)
            {
                SysModule.LogError(ex.Message, ex.StackTrace);

                string caption = "Error Occurred";
                string message = "Process failed. \nSave and restart ArcGIS Pro and try process again.\n" +
                                 "If problem persist, contact your GIS Admin.";

                //Using the ArcGIS Pro SDK MessageBox class
                MessageBox.Show(message, caption);
            }
        }
示例#7
0
        public void UpdateOpenJawReplacedEndPoint([CanBeNull] MapPoint point)
        {
            _openJawReplacedEndPointOverlay?.Dispose();

            if (point != null)
            {
                _openJawReplacedEndPointOverlay =
                    MapView.Active.AddOverlay(
                        point, _openJawReplaceEndSymbol.MakeSymbolReference());
            }
        }
示例#8
0
        private Tuple <IDisposable, IDisposable, Envelope> AddOverlay(MapView mapView, MapPoint location, ValuePointCluster value, SpatialReference spatialRef)
        {
            var text        = value.Count.ToString();
            var textGraphic = new CIMTextGraphic()
            {
                Text = text, Symbol = _textSymbolRef, Shape = location
            };

            var baseSize   = _pointSize * 2;                // smallest size (slightly bigger than for single points)
            var multiplier = 1 + ((text.Length - 1) * 0.5); // increase size by 0.5 for every text digit
            var size       = baseSize * multiplier;

            _pointSymbol.SetSize(size);

            var pointElem = mapView.AddOverlay(location, _pointSymbol.MakeSymbolReference());
            var textElem  = mapView.AddOverlay(textGraphic);
            var hitbox    = CreateHitBox(mapView, location, size / 2, spatialRef);

            return(new Tuple <IDisposable, IDisposable, Envelope>(pointElem, textElem, hitbox));
        }
示例#9
0
        /// <summary>
        /// This function builds the map topology graph of the current map view extent.
        /// </summary>
        /// <returns></returns>
        private async Task BuildGraphWithActiveView()
        {
            await QueuedTask.Run(() =>
            {
                ClearOverlay();

                //Build the map topology graph
                MapView.Active.BuildMapTopologyGraph <TopologyDefinition>(topologyGraph =>
                {
                    //Getting the nodes and edges present in the graph
                    topologyGraphNodes = topologyGraph.GetNodes();
                    topologyGraphEdges = topologyGraph.GetEdges();

                    if (_symbol == null)
                    {
                        //Construct point and line symbols
                        _symbol     = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.BlueRGB, 6.0, SimpleMarkerStyle.Circle);
                        _symbolLine = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 3.0);
                        //Get symbol references from the symbols
                        _symbolReference     = _symbol.MakeSymbolReference();
                        _symbolReferenceLine = _symbolLine.MakeSymbolReference();
                    }

                    //Draw the nodes and edges on the overlay to highlight them
                    foreach (var node in topologyGraphNodes)
                    {
                        _overlayObject = MapView.Active.AddOverlay(node.GetShape() as MapPoint, _symbolReference);
                        snapshot.Add(_overlayObject);
                    }
                    foreach (var edge in topologyGraphEdges)
                    {
                        _overlayObject = MapView.Active.AddOverlay(edge.GetShape() as Polyline, _symbolReferenceLine);
                        snapshot.Add(_overlayObject);
                    }

                    MessageBox.Show($"Number of topo graph nodes are:  {topologyGraphNodes.Count}.\n Number of topo graph edges are {topologyGraphEdges.Count}.", "Map Topology Info");
                });
            });
        }
        public static void ShowCurrentBingMapCoord(MapPoint mapPoint)
        {
            var activeMapView = MapView.Active;

            if (activeMapView == null)
            {
                return;
            }
            lock (Lock)
            {
                foreach (var graphic in BingMapCoords)
                {
                    graphic.Dispose();
                }
                BingMapCoords.Clear();
                Debug.WriteLine($"SetCurrentBingMapCoord: {mapPoint.X} {mapPoint.Y}");
                BingMapCoords.Add(
                    activeMapView.AddOverlay(
                        mapPoint,
                        _pointCoordSymbol.MakeSymbolReference()));
            }
        }
        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 (_pointSymbol == 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 Point?
                if (selectedElements.Count() == 1)
                {
                    if (selectedElements.FirstOrDefault().GetGraphic() is CIMPointGraphic) //It is a Point
                    {
                        //So we use it
                        var polySymbol = selectedElements.FirstOrDefault().GetGraphic() as CIMPointGraphic;
                        _pointSymbol = polySymbol.Symbol.Symbol as CIMPointSymbol;
                    }
                }
                var cimGraphicElement = new CIMPointGraphic
                {
                    Location = geometry as MapPoint,
                    Symbol = _pointSymbol.MakeSymbolReference()
                };
                Module1.Current.SelectedGraphicsLayerTOC.AddElement(cimGraphicElement);
                return true;
            }));
        }
示例#12
0
        public async Task UpdateAsync(double x, double y, double size)
        {
            Settings           settings = Settings.Instance;
            MySpatialReference spatRel  = settings.CycloramaViewerCoordinateSystem;

            await QueuedTask.Run(() =>
            {
                MapView thisView = MapView.Active;
                Map map          = thisView?.Map;
                SpatialReference mapSpatialReference = map?.SpatialReference;
                SpatialReference spatialReference    = spatRel?.ArcGisSpatialReference ?? mapSpatialReference;
                MapPoint point = MapPointBuilder.CreateMapPoint(x, y, spatialReference);
                MapPoint mapPoint;

                if (mapSpatialReference != null && spatialReference.Wkid != mapSpatialReference.Wkid)
                {
                    ProjectionTransformation projection = ProjectionTransformation.Create(spatialReference, mapSpatialReference);
                    mapPoint = GeometryEngine.Instance.ProjectEx(point, projection) as MapPoint;
                }
                else
                {
                    mapPoint = (MapPoint)point.Clone();
                }

                if (mapPoint != null && !mapPoint.IsEmpty)
                {
                    CIMColor cimColor          = ColorFactory.Instance.CreateColor(Color.Black);
                    CIMMarker cimMarker        = SymbolFactory.Instance.ConstructMarker(cimColor, size, SimpleMarkerStyle.Cross);
                    CIMPointSymbol pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(cimMarker);
                    CIMSymbolReference pointSymbolReference = pointSymbol.MakeSymbolReference();
                    IDisposable disposeCross = thisView.AddOverlay(mapPoint, pointSymbolReference);

                    _disposeCross?.Dispose();
                    _disposeCross = disposeCross;
                }
            });
        }
        internal static CIMSymbolReference GetPointSymbolRef()
        {
            if (Is3D)
            {
                if (_point3DSymbolRef != null)
                {
                    return(_point3DSymbolRef);
                }
                var            pointSymbol = GetPointSymbol("ArcGIS 3D", @"Pushpin 2");
                CIMPointSymbol pnt3DSym    = pointSymbol.Symbol as CIMPointSymbol;
                pnt3DSym.SetSize(200);
                pnt3DSym.SetRealWorldUnits(true);
                _point3DSymbolRef = pnt3DSym.MakeSymbolReference();
                return(_point3DSymbolRef);
            }
            if (_point2DSymbolRef != null)
            {
                return(_point2DSymbolRef);
            }
            CIMPointSymbol pntSym = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 8, SimpleMarkerStyle.Circle);

            _point2DSymbolRef = pntSym.MakeSymbolReference();
            return(_point2DSymbolRef);
        }
        public async Task RedrawPointAsync()
        {
            await QueuedTask.Run(() =>
            {
                GlobeSpotter globeSpotter       = GlobeSpotter.Current;
                MeasurementList measurementList = globeSpotter.MeasurementList;
                _disposeText?.Dispose();

                if ((globeSpotter.InsideScale() && (!_isDisposed) && (Point != null) &&
                     ((Measurement?.IsOpen ?? false) ||
                      ((Measurement?.IsPointMeasurement ?? false) && (measurementList.Sketch == null))) &&
                     (Measurement?.DrawPoint ?? false) && (!double.IsNaN(Point.X)) && (!double.IsNaN(Point.Y))))
                {
                    MapView thisView = MapView.Active;
                    Point winPoint   = thisView.MapToScreen(Point);
                    float fontSize   = _constants.MeasurementFontSize;
                    int fontSizeT    = (int)(fontSize * 2);
                    int fontSizeR    = (int)((fontSize * 3) / 2);
                    int fontSizeK    = (int)(fontSize / 4);
                    int txt          = (Measurement?.IsOpen ?? true) ? Index : measurementList.GetMeasurementNumber(Measurement);
                    string text      = txt.ToString(_ci);
                    int characters   = text.Length;
                    Bitmap bitmap    = new Bitmap((fontSizeT *characters), fontSizeT);

                    double pointSize      = _constants.MeasurementPointSize;
                    double pointSizePoint = (pointSize * 6) / 4;
                    Point winPointText    = new Point {
                        X = (winPoint.X + pointSizePoint), Y = (winPoint.Y - pointSizePoint)
                    };
                    MapPoint pointText = thisView.ScreenToMap(winPointText);

                    using (var sf = new StringFormat())
                    {
                        using (Graphics g = Graphics.FromImage(bitmap))
                        {
                            g.Clear(Color.Transparent);
                            Font font           = new Font("Arial", fontSize);
                            sf.Alignment        = StringAlignment.Center;
                            Rectangle rectangle = new Rectangle(fontSizeK, fontSizeK, (fontSizeR *characters), fontSizeR);
                            g.DrawString(text, font, Brushes.Black, rectangle, sf);
                        }
                    }

                    BitmapSource source = bitmap.ToBitmapSource();
                    var frame           = BitmapFrame.Create(source);
                    var encoder         = new PngBitmapEncoder();
                    encoder.Frames.Add(frame);

                    using (MemoryStream stream = new MemoryStream())
                    {
                        encoder.Save(stream);
                        byte[] imageBytes   = stream.ToArray();
                        string base64String = Convert.ToBase64String(imageBytes);
                        string url          = $"data:image/bmp;base64,{base64String}";

                        CIMPictureMarker marker = new CIMPictureMarker
                        {
                            URL    = url,
                            Enable = true,
                            ScaleX = 1,
                            Size   = fontSizeR
                        };

                        CIMPointSymbol symbol = SymbolFactory.Instance.ConstructPointSymbol(marker);
                        CIMSymbolReference symbolReference = symbol.MakeSymbolReference();
                        _disposeText = thisView.AddOverlay(pointText, symbolReference);
                    }
                }
            });
        }
示例#15
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);
                    }
                }
            });
        }
        protected override async void OnToolMouseMove(MapViewMouseEventArgs e)
        {
            //All of this logic is to avoid unnecessarily updating the graphic position
            //for ~every~ mouse move. We skip any "intermediate" points in-between rapid
            //mouse moves.
            lock (_lock) {
                if (_trackingMouseMove == TrackingState.NotTracking)
                {
                    return;
                }
                else
                {
                    if (_workingLocation.HasValue)
                    {
                        _lastLocation = e.ClientPoint;
                        return;
                    }
                    else
                    {
                        _lastLocation    = e.ClientPoint;
                        _workingLocation = e.ClientPoint;
                    }
                }
                _trackingMouseMove = TrackingState.Tracking;
            }

            //The code "inside" the QTR will execute for all points that
            //get "buffered" or "queued". This avoids having to spin up a QTR
            //for ~every~ point of ~every mouse move.
            await QueuedTask.Run(() => {
                var symReference = _pointSymbol.MakeSymbolReference();
                while (true)
                {
                    System.Windows.Point?point;
                    Polyline lineFeature = null;
                    IDisposable graphic  = null;
                    lock (_lock) {
                        point            = _lastLocation;
                        _lastLocation    = null;
                        _workingLocation = point;

                        if (point == null || !point.HasValue)  //No new points came in while we updated the overlay
                        {
                            _workingLocation = null;
                            break;
                        }
                        else if (_lineFeature == null || _graphic == null)  //conflict with the mouse down,
                        //If this happens then we are done. A new line and point will be
                        //forthcoming from the SketchCompleted callback
                        {
                            _trackingMouseMove = TrackingState.NotTracking;
                            break;
                        }
                        lineFeature = _lineFeature;
                        graphic     = _graphic;
                    }
                    //update the graphic overlay
                    var nearest = GeometryEngine.Instance.NearestPoint(lineFeature, MapView.Active.ClientToMap(point.Value));
                    this.UpdateOverlay(graphic, nearest.Point, symReference);
                }
            });
        }
示例#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 (_pointSymbol == 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 Point?
                if (selectedElements.Count() == 1)
                {
                    if (selectedElements.FirstOrDefault().GetGraphic() is CIMPointGraphic) //It is a Point
                    {
                        //So we use it
                        var polySymbol = selectedElements.FirstOrDefault().GetGraphic() as CIMPointGraphic;
                        _pointSymbol = polySymbol.Symbol.Symbol as CIMPointSymbol;
                    }
                }
                var cimGraphicElement = new CIMPointGraphic
                {
                    Location = geometry as MapPoint,
                    Symbol = _pointSymbol.MakeSymbolReference()
                };
                Module1.Current.SelectedGraphicsLayerTOC.AddElement(cimGraphicElement);

                //  Add a text label graphic next to the point graphic:
                if (selectedElements.Count() == 1)
                {
                    if (selectedElements.FirstOrDefault().GetGraphic() is CIMTextGraphic) //It is a Text
                    {
                        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 box
                    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 CIMTextGraphic
                {
                    Symbol = _textSymbol.MakeSymbolReference(),
                    Shape = geometry as MapPoint,
                    Text = txtBoxString
                };
                Module1.Current.SelectedGraphicsLayerTOC.AddElement(textGraphic);
                Module1.Current.SelectedGraphicsLayerTOC.ClearSelection();

                return true;
            }));
        }
示例#18
0
        internal async void UpdateCluster(bool isTolerance)
        {
            if (MapView.Active == null)
            {
                return;
            }
            // Get Layer Name
            string inputFC = SelectedLayer.Name;

            int  minPoints = 2;
            bool parsed    = Int32.TryParse(MinPoints, out minPoints);

            /// Set PYT path -This could be inserted as a resource file //
            string tool_path = "C:\\Dev_summit\\2018\\InteractiveAnalytics\\pyt\\UpdateCluster.pyt\\UpdateClusterTool";

            IReadOnlyList <string> args = null;

            if (isTolerance)
            {
                /// Arguments for executing process using Tolerance
                args = Geoprocessing.MakeValueArray(inputFC, minPoints, ValueSlider, -1);
            }
            else
            {
                /// Arguments for executing process using Threshold
                args = Geoprocessing.MakeValueArray(inputFC, minPoints, -1, ValueThreshold);
            }

            Task <IGPResult> task;

            /// Execute the Tool in the python toolbox
            task = Geoprocessing.ExecuteToolAsync(tool_path, args, flags: GPExecuteToolFlags.AddToHistory);


            StyleProjectItem style;
            CIMPointSymbol   pointSymbol = null;

            /// Get Pro Styles
            style = await QueuedTask.Run <StyleProjectItem>(() => Project.Current.GetItems <StyleProjectItem>().First(s => s.Name == "ArcGIS 2D"));


            await QueuedTask.Run(() =>
            {
                /// Search for a specific Symbol
                /// Other styles Arcgis/Resouces/Styles/Styles.stylx SQLite DB
                SymbolStyleItem symbolStyleItem = (SymbolStyleItem)style.LookupItem(StyleItemType.PointSymbol, "Circle 1_Shapes_3");
                pointSymbol = (CIMPointSymbol)symbolStyleItem.Symbol;

                /// Cluster Ids based in Color Schema
                int[] ids = new int[] { -1, 1, 2, 3, 4, 5, 6, 7, 8 };

                /// Set Colors
                string[] colors = new string[] { "156,156,156", "166,206,227", "31,120,180", "178,223,138",
                                                 "51,160,44", "251,154,153", "227,26,28", "253,191,111",
                                                 "255,127,0" };
                /// Color Field
                String[] fields = new string[] { "COLOR_ID" };

                /// Make a reference of the point symbol
                CIMSymbolReference symbolPointTemplate = pointSymbol.MakeSymbolReference();

                /// Get definition of type symbology unique values
                UniqueValueRendererDefinition uniqueValueRendererDef = new UniqueValueRendererDefinition(fields, symbolPointTemplate, null, symbolPointTemplate, false);

                /// Get Current renderer of the Selected Layer
                CIMUniqueValueRenderer renderer  = (CIMUniqueValueRenderer)SelectedLayer.CreateRenderer(uniqueValueRendererDef);
                CIMUniqueValueClass[] newClasses = new CIMUniqueValueClass[colors.Count()];

                /// Get Point Symbol as string for creating other point colors
                string point = pointSymbol.ToXml();

                /// Create Each Color
                for (int i = 0; i < ids.Length; i++)
                {
                    CIMPointSymbol npoint = CIMPointSymbol.FromXml(point);
                    if (ids[i] == -1)
                    {
                        npoint.SetSize(4);
                    }
                    else
                    {
                        npoint.SetSize(6);
                    }
                    CIMSymbolReference symbolPointTemplatei = npoint.MakeSymbolReference();
                    newClasses[i]                          = new CIMUniqueValueClass();
                    newClasses[i].Values                   = new CIMUniqueValue[1];
                    newClasses[i].Values[0]                = new CIMUniqueValue();
                    newClasses[i].Values[0].FieldValues    = new string[1];
                    newClasses[i].Values[0].FieldValues[0] = ids[i].ToString();
                    newClasses[i].Label                    = ids[i].ToString();
                    newClasses[i].Symbol                   = symbolPointTemplatei;
                    var color = colors[i].Split(',');
                    double r  = Convert.ToDouble(color[0]);
                    double g  = Convert.ToDouble(color[1]);
                    double b  = Convert.ToDouble(color[2]);
                    newClasses[i].Symbol.Symbol.SetColor(CIMColor.CreateRGBColor(r, g, b));
                }
                /// Add Colors into the renderer
                renderer.Groups[0].Classes = newClasses;

                /// Apply new renderer in the layer
                SelectedLayer.SetRenderer(renderer);

                //SelectedLayer.RecalculateRenderer();
            });
        }
        /// <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;
                    }
                }
            }
        }
示例#20
0
        // Methods to create the selection layers.
        public static void MakeSewersLayers(Map mapView)
        {
            try
            {
                var mh    = mapView.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(s => s.Name == "Manholes");
                var lines = mapView.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(s => s.Name == "Sewer Lines");

                //Get the selected features from the map.
                var mhOIDList    = mh.GetSelection().GetObjectIDs();                 // Gets a list of Object IDs
                var mhOID        = mh.GetTable().GetDefinition().GetObjectIDField(); // Gets the OBJECTID field name for the def query
                var linesOIDList = lines.GetSelection().GetObjectIDs();
                var linesOID     = lines.GetTable().GetDefinition().GetObjectIDField();

                //Check to see if there are mmanhole or sewer line features selected in map.
                if (mhOIDList.Count() == 0 && linesOIDList.Count() == 0)
                {
                    MessageBox.Show("Manholes & Sewers contain no selected features.", "Warning");
                }

                else if (mhOIDList.Count() == 0 && linesOIDList.Count() > 0)
                {
                    MessageBox.Show("Manholes layer contains no selected features.", "Warning");
                }

                else if (mhOIDList.Count() > 0 && linesOIDList.Count() == 0)
                {
                    MessageBox.Show("Sewer Lines layer contains no selected features.", "Warning");
                }

                else
                {
                    // CREATE THE SEWER LINES SELECTION LAYER
                    // Create the defenition query
                    string linesDefQuery = $"{linesOID} in ({string.Join(",", linesOIDList)})";
                    string linesURL      = @"O:\SHARE\405 - INFORMATION SERVICES\GIS_Layers\[email protected]\SDE.SEWERMAN.SEWERS_VIEW";

                    // Create the Uri object create the feature layer.
                    Uri linesURI      = new Uri(linesURL);
                    var linesSelLayer = LayerFactory.Instance.CreateFeatureLayer(linesURI, mapView, 0, "Sewer Lines SELECTION");

                    // Apply the definition query
                    linesSelLayer.SetDefinitionQuery(linesDefQuery);

                    // Create the line symbol renderer.
                    CIMLineSymbol lineSymbol = SymbolFactory.Instance.ConstructLineSymbol(
                        ColorFactory.Instance.RedRGB,
                        3.0,
                        SimpleLineStyle.Solid
                        );
                    CIMSimpleRenderer lineRenderer = linesSelLayer.GetRenderer() as CIMSimpleRenderer;

                    // Renference the existing renderer
                    lineRenderer.Symbol = lineSymbol.MakeSymbolReference();
                    // Apply the new renderer
                    linesSelLayer.SetRenderer(lineRenderer);


                    // CREATE THE MANHOLES SELECTION LAYER
                    // Create the defenition query
                    string mhDefQuery = $"{mhOID} in ({string.Join(",", mhOIDList)})";
                    string mhURL      = @"O:\SHARE\405 - INFORMATION SERVICES\GIS_Layers\[email protected]\SDE.SEWERMAN.MANHOLES_VIEW";

                    // Create the Uri object create the feature layer.
                    Uri mhURI      = new Uri(mhURL);
                    var mhSelLayer = LayerFactory.Instance.CreateFeatureLayer(mhURI, mapView, 0, "Manholes SELECTION");

                    // Apply the definition query
                    mhSelLayer.SetDefinitionQuery(mhDefQuery);

                    // Create the point symbol renderer.
                    CIMPointSymbol pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(
                        ColorFactory.Instance.GreenRGB,
                        8.0,
                        SimpleMarkerStyle.Circle
                        );
                    CIMSimpleRenderer pointRenderer = mhSelLayer.GetRenderer() as CIMSimpleRenderer;

                    // Renference the existing renderer
                    pointRenderer.Symbol = pointSymbol.MakeSymbolReference();
                    // Apply the new renderer
                    mhSelLayer.SetRenderer(pointRenderer);
                }
            }

            catch (Exception ex)
            {
                string caption = "Module1.MakeSewersLayers method failed!";
                string message = "Process failed. \n\nSave and restart ArcGIS Pro and try process again.\n\n" +
                                 $"If problem persist, contact your local GIS nerd.\n\n{ex}";

                //Using the ArcGIS Pro SDK MessageBox class
                MessageBox.Show(message, caption);
            }
        }
示例#21
0
        /// <summary>
        /// Called after the feature selection changed.
        /// Method for retrieving map items in the project.
        /// </summary>
        private async void FindLinkedFeatures(MapSelectionChangedEventArgs args)
        {
            await QueuedTask.Run(() =>
            {
                //Clear the collections
                _listOfLinkedFeatures.Clear();

                //Clearing the currently drawn overlay on the map
                foreach (var graphic in snapshot)
                {
                    graphic.Dispose();
                }
                snapshot.Clear();

                Feature selectedFeature = null;
                //Gets the feature that is currently selected in the map
                var selectedFeat = MapView.Active.Map.GetSelection().ToDictionary().Where(kvp => layerNames.Contains(kvp.Key.ToString())).FirstOrDefault();
                if (selectedFeat.Value == null)
                {
                    return;
                }
                var layer = pLayers.Where(l => l.Name.Equals(selectedFeat.Key.ToString(), StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                QueryFilter queryFilter = new QueryFilter()
                {
                    ObjectIDs = selectedFeat.Value
                };

                using (RowCursor cursor = layer.Search(queryFilter))
                {
                    System.Diagnostics.Debug.Assert(cursor.MoveNext());
                    selectedFeature = (Feature)cursor.Current;
                }

                if (selectedFeature != null)
                {
                    //Add Overlay showing all the connected topology nodes and for that selected feature
                    if (_symbol == null)
                    {
                        //Construct point and line symbols
                        _symbol     = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 10.0, SimpleMarkerStyle.Circle);
                        _symbolLine = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.RedRGB, 5.0);
                        //Get symbol reference from the symbol
                        _symbolReference     = _symbol.MakeSymbolReference();
                        _symbolReferenceLine = _symbolLine.MakeSymbolReference();
                    }

                    MapView.Active.BuildMapTopologyGraph <TopologyDefinition>(topologyGraph =>
                    {
                        var nodes = topologyGraph.GetNodes(selectedFeature); //Topology nodes via that feature

                        foreach (TopologyNode node in nodes)
                        {
                            var edges = node.GetEdges();

                            var parent = node.GetParentFeatures();
                            foreach (var p in parent)
                            {
                                //Skipping the currently selected feature so as not to list it in the pane
                                if (p.FeatureClassName.Equals(selectedFeat.Key.ToString()) && p.ObjectID.Equals(selectedFeature.GetObjectID()))
                                {
                                    continue;
                                }
                                if (!_listOfLinkedFeatures.Contains(p))
                                {
                                    _listOfLinkedFeatures.Add(p);
                                }
                            }

                            foreach (TopologyEdge edge in edges)
                            {
                                var shape      = edge.GetShape();
                                _overlayObject = MapView.Active.AddOverlay(edge.GetShape() as Polyline, _symbolReferenceLine);
                                snapshot.Add(_overlayObject);
                            }
                            var nodeShape  = node.GetShape();
                            _overlayObject = MapView.Active.AddOverlay(node.GetShape() as MapPoint, _symbolReference);
                            snapshot.Add(_overlayObject);
                        }
                    });
                    System.Diagnostics.Debug.WriteLine($"Number of topologically connected features are:  {_listOfLinkedFeatures.Count}.");
                }
            });
        }