【问题标题】:Drawing onto ESRI.ArcGIS.Client.FeatureLayer with a specific color使用特定颜色绘制到 ESRI.ArcGIS.Client.FeatureLayer
【发布时间】:2015-07-06 07:06:53
【问题描述】:

我正在尝试构建一个功能,让用户可以使用特定颜色绘制到特定功能图层上。通过更改 FeatureLayer.Renderer,图层上的所有注释都会更改为指定的颜色,即使是之前会话中的注释。我希望能够在那里使用特定颜色的旧注释,并使用特定颜色(可能不同)绘制新注释。

这是定义地图和要素图层的 XAML

    <UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="GraphicsDictionary.xaml" x:Name="LineSymbolResourceDictionary"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

<Grid Name="MapGrid">
    <esri:Map x:Name="MyMap">

        <esri:ArcGISTiledMapServiceLayer 
            ID="StreetMapLayer" 
            x:Name="BaseMap"
            Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" 
            >
        </esri:ArcGISTiledMapServiceLayer>

        <esri:FeatureLayer 
            ID="MyFeatureLayer" 
            x:Name="MyFeatureLayer"
            Url="http://123.123.123.12:6080/arcgis/rest/services/Prj/FeatureServer/0" 
            Renderer="{StaticResource BlueSimpleRenderer}"
            EndSaveEdits="drawLayer_EndSaveEdits" 
            >
        </esri:FeatureLayer>
    </esri:Map>
</Grid>

资源字典:

<ResourceDictionary 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esriSymbols="clr-namespace:ESRI.ArcGIS.Client.Symbols;assembly=ESRI.ArcGIS.Client" 
xmlns:esri="clr-namespace:ESRI.ArcGIS.Client;assembly=ESRI.ArcGIS.Client"
x:Class="ClassName.GraphicsDictionary"
>

<esri:SimpleRenderer x:Key="BlueSimpleRenderer">
    <esri:SimpleRenderer.Symbol>
        <esriSymbols:SimpleLineSymbol x:Name="BlueLineSymbol" Color="#00007F" Width="5"/>
    </esri:SimpleRenderer.Symbol>
</esri:SimpleRenderer>

绘图的 C# 代码:

public void StartDrawing(FeatureLayer inputLayer, string inputColorInHex)
{
    MyMap.Cursor = System.Windows.Input.Cursors.Pen;
    //Below's the color that might be different from the original renderer
    SimpleRenderer newRend= new SimpleRenderer 
    { 
       Symbol = new SimpleLineSymbol((Color)ColorConverter.ConvertFromString(inputColorInHex), 12)        
    };
    inputLayer.Renderer = newRend as IRenderer;
    MyDrawObject.DrawMode = ESRI.ArcGIS.Client.DrawMode.Freehand;
    MyDrawObject.IsEnabled = true;
}

【问题讨论】:

    标签: c# wpf arcgis


    【解决方案1】:

    渲染器适用于图层中的所有功能(图形),因此如果您想使用渲染器,您可以使用唯一值渲染器并为不同的属性值设置不同的样式,但这意味着您知道在定义时要使用哪些值颜色。同样,如果您想根据一系列值控制颜色,则可以使用分类中断渲染器。

    在您的情况下,您可能只想为功能设置特定符号,因为符号将覆盖渲染器。您只需将符号应用于图形以便使用它。例如

    var markerSym = new Esri.ArcGISRuntime.Symbology.SimpleMarkerSymbol
    {
        Style = Esri.ArcGISRuntime.Symbology.SimpleMarkerStyle.Diamond,
        Color = Colors.Green,
        Size = 18
    };
    
    var pointGraphic = new Esri.ArcGISRuntime.Layers.Graphic(point, markerSym);
    
    graphicsLayer.Graphics.Add(pointGraphic);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-15
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多