I am trying to create Composite Symbols that contain both a Picture Marker Symbol and a Text Symbol.
for some reason, the picture Marker Symbol is not consistently created in the composite symbol. So I am hoping that someone here can see what has been done wrong and help me out. Using C#, here is my code:
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 (RequestInfoModel entry in PermitList)
{
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.InspectorArea) ? 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.InspectorArea) ? 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);
}
as you can see, i am awaiting the SymbolUtility, so here is that code:
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 pc; });
}
here is a screen grab of 1 symbol that generated properly, and 2 that didn't:
I have created a thread on StackOverflow here, but a person there directed me here to ask. Thank you for reading this far. any help would be greatly appreciated.
UPDATE:
Here is the additional info requested below:
the graphic.Geometry :
{"x":-13703208.904060207,"y":5882055.3633824475,"spatialReference":{"wkid":102100,"latestWkid":3857}}
the Spatial Reference = 3857
I will try that first thing tomorrow, since I reverted back to 4.6.0 today already.
Completing this is not an option for me, due to time constraints and the regression testing needed to ensure it was done properly.
Quick Question though:
What type of files could be used as a PictureMarkerSymbol? I am thinking that the .PNG files might not scale well to a vector tile base map, and the visible extent, so I was going to try converting to a .SVG file. But thats a lot of work, so I want to be sure the object can render it properly.