我的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部分,但将始终返回该符号的文本部分。
如果有人对此有任何想法,我将不胜感激。
答案 0 :(得分:1)
如果在Image控件中使用了图标路径,您是否看到了图像?可能是图标路径不正确,或者需要更改生成操作或复制到输出目录(请参见: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中为您提供帮助。