【问题标题】:Issue with Creating a symbol on an ESRI Map在 ESRI 地图上创建符号的问题
【发布时间】:2019-05-24 20:24:41
【问题描述】:

我的 MVVM 客户端应用程序从 ESRI.ArcGISRuntime.Toolkit v10.2.7.0 进入 ESRI ArcGISRuntime v100.1 时遇到问题,我用来定位停靠点的符号不是随机创建的。我将 List 传递给以下方法:

 private async void SetMapSymbols()
    {
        var previousLayer = GraphicsLayer[SEARCH_LAYER];
        GraphicsLayer.Remove(previousLayer);

        var graphicsOverlay = new GraphicsOverlay() { Id = SEARCH_LAYER };
        var graphicList = new List<Graphic>();

        int order = 0;

        foreach (ObjectInfoModel entry in ObjectList)
        {
            order++;

            if (entry.SiteGeoLat == null || entry.SiteGeoLong == null) continue;

            var pointAttribList = ConvertObjectToDictionary(entry);
            DictionaryUtility.AddItemTodictionaryAttribute(pointAttribList, ORDER_ATTRIBUTE, order.ToString());
            var geo = entry.AltSiteGeoLat != null && entry.AltSiteGeoLong != null ? WebMercatorUtility.ConvertToMercator(entry.AltSiteGeoLong.Value, entry.AltSiteGeoLat.Value) : WebMercatorUtility.ConvertToMercator(entry.SiteGeoLong.Value, entry.SiteGeoLat.Value);
            var graphic = new Graphic(
                        new MapPoint(geo.Lon, geo.Lat, new SpatialReference(SPATIAL_REFERENCE)),
                        pointAttribList,
                     string.IsNullOrEmpty(entry.Area) ? await SymbolUtility.CreateSymbols(order.ToString(), SymbolTypes.Blue, SymbolShapes.Pin) :
                                                                await SymbolUtility.CreateSymbols(order.ToString(), SymbolTypes.Red, SymbolShapes.Arrow));
            if (entry.SiteGeoTypeCode != MAPPABLE)
            {
                graphic.Symbol = string.IsNullOrEmpty(entry.Area) ? await SymbolUtility.CreateSymbols(order.ToString(), SymbolTypes.Blue, SymbolShapes.Pin2) :
                                                                             await SymbolUtility.CreateSymbols(order.ToString(), SymbolTypes.Red, SymbolShapes.Arrow2);
            }

            graphicList.Add(graphic);

        }

        graphicList.ForEach(x => graphicsOverlay.Graphics.Add(x));
        GraphicsLayer.Add(graphicsOverlay);
    }

如您所见,它等待 SymbolUtility 为列表中的每个项目创建一个符号。所以这里是那个方法:

        public static async Task<Symbol> CreateSymbols(string text, SymbolTypes type, SymbolShapes shape)
    {
        var iconPath = string.Empty;
        iconPath = string.Format(@"pack://application:,,,/Images/{0}_{1}.png", type.ToString(), shape.ToString());

        var pc = new PictureMarkerSymbol(new Uri(iconPath, UriKind.RelativeOrAbsolute));
        pc.Width = 30;
        pc.Height = 30;

        var cm = new CompositeSymbol();
        var ts = new TextSymbol()
        {
            Color = Colors.Black,
            FontStyle = FontStyle.Normal,
            FontDecoration = FontDecoration.None,
            FontFamily = "Arial",
            FontWeight = FontWeight.Bold,
            Size = 14,
            VerticalAlignment = VerticalAlignment.Middle,
            HorizontalAlignment = HorizontalAlignment.Center,
            OffsetY = shape == SymbolShapes.Arrow ? 5 : 0
        };

        ts.Text = text;
        cm.Symbols.Add(pc);
        cm.Symbols.Add(ts);

        return await Task.Factory.StartNew<Symbol>(() => { return cm; });
    }

PNG 文件与实用程序位于同一解决方案中,但不是同一项目。 发生的问题是符号不会随机呈现 PNG 部分,但总是会返回符号的文本部分。

如果有人对此有任何想法,我将不胜感激。

【问题讨论】:

    标签: symbols esri arcgis-runtime arcgis-runtime-net


    【解决方案1】:

    如果在图像控件中使用了图标路径,您看到图像了吗?可能是图标路径不正确或构建操作或复制到输出目录需要更改(请参阅:msdn doc)如果图标路径良好,符号是否在 CompositeSymbol 外部呈现(仅使用 PictureMarkerSymbol)?如果是,是否可以通过将 SDK 更新到 100.4 或更新 GraphicsRenderingMode 或放大/缩小地图来解决?

    我无法使用以下代码重现 note.png 添加为内容,如果更新则复制。

    MyMapView.Map = new Map(SpatialReferences.Wgs84);
    var symbol = new CompositeSymbol();
    symbol.Symbols.Add(new PictureMarkerSymbol(new Uri("pack://application:,,,/note.png")));
    symbol.Symbols.Add(new TextSymbol("1", Color.Black, 10, Esri.ArcGISRuntime.Symbology.HorizontalAlignment.Center, Esri.ArcGISRuntime.Symbology.VerticalAlignment.Middle));
    var overlay = new GraphicsOverlay();
    overlay.Graphics.Add(new Graphic(new MapPoint(0, 0), symbol));
    MyMapView.GraphicsOverlays.Add(overlay);
    

    ArcGIS Runtime 开发人员可能会在forum 中为您提供帮助。

    【讨论】:

    • 我知道PNG图像的路径很好,放大和缩小并不能修复图标,就像上面的片段一样。唯一能解决的就是重新加载地图。我明天可以试试你使用的格式。非常感谢您的建议和链接。如果您的建议没有帮助,我会去那里。
    • 不幸的是,这并没有解决我的问题。但是,它是一种更简洁的方式来构造符号,所以我仍然会使用它。
    猜你喜欢
    • 2016-11-07
    • 2013-11-17
    • 1970-01-01
    • 1970-01-01
    • 2022-01-01
    • 2015-07-09
    • 1970-01-01
    • 2022-01-03
    • 2014-09-08
    相关资源
    最近更新 更多