问题描述
我在 Xamarin Forms 项目中使用 Naxam MapBox 项目。 单击标记并在信息窗口中有文本时,我能够生成一个弹出窗口。 在 Android 上,我可以通过传递一个 float[] 来将 Padding 添加到 IconTextFitPadding,这会一直在文本上添加漂亮的填充。但是在 IOS 中它会抛出异常。 “'Objective-C 异常抛出。名称:NSRangeException 原因:*** -[__NSArrayI objectAtIndexedSubscript:]:索引 4 超出范围 [0 .. 3]”
如果我只传递一个浮点值,那么它会在顶部添加填充并且不会抛出任何错误。
请在下面找到实现的代码。 我还包含了弹出窗口在 IOS 和 Android 上的外观图片。
private SymbolLayer GetLayerInfowWindow(CustomPinType pinType)
{
FormatEntry newLine = Expression.CreateFormatEntry("\n",FormatOption.FormatFontScale(0.5));
FormatEntry feRegistration = Expression.CreateFormatEntry(
Expression.Get("registration"),FormatOption.FormatFontScale(1.2),FormatOption.FormatTextColor(Color.Black),FormatOption.FormatTextFont(new[]
{
"Arial Unicode MS Regular"
})
);
FormatEntry feDateTime = Expression.CreateFormatEntry(
Expression.Get("datetime"),FormatOption.FormatFontScale(1.0),FormatOption.FormatTextColor(Color.FromHex("#545252")),FormatOption.FormatTextFont(new[] {
"Arial Unicode MS Regular"
})
);
FormatEntry feException = Expression.CreateFormatEntry(
Expression.Get("exceptions"),FormatOption.FormatTextColor(Color.FromHex("#ee0000")),FormatOption.FormatTextFont(new[] {
"Arial Unicode MS Regular"
})
);
FormatEntry feStart = Expression.CreateFormatEntry(
Expression.Concat("Trip start"),FormatOption.FormatTextFont(new[] {
"Arial Unicode MS Regular"
})
);
FormatEntry feEnd = Expression.CreateFormatEntry(
Expression.Concat("Trip end"),FormatOption.FormatTextFont(new[] {
"Arial Unicode MS Regular"
})
);
FormatEntry feSpeed = Expression.CreateFormatEntry(
Expression.Concat("Max speed: ",Expression.Get("speed"),"km/h\r\n"),FormatOption.FormatTextFont(new[] {
"Arial Unicode MS Regular"
})
);
string symbolName = pinType.ToString().ToLower();
SymbolLayer symbol = new SymbolLayer($"layer.popup.{symbolName}.{PINSID}",$"source.{PINSID}")
{
Filter = Expression.All(
Expression.Eq(Expression.Get("selected"),Expression.Literal(true)),Expression.Eq(Expression.Get("pintype"),Expression.Literal(symbolName))
),IconAllowOverlap = Expression.Bool(false),IconPadding = 10,SymbolPlacement = "point",IconImage = $"image.infowindow",IconTextFit = "both",// scale balloon to text
IconPitchAlignment = "viewport",// aligned to the plane of the viewport.
IconAnchor = "bottom",IconKeepUpright = Expression.Bool(true),// flip with screen
IconColor = Color.FromHex("FFFFFF"),Iconopacity = 1.0,// default is 1
IconTextFitPadding = (new float[]
{
5f,// top,10f,// right,15f,// bottom,10f // left.
}),IconOffset = (new float[] {
0f,// right
0f // down
}),// move anchor // right down
IconTranslate = (new float[] {
0.0f,// right
-1.0f // down
}),TextSize = 16,TextPitchAlignment = "viewport",// aligned to the plane of the viewport.
TextKeepUpright = Expression.Bool(true),// flip with screen
TextAnchor = "bottom",TextJustify = "left",TextOpacity = 1.0,TextOffset = (new float[] {
0.0f,TextTranslate = (new float[] {
0.0f,0.0f
}),TextAllowOverlap = Expression.Bool(false),IconIgnorePlacement = Expression.Bool(false),TextIgnorePlacement = Expression.Bool(false)
};
switch (pinType)
{
case (CustomPinType.TripStart):
symbol.TextField = Expression.Format(feRegistration,newLine,feDateTime,feStart);
break;
case (CustomPinType.TripArrow):
symbol.TextField = Expression.Format(feRegistration,feSpeed);
break;
case (CustomPinType.TripExceptionArrow):
symbol.TextField = Expression.Format(feRegistration,feSpeed,feException,newLine);
break;
case (CustomPinType.TripEnd):
symbol.TextField = Expression.Format(feRegistration,feEnd);
break;
}
return symbol;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)