private void ShowLabel() { if (labelOn) { if (!this.cbxActiveMap.HasItems || !this.cbxFeatureLayer.HasItems || !this.cbxField.HasItems) { return; } if (annoPropCol != null) { annoPropCol.Clear(); } labelLayer = this.m_map.Map.get_Layer(this.cbxFeatureLayer.SelectedIndex) as IFeatureLayer; gLabelLayer = labelLayer as IGeoFeatureLayer; annoPropCol = gLabelLayer.AnnotationProperties; ITextSymbol pTextSyl = new TextSymbol(); IFontDisp font = new StdFont() as IFontDisp; font.Size = 20; font.Italic = true; pTextSyl.Font = font; RgbColor color = new RgbColor(); color.Red = LabelColor.R; color.Green = LabelColor.G; color.Blue = LabelColor.B; pTextSyl.Color = color; IBasicOverposterLayerProperties pBasic = new BasicOverposterLayerProperties(); IPointPlacementPriorities pPlacementPoint = new PointPlacementPriorities(); pBasic.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint; pBasic.PointPlacementPriorities = pPlacementPoint; pBasic.PointPlacementOnTop = false; pBasic.PointPlacementMethod = esriOverposterPointPlacementMethod.esriOnTopPoint; ILabelEngineLayerProperties labelField = new LabelEngineLayerProperties() as ILabelEngineLayerProperties; //IFeatureClass fClass = ((IFeatureLayer)labelLayer).FeatureClass; //IFields fields = fClass.Fields; //String fieldName = fields.get_Field(this.cbxField.SelectedIndex).Name; string fieldName = (string)cbxField.SelectedItem; //Console.WriteLine(fields.FindField(fieldName)); labelField.Expression = "[" + fieldName + "]"; //set postion labelField.BasicOverposterLayerProperties = pBasic; //set symbol labelField.Symbol = pTextSyl; IAnnotateLayerProperties annoProp = labelField as IAnnotateLayerProperties; annoPropCol.Add(annoProp); gLabelLayer.DisplayAnnotation = true; m_map.Refresh(); } }
/// <summary> /// 获取文本标记,如果超过最大数量,则新建文本标记 /// </summary> /// <param name="_index"></param> /// <returns></returns> private static TextSymbol GetTextSymbol(int _index) { if (_index >= m_TextSymbols.Count) { var textSymbol = new TextSymbol(); m_TextSymbols.Add(textSymbol); return(textSymbol); } return(m_TextSymbols[_index]); }
public override void OnClick() { frmInputText frmInputText = new frmInputText(); if (frmInputText.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string text = frmInputText.txtText.Text; IElement element = new TextElement(); ITextElement textElement = element as ITextElement; ITextSymbol textSymbol = new TextSymbol(); textSymbol.Text = text; textSymbol.Size = 48.0; IActiveView activeView = this._context.ActiveView as IActiveView; activeView.ScreenDisplay.StartDrawing(0, 0); double num; double num2; textSymbol.GetTextSize(activeView.ScreenDisplay.WindowDC, activeView.ScreenDisplay.DisplayTransformation, text, out num, out num2); activeView.ScreenDisplay.FinishDrawing(); textSymbol.Text = text; num *= 0.0353; num2 *= 0.0353; IEnvelope extent = (this._context.ActiveView as IActiveView).Extent; double num3; double num4; double num5; double num6; extent.QueryCoords(out num3, out num4, out num5, out num6); num3 = (num3 + num5) / 2.0; num4 = num6 - 3.0; num5 = num3 + 1.2 * num; num6 = num4 + 1.2 * num2; num3 = (double)((int)num3); num4 = (double)((int)num4); num5 = (double)((int)num5); num6 = (double)((int)num6); extent.PutCoords(num3, num4, num5, num6); textElement.Symbol = textSymbol; textElement.Text = text; IPoint point = new ESRI.ArcGIS.Geometry.Point(); point.PutCoords(num3, num4); element.Geometry = point; IGraphicsContainer arg_181_0 = activeView.GraphicsContainer; (element as IElementProperties2).AutoTransform = true; INewElementOperation operation = new NewElementOperation { ActiveView = this._context.ActiveView, Element = element }; this._context.OperationStack.Do(operation); } }
private void LayerAnnotation(IGeoFeatureLayer pGeoFeatLyr, string annoField) { IGeoFeatureLayer pGeoFeatLayer; pGeoFeatLayer = pGeoFeatLyr; IAnnotateLayerPropertiesCollection pAnnoProps; pAnnoProps = pGeoFeatLyr.AnnotationProperties; pAnnoProps.Clear(); IAnnotateLayerProperties pAnnoLayerProps; ILabelEngineLayerProperties pLabelEngine; ILineLabelPosition pPosition; ILineLabelPlacementPriorities pPlacement; IBasicOverposterLayerProperties pBasic; //'定义标注的字体 ITextSymbol pTextSyl; pTextSyl = new TextSymbol(); stdole.IFontDisp pFont; pFont = new stdole.StdFont() as stdole.IFontDisp; pFont.Name = "仿宋"; pFont.Size = 12; pFont.Bold = true; pTextSyl.Font = pFont; IRgbColor pcolor = new RgbColorClass(); pcolor.Red = 255; pcolor.Green = 10; pcolor.Blue = 20; pTextSyl.Color = pcolor; pPosition = new LineLabelPosition(); pPosition.Parallel = false; pPosition.Perpendicular = true; pPlacement = new LineLabelPlacementPriorities(); pBasic = new BasicOverposterLayerProperties(); pBasic.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline; pBasic.LineLabelPlacementPriorities = pPlacement; pBasic.LineLabelPosition = pPosition; pLabelEngine = new LabelEngineLayerProperties() as ILabelEngineLayerProperties; pLabelEngine.Symbol = pTextSyl; pLabelEngine.BasicOverposterLayerProperties = pBasic; //field的形式必须是[fieldname] pLabelEngine.Expression = annoField; pAnnoLayerProps = (IAnnotateLayerProperties)pLabelEngine; pAnnoProps.Add(pAnnoLayerProps); pGeoFeatLyr.DisplayAnnotation = true; axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
/// <summary> /// 文字设置 /// </summary> /// <param name="txtEle"></param> /// <param name="size"></param> /// <param name="hAlignment"></param> /// <param name="vAligment"></param> protected ITextSymbol FontStyle(double size, esriTextHorizontalAlignment hAlignment, esriTextVerticalAlignment vAligment) { ITextSymbol textSymbolClass = new TextSymbol() { Size = size, Color = ColorManage.CreatColor(0, 0, 0), HorizontalAlignment = hAlignment, VerticalAlignment = vAligment }; return(textSymbolClass); }
private void QueryBoundsFromGeom(int hDC, ref IDisplayTransformation transform, ref IPolygon boundary, ref IGeometry point) { IPointCollection pointCollection = null; pointCollection = (IPointCollection)boundary; try { IPolygon polygonClass = new Polygon() as IPolygon; ITextSymbol textSymbolClass = new TextSymbol() { Text = this.m_NumeratorText }; (textSymbolClass as ISymbol).QueryBoundary(hDC, transform, point, polygonClass); IEnvelope envelope = polygonClass.Envelope; IPolygon polygon = new Polygon() as IPolygon; textSymbolClass = new TextSymbol() { Text = this.m_DenominatorText }; (textSymbolClass as ISymbol).QueryBoundary(hDC, transform, point, polygon); envelope.Union(polygon.Envelope); envelope.Expand(4, 0, false); object value = Missing.Value; object obj = Missing.Value; pointCollection.AddPoint(envelope.LowerLeft, ref value, ref value); pointCollection.AddPoint(envelope.LowerRight, ref value, ref value); pointCollection.AddPoint(envelope.UpperRight, ref value, ref value); pointCollection.AddPoint(envelope.UpperLeft, ref value, ref value); pointCollection.AddPoint(envelope.LowerLeft, ref value, ref value); ITransform2D transform2D = null; if (this.m_Angle + this.m_dMapRotation != 0) { transform2D = boundary as ITransform2D; if (point is IPoint) { transform2D.Rotate(point as IPoint, Utility.Radians(this.m_Angle + this.m_dMapRotation)); } else if (point is IEnvelope) { transform2D.Rotate((point as IEnvelope).LowerLeft, Utility.Radians(this.m_Angle + this.m_dMapRotation)); } } } catch (Exception exception) { exception.ToString(); } }
private void ChangeTextHandler(object sender, RoutedEventArgs e) { //Graphic g = sender as Graphic; _currentPoint = Ambient.SelectedSymbol.Geometry as MapPoint; TextSymbol ts = Ambient.SelectedSymbol.Symbol as TextSymbol; TextSymbolPropsWindow win = new TextSymbolPropsWindow(); win.TextFont = ts.FontFamily.Source; win.TextFontSize = ts.FontSize; win.Annotation = ts.Text; win.EditMode = true; win.Closed += new EventHandler(win_Closed); win.Show(); }
public static Graphic NewText(string text, MapPoint p, Color color, SymbolFont font) { TextSymbol textSymbol = new TextSymbol(); textSymbol.Text = text; textSymbol.Color = color; textSymbol.Font = font; Graphic graphicText = new Graphic(); graphicText.Symbol = textSymbol; graphicText.Geometry = p; return(graphicText); }
//文本标注 private void btnTextElement_Click(object sender, EventArgs e) { if (axMapControl1.LayerCount > 0) { IGeoFeatureLayer pGeoFeatureLayer; ILineLabelPosition pLineLabelPosition; ILabelEngineLayerProperties pLabelEngineLayerProperties; IAnnotateLayerProperties pAnnotateLayerProperties; pGeoFeatureLayer = (IGeoFeatureLayer)axMapControl1.get_Layer(0); pGeoFeatureLayer.AnnotationProperties.Clear(); pLineLabelPosition = new LineLabelPosition(); pLineLabelPosition.Above = false; pLineLabelPosition.AtEnd = false; pLineLabelPosition.Below = false; pLineLabelPosition.Horizontal = false; pLineLabelPosition.InLine = true; pLineLabelPosition.OnTop = true; pLineLabelPosition.Parallel = true; pLineLabelPosition.ProduceCurvedLabels = true; ITextSymbol pTextSymbol = new TextSymbol(); IColor pColor = new RgbColor(); pColor.RGB = 100; pTextSymbol.Size = 12; pTextSymbol.Font.Name = "宋体"; pTextSymbol.Color = pColor; pLabelEngineLayerProperties = new LabelEngineLayerProperties() as ILabelEngineLayerProperties; pLabelEngineLayerProperties.Symbol = pTextSymbol; pLabelEngineLayerProperties.IsExpressionSimple = true; pLabelEngineLayerProperties.Expression = "[DESCRIP]";//需要中括号,这里显示NAME字段属性 pLabelEngineLayerProperties.BasicOverposterLayerProperties.LineLabelPosition = pLineLabelPosition; pAnnotateLayerProperties = (IAnnotateLayerProperties)pLabelEngineLayerProperties; pAnnotateLayerProperties.DisplayAnnotation = true; pAnnotateLayerProperties.FeatureLayer = pGeoFeatureLayer; pAnnotateLayerProperties.LabelWhichFeatures = esriLabelWhichFeatures.esriAllFeatures; pAnnotateLayerProperties.WhereClause = ""; pGeoFeatureLayer.AnnotationProperties.Add(pAnnotateLayerProperties); pGeoFeatureLayer.DisplayAnnotation = true; axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); axMapControl1.ActiveView.Refresh(); } }
async partial void ButtonQuote_TouchUpInside(UIButton sender) { if (string.IsNullOrWhiteSpace(TextSymbol.Text)) { var alert = new UIAlertView("No symbol", string.Empty, null, "OK"); alert.Show(); return; } TextSymbol.ResignFirstResponder(); ProgressBar.StartAnimating(); var quoteTask = viewModel.GetQuote(TextSymbol.Text); var historyTask = viewModel.GetHistory( TextSymbol.Text, DateTime.Today.AddDays(-14), DateTime.Today); await Task.WhenAll(quoteTask, historyTask); var quote = quoteTask.Result; if (quote == null) { LabelQuote.Text = "Invalid"; ProgressBar.StopAnimating(); return; } LabelQuote.Text = quote.CurrentQuote + " | " + quote.Change; LabelQuote.TextColor = quote.StockIsUp ? UIColor.Green : UIColor.Red; var items = historyTask.Result; if (items != null) { barChart.ItemsSource = items.Select( s => new BarChart.BarModel { Value = s.Value, Legend = s.Date.Remove(0, 5) }).ToList(); } ProgressBar.StopAnimating(); }
private static PictureMarkerSymbol CreateEntityIconSymbol(TextSymbol entityLabel, double textHeight) { var entityRuntimeImage = new RuntimeImage(ToByteArray(sScaledBitmap, ImageFormat.Png)); var iconSymbol = new PictureMarkerSymbol(entityRuntimeImage) { Height = 32, Width = 32 }; iconSymbol.OffsetY = textHeight > 0 ? entityLabel.OffsetY + (textHeight / 2 + iconSymbol.Height / 2 + SymbolSpacer) : entityLabel.OffsetY + (iconSymbol.Height / 2 + SymbolSpacer); return(iconSymbol); }
public ExMap(MapView esriMapView) { _mapView = esriMapView; ArcGISTiledMapServiceLayer layer = new ArcGISTiledMapServiceLayer(); layer.ServiceUri = "http://server.arcgisonline.com/arcgis/rest/services/ESRI_StreetMap_World_2D/MapServer"; _myLocationLayer = new GraphicsLayer(); _redliningGraphicsLayer = new GraphicsLayer(); _mapView.Map.Layers.Add(layer); _mapView.Map.Layers.Add(_redliningGraphicsLayer); _mapView.Map.Layers.Add(_myLocationLayer); _mapView.ExtentChanged += _mapView_ExtentChanged; _mapView.NavigationCompleted += _mapView_NavigationCompleted; //////////Init DrawControl////////// //_drawControl = new DrawControl(_mapView); //_drawMode = GeoDrawMode.None; //_drawControl.SetDrawMode(DrawMode.None); //_drawControl.DrawCompletedEvent += _drawControl_DrawCompletedEvent; ///////Init default Draw Symbols//////// PointMarkerSymbol = new SimpleMarkerSymbol(); PointMarkerSymbol.Color = Colors.Red; PointMarkerSymbol.Size = 15; PointMarkerSymbol.Style = SimpleMarkerStyle.Circle; PolygonFillSymbol = new SimpleFillSymbol(); PolygonFillSymbol.Outline = new SimpleLineSymbol(); PolygonFillSymbol.Outline.Color = Colors.Red; PolygonFillSymbol.Outline.Width = 3; PolygonFillSymbol.Color = Color.FromArgb(100, 255, 0, 0); LineSymbol = new SimpleLineSymbol(); LineSymbol.Color = Colors.Red; LineSymbol.Width = 5; LineSymbol.Style = SimpleLineStyle.Solid; TextDrawsymbol = new TextSymbol(); TextDrawsymbol.Text = "Text"; TextDrawsymbol.Font = new SymbolFont("Arial", 15); }
/// <summary> /// 画注记 /// </summary> /// <param name="g"></param> /// <param name="bounds"></param> /// <param name="centerPos"></param> /// <param name="scale"></param> /// <param name="fid2Text"></param> internal override void DrawLabel(Graphics g, Rectangle bounds, PointF centerPos, double scale, Dictionary <int, string> fid2Text, TextSymbol textSymbol) { MyPoint xyCenter = ETCProjection.LngLat2XY(new MyPoint(centerPos.X, centerPos.Y)); double xmin = xyCenter.X - scale * bounds.Width / 2; double xmax = xyCenter.X + scale * bounds.Width / 2; double ymin = xyCenter.Y - scale * bounds.Height / 2; double ymax = xyCenter.Y + scale * bounds.Height / 2; for (int i = 0; i < myPoints.Count; i++) { string text = fid2Text[myPoints[i].FID]; MyPoint xyProjection = ETCProjection.LngLat2XY(myPoints[i]); double xScreen = bounds.Width * (xyProjection.X - xmin) / (xmax - xmin); double yScreen = bounds.Height * (xyProjection.Y - ymin) / (ymax - ymin); TextSymbol.PointLabel(new PointF((float)xScreen, bounds.Height - (float)yScreen), g, textSymbol, text); //此处注记样式不能修改。待完善 } }
/// <summary> /// LPY 2016-3-25 添加 /// 根据JSON,在大屏上标出测量的距离或者面积结果 /// </summary> /// <param name="json"></param> public static void ShowLengthOrAreaByJSON(JObject json) { PublicParams.pubMainMap.Dispatcher.BeginInvoke(new Action(() => { try { string result = json["RESULT"].ToString(); Geometry geometry = Geometry.FromJson(json["GRAPHIC"]["Geometry"].ToString()); Graphic graphic = new Graphic() { Geometry = geometry }; switch (json["TYPE"].ToString()) { case "Polygon": graphic.Symbol = PublicParams.areaSymbol; break; case "Polyline": graphic.Symbol = PublicParams.lengthSymbol; break; default: break; } MapLayers.AddGraphicToGLayerByLayerID(graphic, PublicParams.gLayerLengthOrArea); double xCenter = (graphic.Geometry.Extent.XMax + graphic.Geometry.Extent.XMin) / 2;//查找中心点 double yCenter = (graphic.Geometry.Extent.YMax + graphic.Geometry.Extent.YMin) / 2; MapPoint mpCenter = new MapPoint(xCenter, yCenter, graphic.Geometry.SpatialReference); TextSymbol txtSymbol = PublicParams.textSymbol; Graphic gResult = new Graphic() { Geometry = mpCenter, Symbol = txtSymbol }; gResult.Attributes["Result"] = result; gResult.SetZIndex(2); MapLayers.AddGraphicToGLayerByLayerID(gResult, PublicParams.gLayerLengthOrArea); } catch (Exception) { } })); }
void win_Closed(object sender, EventArgs e) { TextSymbolPropsWindow win = sender as TextSymbolPropsWindow; if ((bool)win.DialogResult) { GraphicsLayer graphicsLayer = BoundMap.Layers["AnnoLayer"] as GraphicsLayer; string input = win.Annotation; if (!String.IsNullOrEmpty(input)) { MapPoint pt = _currentPoint; TextSymbol sym = new TextSymbol(); sym.FontFamily = new FontFamily(win.TextFont); sym.FontSize = win.TextFontSize; sym.Text = win.Annotation; sym.Foreground = new SolidColorBrush { Color = Colors.Black }; Zekiah.Samples.Font f = new Font(); f.Family = sym.FontFamily; f.Size = sym.FontSize; f.Style = FontStyles.Normal; f.Weight = FontWeights.Normal; String s = new String(input.ToCharArray()); Size size = s.Measure(f); sym.OffsetX = size.Width / 2; sym.OffsetY = size.Height / 2; ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = pt, Symbol = sym, }; graphic.MouseEnter += new MouseEventHandler(graphic_MouseEnter); graphic.MouseLeave += new MouseEventHandler(graphic_MouseLeave); graphic.MouseRightButtonDown += new System.Windows.Input.MouseButtonEventHandler(graphic_MouseRightButtonDown); if (win.EditMode) { graphicsLayer.Graphics.Remove(Ambient.SelectedSymbol); } graphicsLayer.Graphics.Add(graphic); } } }
public static Graphic NewText(string text, MapPoint p, Color color, string fontName, double fontSize) { TextSymbol textSymbol = new TextSymbol(); textSymbol.Text = text; textSymbol.Color = color; SymbolFont font = new SymbolFont(fontName, fontSize); textSymbol.Font = font; Graphic graphicText = new Graphic(); graphicText.Symbol = textSymbol; graphicText.Geometry = p; return(graphicText); }
public GeoMap(Map esriMap) { _map = esriMap; ArcGISTiledMapServiceLayer layer = new ArcGISTiledMapServiceLayer(); layer.Url = "http://server.arcgisonline.com/arcgis/rest/services/ESRI_StreetMap_World_2D/MapServer"; _myLocationLayer = new GraphicsLayer(); _redliningGraphicsLayer = new GraphicsLayer(); _map.Layers.Add(layer); _map.Layers.Add(_redliningGraphicsLayer); _map.Layers.Add(_myLocationLayer); _map.ExtentChanged += _map_ExtentChanged; ////////Init DrawControl////////// _drawControl = new DrawControl(_map); _drawMode = GeoDrawMode.None; _drawControl.SetDrawMode(DrawMode.None); _drawControl.DrawCompletedEvent += _drawControl_DrawCompletedEvent; ///////Init default Draw Symbols//////// PointMarkerSymbol = new SimpleMarkerSymbol(); PointMarkerSymbol.Color = new SolidColorBrush(Colors.Red); PointMarkerSymbol.Size = 15; PointMarkerSymbol.Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle; PolygonFillSymbol = new SimpleFillSymbol(); PolygonFillSymbol.BorderBrush = new SolidColorBrush(Colors.Red); PolygonFillSymbol.BorderThickness = 3; PolygonFillSymbol.Fill = new SolidColorBrush(System.Windows.Media.Color.FromArgb(100, 255, 0, 0)); LineSymbol = new SimpleLineSymbol(); LineSymbol.Color = new SolidColorBrush(Colors.Red); LineSymbol.Width = 5; LineSymbol.Style = SimpleLineSymbol.LineStyle.Solid; TextDrawsymbol = new TextSymbol(); TextDrawsymbol.Text = "Text"; TextDrawsymbol.FontSize = 15; }
public override void Refresh(int hdc) { if (this.ifeature_0 != null) { _context.ActiveView.ScreenDisplay.StartDrawing(_context.ActiveView.ScreenDisplay.hDC, -1); ISimpleTextSymbol simpleTextSymbol = new TextSymbol() as ISimpleTextSymbol; ISimpleTextSymbol arg_72_0 = simpleTextSymbol; IRgbColor rgbColorClass = new RgbColor() { Blue = 255, Green = 0, Red = 0, Transparency = 30 }; arg_72_0.Color = (rgbColorClass); simpleTextSymbol.Size = (15.0); _context.ActiveView.ScreenDisplay.SetSymbol((ISymbol)simpleTextSymbol); _context.ActiveView.ScreenDisplay.DrawText(this.ifeature_1.Shape, "起点"); _context.ActiveView.ScreenDisplay.FinishDrawing(); } else if (this.ipolyline_0 != null) { _context.ActiveView.ScreenDisplay.StartDrawing(_context.ActiveView.ScreenDisplay.hDC, -1); ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol(); IRgbColor rgbColor = new RgbColor() { Blue = 0, Red = 255, Green = 0, Transparency = 30 }; simpleLineSymbol.Color = (rgbColor); simpleLineSymbol.Width = (2.0); _context.ActiveView.ScreenDisplay.SetSymbol((ISymbol)simpleLineSymbol); _context.ActiveView.ScreenDisplay.DrawPolyline(this.ipolyline_0); ISimpleTextSymbol simpleTextSymbol2 = new TextSymbol() as ISimpleTextSymbol; rgbColor.Blue = (255); rgbColor.Green = (0); rgbColor.Red = (0); rgbColor.Transparency = (30); simpleTextSymbol2.Color = (rgbColor); simpleTextSymbol2.Size = (15.0); _context.ActiveView.ScreenDisplay.SetSymbol((ISymbol)simpleTextSymbol2); _context.ActiveView.ScreenDisplay.DrawText(this.ifeature_1.Shape, "起点"); _context.ActiveView.ScreenDisplay.DrawText(this.ifeature_2.Shape, "终点"); _context.ActiveView.ScreenDisplay.FinishDrawing(); } }
private static TextSymbol CreateEntityLabelSymbol(string text, SimpleMarkerSymbol pointMarker, bool isGrayed, out double textHeight) { var entityLabelSymbol = new TextSymbol { HorizontalAlignment = HorizontalAlignment.Center, Text = text }; if (text.Length > 0) { var lineCount = entityLabelSymbol.Text.Split('\n').Length; var fontFamily = new System.Windows.Media.FontFamily(entityLabelSymbol.FontFamily); var height = fontFamily.LineSpacing * entityLabelSymbol.Size; textHeight = lineCount * height; if (pointMarker != null) { entityLabelSymbol.OffsetY = Math.Abs(pointMarker.OffsetY) + (pointMarker.Size + textHeight / 2); } } else { entityLabelSymbol.Text = String.Empty; textHeight = 0; if (pointMarker != null) { entityLabelSymbol.OffsetY = Math.Abs(pointMarker.OffsetY); } } entityLabelSymbol.Color = Color.Black; entityLabelSymbol.HaloColor = sTextOutlineColor; // To workaround an Esri issue with TextSymbol selection with transparency where the text has unwanted ghosting effect. // The BorderLineSize is set to zero when entity symbol is determined to be grayed to improve the visibility. entityLabelSymbol.HaloWidth = isGrayed ? 0 : TextOutlineSize; return(entityLabelSymbol); }
/// <summary> /// 应用 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_Apply_Click(object sender, EventArgs e) { if (HasLabel.Checked == true) { inputlayer.HasText = true; TextSymbol newtextsymbol = new TextSymbol(); newtextsymbol.TextStyle = new LetterStyle(newcolor, newfont); MyRenderer.TextRenderer newtextrenderer = new MyRenderer.TextRenderer(newtextsymbol, CB_LabelFields.SelectedItem.ToString()); inputlayer.Textrender = newtextrenderer; if (HasSQL.Checked == true) { inputlayer.Textrender.SQL = TB_SQL.Text; } } else { inputlayer.HasText = false; } }
void win_Closed(object sender, EventArgs e) { TextSymbolPropsWindow win = sender as TextSymbolPropsWindow; GraphicsLayer graphicsLayer = _map.Map.Layers["defaultTextGraphicsLayer"] as GraphicsLayer; string input = win.Annotation; // System.Windows.Browser.HtmlPage.Window.Prompt("Enter text to display"); if (!String.IsNullOrEmpty(input)) { MapPoint pt = _currentPoint; TextSymbol sym = new TextSymbol(); sym.FontFamily = new FontFamily(win.TextFont); // new FontFamily("Arial"); sym.FontSize = win.TextFontSize; // 20; sym.Text = win.Annotation; // input; sym.Foreground = new SolidColorBrush { Color = Colors.Black }; Main.Helpers.Font f = new Font(); f.Family = sym.FontFamily; f.Size = sym.FontSize; f.Style = FontStyles.Normal; f.Weight = FontWeights.Normal; String s = new String(input.ToCharArray()); Size size = s.Measure(f); sym.OffsetX = size.Width / 2; sym.OffsetY = size.Height / 2; //MessageBox.Show("h:" + size.Height.ToString() + " w:" + size.Width.ToString()); //TODO: Apply offest to center label ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = pt, Symbol = sym, }; graphic.MouseLeftButtonUp += new MouseButtonEventHandler(graphic_MouseLeftButtonUp); graphic.MouseRightButtonDown += new System.Windows.Input.MouseButtonEventHandler(graphic_MouseRightButtonDown); if (win.EditMode) { graphicsLayer.Graphics.Remove(SelectedSymbol); }//_map.PreviousExtents.Push(_map.Map.Extent); graphicsLayer.Graphics.Add(graphic); } }
public static ITextSymbol MakeTextSymbol(string string_0, double double_0) { try { ISimpleTextSymbol symbol = new TextSymbol() as ISimpleTextSymbol; IFontDisp disp = (IFontDisp) new StdFont(); disp.Name = string_0; symbol.Font = disp; symbol.Angle = 0.0; symbol.RightToLeft = false; symbol.Size = double_0; symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; return(symbol); } catch { return(null); } }
private LabelDefinition MakeLabelDefinition(string partyName, Color color) { // Create a text symbol for styling the label. TextSymbol textSymbol = new TextSymbol { Size = 12, Color = color, HaloColor = Color.White, HaloWidth = 2, }; // Create a label expression using an Arcade expression script. LabelExpression arcadeLabelExpression = new ArcadeLabelExpression("$feature.NAME + \" (\" + left($feature.PARTY,1) + \")\\nDistrict \" + $feature.CDFIPS"); return(new LabelDefinition(arcadeLabelExpression, textSymbol) { Placement = Esri.ArcGISRuntime.ArcGISServices.LabelingPlacement.PolygonAlwaysHorizontal, WhereClause = $"PARTY = '{partyName}'", }); }
private void AddPictureMarkerAndTextGraphics() { string gpsNMEASentences = "$GPGGA, 92204.9, -35.6334, N, -60.2343, W, 1, 04, 2.4, 25.7, M,,,,*75\r\n" + "$GPGGA, 92510.5, -49.9334, N, -65.2131, W, 1, 04, 2.6, 1.7, M,,,,*75\r\n"; string[] gpsNMEASentenceArray = gpsNMEASentences.Split('\n'); GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; for (int i = 0; i < gpsNMEASentenceArray.Length - 1; i++) { string[] gpsNMEASentence = gpsNMEASentenceArray[i].Split(','); MapPoint mp = new MapPoint(Convert.ToDouble(gpsNMEASentence[4]), Convert.ToDouble(gpsNMEASentence[2])); MapPoint conv_mp = wm.FromGeographic(mp) as MapPoint; Graphic graphic = new Graphic() { Geometry = conv_mp, Symbol = GlobePictureSymbol }; graphicsLayer.Graphics.Add(graphic); TextSymbol textSymbol = new TextSymbol() { FontFamily = new System.Windows.Media.FontFamily("Arial"), Foreground = new System.Windows.Media.SolidColorBrush(Colors.Black), FontSize = 18, Text = gpsNMEASentence[9] }; Graphic graphicText = new Graphic() { Geometry = conv_mp, Symbol = textSymbol }; graphicsLayer.Graphics.Add(graphicText); } }
private void AddPictureMarkerAndTextGraphics() { string gpsNMEASentences = "$GPGGA, 92204.9, -35.6334, N, -60.2343, W, 1, 04, 2.4, 25.7, M,,,,*75\r\n" + "$GPGGA, 92510.5, -49.9334, N, -65.2131, W, 1, 04, 2.6, 1.7, M,,,,*75\r\n"; string[] gpsNMEASentenceArray = gpsNMEASentences.Split('\n'); GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; for (int i = 0; i < gpsNMEASentenceArray.Length - 1; i++) { string[] gpsNMEASentence = gpsNMEASentenceArray[i].Split(','); Graphic graphic = new Graphic() { Geometry = mercator.FromGeographic(new MapPoint(Convert.ToDouble(gpsNMEASentence[4], System.Globalization.CultureInfo.InvariantCulture), Convert.ToDouble(gpsNMEASentence[2], System.Globalization.CultureInfo.InvariantCulture))), Symbol = LayoutRoot.Resources["GlobePictureSymbol"] as Symbol }; graphicsLayer.Graphics.Add(graphic); TextSymbol textSymbol = new TextSymbol() { FontFamily = new System.Windows.Media.FontFamily("Arial"), Foreground = new System.Windows.Media.SolidColorBrush(Colors.Black), FontSize = 10, Text = gpsNMEASentence[9] }; Graphic graphicText = new Graphic() { Geometry = mercator.FromGeographic(new MapPoint(Convert.ToDouble(gpsNMEASentence[4], System.Globalization.CultureInfo.InvariantCulture), Convert.ToDouble(gpsNMEASentence[2], System.Globalization.CultureInfo.InvariantCulture))), Symbol = textSymbol }; graphicsLayer.Graphics.Add(graphicText); } }
private void ShowTextSymbolByGraphic(Graphic graphic, string result) { MapLayers.AddGraphicToGLayerByLayerID(graphic, PublicParams.gLayerLengthOrArea); double xCenter = (graphic.Geometry.Extent.XMax + graphic.Geometry.Extent.XMin) / 2; double yCenter = (graphic.Geometry.Extent.YMax + graphic.Geometry.Extent.YMin) / 2; MapPoint mpCenter = new MapPoint(xCenter, yCenter, graphic.Geometry.SpatialReference); TextSymbol txtSymbol = PublicParams.textSymbol; Graphic gResult = new Graphic() { Geometry = mpCenter, Symbol = txtSymbol }; gResult.Attributes["Result"] = result; gResult.SetZIndex(2); MapLayers.AddGraphicToGLayerByLayerID(gResult, PublicParams.gLayerLengthOrArea); //发送到大屏 MapMethods.SendLengthOrAreaResult(graphic, result, graphic.Geometry.GetType().Name); }
private void CreateText() { // Create two text symbols TextSymbol bassRockTextSymbol = new TextSymbol("Black Rock", Color.Blue, 10, HorizontalAlignment.Left, VerticalAlignment.Bottom); TextSymbol craigleithTextSymbol = new TextSymbol("Craigleith", Color.Blue, 10, HorizontalAlignment.Right, VerticalAlignment.Top); // Create two points MapPoint bassPoint = new MapPoint(-2.64, 56.079, SpatialReferences.Wgs84); MapPoint craigleithPoint = new MapPoint(-2.72, 56.076, SpatialReferences.Wgs84); // Create two graphics from the points and symbols Graphic bassRockGraphic = new Graphic(bassPoint, bassRockTextSymbol); Graphic craigleithGraphic = new Graphic(craigleithPoint, craigleithTextSymbol); // Add graphics to the graphics overlay _overlay.Graphics.Add(bassRockGraphic); _overlay.Graphics.Add(craigleithGraphic); }
public void add_rr() { ITextElement textElement; ITextSymbol textSymbol; IColor color; activeView = pageLayoutControl.PageLayout as IActiveView; envelope = new Envelope() as IEnvelope; envelope.PutCoords(7, 20, 15, 30); textElement = new TextElement() as ITextElement; element = textElement as IElement; element.Geometry = envelope; textElement.Text = "实验五地图"; textSymbol = new TextSymbol(); color = C_S_R.getRGB(0, 0, 0); textSymbol.Color = color; textSymbol.Size = 30; textElement.Symbol = textSymbol; graphicsContainer = activeView as IGraphicsContainer; graphicsContainer.AddElement(element, 0); }
void ShowCluster(Cluster c) { //edited 20/12/2015 Graphic g = new Graphic(); if (c.clusterAttributes.clusterCount > 1) { MapPoint point = new MapPoint(c.X, c.Y, this.spatialReference); g.Geometry = point; g.Attributes.Add("clusterCount", c.clusterAttributes.clusterCount); g.Attributes.Add("clusterId", c.clusterAttributes.clusterId); this.Graphics.Add(g); // show number of points in the cluster TextSymbol label = new TextSymbol(); label.Text = c.clusterAttributes.clusterCount.ToString(); label.Color = ClusterLabelColor; label.XOffset = 0; label.YOffset = this.ClusterLabelOffset; Graphic g2 = new Graphic(); g2.Geometry = point; g2.Attributes.Add("clusterCount", c.clusterAttributes.clusterCount); g2.Attributes.Add("clusterId", c.clusterAttributes.clusterId); g2.Symbol = label; this.Graphics.Add(g2); } //add your symbol ,check for attribute and the symbol // code below is used to not label clusters with a single point else { MapPoint point = new MapPoint(c.X, c.Y, this.spatialReference); g.Geometry = point; g.Symbol = SingleSym; g.Attributes.Add("clusterCount", c.clusterAttributes.clusterCount); g.Attributes.Add("clusterId", c.clusterAttributes.clusterId); this.Graphics.Add(g); return; } }
private async void HandleMapTap(MapPoint mapLocation) { // Normalize geometry - important for geometries that will be sent to a server for processing. mapLocation = (MapPoint)GeometryEngine.NormalizeCentralMeridian(mapLocation); switch (_currentSampleState) { case SampleState.AddingBarriers: // Buffer the tapped point to create a larger barrier. Geometry bufferedGeometry = GeometryEngine.BufferGeodetic(mapLocation, 500, LinearUnits.Meters); // Create the graphic to show the barrier. Graphic barrierGraphic = new Graphic(bufferedGeometry, _barrierSymbol); // Add the graphic to the overlay - this will cause it to appear on the map. _barriersOverlay.Graphics.Add(barrierGraphic); break; case SampleState.AddingStops: // Get the name of this stop. string stopName = $"{_stopsOverlay.Graphics.Count + 1}"; // Create the marker to show underneath the stop number. PictureMarkerSymbol pushpinMarker = await GetPictureMarker(); // Create the text symbol for showing the stop. TextSymbol stopSymbol = new TextSymbol(stopName, System.Drawing.Color.White, 15, HorizontalAlignment.Center, VerticalAlignment.Middle); stopSymbol.OffsetY = 15; CompositeSymbol combinedSymbol = new CompositeSymbol(new MarkerSymbol[] { pushpinMarker, stopSymbol }); // Create the graphic to show the stop. Graphic stopGraphic = new Graphic(mapLocation, combinedSymbol); // Add the graphic to the overlay - this will cause it to appear on the map. _stopsOverlay.Graphics.Add(stopGraphic); break; } }
public IElement addTitleToLayout(IMxDocument pMxDoc,double S, double x, double y, IGraphicsContainer pGc, bool b, string texto) { ITextElement pTxtElem; ITextSymbol pTxtSym = default(ITextSymbol); IRgbColor myColor = default(IRgbColor); stdole.IFontDisp myFont; IElement pElem; IEnvelope pEnv; IPoint pPoint = default(IPoint); try{ // pGc.Reset() //Set the font and color properties //for the title myFont = (stdole.IFontDisp)new stdole.StdFont(); myFont.Name = "Times New Roman"; myFont.Bold = b; // myFont.Size = S; myColor = new RgbColor(); myColor.Red = 0; myColor.Green = 0; myColor.Blue = 0; ///'''''''''''''''''''''''''''''' //Create a text element pTxtElem = (ITextElement)new TextElement(); //Create a text symbol pTxtSym = new TextSymbol(); pTxtSym.Color = myColor; pTxtSym.Font = myFont; pTxtSym.Size = S; //Set symbol property pTxtElem.Symbol = pTxtSym; //set the text property to be the layer's name (Uppercase) pTxtElem.Text = texto; //Create an envelope for the TextElements Geometry pEnv = (IEnvelope)new Envelope(); pPoint = new ESRI.ArcGIS.Geometry.Point(); pPoint.X = x; pPoint.Y = y; pEnv.LowerLeft = pPoint; pPoint.X = 1; pPoint.Y = 1; pEnv.UpperRight = pPoint; //set the text elements geomtery pElem = (IElement)pTxtElem; pElem.Geometry = pEnv; //Add the element to the graphics container pGc.AddElement(pElem, 1); pMxDoc.ActiveView.Refresh(); return (pElem); } catch (System.Exception ex) { MessageBox.Show("Error: " + ex.Message, "clsMapTools.addTitleToLayout"); MessageBox.Show("Error: " + ex.StackTrace); return null ; } }
public static Graphic NewText(string text, MapPoint p, Color color, string fontName, double fontSize) { TextSymbol textSymbol = new TextSymbol(); textSymbol.Text = text; textSymbol.Color = color; SymbolFont font = new SymbolFont(fontName, fontSize); textSymbol.Font = font; Graphic graphicText = new Graphic(); graphicText.Symbol = textSymbol; graphicText.Geometry = p; return graphicText; }
public static Graphic NewText(string text, MapPoint p, Color color, SymbolFont font) { TextSymbol textSymbol = new TextSymbol(); textSymbol.Text = text; textSymbol.Color = color; textSymbol.Font = font; Graphic graphicText = new Graphic(); graphicText.Symbol = textSymbol; graphicText.Geometry = p; return graphicText; }
private new void AddPoi(PoI p) { try { p.UpdateAnalysisStyle(); if (string.IsNullOrEmpty(p.Layer) && p.PoiType != null) p.Layer = p.PoiType.Layer; var l = FindPoiLayer(p); if (!string.IsNullOrEmpty(p.PoiTypeId) && p.PoiType == null) p.PoiType = Service.PoITypes.FirstOrDefault(k => (k).ContentId == p.PoiTypeId) as PoI; if (p.PoiType == null) { p.PoiType = new PoI { StrokeColor = Colors.White, Service = service, StrokeWidth = 2, DrawingMode = DrawingModes.Polygon }; } if (p.Data == null) p.Data = new Dictionary<string, object>(); p.Data["layer"] = this; var g = new StaticGraphic { Service = Service, Poi = p }; if (p.DrawingMode == DrawingModes.MultiPolygon) { var converted = p.WktText.ConvertFromWkt(); if (converted is MultiPolygon) { // NOTE Others have not been implemented, such as MultiPoint or Path var mp = converted as MultiPolygon; var gs = new List<StaticGraphic>(); foreach (var poly in mp.Polygons) { g = new StaticGraphic {Service = Service, Poi = p}; ConvertPolygonToGraphic(poly, g); g.Layer = this; g.Poi = p; g.Symbol = new SimpleFillSymbol { BorderBrush = new SolidColorBrush(p.NEffectiveStyle.StrokeColor.Value), BorderThickness = p.NEffectiveStyle.StrokeWidth.Value, Fill = new SolidColorBrush(p.NEffectiveStyle.FillColor.Value) { Opacity = p.NEffectiveStyle.FillOpacity.Value } }; l.Graphics.Add(g); gs.Add(g); } p.Data["graphics"] = gs; } else if (converted is MultiLineString) { var ml = converted as MultiLineString; var gs = new List<StaticGraphic>(); foreach (var line in ml.Lines) { g = new StaticGraphic { Service = Service, Poi = p }; ConvertPolylineToGraphic(line, g); g.Layer = this; g.Poi = p; g.Symbol = new SimpleFillSymbol { BorderBrush = new SolidColorBrush(p.NEffectiveStyle.StrokeColor.Value), BorderThickness = p.NEffectiveStyle.StrokeWidth.Value, Fill = new SolidColorBrush(p.NEffectiveStyle.FillColor.Value) { Opacity = p.NEffectiveStyle.FillOpacity.Value } }; l.Graphics.Add(g); gs.Add(g); } p.Data["graphics"] = gs; } } else { g = new StaticGraphic { Service = Service, Poi = p }; g.SetZIndex(p.ZIndex); GetGraphic(p, ref g); l.Graphics.Add(g); p.Data["graphic"] = g; } p.PositionChanged += p_PositionChanged; var height = p.NEffectiveStyle.IconHeight == null ? 32 : p.NEffectiveStyle.IconHeight.Value; var width = p.NEffectiveStyle.IconWidth == null ? 32 : p.NEffectiveStyle.IconWidth.Value; if (p.NEffectiveStyle.DrawingMode.Value == DrawingModes.Point) { if (!string.IsNullOrEmpty(p.NEffectiveStyle.Icon)) { //var ig = new StaticGraphic {Poi = p, Geometry = g.Geometry, Service = Service}; var ig = new Graphic { Geometry = g.Geometry }; if (p.NEffectiveStyle.IconUri.OriginalString.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) { p.NEffectiveStyle.Picture = new BitmapImage(p.NEffectiveStyle.IconUri); } else { var s = Service.MediaFolder + p.NEffectiveStyle.Icon; ig.Attributes["staticgraphic"] = g; if (service.store.HasFile(s)) { p.NEffectiveStyle.Picture = new BitmapImage(new Uri(s)); } } // When image not found display not_found image (so poi is visible on map) /* if (p.NEffectiveStyle.Picture == null) { p.NEffectiveStyle.Picture = LoadImageFromResource("csCommon.Resources.Icons.ImageNotFound.png"); } */ //Fix by Jeroen: Invalid bitmap, don't add if (p.NEffectiveStyle.Picture == null) return; var sym = new PictureMarkerSymbol { Source = p.NEffectiveStyle.Picture, Width = width, Height = height, OffsetX = width / 2, OffsetY = height / 2, }; if (p.Position != null ) sym.Angle = p.Position.Course; ig.Symbol = sym; l.Graphics.Add(ig); ig.MouseLeftButtonDown += (e, st) => g.PoiGraphic_MouseLeftButtonDown(e, st); ig.MouseLeftButtonUp += (e, st) => g.PoiGraphic_MouseLeftButtonUp(e, st); g.ImageGraphic = ig; } } if (p.NEffectiveStyle.TitleMode.HasValue && p.NEffectiveStyle.TitleMode.Value != TitleModes.None) { var sym = new TextSymbol { Text = p.Labels.ContainsKey(p.NEffectiveStyle.NameLabel) ? p.Labels[p.NEffectiveStyle.NameLabel] : string.Empty, FontSize = 12, Foreground = Brushes.Black, //OffsetX = -p.Name.Length * 24, OffsetY = height / -2 }; var tg = new Graphic { Geometry = g.BaseGeometry, Symbol = sym }; tg.Attributes["staticgraphic"] = g; l.Graphics.Add(tg); g.LabelGraphic = tg; } if (!string.IsNullOrEmpty(p.InnerText)) { var sym = new TextSymbol { Text = p.InnerText, FontSize = 16, Foreground = new SolidColorBrush(p.NEffectiveStyle.InnerTextColor.Value), OffsetX = (p.InnerText.Length * 5.0), OffsetY = 8, FontWeight = FontWeights.ExtraBold }; if (p.DrawingMode == DrawingModes.Line || p.DrawingMode == DrawingModes.Polyline) { var p0 = p.Points[0]; var p1 = p.Points[1]; var xdelta = (p1.X - p0.X); var ydelta = (p1.Y - p0.Y); const double rad2Deg = 180.0 / Math.PI; var angle = rad2Deg * Math.Atan2(xdelta, ydelta); sym.OffsetX -= 10 * Math.Cos(angle / rad2Deg); sym.OffsetY -= 10 * Math.Sin(angle / rad2Deg); //angle = (angle + 360.0)%360.0; ////Item is either N or S //if ((angle < 20 || angle > 340) || (angle > 160 && angle < 200)) // sym.OffsetY += 10; ////Item is either NW or SW or NE or SE //else if ((angle > 20 && angle < 70) || (angle > 200 && angle < 250)) //{ // sym.OffsetX += 10; // sym.OffsetY += 10; //} ////Item is either W or E //else if ((angle > 70 && angle < 110) || (angle > 250 && angle < 290)) // sym.OffsetX += 10; ////Item is either NW or SW or NE or SE //else if ((angle > 110 && angle < 160) || (angle > 290 && angle < 340)) //{ // sym.OffsetX += 10; // sym.OffsetY += 10; //} //// else glabel = "dunno!"; } var tg = new Graphic { Geometry = g.BaseGeometry, Symbol = sym }; tg.MouseLeftButtonDown += (e, st) => g.PoiGraphic_MouseLeftButtonDown(e, st); l.Graphics.Add(tg); g.InnerTextGraphic = tg; } g.UpdateScale(); base.AddPoi(p); //p.UpdateAnalysisStyle(); } catch (Exception e) { LogCs.LogException("dsStaticLayer.AddPoi: Exception adding poi icon on map (causes strange behaviour of poi icon (missing eventhandler etc.)) ", e); Logger.Log("dsStaticLayer.AddPoi", "Error adding graphic", e.Message, Logger.Level.Error); } }
private static BaseSymbol GetSymbolFromType(int objectType, byte symType) { BaseSymbol bs = null; switch (objectType) { case 1: bs = new PointSymbol(); break; case 2: if (symType == 0x01) bs = new LineTextSymbol(); else bs = new LineSymbol(); break; case 3: bs = new AreaSymbol(); break; case 4: bs = new TextSymbol(); break; case 5: bs = new RectangleSymbol(); break; default: throw new ApplicationException("Unknown objectType: " + objectType); } return bs; }
public bool WrappedTextFits(object font, string text, RectangleF rect, StringAlignment horizAlignment) { TextSymDef symdef = (TextSymDef) font; PointF baseLocation; float x = rect.Left; float y = rect.Top; baseLocation = Geometry.TransformPoint(new PointF(x, y), currentTransform); // Need to create the symbol to get it's height. TextSymbol symbol = new TextSymbol(symdef, new string[1] { text }, baseLocation, 0, Geometry.TransformDistance(rect.Width, currentTransform), TextSymDefHorizAlignment.Default, TextSymDefVertAlignment.Default); return symbol.TextSize.Height <= Geometry.TransformDistance(rect.Height, currentTransform); }
private void AddSic(string sic) { const double INCREMENT = 2000000; const double HALF_INCREMENT = INCREMENT / 2.0; Message msg = new Message(); msg.Id = Guid.NewGuid().ToString(); msg.Add("_type", "position_report"); msg.Add("_action", "update"); msg.Add("_wkid", "3857"); msg.Add("sic", sic); msg.Add("uniquedesignation", sic); SymbolProperties code = null; if (sidc2SymbolProps.ContainsKey(sic)) code = this.sidc2SymbolProps[sic]; string geoType = "Point"; if (code != null) geoType = code.Values["GeometryType"]; if (geoType == "Point") msg.Add("_control_points", x.ToString() + "," + y.ToString()); else if (geoType == "Line") { double x2 = x + HALF_INCREMENT; msg.Add("_control_points", x.ToString() + "," + y.ToString() + ";" + x2.ToString() + "," + y.ToString()); } else if (geoType == "Polygon") { double yMinusHalf = y - HALF_INCREMENT; double xPlusHalf = x + HALF_INCREMENT; msg.Add("_control_points", x.ToString() + "," + y.ToString() + ";" + xPlusHalf.ToString() + "," + y.ToString() + ";" + xPlusHalf.ToString() + "," + yMinusHalf.ToString() + ";" + x.ToString() + "," + yMinusHalf.ToString() + ";" + x.ToString() + "," + y.ToString()); } var imgSource = _symbolDictionary.GetSymbolImage(sic, 48, 48); var img = new Image(); img.Source = imgSource; swatches.Add(img); ListBox_Swatches.SelectedIndex = swatches.Count - 1; _messageLayer.ProcessMessage(msg); if (!string.IsNullOrEmpty(geoType)) { // var pt = new MapPoint(0, y); var pt = new MapPoint(x, y); var text = sic; if (code != null) text = sic + " : " + code.Values["Category"] + " : " + code.Name ; // The main point of this App // Compare the output of the Exported/Swatch version with the Map Version: // (They should be the same except for some exceptions for patterned lines) var tx = new TextSymbol() { Text = text }; _graphicsLayer.Graphics.Add(new Graphic() { Symbol = tx, Geometry = pt }); var pm = new PictureMarkerSymbol() { Source = imgSource, OffsetX = 128, OffsetY = 64 }; _graphicsLayer.Graphics.Add(new Graphic() { Symbol = pm, Geometry = pt }); } y -= INCREMENT; if (y < -INITIAL_Y) { y = INITIAL_Y; x = x + (3 * INCREMENT); } }
private Symbol CreateTextSymbol(string text) { var ts = new TextSymbol { Text = text, OffsetX = -5, OffsetY = -5, FontSize = 12, FontWeight = FontWeights.Bold }; return ts; }
public async Task Query(string text) { try { if (Controller == null) return; IsLoadingSearchResults = true; text = text.Trim(); if (_searchCancellationTokenSource != null) { if (_currentSearchString != null && _currentSearchString == text) return; _searchCancellationTokenSource.Cancel(); } _searchCancellationTokenSource = new CancellationTokenSource(); var cancellationToken = _searchCancellationTokenSource.Token; Envelope boundingBox = Controller.Extent; if (string.IsNullOrWhiteSpace(text)) return; if (_currentSearchString != null && _currentSearchString != text) { if (!cancellationToken.IsCancellationRequested) _searchCancellationTokenSource.Cancel(); } _searchResultLayer.Graphics.Clear(); var geo = new OnlineLocatorTask(new Uri("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer", UriKind.Absolute), ""); boundingBox = boundingBox.Expand(1.2); _currentSearchString = text; SearchResultStatus = string.Format("Searching for '{0}'...", text.Trim()); var result = await geo.FindAsync(new OnlineLocatorFindParameters(text) { MaxLocations = 25, OutSpatialReference = WebMapVM.SpatialReference, SearchExtent = boundingBox, Location = (MapPoint)GeometryEngine.NormalizeCentralMeridian(boundingBox.GetCenter()), Distance = GetDistance(boundingBox), OutFields = new List<string>() { "PlaceName", "Type", "City", "Country" } }, cancellationToken); // if no results, try again with larger and larger extent var retries = 3; while (result.Count == 0 && --retries > 0) { if (cancellationToken.IsCancellationRequested) return; boundingBox = boundingBox.Expand(2); result = await geo.FindAsync(new OnlineLocatorFindParameters(text) { MaxLocations = 25, OutSpatialReference = WebMapVM.SpatialReference, SearchExtent = boundingBox, Location = (MapPoint)GeometryEngine.NormalizeCentralMeridian(boundingBox.GetCenter()), Distance = GetDistance(boundingBox), OutFields = new List<string>() { "PlaceName", "Type", "City", "Country"} }, cancellationToken); } if (cancellationToken.IsCancellationRequested) return; if (result.Count == 0) { // atfer trying to expand the bounding box several times and finding no results, // let us try finding results without the spatial bound. result = await geo.FindAsync(new OnlineLocatorFindParameters(text) { MaxLocations = 25, OutSpatialReference = WebMapVM.SpatialReference, OutFields = new List<string>() { "PlaceName", "Type", "City", "Country"} }, cancellationToken); if (result.Any()) { // since the results are not bound by any spatial filter, let us show well known administrative // places e.g. countries and cities, and filter out other results e.g. restaurents and business names. var typesToInclude = new List<string>() { "", "city", "community", "continent", "country", "county", "district", "locality", "municipality", "national capital", "neighborhood", "other populated place", "state capital", "state or province", "territory", "village"}; for (var i = result.Count - 1; i >= 0; --i) { // get the result type var resultType = ((string)result[i].Feature.Attributes["Type"]).Trim().ToLower(); // if the result type exists in the inclusion list above, keep it in the list of results if (typesToInclude.Contains(resultType)) continue; // otherwise, remove it from the list of results result.RemoveAt(i); } } } if (result.Count == 0) { SearchResultStatus = string.Format("No results for '{0}' found", text); if (Locations != null) Locations.Clear(); //await new Windows.UI.Popups.MessageDialog(string.Format("No results for '{0}' found", text)).ShowAsync(); } else { SearchResultStatus = string.Format("Found {0} results for '{1}'", result.Count.ToString(), text); Envelope extent = null; var color = (App.Current.Resources["AppAccentBrush"] as SolidColorBrush).Color; var color2 = (App.Current.Resources["AppAccentForegroundBrush"] as SolidColorBrush).Color; SimpleMarkerSymbol symbol = new SimpleMarkerSymbol() { Color = Colors.Black, Outline = new SimpleLineSymbol() { Color = Colors.Black, Width = 2 }, Size = 16, Style = SimpleMarkerStyle.Square }; // set the picture marker symbol used in the search result composite symbol. var imageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Icons/SearchResult.png")); var imageSource = await imageFile.OpenReadAsync(); var pictureMarkerSymbol = new PictureMarkerSymbol(); await pictureMarkerSymbol.SetSourceAsync(imageSource); // apply an x and y offsets so that the tip of of the pin points to the correct location. pictureMarkerSymbol.XOffset = SearchResultPinXOffset; pictureMarkerSymbol.YOffset = SearchResultPinYOffset; int ID = 1; foreach (var r in result) { if (extent == null) extent = r.Extent; else if (r.Extent != null) extent = extent.Union(r.Extent); var textSymbol = new TextSymbol() { Text = ID.ToString(), Font = new SymbolFont() { FontFamily = "Verdena", FontSize = 10, FontWeight = SymbolFontWeight.Bold }, Color = color2, BorderLineColor = color2, HorizontalTextAlignment = Esri.ArcGISRuntime.Symbology.HorizontalTextAlignment.Center, VerticalTextAlignment = Esri.ArcGISRuntime.Symbology.VerticalTextAlignment.Bottom, XOffset = SearchResultPinXOffset, YOffset = SearchResultPinYOffset }; //Looks like Top and Bottom are switched - potential CR // a compsite symbol for both the PictureMarkerSymbol and the TextSymbol could be used, but we // wanted to higlight the pin without the text; therefore, we will add them separately. // add the PictureMarkerSymbol to _searchResultLayer Graphic pin = new Graphic() { Geometry = r.Extent.GetCenter(), Symbol = pictureMarkerSymbol, }; pin.Attributes["ID"] = ID; pin.Attributes["Name"] = r.Name; _searchResultLayer.Graphics.Add(pin); // add the text to _searchResultLayer Graphic pinText = new Graphic() { Geometry = r.Extent.GetCenter(), Symbol = textSymbol, }; pinText.Attributes["ID"] = ID; pinText.Attributes["Name"] = r.Name; _searchResultLayer.Graphics.Add(pinText); ID++; } SetResult(result); base.RaisePropertyChanged("IsClearGraphicsVisible"); if (extent != null) { var _ = SetViewAsync(extent, 50); } } } finally { IsLoadingSearchResults = false; _searchCancellationTokenSource = null; _currentSearchString = null; } }
private static MarkerSymbol cloneMarkerSymbol(MarkerSymbol symbol) { if (symbol == null) return null; ESRI.ArcGIS.Mapping.Core.Symbols.ImageFillSymbol imageFillSymbol = symbol as ESRI.ArcGIS.Mapping.Core.Symbols.ImageFillSymbol; if (imageFillSymbol != null) { ESRI.ArcGIS.Mapping.Core.Symbols.ImageFillSymbol ifs = new ESRI.ArcGIS.Mapping.Core.Symbols.ImageFillSymbol() { Color = CloneBrush(imageFillSymbol.Color), ControlTemplate = imageFillSymbol.ControlTemplate, OffsetX = imageFillSymbol.OffsetX, OffsetY = imageFillSymbol.OffsetY, OriginX = imageFillSymbol.OriginX, OriginY = imageFillSymbol.OriginY, Opacity = imageFillSymbol.Opacity, Size = imageFillSymbol.Size, ImageData = imageFillSymbol.ImageData, Source = imageFillSymbol.Source, Fill = CloneBrush(imageFillSymbol.Fill), CursorName = imageFillSymbol.CursorName, }; return ifs; } ESRI.ArcGIS.Mapping.Core.Symbols.MarkerSymbol ms = symbol as ESRI.ArcGIS.Mapping.Core.Symbols.MarkerSymbol; if (ms != null) { ESRI.ArcGIS.Mapping.Core.Symbols.MarkerSymbol marSymb = new ESRI.ArcGIS.Mapping.Core.Symbols.MarkerSymbol() { DisplayName = ms.DisplayName, Offset = new Point(ms.Offset.X, ms.Offset.Y), Color = CloneBrush(ms.Color), ControlTemplate = ms.ControlTemplate, OffsetX = ms.OffsetX, OffsetY = ms.OffsetY, OriginX = ms.OriginX, OriginY = ms.OriginY, Opacity = ms.Opacity, Size = ms.Size, }; return marSymb; } ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol simpleMarkerSymbol = symbol as ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol; if (simpleMarkerSymbol != null) { ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol sms = new ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol() { Color = CloneBrush(simpleMarkerSymbol.Color), ControlTemplate = simpleMarkerSymbol.ControlTemplate, Size = simpleMarkerSymbol.Size, // Simple marker symbol doesn't allow setting OffsetX, OffsetY }; return sms; } TextSymbol textSymbol = symbol as TextSymbol; if (textSymbol != null) { TextSymbol ts = new TextSymbol() { ControlTemplate = textSymbol.ControlTemplate, FontFamily = textSymbol.FontFamily, FontSize = textSymbol.FontSize, Foreground = CloneBrush(textSymbol.Foreground), OffsetX = textSymbol.OffsetX, OffsetY = textSymbol.OffsetY, Text = textSymbol.Text, }; return ts; } PictureMarkerSymbol pictureMarkerSymbol = symbol as PictureMarkerSymbol; if (pictureMarkerSymbol != null) { PictureMarkerSymbol pictMs = new PictureMarkerSymbol() { ControlTemplate = pictureMarkerSymbol.ControlTemplate, Height = pictureMarkerSymbol.Height, OffsetX = pictureMarkerSymbol.OffsetX, OffsetY = pictureMarkerSymbol.OffsetY, Opacity = pictureMarkerSymbol.Opacity, Source = pictureMarkerSymbol.Source, Width = pictureMarkerSymbol.Width, }; return pictMs; } MarkerSymbol markerS = new MarkerSymbol() { ControlTemplate = symbol.ControlTemplate, OffsetX = symbol.OffsetX, OffsetY = symbol.OffsetY, }; return markerS; }
private void WorkflowA(object sender, RoutedEventArgs e) { ClearGraphics(); Button button = sender as Button; if (_mapPoints == null) _mapPoints = GenerateRandomPoints(_numberOfPoints); SymbolFont font = new SymbolFont { FontFamily = "Tahoma", FontSize = 12, FontStyle = SymbolFontStyle.Italic, FontWeight = SymbolFontWeight.Bold, TextDecoration = SymbolTextDecoration.Underline }; TextSymbol symbol; switch (button.Name) { case "Button01": symbol = new TextSymbol { Font = font }; break; case "Button02": symbol = new TextSymbol { Font = font, Color = Colors.DarkGreen }; break; case "Button03": symbol = new TextSymbol { Font = font, Color = Colors.DarkGreen, BorderLineColor = Colors.White, BorderLineSize = 1 }; break; case "Button04": symbol = new TextSymbol { Font = font, Color = Colors.DarkGreen, BorderLineColor = Colors.White, BorderLineSize = 1, BackgroundColor = Colors.Red }; break; default: symbol = new TextSymbol(); break; } for (int i = 0; i < _mapPoints.Length; i++) { symbol.Text = i.ToString(CultureInfo.InvariantCulture); MyGraphicsLayer.Graphics.Add(new Graphic {Geometry = _mapPoints[i], Symbol = symbol}); } }
// *********************************************************************************** // * Add a from location point on the map... closest facility will be found for this location // *********************************************************************************** void SolveClosestFacility_Completed(object sender, RouteEventArgs e) { _routesGraphicsLayer.Graphics.Clear(); _routeLabelsGraphicsLayer.Graphics.Clear(); if (e.RouteResults != null) { int i = 0; Random randomGen = new Random(); foreach (RouteResult route in e.RouteResults) { Graphic routeGraphic = route.Route; Color color = createRandomColor(randomGen); randomGen.Next(255); routeGraphic.Symbol = new SimpleLineSymbol() { Width = 5, Color = new SolidColorBrush(color) }; _routesGraphicsLayer.Graphics.Add(routeGraphic); //Route rank identification symbols... client.Geometry.Polyline pl = (client.Geometry.Polyline)routeGraphic.Geometry; int index = pl.Paths[0].Count / 4; Graphic squareGraphic = new Graphic(); client.Geometry.PointCollection ptColl = pl.Paths[pl.Paths.Count/2]; squareGraphic.Geometry = ptColl[ptColl.Count / 2]; //this is the white outline... SimpleMarkerSymbol sms = new SimpleMarkerSymbol() { Style = SimpleMarkerSymbol.SimpleMarkerStyle.Square, Size = 24, Color = new SolidColorBrush(Color.FromRgb(255, 255, 255)), }; squareGraphic.Symbol = sms; _routeLabelsGraphicsLayer.Graphics.Add(squareGraphic); //purple rectangle behind the rank number Graphic squareGraphic2 = new Graphic(); SimpleMarkerSymbol sms2 = new SimpleMarkerSymbol() { Style = SimpleMarkerSymbol.SimpleMarkerStyle.Square, Size = 20, Color = new SolidColorBrush(Color.FromRgb(0,0,139)) }; squareGraphic2.Symbol = sms2; squareGraphic2.Geometry = ptColl[ptColl.Count / 2]; _routeLabelsGraphicsLayer.Graphics.Add(squareGraphic2); //rank number text symbol Graphic routeRankGraphic = new Graphic(); routeRankGraphic.Geometry = ptColl[ptColl.Count / 2]; TextSymbol routeRankSymbol = new TextSymbol(); routeRankSymbol.FontFamily = new FontFamily("Arial Black"); //Modified offsetx from -4 to 5 routeRankSymbol.OffsetX = 5; routeRankSymbol.OffsetY = 10; routeRankSymbol.Text = e.RouteResults[i].Directions.RouteID.ToString(); routeRankSymbol.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); routeRankSymbol.FontSize = 16; routeRankGraphic.Symbol = routeRankSymbol; _routeLabelsGraphicsLayer.Graphics.Add(routeRankGraphic); i++; } //zoom to the map if (chkZoomToMap.IsChecked ?? false) _mapWidget.Map.Extent = _routesGraphicsLayer.FullExtent; //Create and Display Closest Facilities List window... _result = new FindCloseFacilityResultView(this, e.RouteResults, _mapWidget); _mapWidget.SetToolbar(_result); } }
protected override void AddToMap(Map map, SymDef symdef) { TextSymbol sym = new TextSymbol((TextSymDef) symdef, new string[1] { text }, topLeft, 0, 0, TextSymDefHorizAlignment.Default, TextSymDefVertAlignment.Default); /*Show size of text * PointF[] pts = { topLeft, new PointF(topLeft.X, topLeft.Y - size.Height), new PointF(topLeft.X + size.Width, topLeft.Y - size.Height), new PointF(topLeft.X + size.Width, topLeft.Y), topLeft }; PointKind[] kinds = { PointKind.Normal, PointKind.Normal, PointKind.Normal, PointKind.Normal, PointKind.Normal }; SymPathWithHoles path = new SymPathWithHoles(new SymPath(pts, kinds), null); AreaSymbol sym = new AreaSymbol((AreaSymDef) symdef, path, 0); */ map.AddSymbol(sym); }
public void DrawSingleLineText(object font, string text, RectangleF rect, StringAlignment horizAlignment) { TextSymDef symdef = (TextSymDef) font; PointF baseLocation; // base location of the text -- top of the character. // Place the top of the character at 1/2 the height of the character above the vertical mid-line of the rectangle. float x = rect.Left; float y = (rect.Top + rect.Bottom) / 2; // mid-point. float width = Geometry.TransformDistance(rect.Width, currentTransform); baseLocation = Geometry.TransformPoint(new PointF(x, y), currentTransform); baseLocation.Y += (symdef.FontAscent + symdef.FontDescent) / 2; // half the character height. if (horizAlignment == StringAlignment.Center) baseLocation.X += width / 2; else if (horizAlignment == StringAlignment.Far) baseLocation.X += width; TextSymbol symbol = new TextSymbol(symdef, new string[1] { text }, baseLocation, 0, width, TextSymDefHorizAlignment.Default, TextSymDefVertAlignment.Default); map.AddSymbol(symbol); }
public void DrawWrappedText(object font, string text, RectangleF rect, StringAlignment horizAlignment) { TextSymDef symdef = (TextSymDef) font; PointF baseLocation; // base location of the text -- top of the character. // Place the top of the character at 1/2 the height of the text above the vertical med-line of the rectangle. float x = rect.Left; float y = (rect.Top + rect.Bottom) / 2; // mid-point. float width = Geometry.TransformDistance(rect.Width, currentTransform); baseLocation = Geometry.TransformPoint(new PointF(x, y), currentTransform); // Need to create the symbol to get it's height, which is needed to correctly place it. So we create the symbol twice. TextSymbol symbol = new TextSymbol(symdef, new string[1] { text }, baseLocation, 0, width, TextSymDefHorizAlignment.Default, TextSymDefVertAlignment.Default); baseLocation.Y += symbol.TextSize.Height / 2; if (horizAlignment == StringAlignment.Center) baseLocation.X += width / 2; else if (horizAlignment == StringAlignment.Far) baseLocation.X += width; symbol = new TextSymbol(symdef, new string[1] { text }, baseLocation, 0, width, TextSymDefHorizAlignment.Default, TextSymDefVertAlignment.Default); map.AddSymbol(symbol); }