示例#1
0
        StyleLayer CreateStyleLayer(MGLVectorStyleLayer vectorLayer, string layerId = null)
        {
            if (vectorLayer is MGLSymbolStyleLayer sl && sl.IconImageName != null)
            {
                var newLayer = new SymbolLayer(layerId ?? vectorLayer.Identifier, vectorLayer.SourceIdentifier.TrimCustomId());
                if (sl.IconImageName is MGLCameraStyleFunction csFunc)
                {
                    var imgName = GetValueFromCameraStyleFunction(csFunc);
                    if (imgName != null)
                    {
                        newLayer.IconImageName = imgName.ToString();
                    }
                }
                else
                {
                    var imgName = GetObjectFromStyleValue(sl.IconImageName);
                    if (imgName != null)
                    {
                        newLayer.IconImageName = imgName.ToString();
                    }
                }
                return(newLayer);
            }

            if (vectorLayer is MGLLineStyleLayer ll)
            {
                var newLayer = new LineLayer(layerId ?? vectorLayer.Identifier, vectorLayer.SourceIdentifier.TrimCustomId())
                {
                    LineColor = (GetObjectFromStyleValue(ll.LineColor) as UIColor).ToColor()
                };

                if (ll.LineDashPattern != null)
                {
                    if (GetObjectFromStyleValue(ll.LineDashPattern) is NSArray arr && arr.Count != 0)
                    {
                        var dash = new List <double>();
                        for (nuint i = 0; i < arr.Count; i++)
                        {
                            var obj = arr.GetItem <NSNumber>(i);
                            dash.Add(obj.DoubleValue);
                        }
                        newLayer.Dashes = dash.ToArray();
                    }
                    else
                    {
                        //TODO
                    }
                }
                return(newLayer);
            }
        StyleLayer CreateStyleLayer(MGLVectorStyleLayer vectorLayer, string layerId = null)
        {
            if (vectorLayer is MGLSymbolStyleLayer sl)
            {
                var newLayer = new SymbolLayer(layerId ?? vectorLayer.Identifier, vectorLayer.SourceIdentifier.TrimCustomId());
                if (sl.IconImageName is NSExpression csFunc)
                {
                    var imgName = GetValueFromExpression <NSString>(sl.IconImageName);
                    if (imgName != null)
                    {
                        newLayer.IconImageName = imgName.ToString();
                    }
                }
                else
                {
                    var imgName = GetValueFromExpression <NSString>(sl.IconImageName);
                    if (imgName != null)
                    {
                        newLayer.IconImageName = imgName.ToString();
                    }
                }
                return(newLayer);
            }

            if (vectorLayer is MGLLineStyleLayer ll)
            {
                var newLayer = new LineLayer(layerId ?? vectorLayer.Identifier, vectorLayer.SourceIdentifier.TrimCustomId())
                {
                    LineColor = (GetValueFromExpression <UIColor>(ll.LineColor) as UIColor).ToColor()
                };

                if (ll.LineDashPattern != null)
                {
                    if (GetValueFromExpression <NSArray>(ll.LineDashPattern) is NSArray arr && arr.Count != 0)
                    {
                        var dash = new List <double>();
                        for (nuint i = 0; i < arr.Count; i++)
                        {
                            var obj = arr.GetItem <NSObject>(i);
                            switch (obj)
                            {
                            case NSExpression expression:
                                if (expression.ExpressionType == NSExpressionType.ConstantValue)
                                {
                                    var number = GetValueFromExpression <NSNumber>(expression);
                                    dash.Add(number.DoubleValue);
                                }
                                break;

                            case NSNumber number:
                                dash.Add(number.DoubleValue);
                                break;

                            default:
                                break;
                            }
                        }
                        newLayer.Dashes = dash.ToArray();
                    }
                    else
                    {
                        //TODO
                    }
                }
                return(newLayer);
            }