/// <summary> /// Creates and displays a <see cref="ProgressGraphic"/>. /// </summary> /// <remarks> /// This method will invoke the graphic's <see cref="IDrawable.Draw"/> method, so do not call it from a draw routine in the same scene graph! /// </remarks> /// <param name="source">The source from which progress information is retrieved and displayed.</param> /// <param name="parentCollection">The graphics collection on which the progress graphic should be shown.</param> /// <param name="autoClose">A value indicating whether or not the progress graphic should be automatically removed when the task is terminated.</param> /// <param name="progressBarGraphicStyle">The style of the progress bar.</param> public static void Show(IProgressGraphicProgressProvider source, GraphicCollection parentCollection, bool autoClose, ProgressBarGraphicStyle progressBarGraphicStyle) { ProgressGraphic progressGraphic = new ProgressGraphic(source, autoClose, progressBarGraphicStyle); parentCollection.Add(progressGraphic); progressGraphic.Draw(); }
private void OnView_Tapped(object sender, Esri.ArcGISRuntime.UI.GeoViewInputEventArgs e) { MapPoint geoPoint = getGeoPoint(e); geoPoint = (MapPoint)GeometryEngine.Project(geoPoint, SpatialReference.Create(3857)); Polygon buffer = (Polygon)GeometryEngine.Buffer(geoPoint, 1000.0); GraphicCollection graphics = (threeD ? bufferAndQuerySceneGraphics : bufferAndQueryMapGraphics).Graphics; graphics.Clear(); graphics.Add(new Graphic(buffer, BUFFER_SYMBOL)); graphics.Add(new Graphic(geoPoint, CLICK_SYMBOL)); Esri.ArcGISRuntime.Data.QueryParameters query = new Esri.ArcGISRuntime.Data.QueryParameters(); query.Geometry = buffer; LayerCollection operationalLayers; if (threeD) { operationalLayers = sceneView.Scene.OperationalLayers; } else { operationalLayers = mapView.Map.OperationalLayers; } foreach (Layer layer in operationalLayers) { ((FeatureLayer)layer).SelectFeaturesAsync(query, SelectionMode.New); } }
protected override Graphic OnCreateGraphic(GraphicCollection cluster, MapPoint point, int maxClusterCount) { if (cluster.Count == 1) return cluster[0]; double sum = 0; foreach (var g in cluster) { if (!g.Attributes.ContainsKey("Poi")) continue; try { var poi = g.Attributes["Poi"] as PoI; if (poi == null) continue; if (poi.Labels.ContainsKey(AggregateLabel)) sum += Convert.ToDouble(poi.Labels[AggregateLabel]); } catch { } } //double size = (sum + 450) / 30; var size = (Math.Log(sum * SymbolScale / 10) * 10 + 20); if (size < 12) size = 12; var graphic = new Graphic { Symbol = new ClusterSymbol { Size = size }, Geometry = point }; graphic.Attributes.Add("Count", sum); graphic.Attributes.Add("Size", size); graphic.Attributes.Add("Color", InterpolateColor(size - 12, 100)); return graphic; }
protected override Graphic OnCreateGraphic(GraphicCollection cluster, MapPoint center, int maxClusterCount) { if (cluster.Count == 1) { return(cluster[0]); } Graphic graphic = null; double sum = cluster.Count; double size = 100;//(Math.Log(sum * SymbolScale / 10) * 10 + 20); Brush color = new SolidColorBrush(Colors.Transparent); graphic = new Graphic() { Symbol = new ClusterSymbol() { Size = size }, Geometry = center }; GetSizeAndColorByCount(sum, ref size, ref color); graphic.Attributes.Add("Count", sum); graphic.Attributes.Add("Size", size); graphic.Attributes.Add("Color", color); //InterpolateColor(size - 12, 100)); return(graphic); }
public SerializableGraphicCollection(GraphicCollection graphicCollection) { foreach (Graphic g in graphicCollection) { Add(new SerializableGraphic(g)); } }
public ClusterLayer(Options options) { this.ClusterTolerance = options.distance; if (options.data != null) { this.ClusterData = options.data; } this.Clusters = new List <Cluster>(); if (options.labelColor != null) { this.ClusterLabelColor = options.labelColor; } // labelOffset can be zero so handle it differently this.ClusterLabelOffset = options.labelOffset; // graphics that represent a single point this.Singles = new List <Graphic>(); // populated when a graphic is clicked // symbol for single graphics if (options.singleSymbol != null) { this.SingleSym = options.singleSymbol; } else { this.SingleSym = new SimpleMarkerSymbol(); this.SingleSym.Color = Colors.Brown; this.SingleSym.Size = 10; this.SingleSym.Style = SimpleMarkerStyle.Circle; } if (options.maxSingles != null) { this.MaxSingles = options.maxSingles.Value; } this.spatialReference = options.spatialReference; }
private void CreateGPParamsAndExtract(GraphicCollection clipGraphics) { FeatureSet clipFS = new FeatureSet(); clipFS.GeometryType = GeometryType.Polygon; clipFS.SpatialReference = this.MapControl.SpatialReference; foreach (Graphic graphic in clipGraphics) { clipFS.Features.Add(graphic); } if (clipFS.Features.Count > 0) { List <GPParameter> gpParams = CreateGPParams(clipFS); if (gpParams.Count > 0) { gpService.ProcessSpatialReference = this.MapControl.SpatialReference; gpService.OutputSpatialReference = this.MapControl.SpatialReference; this.IsBusy = true; txtExtractionStatus.Visibility = Visibility.Visible; gpService.SubmitJobAsync(gpParams); } } }
private void AddLayers(DrawArgs args) { IAssociatedTissues volume = args.SceneGraph.ParentPresentationImage as IAssociatedTissues; if (volume == null) { return; } GraphicCollection layers = volume.TissueLayers; vtkPropCollection props = _vtkRenderer.GetViewProps(); foreach (VolumeGraphic volumeGraphic in layers) { if (props.IsItemPresent(volumeGraphic.VtkProp) == 0) { _vtkRenderer.AddViewProp(volumeGraphic.VtkProp); } //if (volumeLayer.OldVtkProp != null) //{ // if (props.IsItemPresent(volumeLayer.OldVtkProp) != 0) // { // props.RemoveItem(volumeLayer.OldVtkProp); // volumeLayer.OldVtkProp = null; // } //} } }
private void ExtractButton_Click(object sender, RoutedEventArgs e) { if (clipByExtent) { GraphicCollection clipGraphics = new GraphicCollection(); clipGraphics.Add(new Graphic() { Geometry = GeometryTool.EnvelopeToPolygon(this.MapControl.Extent) }); CreateGPParamsAndExtract(clipGraphics); } else { if (needGeneralized) { GeneralizeParameters genParam = new GeneralizeParameters() { DeviationUnit = LinearUnit.Meter, MaxDeviation = 10 }; geometryService.GeneralizeAsync(this.GraphicsLayer.Graphics, genParam); } else { CreateGPParamsAndExtract(this.GraphicsLayer.Graphics); } } }
public static GraphicCollection LoadGraphics( gpxType source ) { source.RequireArgument<gpxType>( "source" ).NotNull<gpxType>(); GraphicCollection graphics = new GraphicCollection(); if( source == null ) return graphics; if( source.wpt != null ) { GraphicCollection gcs = LoadWayPoints( source.wpt ); gcs.ForEach<Graphic>( g => graphics.Add(g) ); } if( source.rte != null ) { GraphicCollection gcs = LoadRoutes( source.rte ); gcs.ForEach<Graphic>( g => graphics.Add(g) ); } if( source.trk != null ) { GraphicCollection gcs = LoadTracks( source.trk ); gcs.ForEach<Graphic>( g => graphics.Add( g ) ); } return graphics; }
private bool graphicsRequireReprojection(GraphicCollection graphicCollection) { if (Map.SpatialReference == null) { return(false); } bool requiresProjection = false; if (graphicCollection != null) { foreach (Graphic graphic in graphicCollection) { if (graphic.Geometry == null || graphic.Geometry.SpatialReference == null) { continue; } if (!Map.SpatialReference.Equals(graphic.Geometry.SpatialReference)) { requiresProjection = true; break; } } } return(requiresProjection); }
private async void Load3DPolygonLayer(object parameter) { try { var queryTask = new QueryTask(new Uri("http://119.2.29.21:6080/arcgis/rest/services/ChinaMap/MapServer/0")); Query query = new Query("1=1"); query.OutFields.Add("POPU");//人口数 var result = await queryTask.ExecuteAsync(query); var res = new GraphicCollection(); foreach (var state in result.FeatureSet.Features) { res.Add(new Graphic(state.Geometry, state.Attributes)); } var graphicLayer = new GraphicsLayer(); graphicLayer.DisplayName = "3D面图层"; graphicLayer.GraphicsSource = res; graphicLayer.Renderer = App.Current.Resources["3DPolygonRenderer"] as Renderer; graphicLayer.SceneProperties.SurfacePlacement = SurfacePlacement.Relative; graphicLayer.ID = "3DPolygonLayer"; scene.Layers.Add(graphicLayer); } catch (Exception ex) { MessageBox.Show(ex.Message, "Sample Error"); } }
private static void SetVisible(GraphicCollection graphics, bool visible) { foreach (var graphic in graphics) { graphic.Visible = visible; } }
public GraphicsVisibilityHelper(GraphicCollection graphics) { _graphics = graphics; foreach (var graphic in _graphics) { _visibility[graphic] = graphic.Visible; } }
/// <summary> /// Creates and displays a <see cref="ProgressGraphic"/>. /// </summary> /// <param name="task">The <see cref="BackgroundTask"/> to execute. The task is automatically started if it is not already running.</param> /// <param name="parentCollection">The graphics collection on which the progress graphic should be shown.</param> /// <param name="autoClose">A value indicating whether or not the progress graphic should be automatically removed when the task is terminated.</param> /// <param name="progressBarStyle">The style of the progress bar.</param> /// <param name="drawImmediately">Specifies that a draw should be performed immediately after creation (should be set to FALSE if calling from a draw routine in the same scene graph, as that would otherwise cause a <see cref="StackOverflowException"/>.)</param> public static void Show(BackgroundTask task, GraphicCollection parentCollection, bool autoClose = _defaultAutoClose, ProgressBarGraphicStyle progressBarStyle = _defaultStyle, bool drawImmediately = _defaultDrawImmediately) { if (!task.IsRunning) { task.Run(); } Show(new BackgroundTaskProgressAdapter(task), parentCollection, autoClose, progressBarStyle, drawImmediately); }
/// <summary> /// Creates and displays a <see cref="ProgressGraphic"/>. /// </summary> /// <remarks> /// This method will invoke the graphic's <see cref="IDrawable.Draw"/> method, so do not call it from a draw routine in the same scene graph! /// </remarks> /// <param name="task">The <see cref="BackgroundTask"/> to execute. The task is automatically started if it is not already running.</param> /// <param name="parentCollection">The graphics collection on which the progress graphic should be shown.</param> public static void Show(BackgroundTask task, GraphicCollection parentCollection) { if (!task.IsRunning) { task.Run(); } Show(new BackgroundTaskProgressAdapter(task), parentCollection); }
/// <summary> /// Creates and displays a <see cref="ProgressGraphic"/>. /// </summary> /// <remarks> /// This method will invoke the graphic's <see cref="IDrawable.Draw"/> method, so do not call it from a draw routine in the same scene graph! /// </remarks> /// <param name="task">The <see cref="BackgroundTask"/> to execute. The task is automatically started if it is not already running.</param> /// <param name="parentCollection">The graphics collection on which the progress graphic should be shown.</param> /// <param name="autoClose">A value indicating whether or not the progress graphic should be automatically removed when the task is terminated.</param> /// <param name="progressBarGraphicStyle">The style of the progress bar.</param> public static void Show(BackgroundTask task, GraphicCollection parentCollection, bool autoClose, ProgressBarGraphicStyle progressBarGraphicStyle) { if (!task.IsRunning) { task.Run(); } Show(new BackgroundTaskProgressAdapter(task), parentCollection, autoClose, progressBarGraphicStyle); }
public AddGraphicCommand(IGraphic graphic, GraphicCollection parentCollection) { Platform.CheckForNullReference(graphic, "graphic"); Platform.CheckForNullReference(parentCollection, "parentCollection"); _parentCollection = parentCollection; _graphic = graphic; }
public static void Show(IProgressGraphicProgressProvider source, GraphicCollection parentCollection, bool autoClose = _defaultAutoClose, ProgressBarGraphicStyle progressBarStyle = _defaultStyle, bool drawImmediately = _defaultDrawImmediately) { ProgressGraphic progressGraphic = new ProgressGraphic(source, autoClose, progressBarStyle); parentCollection.Add(progressGraphic); if (drawImmediately) { progressGraphic.Draw(); } }
void Graphics_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { GraphicCollection collection = sender as GraphicCollection; if (collection != null) { collection.CollectionChanged -= Graphics_CollectionChanged; } refreshLayers(); }
public InsertGraphicCommand(IGraphic graphic, GraphicCollection parentCollection, int index) { Platform.CheckForNullReference(graphic, "graphic"); Platform.CheckForNullReference(parentCollection, "parentCollection"); Platform.CheckTrue(index >= 0, "Insert index positive"); _parentCollection = parentCollection; _graphic = graphic; _index = index; }
/// <summary> /// 地图边界盒改变,进行聚合操作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Map_ExtentChanged(object sender, EventArgs e) { if (!IsCluster) { return; } if (Math.Abs(_lastScale - MapObj.MapView.Scale) < 0.001) { return; } _lastScale = MapObj.MapView.Scale; if (_originalGraphics == null) { _originalGraphics = new GraphicCollection(); foreach (var g in Graphics) { _originalGraphics.Add(new Graphic(g.Geometry, g.Attributes, g.Symbol)); } } Graphics.Clear(); var cs = new List <ClusterItem>(); foreach (var g in _originalGraphics) { if (!(g.Geometry is MapPoint)) { continue; } if (((MapPoint)g.Geometry).X < MapObj.MapView.Extent.XMin || ((MapPoint)g.Geometry).X > MapObj.MapView.Extent.XMax || ((MapPoint)g.Geometry).Y < MapObj.MapView.Extent.YMin || ((MapPoint)g.Geometry).Y > MapObj.MapView.Extent.YMax) { continue; } cs.Add(new ClusterItem(MapObj.MapView, g, _originalGraphics.Count)); } //如果地图已经放到最大那么就不再聚合 if (MapObj.TiledInfo != null && MapObj.TiledInfo.Lods.Count > 0 && Math.Abs(MapObj.TiledInfo.Lods[MapObj.TiledInfo.Lods.Count - 1].Scale - MapObj.MapView.Scale) < 0.001) { foreach (var ci in cs) { Graphics.Add(ci.GetGraphic()); } return; } _clusterThread?.Abort(); _clusterThread = new Thread(DoCluster); _clusterThread.Start(cs); }
private static Graphic CreateCustomFlareCluster(GraphicCollection cluster, MapPoint point) { ClusterGraphicObject clGr = ClusterGraphicObject.Create(point, cluster); clGr.Attributes.Add(COUNT_PROPERTY_NAME, cluster.Count); for (int index = 0; index < cluster.Count; index++) { clGr.Attributes.Add(GRAPHIC_PROPERTY_NAME + index.ToString(), cluster[index]); } return clGr; }
/// <summary> /// union the polygon shapes in every graphic into one big multi part polygon. /// return esri polygon /// </summary> /// <param name="graphics"></param> /// <returns>esri polygon</returns> public static ESRI.ArcGIS.Client.Geometry.Polygon UnionEsriPolygon(GraphicCollection graphics) { ESRI.ArcGIS.Client.Geometry.Polygon p = new ESRI.ArcGIS.Client.Geometry.Polygon(); foreach (Graphic g in graphics) { foreach (ESRI.ArcGIS.Client.Geometry.PointCollection pc in (g.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon).Rings) { p.Rings.Add(pc); } } return(p); }
public static Graphic GetRandomGraphic <T>(this AbstractLayer <T> layer) where T : IDisplayableGeoElement { Random random = new Random(); GraphicCollection graphics = layer.GetOverlay().Graphics; if (graphics.Count == 0) { return(null); } return(graphics[random.Next(0, graphics.Count)]); }
private static Graphic CreateCustomFlareCluster(GraphicCollection cluster, MapPoint point) { ClusterGraphicObject clGr = ClusterGraphicObject.Create(point, cluster); clGr.Attributes.Add(COUNT_PROPERTY_NAME, cluster.Count); for (int index = 0; index < cluster.Count; index++) { clGr.Attributes.Add(GRAPHIC_PROPERTY_NAME + index.ToString(), cluster[index]); } return(clGr); }
private static bool IsGraphicInCollection(IGraphic graphic, GraphicCollection graphicCollection) { IGraphic testGraphic = graphic; while(testGraphic != null) { if (graphicCollection.Contains(testGraphic)) return true; testGraphic = testGraphic.ParentGraphic; } return false; }
private void geometryService_GeneralizeCompleted(object sender, GraphicsEventArgs e) { if (e.Results != null && e.Results.Count > 0) { GraphicCollection clipGraphics = new GraphicCollection(); foreach (Graphic graphic in e.Results) { clipGraphics.Add(graphic); } CreateGPParamsAndExtract(clipGraphics); } }
protected override Graphic OnCreateGraphic(GraphicCollection cluster, MapPoint point, int maxClusterCount) { if (OnClusteringComplete != null) OnClusteringComplete(this, EventArgs.Empty); if (cluster.Count == 1) return cluster[0]; //if (cluster.Count > MaximumFlareCount) // return base.OnCreateGraphic(cluster, point, maxClusterCount); return CreateCustomFlareCluster(cluster, point); }
private void AddTissueLayers(VolumePresentationImage image) { GraphicCollection layers = image.TissueLayers; TissueSettings tissue = new TissueSettings(); tissue.SelectPreset("Bone"); layers.Add(new VolumeGraphic(tissue)); tissue = new TissueSettings(); tissue.SelectPreset("Blood"); layers.Add(new VolumeGraphic(tissue)); }
public ClusterItem(ViewBase map, Graphic g, int totalCount) { _totalCount = totalCount; Graphics = new GraphicCollection { new Graphic(g.Geometry, g.Attributes, g.Symbol) }; var mapPoint = g.Geometry as MapPoint; if (mapPoint != null) { _center = new MapPoint(mapPoint.X, mapPoint.Y); } ScreenLocation = map.LocationToScreen(_center); }
private void CreateAnAttributeTypeLookup() { if (GraphicCollection == null || GraphicCollection.Count == 0) { return; } var graphic = GraphicCollection.FirstOrDefault(); UniqueAttributes.Clear(); foreach (var attribute in graphic.Attributes) { UniqueAttributes.Add(attribute.Key, attribute.Value == null ? typeof(string) : attribute.Value.GetType()); } }
private void SetSymbols(GraphicCollection graphics = null) { if (graphics == null) { graphics = Graphics; } foreach (BikeTouringGISGraphic graphic in graphics) { var symbol = _symbols[graphic.Type]; if (symbol is Symbol) { graphic.Symbol = (Symbol)_symbols[graphic.Type]; } } }
public static GraphicCollection LoadTracks( trkTypeCollection trks ) { trks.RequireArgument<trkTypeCollection>( "trks" ).NotNull<trkTypeCollection>(); GraphicCollection lines = new GraphicCollection(); foreach( var trk in trks ) { Graphic gr = new Graphic(); gr.Geometry = LoadTrack(trk.trkseg); LoadTrackAttributes( trk, gr.Attributes ); lines.Add( gr ); } return lines; }
private static bool IsGraphicInCollection(IGraphic graphic, GraphicCollection graphicCollection) { IGraphic testGraphic = graphic; while (testGraphic != null) { if (graphicCollection.Contains(testGraphic)) { return(true); } testGraphic = testGraphic.ParentGraphic; } return(false); }
public static Envelope GetGraphicsEnvelope(GraphicCollection gc) { if (gc.Count == 0) { return(null); } EnvelopeBuilder envBuilder = new EnvelopeBuilder(gc[0].Geometry.Extent); Envelope env = envBuilder.ToGeometry(); foreach (Graphic g in gc) { env.Union(g.Geometry.Extent); } return(env); }
private void ClearBufferPolygons() { // Get the collection of graphics in the graphics overlay (points and buffer polygons). GraphicCollection bufferGraphics = MyMapView.GraphicsOverlays["buffers"].Graphics; // Loop (backwards) through all graphics. for (int i = bufferGraphics.Count - 1; i >= 0; i--) { // If the graphic is a polygon, remove it from the overlay. Graphic thisGraphic = bufferGraphics[i]; if (thisGraphic.Geometry.GeometryType == GeometryType.Polygon) { bufferGraphics.RemoveAt(i); } } }
/// <summary> /// Clone Map Layers /// </summary> private Layer CloneLayer(Layer layer) { Layer toLayer = null; if (layer is GraphicsLayer) // Include FeatureLayer and GeoRSS layers { GraphicsLayer fromLayer = layer as GraphicsLayer; GraphicsLayer printLayer = new GraphicsLayer(); printLayer.Renderer = fromLayer.Renderer; printLayer.Clusterer = fromLayer.Clusterer; // todo : clone ? GraphicCollection graphicCollection = new GraphicCollection(); foreach (Graphic graphic in fromLayer.Graphics) { Graphic clone = new Graphic(); foreach (var kvp in graphic.Attributes) { clone.Attributes.Add(kvp); } clone.Geometry = graphic.Geometry; clone.Symbol = graphic.Symbol; clone.Selected = graphic.Selected; clone.TimeExtent = graphic.TimeExtent; graphicCollection.Add(clone); } printLayer.Graphics = graphicCollection; toLayer = printLayer; toLayer.ID = layer.ID; toLayer.Opacity = layer.Opacity; toLayer.Visible = layer.Visible; toLayer.MaximumResolution = layer.MaximumResolution; toLayer.MinimumResolution = layer.MinimumResolution; } else { // Clone other layer types toLayer = layer.Clone(); } return(toLayer); }
public static ESRI.ArcGIS.Client.GraphicsLayer CreateSearchLyr(ESRI.ArcGIS.Client.Geometry.Geometry mp) { ESRI.ArcGIS.Client.GraphicsLayer gl = new GraphicsLayer(); ESRI.ArcGIS.Client.GraphicCollection listGc = new GraphicCollection(); ESRI.ArcGIS.Client.Graphic gp = new Graphic() { Geometry = mp }; listGc.Add(gp); gl.ID = "SearchLyr"; gl.Graphics = listGc; ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol skb = new ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol(); skb.Color = Brushes.Red; skb.Size = 15; var render = new SimpleRenderer(); render.Symbol = skb; gl.Renderer = render as IRenderer; return gl; }
private async void Initialize() { try { CreateExtrusionInfos(); // Set initial viewpoint var viewpoint = new ViewpointCenter(new MapPoint(-96, 39), 15000000); await MySceneView.SetViewAsync(viewpoint); // Query states with statistical attributes var queryTask = new QueryTask( new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5")); Query query = new Query("1=1"); query.OutFields.Add("STATE_NAME"); query.OutFields.Add("AGE_5_17"); query.OutFields.Add("AGE_18_21"); query.OutFields.Add("AGE_22_29"); query.OutFields.Add("AGE_30_39"); query.OutFields.Add("AGE_40_49"); query.OutFields.Add("AGE_50_64"); query.OutFields.Add("AGE_65_UP"); var result = await queryTask.ExecuteAsync(query); var states = new GraphicCollection(); foreach (var state in result.FeatureSet.Features) states.Add(new Graphic(state.Geometry, state.Attributes)); // Make sure that all layers are loaded await MySceneView.LayersLoadedAsync(); // Set graphics to the overlay var statesOverlay = MySceneView.GraphicsOverlays["statesOverlay"]; statesOverlay.GraphicsSource = states; } catch (Exception ex) { MessageBox.Show(ex.Message, "Graphics Extrusion Sample"); } }
private void RadioButton_Checked(object sender, RoutedEventArgs e) { ClearAll(); string shapeTag = (string)((RadioButton)sender).Tag; switch (shapeTag) { case "Point": GraphicCollection absoluteGC = new GraphicCollection(); GraphicCollection relativeGC = new GraphicCollection(); GraphicCollection drapedGC = new GraphicCollection(); foreach (MapPoint mp in _coordinates) { absoluteGC.Add(new Graphic(mp, GetPointSymbol(SurfacePlacement.Absolute))); relativeGC.Add(new Graphic(mp, GetPointSymbol(SurfacePlacement.Relative))); drapedGC.Add(new Graphic(mp, GetPointSymbol(SurfacePlacement.Draped))); } _absoluteModeGL.Graphics.AddRange(absoluteGC); _relativeModeGL.Graphics.AddRange(relativeGC); _drapedModeGL.Graphics.AddRange(drapedGC); break; case "Line": var line = new Polyline(_coordinates, SpatialReferences.Wgs84); _absoluteModeGL.Graphics.Add(new Graphic(line, GetPolylineSymbol(SurfacePlacement.Absolute))); _relativeModeGL.Graphics.Add(new Graphic(line, GetPolylineSymbol(SurfacePlacement.Relative))); _drapedModeGL.Graphics.Add(new Graphic(line, GetPolylineSymbol(SurfacePlacement.Draped))); break; case "Polygon": var polygon = new Polygon(_coordinates, SpatialReferences.Wgs84); _absoluteModeGL.Graphics.Add(new Graphic(polygon, GetPolygonSymbol(SurfacePlacement.Absolute))); _relativeModeGL.Graphics.Add(new Graphic(polygon, GetPolygonSymbol(SurfacePlacement.Relative))); _drapedModeGL.Graphics.Add(new Graphic(polygon, GetPolygonSymbol(SurfacePlacement.Draped))); break; } }
// Draw horizontal distributed load // Note: x1<x2, (x1,y1)-(x2,y1) is a horizontal line, (x1,y2)-(x2,y3) is a oblique line // public static GraphicCollection DistributedLoad_Horizontal(double x1, double x2, double y1, double y2, double y3, Symbol backgroundFillSymbol, Symbol arrowFillSymbol, Symbol lineSymbol) { GraphicCollection gc = new GraphicCollection(); MapPoint p1 = new MapPoint(x1, y1); MapPoint p2 = new MapPoint(x1, y2); MapPoint p3 = new MapPoint(x2, y3); MapPoint p4 = new MapPoint(x2, y1); Graphic g = ArcGISMappingUtility.NewQuadrilateral(p1, p2, p3, p4); g.Symbol = backgroundFillSymbol; gc.Add(g); Esri.ArcGISRuntime.Geometry.PointCollection pc = new Esri.ArcGISRuntime.Geometry.PointCollection(); pc.Add(p1); pc.Add(p2); pc.Add(p3); pc.Add(p4); pc.Add(p1); g = ArcGISMappingUtility.NewPolyline(pc); g.Symbol = lineSymbol; gc.Add(g); double x00, y00, y01; for (int i = 0; i <= 10; ++i) { x00 = x1 + i * (x2 - x1) / 10.0; y00 = y1; y01 = y2 + i * (y3 - y2) / 10.0; MapPoint p00 = new MapPoint(x00, y00); MapPoint p01 = new MapPoint(x00, y01); g = ArcGISMappingUtility.NewLine(p00, p01); g.Symbol = lineSymbol; gc.Add(g); pc = ArcGISMappingUtility.VectorArrowPoints(x00, y2, p00); g = ArcGISMappingUtility.NewPolygon(pc); g.Symbol = arrowFillSymbol; gc.Add(g); } return gc; }
public static Envelope GetGraphicsEnvelope(GraphicCollection gc) { if (gc.Count == 0) return null; EnvelopeBuilder envBuilder = new EnvelopeBuilder(gc[0].Geometry.Extent); Envelope env = envBuilder.ToGeometry(); foreach (Graphic g in gc) { env.Union(g.Geometry.Extent); } return env; }
/// <summary> /// Creates and displays a <see cref="ProgressGraphic"/>. /// </summary> /// <remarks> /// This method will invoke the graphic's <see cref="IDrawable.Draw"/> method, so do not call it from a draw routine in the same scene graph! /// </remarks> /// <param name="task">The <see cref="BackgroundTask"/> to execute. The task is automatically started if it is not already running.</param> /// <param name="parentCollection">The graphics collection on which the progress graphic should be shown.</param> /// <param name="autoClose">A value indicating whether or not the progress graphic should be automatically removed when the task is terminated.</param> /// <param name="progressBarStyle">The style of the progress bar.</param> public static void Show(BackgroundTask task, GraphicCollection parentCollection, bool autoClose = _defaultAutoClose, ProgressBarGraphicStyle progressBarStyle = _defaultStyle) { if (!task.IsRunning) task.Run(); Show(new BackgroundTaskProgressAdapter(task), parentCollection, autoClose, progressBarStyle); }
public static void Show(IProgressGraphicProgressProvider source, GraphicCollection parentCollection, bool autoClose = _defaultAutoClose, ProgressBarGraphicStyle progressBarStyle = _defaultStyle) { ProgressGraphic progressGraphic = new ProgressGraphic(source, autoClose, progressBarStyle); parentCollection.Add(progressGraphic); progressGraphic.Draw(); }
public static GraphicCollection LoadWayPoints( wptTypeCollection wpts ) { wpts.RequireArgument<wptTypeCollection>( "wpts" ).NotNull<wptTypeCollection>(); GraphicCollection pts = new GraphicCollection(); foreach( var wpt in wpts ) { Graphic gr = new Graphic(); gr.Geometry = LoadWayPointGeometry( wpt ); LoadWayPointAttributes( wpt, gr.Attributes ); pts.Add( gr ); } return pts; }
public static GraphicCollection ToGraphic(this JObject geoJson, SpatialReference sourceSpatialReference = null) { var graphics = new GraphicCollection(); if (sourceSpatialReference == null) { sourceSpatialReference = new SpatialReference(4326); } var src = ProjectionInfo.FromEpsgCode(sourceSpatialReference.WKID); var dest = ProjectionInfo.FromEpsgCode(4326); var sr = new SpatialReference(4326); var jFeatures = geoJson["features"] as JArray; if (jFeatures == null) return null; foreach (var jFeature in jFeatures.OfType<JObject>()) { var jGeometry = jFeature["geometry"]; if (jGeometry == null) continue; var geometryType = (string)jGeometry["type"]; switch (geometryType) { case "MultiPolygon": var jPolygons = jGeometry["coordinates"] as JArray; if (jPolygons == null) continue; foreach (var jPolygon in jPolygons.OfType<JArray>()) { if (jPolygon.Count == 0) continue; var polygon = new Polygon(); polygon.SpatialReference = sr; foreach (var jLinearRing in jPolygon.OfType<JArray>()) { if (src == dest) { var pointCollection = new PointCollection(jLinearRing.OfType<JArray>().Select(point=>new MapPoint((double)point[0], (double)point[1], sourceSpatialReference))); polygon.Rings.Add(pointCollection); } else { // reproject var points = jLinearRing.OfType<JArray>().SelectMany(point=>new double[2]{(double)point[0], (double)point[1]}).ToArray(); Reproject.ReprojectPoints(points, null, src, dest, 0, points.Length/2); var pointCollection = new PointCollection(Enumerable.Range(0, points.Length / 2).Select(i=>new MapPoint(points[i*2], points[(i*2)+1], sr))); polygon.Rings.Add(pointCollection); } } var graphic = new Graphic(); graphic.Geometry = polygon; graphic.Symbol = new SimpleFillSymbol { BorderBrush = new SolidColorBrush(Colors.Black), BorderThickness = 4, Fill = new SolidColorBrush(Colors.Blue) { Opacity = 0.8f} }; graphics.Add(graphic); } break; default: throw new NotSupportedException(string.Format("Geometry type {0} is not supported. Supported geometry types are: MultiPolygon.", geometryType)); } } return graphics; }
internal static void CopyGraphics(System.Collections.Generic.IList<Graphic> fromCollection, GraphicCollection toCollection) { // copy all graphics foreach (Graphic featureGraphic in fromCollection) { Graphic graphic = new Graphic(); foreach (String attributeName in featureGraphic.Attributes.Keys) graphic.Attributes[attributeName] = featureGraphic.Attributes[attributeName]; graphic.Geometry = featureGraphic.Geometry; graphic.Symbol = featureGraphic.Symbol; toCollection.Add(graphic); } }
/// <summary> /// Creates graphic elements and adds them to the graphics layer. /// </summary> /// <param name="layer">Graphics layer that will have features added to it.</param> /// <param name="images">Dictionary of images coming from kmz content or from previous parsing</param> public void CreateGraphics(KmlGraphicsLayer layer, IDictionary<string, ImageBrush> images) { if (layer == null) return; GraphicCollection graphics = new GraphicCollection(); UniqueValueRenderer renderer = new UniqueValueRenderer(); // dummy renderer used to create the legend items (since creation of the swatches from the symbol is not that obvious) // Process each metadata feature in the list foreach (PlacemarkDescriptor feature in placemarks) { KMLStyle style = feature.Symbol.style; if (style.ZipFile != null) { // Look for the image in the zip file if (style.IconImage == null && !String.IsNullOrEmpty(style.IconHref)) { style.IconImage = GetIconImage(style.ZipFile, style.IconHref.ToLower()); } style.ZipFile.Dispose(); style.ZipFile = null; } // If the style has an HREF then it is associated with an image if (style.IconImage == null && !String.IsNullOrEmpty(style.IconHref)) { // If the image is already loaded in the image dictionary, use it if (images.ContainsKey(style.IconHref.ToLower())) style.IconImage = images[style.IconHref.ToLower()]; else { // Get the image using the HREF and store the image in the images dictionary so that if // other features reference it, it is cached style.IconImage = GetIconImage(style.IconHref); images.Add(style.IconHref.ToLower(), style.IconImage); } } // Create a new graphic from the metadata and construct the symbol using polymorphism Graphic g = new Graphic() { Geometry = feature.Geometry, Symbol = feature.Symbol.CreateSymbol() }; // Create legend entry string label = null; string description = null; if (string.IsNullOrEmpty(style.StyleId)) { //if the feature is not using a shared style -> create an entry by graphic with the name as ident if (feature.Attributes.ContainsKey("name")) label = feature.Attributes["name"].ToString(); if (feature.Attributes.ContainsKey("description")) description = feature.Attributes["description"].ToString(); } else { //if the feature is using a shared style -> create an entry for the style label = style.StyleId; } if (!string.IsNullOrEmpty(label) && !renderer.Infos.Any(info => info.Label == label)) renderer.Infos.Add(new UniqueValueInfo { Label = label, Description = description, Symbol = g.Symbol }); // Adjust and assign picture marker symbol properties if (g.Geometry is ESRI.ArcGIS.Client.Geometry.MapPoint && g.Symbol is KmlPlaceMarkerSymbol) { try { #if SILVERLIGHT string ext = style.IconHref.Substring(style.IconHref.LastIndexOf(".")).ToLower(); switch (ext) { case ".jpg": case ".jpeg": case ".png": break; default: throw new System.Exception(string.Format(Properties.Resources.FeatureDefinition_ImageTypeNotSupported, ext)); } #endif KmlPlaceMarkerSymbol ms = g.Symbol as KmlPlaceMarkerSymbol; // To match sizing of Google Earth, default size of point images is 40x40 ms.Height = 40; ms.Width = 40; ms.Fill = style.IconImage as ImageBrush; // Default to half the pixel size (width and height) if symbol offsets are 0 (supported in wpf and sl3) ImageBrush ib = ms.Fill; BitmapImage bi = ib.ImageSource as BitmapImage; #if SILVERLIGHT if (bi.PixelHeight == 0 || bi.PixelWidth == 0) { EventHandler<RoutedEventArgs> completed = null; completed = (s, e) => { bi.ImageOpened -= completed; ComputeIconTranslationValues(style, ms, bi); }; bi.ImageOpened += completed; } #else if (bi.IsDownloading) { EventHandler completed = null; completed = (s, e) => { bi.DownloadCompleted -= completed; ComputeIconTranslationValues(style, ms, bi); }; bi.DownloadCompleted += completed; } #endif else { ComputeIconTranslationValues(style, ms, bi); } } catch { g.Symbol = new SimpleMarkerSymbol(); } } // Copy attributes values from metadata to graphic foreach (var attribute in feature.Attributes) { g.Attributes.Add(attribute.Key, attribute.Value); } // If the balloontext property has been assigned a value in the style associated with this // graphic feature, then add it to the attributes collection. if (!String.IsNullOrEmpty(style.BalloonText)) { g.Attributes.Add("balloonText", style.BalloonText); } // Add graphic to graphics layer graphics.Add(g); } layer.Graphics = graphics; // Use the renderer to create the legend itens (asynchronously since creating a swatch from a symbol is asynchronous) renderer.QueryLegendInfos(layerLegendInfo => { layer.LegendInfo = layerLegendInfo;}, null); }
private void RadioButton_Click(object sender, RoutedEventArgs e) { // Clear all existing graphics var graphicLayers = MySceneView.Scene.Layers.OfType<GraphicsLayer>(); foreach (GraphicsLayer gl in graphicLayers) gl.Graphics.Clear(); string shapeTag = (string)((RadioButton)sender).Tag; switch (shapeTag) { case "Point": // Add coordinates to all graphics layers using GraphicCollection and populate the data GraphicCollection absoluteCollection = new GraphicCollection(); GraphicCollection relativeCollection = new GraphicCollection(); GraphicCollection drapedCollection = new GraphicCollection(); foreach (MapPoint point in _coordinates) { // Use graphics with different ElevationModes absoluteCollection.Add(new Graphic(point, GetPointSymbol(SurfacePlacement.Absolute))); relativeCollection.Add(new Graphic(point, GetPointSymbol(SurfacePlacement.Relative))); drapedCollection.Add(new Graphic(point, GetPointSymbol(SurfacePlacement.Draped))); } _absoluteGraphicsLayer.Graphics.AddRange(absoluteCollection); _drapedGraphicsLayer.Graphics.AddRange(drapedCollection); _relativeGraphicsLayer.Graphics.AddRange(relativeCollection); break; case "Line": // Create polylines with different ElevationModes var line = new Polyline(_coordinates, SpatialReferences.Wgs84); _absoluteGraphicsLayer.Graphics.Add( new Graphic( line, GetPolylineSymbol(SurfacePlacement.Absolute))); _drapedGraphicsLayer.Graphics.Add( new Graphic( line, GetPolylineSymbol(SurfacePlacement.Draped))); _relativeGraphicsLayer.Graphics.Add( new Graphic( line, GetPolylineSymbol(SurfacePlacement.Relative))); break; case "Polygon": // Create polygons using different ElevationModes var polygon = new Polygon(_coordinates, SpatialReferences.Wgs84); _absoluteGraphicsLayer.Graphics.Add( new Graphic(polygon, GetPolygonSymbol(SurfacePlacement.Absolute))); _drapedGraphicsLayer.Graphics.Add( new Graphic(polygon, GetPolygonSymbol(SurfacePlacement.Draped))); _relativeGraphicsLayer.Graphics.Add( new Graphic(polygon, GetPolygonSymbol(SurfacePlacement.Relative))); break; } }
private async void Load3DPolygonLayer(object parameter) { try { var queryTask = new QueryTask(new Uri("http://119.2.29.21:6080/arcgis/rest/services/ChinaMap/MapServer/0")); Query query = new Query("1=1"); query.OutFields.Add("POPU");//人口数 var result = await queryTask.ExecuteAsync(query); var res = new GraphicCollection(); foreach (var state in result.FeatureSet.Features) res.Add(new Graphic(state.Geometry, state.Attributes)); var graphicLayer = new GraphicsLayer(); graphicLayer.DisplayName = "3D面图层"; graphicLayer.GraphicsSource = res; graphicLayer.Renderer = App.Current.Resources["3DPolygonRenderer"] as Renderer; graphicLayer.SceneProperties.SurfacePlacement = SurfacePlacement.Relative; graphicLayer.ID = "3DPolygonLayer"; scene.Layers.Add(graphicLayer); } catch (Exception ex) { MessageBox.Show(ex.Message, "Sample Error"); } }
protected override Graphic OnCreateGraphic(GraphicCollection cluster, MapPoint point, int maxClusterCount) { if (cluster.Count == 1) return cluster[0]; Graphic graphic = null; double sum = 0; foreach (Graphic g in cluster) { if (g.Attributes.ContainsKey(AggregateColumn)) { try { sum += Convert.ToDouble(g.Attributes[AggregateColumn]); } catch { } } } double size = (sum + 450) / 30; size = (Math.Log(sum * SymbolScale / 10) * 10 + 20); if (size < 12) size = 12; graphic = new Graphic() { Symbol = new ClusterSymbol() { Size = size }, Geometry = point }; graphic.Attributes.Add("Count", sum); graphic.Attributes.Add("Size", size); graphic.Attributes.Add("Color", InterpolateColor(size - 12, 100)); return graphic; }
public override void Execute() { if (_undoCommand != null) throw new InvalidOperationException("The command has already been executed."); Validate(); _parentCollection.Insert(_index, _graphic); _undoCommand = new RemoveGraphicCommand(_graphic); _parentCollection = null; _graphic = null; _index = -1; }
public static GraphicCollection LoadRoutes( rteTypeCollection rtes ) { rtes.RequireArgument<rteTypeCollection>( "rtes" ).NotNull<rteTypeCollection>(); GraphicCollection routes = new GraphicCollection(); foreach( var rte in rtes ) { Graphic gr = new Graphic(); gr.Geometry = LoadRoute( rte.rtept ); LoadRouteAttributes( rte, gr.Attributes ); routes.Add( gr ); } return routes; }
/// <summary> /// Constructor. /// </summary> public InsertGraphicUndoableCommand(IGraphic graphic, GraphicCollection parentCollection, int index) { _command = new InsertGraphicCommand(graphic, parentCollection, index); }
// Plot points defining seismic lines, roughly outlining the area where the seismic survey was conducted private void PlotSeismicLines() { GraphicsLayer mygl = new GraphicsLayer(); mygl.ID = "SeismicLinePoints"; SimpleMarkerSymbol MyPointSymbol = new SimpleMarkerSymbol(); MyPointSymbol.Color = System.Windows.Media.Brushes.DarkMagenta; MyPointSymbol.Size = 8.0; SimpleLineSymbol MyLineSymbol = new SimpleLineSymbol(); MyLineSymbol.Color = System.Windows.Media.Brushes.DarkMagenta; MyLineSymbol.Width = 2.0; SpatialReference OriginalSpatialReference = new SpatialReference(4283); // GDA 1994 SpatialReference TargetSpatialReference = new SpatialReference(3857); // webmercator GeometryService mygeom = LayoutRoot.Resources["GeomService"] as GeometryService; GraphicCollection mygc = new GraphicCollection(); double[][] myPoints = new double[46][] { new double[] {-28.1434989,139.5514607}, new double[] {-28.1278969,139.6851856}, new double[] {-28.1801364,139.5568852}, new double[] {-28.1635794,139.6987722}, new double[] {-28.1901613,139.5583702}, new double[] {-28.1745546,139.6921527}, new double[] {-28.1917250,139.5585937}, new double[] {-28.1761182,139.6923782}, new double[] {-28.1934517,139.5588558}, new double[] {-28.1778446,139.6926424}, new double[] {-28.1939819,139.5844259}, new double[] {-28.1827765,139.6804436}, new double[] {-28.1961695,139.5847537}, new double[] {-28.1849639,139.6807733}, new double[] {-28.1983661,139.5850813}, new double[] {-28.1871603,139.6811028}, new double[] {-28.2013400,139.5855209}, new double[] {-28.1923641,139.6624829}, new double[] {-28.2057240,139.5861662}, new double[] {-28.1967479,139.6631312}, new double[] {-28.2080743,139.5865224}, new double[] {-28.1990981,139.6634891}, new double[] {-28.1125094,139.5809721}, new double[] {-28.2149162,139.5961573}, new double[] {-28.1110919,139.5931426}, new double[] {-28.2134978,139.6083392}, new double[] {-28.1108863,139.5949064}, new double[] {-28.2132921,139.6101047}, new double[] {-28.1105985,139.5973756}, new double[] {-28.2130042,139.6125764}, new double[] {-28.1103518,139.5994922}, new double[] {-28.2127573,139.6146949}, new double[] {-28.1100845,139.6017852}, new double[] {-28.2124898,139.6169900}, new double[] {-28.1098377,139.6039017}, new double[] {-28.2122429,139.6191085}, new double[] {-28.1095498,139.6063709}, new double[] {-28.2119547,139.6215802}, new double[] {-28.1092618,139.6088402}, new double[] {-28.2116666,139.6240517}, new double[] {-28.1077388,139.6218919}, new double[] {-28.2101425,139.6371157}, new double[] {-28.1075947,139.6231264}, new double[] {-28.2099983,139.6383515}, new double[] {-28.1061527,139.6354723}, new double[] {-28.2085555,139.6507091} }; foreach (double[] da in myPoints) { Graphic g = new Graphic(); g.Geometry = new MapPoint(da[1], da[0]); g.Geometry.SpatialReference = OriginalSpatialReference; mygc.Add(g); } IList<Graphic> glist = mygeom.Project(mygc, TargetSpatialReference); foreach (Graphic g in glist) { g.Symbol = MyPointSymbol; mygl.Graphics.Add(g); //System.Diagnostics.Debug.WriteLine((g.Geometry as MapPoint).X + " " + (g.Geometry as MapPoint).Y); } MyMap.Layers.Add(mygl); }
public void Initialize() { CalculationId = Guid.NewGuid(); _effectsPlugin = IoC.Get<IEffectsMapToolPlugin>(); _effectsPlugin.RegisterEffectsMapTool(this); Contours = new GraphicCollection(); }
public void SetCalculatedData(JArray calculatedData) { //.Where(p=>!((new int[]{5,3}).Contains((int)p["ParameterType"]))) OutputParameters = calculatedData.OfType<JObject>().Where(ShowOutputParameter).Select(p => new EffectsOutputParameterViewModel() {Data = p}); Contours = new GraphicCollection(calculatedData.OfType<JObject>().Where(IsContourParameter).Select(p=>((string)p["Data"]["Value"]).ToGraphic(new SpatialReference(28992), new SpatialReference(28992)))); }
/// <summary> /// Creates graphic elements and adds them to the graphics layer. /// </summary> /// <param name="layer">Graphics layer that will have features added to it.</param> /// <param name="images">Dictionary of images coming from kmz content or from previous parsing</param> public void CreateGraphics(KmlGraphicsLayer layer, IDictionary<string, ImageBrush> images) { if (layer == null) return; GraphicCollection graphics = new GraphicCollection(); UniqueValueRenderer renderer = new UniqueValueRenderer(); // dummy renderer used to create the legend items (since creation of the swatches from the symbol is not that obvious) // Process each metadata feature in the list foreach (PlacemarkDescriptor feature in placemarks) { KMLStyle style = feature.Symbol.style; if (style.ZipFile != null) { // Look for the image in the zip file if (style.IconImage == null && !String.IsNullOrEmpty(style.IconHref)) { style.IconImage = GetIconImage(style.ZipFile, style.IconHref.ToLower()); } style.ZipFile.Dispose(); style.ZipFile = null; } //Define handlers upfront so we can unhook from them #if SILVERLIGHT EventHandler<RoutedEventArgs> #else EventHandler #endif imageCompleted = null; #if SILVERLIGHT EventHandler<ExceptionRoutedEventArgs> #else EventHandler<ExceptionEventArgs> #endif imageFailed = null; // If the style has an HREF then it is associated with an image if (style.IconImage == null && !String.IsNullOrEmpty(style.IconHref)) { // If the image is already loaded in the image dictionary, use it if (images.ContainsKey(style.IconHref.ToLower())) style.IconImage = images[style.IconHref.ToLower()]; else { // Get the image using the HREF and store the image in the images dictionary so that if // other features reference it, it is cached style.IconImage = GetIconImage(style.IconHref); if (style.IconImage != null && (style.IconImage as ImageBrush).ImageSource != null) { var bi = (style.IconImage as ImageBrush).ImageSource as BitmapImage; if (bi != null) { imageFailed = (s, e) => { var b = s as BitmapImage; #if SILVERLIGHT if (imageCompleted != null) b.ImageOpened -= imageCompleted; if(imageFailed != null) b.ImageFailed -= imageFailed; #else if (imageCompleted != null) b.DownloadCompleted -= imageCompleted; if (imageFailed != null) b.DownloadFailed -= imageFailed; #endif var key = b.GetValue(BitmapImageKeyProperty) as string; layer.Dispatcher.BeginInvoke((Action)delegate { UpdateGraphicsAndRenderer(layer, renderer, key); }); }; #if SILVERLIGHT bi.ImageFailed += imageFailed; #else bi.DownloadFailed += imageFailed; #endif } } images.Add(style.IconHref.ToLower(), style.IconImage); } } // Create a new graphic from the metadata and construct the symbol using polymorphism Graphic g = new Graphic() { Geometry = feature.Geometry, Symbol = feature.Symbol.CreateSymbol(), TimeExtent = feature.TimeExtent }; g.SetValue(FeaturePlacemarkerDescriptorProperty, feature); // Create legend entry string label; string description; GetRendererInfo(feature, style, out label, out description); if (!string.IsNullOrEmpty(label) && !renderer.Infos.Any(info => info.Label == label)) renderer.Infos.Add(new UniqueValueInfo { Label = label, Description = description, Symbol = g.Symbol }); // Adjust and assign picture marker symbol properties if (g.Geometry is ESRI.ArcGIS.Client.Geometry.MapPoint && g.Symbol is KmlPlaceMarkerSymbol) { try { KmlPlaceMarkerSymbol ms = g.Symbol as KmlPlaceMarkerSymbol; // To match sizing of Google Earth, default size of point images is 40x40 ms.Height = 40; ms.Width = 40; ms.Fill = style.IconImage; ms.IconColor = style.IconColor; // Default to half the pixel size (width and height) if symbol offsets are 0 (supported in wpf and sl3) ImageBrush ib = ms.Fill; BitmapImage bi = ib.ImageSource as BitmapImage; #if SILVERLIGHT if (bi.PixelHeight == 0 || bi.PixelWidth == 0) #else if (bi.IsDownloading) #endif { imageCompleted = (s, e) => { var b = s as BitmapImage; #if SILVERLIGHT if (imageCompleted != null) b.ImageOpened -= imageCompleted; if(imageFailed != null) b.ImageFailed -= imageFailed; #else if (imageCompleted != null) b.DownloadCompleted -= imageCompleted; if (imageFailed != null) b.DownloadFailed -= imageFailed; #endif ComputeIconTranslationValues(style, ms, b); }; #if SILVERLIGHT bi.ImageOpened += imageCompleted; #else bi.DownloadCompleted += imageCompleted; #endif } else { ComputeIconTranslationValues(style, ms, bi); } } catch { g.Symbol = PointSymbolDescriptor.GetDefaultSymbol(); ComputeIconTranslationValues(style, g.Symbol as KmlPlaceMarkerSymbol, ((g.Symbol as KmlPlaceMarkerSymbol).Fill as ImageBrush).ImageSource as BitmapImage); var info = renderer.Infos.FirstOrDefault(i => i.Label == label); if (info != null) { info.Symbol = g.Symbol; } } } // Copy attributes values from metadata to graphic foreach (var attribute in feature.Attributes) { g.Attributes.Add(attribute.Key, attribute.Value); } // If the balloontext property has been assigned a value in the style associated with this // graphic feature, then add it to the attributes collection. if (!String.IsNullOrEmpty(style.BalloonText)) { g.Attributes.Add("balloonText", style.BalloonText); } // Add graphic to graphics layer graphics.Add(g); } layer.Graphics = graphics; // keep the renderer for further usage (when QueryLegendInfos is called) layer.RendererBasedOnStyle = renderer; }
// Plot points and lines highlighting the area where seismic line slices can be obtained, with the seismic line control public void PlotActualSeismicLines() { GraphicsLayer mygl = new GraphicsLayer(); mygl.ID = "ActiveSeismicLinePoints"; SimpleMarkerSymbol MyPointSymbol = new SimpleMarkerSymbol(); MyPointSymbol.Color = System.Windows.Media.Brushes.DarkGreen; MyPointSymbol.Size = 8.0; SimpleLineSymbol MyLineSymbol = new SimpleLineSymbol(); MyLineSymbol.Color = System.Windows.Media.Brushes.DarkGreen; MyLineSymbol.Width = 2.0; SpatialReference OriginalSpatialReference = new SpatialReference(4283); // GDA 1994 SpatialReference TargetSpatialReference = new SpatialReference(3857); // webmercator GeometryService mygeom = LayoutRoot.Resources["GeomService"] as GeometryService; GraphicCollection mygc = new GraphicCollection(); double[][] myPoints = new double[4][] { // (latitude,longitude), ie (y,x) new double[] {-28.1801364, 139.5568852}, new double[] {-28.1434989,139.5514607}, new double[] {-28.1278969,139.6851856}, new double[] {-28.1635794, 139.6987722} }; foreach (double[] da in myPoints) { Graphic g = new Graphic(); g.Geometry = new MapPoint(da[1], da[0]); g.Geometry.SpatialReference = OriginalSpatialReference; mygc.Add(g); } IList<Graphic> glist = mygeom.Project(mygc, TargetSpatialReference); foreach (Graphic g in glist) { g.Symbol = MyPointSymbol; mygl.Graphics.Add(g); //System.Diagnostics.Debug.WriteLine((g.Geometry as MapPoint).X + " " + (g.Geometry as MapPoint).Y); } Graphic lineOne = new Graphic(); lineOne.Geometry = new Polyline(); ESRI.ArcGIS.Client.Geometry.PointCollection lineCollectionOne = new ESRI.ArcGIS.Client.Geometry.PointCollection(); lineCollectionOne.Add((glist[0] as Graphic).Geometry as MapPoint); lineCollectionOne.Add((glist[1] as Graphic).Geometry as MapPoint); lineCollectionOne.Add((glist[2] as Graphic).Geometry as MapPoint); lineCollectionOne.Add((glist[3] as Graphic).Geometry as MapPoint); lineCollectionOne.Add((glist[0] as Graphic).Geometry as MapPoint); (lineOne.Geometry as Polyline).Paths.Add(lineCollectionOne); lineOne.Symbol = MyLineSymbol; mygl.Graphics.Add(lineOne); MyMap.Layers.Add(mygl); }