Exemple #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            View.AddSubview(tableView);
            tableView.MakeConstraints((mk) =>
            {
                mk.Edges.EqualTo(View);
            });
            var groupsDict = new Dictionary <string, List <DisplayedLayer> >();

            foreach (MGLStyleLayer layer in Style.Layers)
            {
                DisplayedLayer newLayer = null;

                var gn = "No group";

                if (layer is MGLVectorStyleLayer vl)
                {
                    if (vl is MGLSymbolStyleLayer sl && sl.IconImageName != null)
                    {
                        newLayer = new ImageLayer()
                        {
                            Id = layer.Identifier
                        };
                        if (sl.IconImageName is MGLCameraStyleFunction csFunc)
                        {
                            var imgName = GetValueFromCameraStyleFunction(csFunc);
                            if (imgName != null)
                            {
                                (newLayer as ImageLayer).Image = Style.ImageForName(imgName.ToString());
                            }
                        }
                        else
                        {
                            var imgName = GetObjectFromStyleValue(sl.IconImageName);
                            if (imgName != null)
                            {
                                (newLayer as ImageLayer).Image = Style.ImageForName(imgName.ToString());
                            }
                        }
                    }
                    else if (vl is MGLLineStyleLayer ll)
                    {
                        newLayer = new LineLayer()
                        {
                            Id        = layer.Identifier,
                            LineColor = GetObjectFromStyleValue(ll.LineColor) as UIColor
                        };

                        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 as LineLayer).Dashes = dash.ToArray();
                            }
                            else
                            {
                            }
                        }
                    }
Exemple #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            View.AddSubview(tableView);
            tableView.MakeConstraints((mk) =>
            {
                mk.Edges.EqualTo(View);
            });
            var groupsDict = new Dictionary <string, List <DisplayedLayer> >();

            foreach (MGLStyleLayer layer in Style.Layers)
            {
                DisplayedLayer newLayer = null;

                var gn = "No group";

                if (layer is MGLVectorStyleLayer vl)
                {
                    if (vl is MGLSymbolStyleLayer sl)
                    {
                        if (GetValueFromExpression <NSString>(sl.IconImageName) is NSString iconName)
                        {
                            newLayer = new ImageLayer()
                            {
                                Id = layer.Identifier
                            };
                            (newLayer as ImageLayer).Image = Style.ImageForName(iconName);
                        }
                        else
                        {
                            newLayer = new TextLayer()
                            {
                                Id        = layer.Identifier,
                                TextColor = GetValueFromExpression <UIColor>(sl.TextColor)
                            };
                        };
                    }
                    else if (vl is MGLLineStyleLayer ll)
                    {
                        newLayer = new LineLayer()
                        {
                            Id        = layer.Identifier,
                            LineColor = GetValueFromExpression <UIColor>(ll.LineColor)
                        };

                        //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<NSExpression>(i);
                        //            if (GetValueFromExpression<NSNumber>(obj) is NSNumber num)
                        //            {
                        //                dash.Add(num.DoubleValue);
                        //            }
                        //        }
                        //        (newLayer as LineLayer).Dashes = dash.ToArray();
                        //    }
                        //    else
                        //    {
                        //        //TODO
                        //    }
                        //}
                    }
                    else if (vl is MGLCircleStyleLayer cl)
                    {
                        newLayer = new CircleLayer()
                        {
                            Id        = layer.Identifier,
                            FillColor = GetValueFromExpression <UIColor>(cl.CircleColor)
                        };
                    }
                    else if (vl is MGLFillStyleLayer fl)
                    {
                        newLayer = new FillLayer()
                        {
                            Id          = layer.Identifier,
                            FillColor   = GetValueFromExpression <UIColor>(fl.FillColor),
                            FillOpacity = GetValueFromExpression <NSNumber>(fl.FillOpacity)?.NFloatValue ?? 1.0f
                        };
                    }

                    if (!string.IsNullOrEmpty(vl.SourceLayerIdentifier))
                    {
                        gn = vl.SourceLayerIdentifier;
                    }
                }
                if (newLayer != null)
                {
                    if (groupsDict.ContainsKey(gn))
                    {
                        groupsDict[gn].Add(newLayer);
                    }
                    else
                    {
                        var lst = new List <DisplayedLayer>()
                        {
                            newLayer
                        };
                        groupsDict.Add(gn, lst);
                    }
                }
            }
            var groupList = new List <LayerGroup>();

            foreach (string gn in groupsDict.Keys)
            {
                groupList.Add(new LayerGroup()
                {
                    Info = new MapboxGroup()
                    {
                        Name = gn
                    },
                    Layers = groupsDict[gn].ToArray()
                });
            }
            groups = groupList.ToArray();
        }