/// <summary> /// Occurs when the tool is activated. /// </summary> /// <param name="hasMapViewChanged">A value indicating if the active <see cref="T:ArcGIS.Desktop.Mapping.MapView"/> has changed.</param> /// <returns> /// A Task that represents a tool activation event. /// </returns> protected async override Task OnToolActivateAsync(bool hasMapViewChanged) { if (_lineSymbol == null) { _lineSymbol = await Module1.CreateLineSymbolAsync(); } this.SketchSymbol = _lineSymbol.MakeSymbolReference(); }
protected override async Task <bool> OnSketchCompleteAsync(Geometry geometry) { //Add an overlay graphic to the map view _graphic = await this.AddOverlayAsync(geometry, _lineSymbol.MakeSymbolReference()); //define the text symbol var textSymbol = new CIMTextSymbol(); //define the text graphic var textGraphic = new CIMTextGraphic(); await QueuedTask.Run(() => { //Create a simple text symbol textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8.5, "Corbel", "Regular"); //Sets the geometry of the text graphic textGraphic.Shape = geometry; //Sets the text string to use in the text graphic textGraphic.Text = "This is my line"; //Sets symbol to use to draw the text graphic textGraphic.Symbol = textSymbol.MakeSymbolReference(); //Draw the overlay text graphic _graphic = this.ActiveMapView.AddOverlay(textGraphic); }); return(true); }
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; })); }
public static void MakeLinesLayer(Map mapView) { try { // Create the "Sewer Lines" object. var lines = mapView.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(s => s.Name == "Sewer Lines"); //Get the selected features from the map. var linesOIDList = lines.GetSelection().GetObjectIDs(); // Gets a list of Object IDs var linesOID = lines.GetTable().GetDefinition().GetObjectIDField(); // Gets the OBJECTID field name for the def query // Check to see if there are sewer lines features selected inthe map. if (linesOIDList.Count() == 0) { MessageBox.Show("There are no sewer lines selected."); } else { //Create the defenition query string defQuery = $"{linesOID} in ({string.Join(",", linesOIDList)})"; string url = @"O:\SHARE\405 - INFORMATION SERVICES\GIS_Layers\[email protected]\SDE.SEWERMAN.SEWERS_VIEW"; // Create the Uri object create the feature layer. Uri uri = new Uri(url); var selectionLayer = LayerFactory.Instance.CreateFeatureLayer(uri, mapView, 0, "Sewer Lines SELECTION"); // Apply the definition query selectionLayer.SetDefinitionQuery(defQuery); // Create the line symbol renderer. CIMLineSymbol lineSymbol = SymbolFactory.Instance.ConstructLineSymbol( ColorFactory.Instance.RedRGB, 3.0, SimpleLineStyle.Solid ); CIMSimpleRenderer renderer = selectionLayer.GetRenderer() as CIMSimpleRenderer; // Reference the existing renderer renderer.Symbol = lineSymbol.MakeSymbolReference(); // Apply the 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); } }
/// <summary> /// Create a line graphic. /// </summary> /// <param name="fieldOfJoy"></param> /// <param name="a"></param> /// <param name="b"></param> /// <param name="lineSymbol"></param> private static void CreateLine(GraphicsLayer fieldOfJoy, MapPoint a, MapPoint b, CIMLineSymbol lineSymbol) { fieldOfJoy.AddElement(new CIMLineGraphic() { Symbol = lineSymbol.MakeSymbolReference(), Line = PolylineBuilder.CreatePolyline(new List <MapPoint>() { a, b }, fieldOfJoy.GetSpatialReference()) }); }
public async Task RedrawObservationAsync() { await QueuedTask.Run(() => { _disposeInnerLine?.Dispose(); _disposeOuterLine?.Dispose(); if (_measurementPoint?.IsObservationVisible() ?? false) { MapView thisView = MapView.Active; MapPoint measPoint = _measurementPoint?.Point; MapPoint mapPointObsLine; if ((measPoint != null) && (!double.IsNaN(measPoint.X)) && (!double.IsNaN(measPoint.Y))) { Point winMeasPoint = thisView.MapToScreen(measPoint); Point winObsPoint = thisView.MapToScreen(Point); double xdir = ((winMeasPoint.X - winObsPoint.X) * 3) / 2; double ydir = ((winMeasPoint.Y - winObsPoint.Y) * 3) / 2; Point winPointObsLine = new Point(winObsPoint.X + xdir, winObsPoint.Y + ydir); mapPointObsLine = thisView.ScreenToMap(winPointObsLine); } else { mapPointObsLine = MapPointBuilder.CreateMapPoint((Point.X + (XDir * DistLine)), (Point.Y + (YDir * DistLine))); } IList <MapPoint> linePointList = new List <MapPoint>(); linePointList.Add(mapPointObsLine); linePointList.Add(Point); Polyline polyline = PolylineBuilder.CreatePolyline(linePointList); Color outerColorLine = Viewer?.Color ?? Color.DarkGray; CIMColor cimOuterColorLine = ColorFactory.Instance.CreateColor(Color.FromArgb(255, outerColorLine)); CIMLineSymbol cimOuterLineSymbol = SymbolFactory.Instance.DefaultLineSymbol; cimOuterLineSymbol.SetColor(cimOuterColorLine); cimOuterLineSymbol.SetSize(OuterLineSize); CIMSymbolReference cimOuterLineSymbolRef = cimOuterLineSymbol.MakeSymbolReference(); _disposeOuterLine = thisView.AddOverlay(polyline, cimOuterLineSymbolRef); Color innerColorLine = Color.LightGray; CIMColor cimInnerColorLine = ColorFactory.Instance.CreateColor(innerColorLine); CIMLineSymbol cimInnerLineSymbol = SymbolFactory.Instance.DefaultLineSymbol; cimInnerLineSymbol.SetColor(cimInnerColorLine); cimInnerLineSymbol.SetSize(InnerLineSize); CIMSymbolReference cimInnerLineSymbolRef = cimInnerLineSymbol.MakeSymbolReference(); _disposeInnerLine = thisView.AddOverlay(polyline, cimInnerLineSymbolRef); } }); }
/// <summary> /// When the active map view changes, update the graphic overlay on the map control /// </summary> /// <param name="args"></param> private void OnMapViewCameraChanged(MapViewCameraChangedEventArgs args) { if (MapView.Active == null) { return; } if (MapView.Active.Extent == null) { return; } if (MapView.Active.ViewingMode != ArcGIS.Core.CIM.MapViewingMode.Map) { return; } //get the Map view's extent var viewExtent = MapView.Active.Extent.Clone() as Envelope; QueuedTask.Run(() => { //Line symbol to be used to draw the overview rectangle. if (_lineSymbol == null) { _lineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.RedRGB, 2.0, SimpleLineStyle.Solid); } _graphic?.Dispose(); //Clear out the old overlay _overviewEnvelope = viewExtent; //overview envelope based on active map view if (_overviewEnvelope == null) { return; } //Creating the overview rectangle IList <MapPoint> segments = new List <MapPoint> { MapPointBuilder.CreateMapPoint(_overviewEnvelope.XMin, _overviewEnvelope.YMin, _overviewEnvelope.SpatialReference), MapPointBuilder.CreateMapPoint(_overviewEnvelope.XMax, _overviewEnvelope.YMin, _overviewEnvelope.SpatialReference), MapPointBuilder.CreateMapPoint(_overviewEnvelope.XMax, _overviewEnvelope.YMax, _overviewEnvelope.SpatialReference), MapPointBuilder.CreateMapPoint(_overviewEnvelope.XMin, _overviewEnvelope.YMax, _overviewEnvelope.SpatialReference), MapPointBuilder.CreateMapPoint(_overviewEnvelope.XMin, _overviewEnvelope.YMin, _overviewEnvelope.SpatialReference) }; _polyLine = PolylineBuilder.CreatePolyline(segments, _overviewEnvelope.SpatialReference); _graphic = _mapControl.AddOverlay(_polyLine, _lineSymbol.MakeSymbolReference()); }); }
/// <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"); }); }); }
protected override async void OnClick() { SharedFunctions.Log("Starting To Create 3D Visualization"); DateTime startTime = DateTime.Now; CIMLineSymbol symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 5.0, SimpleLineStyle.Solid); CIMSymbolReference symbolReference = symbol.MakeSymbolReference(); try { await QueuedTask.Run(async() => { if (!SharedFunctions.LayerExists("DamCandidates") || !SharedFunctions.LayerExists("ReservoirSurfaces")) { return; } var damCandidatesLayer = MapView.Active.Map.FindLayers("DamCandidates").FirstOrDefault(); var reservoirSurfacesLayer = MapView.Active.Map.FindLayers("ReservoirSurfaces").FirstOrDefault(); SpatialReference = damCandidatesLayer.GetSpatialReference(); var damVisLayer = await CreateMultiPatchFeatureClass("DamVisualization"); var reservoirVisLayer = await CreatePolygonFeatureClass("ReservoirVisualization"); Visualize(damVisLayer, reservoirVisLayer, reservoirSurfacesLayer as BasicFeatureLayer, damCandidatesLayer as BasicFeatureLayer); }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { DateTime endTime = DateTime.Now; SharedFunctions.Log("Visualized in " + (endTime - startTime).TotalSeconds.ToString() + " seconds"); } }
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 (_lineSymbol == 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 Line? if (selectedElements.Count() == 1) { if (selectedElements.FirstOrDefault().GetGraphic() is CIMLineGraphic) //It is a line { //So we use it var lineSymbol = selectedElements.FirstOrDefault().GetGraphic() as CIMLineGraphic; _lineSymbol = lineSymbol.Symbol.Symbol as CIMLineSymbol; } } var cimGraphicElement = new CIMLineGraphic { Line = geometry as Polyline, Symbol = _lineSymbol.MakeSymbolReference() }; Module1.Current.SelectedGraphicsLayerTOC.AddElement(cimGraphicElement); return true; })); }
// 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); } }
/// <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}."); } }); }
/// <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; } } } }
protected override async Task <bool> OnSketchCompleteAsync(ArcGIS.Core.Geometry.Geometry geometry) { try { if (_graphic != null) { _graphic.Dispose(); } //Polygon polygon; //await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => //{ // List<Coordinate2D> coordinates2 = 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) //}; // CIMPolygonSymbol _polygonSymbol = null; // _polygonSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlackRGB, SimpleFillStyle.Null, SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid)); // using (PolygonBuilder polygonBuilder = new PolygonBuilder(coordinates2, MapView.Active.Extent.SpatialReference)) // { // polygonBuilder.SpatialReference = MapView.Active.Extent.SpatialReference; // polygon = polygonBuilder.ToGeometry(); // geometry = polygonBuilder.ToGeometry(); // //Geometry geometry2 = GeometryEngine.Instance.ProjectEx(geometry, projTransFromSRs); // _graphic = MapView.Active.AddOverlayAsync(geometry, _polygonSymbol.MakeSymbolReference()); // } //}); //return true; //DockPane pane = FrameworkApplication.DockPaneManager.Find("test_docing_Panel_PlanetDocPane"); DockPane pane = FrameworkApplication.DockPaneManager.Find("test_docing_Panel_Demo"); //PlanetDocPaneViewModel planetDocPaneViewModel = (PlanetDocPaneViewModel)pane; //planetDocPaneViewModel.Users = "New collection" pane.Enabled = true; //Add an overlay graphic to the map view _graphic = await this.AddOverlayAsync(geometry, _lineSymbol.MakeSymbolReference()); //define the text symbol var textSymbol = new CIMTextSymbol(); //define the text graphic var textGraphic = new CIMTextGraphic(); //await QueuedTask.Run(() => //{ // //Create a simple text symbol // textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8.5, "Corbel", "Regular"); // //Sets the geometry of the text graphic // textGraphic.Shape = geometry; // //Sets the text string to use in the text graphic // //textGraphic.Text = "This is my line"; // //Sets symbol to use to draw the text graphic // textGraphic.Symbol = textSymbol.MakeSymbolReference(); // //Draw the overlay text graphic // _graphic = this.ActiveMapView.AddOverlay(textGraphic); //}); string ejson = geometry.ToJson(); Polygon poly = (Polygon)geometry; IReadOnlyList <Coordinate2D> coordinates = poly.Copy2DCoordinatesToList(); ToGeoCoordinateParameter ddParam = new ToGeoCoordinateParameter(GeoCoordinateType.DD); List <string> geocoords = new List <string>(); List <Tuple <double, double> > AllPts = new List <Tuple <double, double> >(); double x; double y; foreach (Coordinate2D item in coordinates) { MapPoint mapPoint = MapPointBuilder.CreateMapPoint(item, MapView.Active.Extent.SpatialReference); List <Tuple <string, string> > pts = new List <Tuple <string, string> >(); string dd1 = mapPoint.ToGeoCoordinateString(ddParam).Split(' ')[0]; pts.Add(new Tuple <string, string>(mapPoint.ToGeoCoordinateString(ddParam).Split(' ')[1], mapPoint.ToGeoCoordinateString(ddParam).Split(' ')[0])); if (pts[0].Item1.Contains("W")) { x = double.Parse("-" + pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)); y = double.Parse(pts[0].Item2.Substring(0, pts[0].Item2.Length - 1)); //AllPts.Add(new Tuple<int, int>(int.Parse("-" + pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)), int.Parse(pts[0].Item2.Substring(0, pts[0].Item2.Length -1)))); } else if (pts[1].Item2.Contains("S")) { x = double.Parse(pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)); y = double.Parse("-" + pts[0].Item2.Substring(0, pts[1].Item2.Length - 1)); //AllPts.Add(new Tuple<int, int>(int.Parse(pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)), int.Parse("-" + pts[0].Item2.Substring(0, pts[1].Item2.Length - 1)))); } else { x = double.Parse(pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)); y = double.Parse(pts[0].Item2.Substring(0, pts[0].Item2.Length - 1)); //AllPts.Add(new Tuple<int, int>(int.Parse(pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)), int.Parse(pts[0].Item2.Substring(0, pts[1].Item2.Length - 1)))); } AllPts.Add(new Tuple <double, double>(x, y)); geocoords.Add(mapPoint.ToGeoCoordinateString(ddParam)); } double[,] sd = new double[AllPts.Count, 2]; for (int i = 0; i < AllPts.Count; i++) { sd[i, 0] = AllPts[i].Item1; //+ "," + AllPts[i].Item2; sd[i, 1] = AllPts[i].Item2; } List <double[, ]> ss = new List <double[, ]>(); ss.Add(sd); Config configPoints = new Config { type = "Polygon", coordinates = ss.ToArray() }; Config configGeom = new Config { type = "GeometryFilter", field_name = "geometry", config = configPoints }; //DateFilter Config dateconfigconfig2 = new Config { gte = "2019-05-19T16:51:19.926Z", lte = "2019-08-19T16:51:19.926Z" }; Config dateconfigconfig = new Config { type = "DateRangeFilter", field_name = "acquired", config = dateconfigconfig2 }; Config dateconfig = new Config { type = "OrFilter", config = new[] { dateconfigconfig } }; SearchFilter searchFilter = new SearchFilter(); List <string> typoes = new List <string>(); typoes.Add("PSScene4Band"); typoes.Add("SkySatCollect"); typoes.Add("REOrthoTile"); List <Config> mainconfigs = new List <Config>(); mainconfigs.Add(dateconfig); mainconfigs.Add(configGeom); searchFilter.item_types = typoes.ToArray(); Filter topfilter = new Filter(); topfilter.type = "AndFilter"; searchFilter.filter = topfilter; Config mainConfig = new Config(); searchFilter.filter.config = mainconfigs.ToArray(); //string json = JsonConvert.SerializeObject(searchFilter); string json = JsonConvert.SerializeObject(searchFilter, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); string asas = "{\"filter\":{\"type\":\"AndFilter\",\"config\":[{\"type\":\"GeometryFilter\",\"field_name\":\"geometry\",\"config\":{\"type\":\"Polygon\",\"coordinates\":[[[-159.44149017333984,21.877787931279187],[-159.44998741149902,21.87679231243837],[-159.45372104644778,21.872769941600623],[-159.45217609405518,21.866835742000745],[-159.44372177124023,21.864207091531895],[-159.43561077117923,21.86930503623256],[-159.44149017333984,21.877787931279187]]]}},{\"type\":\"OrFilter\",\"config\":[{\"type\":\"DateRangeFilter\",\"field_name\":\"acquired\",\"config\":{\"gte\":\"2019-05-22T16:36:32.254Z\",\"lte\":\"2019-08-22T16:36:32.254Z\"}}]}]},\"item_types\":[\"PSScene4Band\",\"REOrthoTile\",\"SkySatCollect\"]}"; //var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.somewhere.com/v2/cases"); HttpClientHandler handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }; HttpClient client = new HttpClient(handler) { BaseAddress = new Uri("https://api.planet.com") }; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "data/v1/quick-search"); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Headers.CacheControl = new CacheControlHeaderValue(); request.Headers.CacheControl.NoCache = true; request.Headers.Host = "api.planet.com"; request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip")); //request.Headers.Remove("Content-Type"); //request.Headers.Add("Content-Type", "application/json"); var content = new StringContent(json, Encoding.UTF8, "application/json"); request.Content = content; var byteArray = Encoding.ASCII.GetBytes("1fe575980e78467f9c28b552294ea410:hgvhgv"); client.DefaultRequestHeaders.Host = "api.planet.com"; //_client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); content.Headers.Remove("Content-Type"); content.Headers.Add("Content-Type", "application/json"); //client.DefaultRequestHeaders.AcceptEncoding.Add(StringWithQualityHeaderValue.Parse("gzip")); client.DefaultRequestHeaders.Add("Connection", "keep-alive"); client.DefaultRequestHeaders.Add("User-Agent", "ArcGISProC#"); //content.Headers.TryAddWithoutValidation("Authorization", "Basic " + Convert.ToBase64String(byteArray)); //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "MWZlNTc1OTgwZTc4NDY3ZjljMjhiNTUyMjk0ZWE0MTA6");//Convert.ToBase64String(byteArray)); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); using (HttpResponseMessage httpResponse = client.SendAsync(request).Result) { using (HttpContent content2 = httpResponse.Content) { var json2 = content2.ReadAsStringAsync().Result; QuickSearchResult quickSearchResult = JsonConvert.DeserializeObject <QuickSearchResult>(json2); //Geometry geometry2 = GeometryEngine.Instance.ImportFromJSON(JSONImportFlags.jsonImportDefaults, JsonConvert.SerializeObject( quickSearchResult.features[5].geometry)); } } pane.Activate(); return(true); } catch (Exception exe) { if (_graphic != null) { _graphic.Dispose(); } return(false); } }
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(); } }); }