Esempio n. 1
0
		private void initializePinsLayer()
		{
			// Just initialize with empty so that it's guaranteed that there are sources initiated
			// when the pins collection is still null
			var mapLockedPinsSource = new MGLShapeSource(mapLockedPinsSourceKey, new NSObject[]{}, null);
			nStyle.AddSource(mapLockedPinsSource);

			// Pins with bearings layer - configure elements
			var mapLockedPinsLayer = new MGLSymbolStyleLayer(mapLockedPinsKey, mapLockedPinsSource) {
				IconImageName = NSExpression.FromKeyPath(pin_image_key),
				IconRotation = NSExpression.FromKeyPath(pin_rotation_key),
				IconScale = NSExpression.FromKeyPath(pin_size_key),
				IconRotationAlignment = NSExpression.FromConstant(NSObject.FromObject("map")), // Finally the map-lock flat = "map"
				IconAllowsOverlap = NSExpression.FromConstant(NSObject.FromObject(true)) // Always overlap
			};
			nStyle.AddLayer(mapLockedPinsLayer);

			// Just initialize with empty so that it's guaranteed that there are sources initiated
			// when the pins collection is still null
			var normalPinsSource = new MGLShapeSource(normalPinsSourceKey, new NSObject[] { }, null);
			nStyle.AddSource(normalPinsSource);

			// Normal pins layer - configure elements
			var normalPinsLayer = new MGLSymbolStyleLayer(normalPinsKey, normalPinsSource) {
				IconImageName = NSExpression.FromKeyPath(pin_image_key),
				IconScale = NSExpression.FromKeyPath(pin_size_key),
				IconOffset = NSExpression.FromKeyPath(pin_offset_key), //https://www.mapbox.com/mapbox-gl-js/style-spec/#layout-symbol-icon-offset
				IconAnchor = NSExpression.FromConstant(NSObject.FromObject("bottom")), // https://www.mapbox.com/mapbox-gl-js/style-spec/#layout-symbol-icon-anchor = "bottom" or "center"
				IconAllowsOverlap = NSExpression.FromConstant(NSObject.FromObject(true))
			};
			nStyle.AddLayer(normalPinsLayer);
		}
Esempio n. 2
0
        static NSExpression ToExpression(NSObject @object)
        {
            switch (@object)
            {
            case NSArray array:
                return(ToExpression(array));

            case NSString @string:
            case NSNumber number:
            case NSValue value:
                return(NSExpression.FromConstant(@object));

            case NSDictionary dict: {
                var dictionary = new NSMutableDictionary();

                foreach (var key in dict.Keys)
                {
                    dictionary[key] = ToExpression(dict[key]);
                }

                return(NSExpression.FromConstant(dictionary));
            }
            }

            if (@object == null || @object.Equals(NSNull.Null))
            {
                return(NSExpressionAdditions.FromConstant(null));
            }

            return(null);
        }
 public void WeakFramework()
 {
     using (var exp = new NSExpression(NSExpressionType.Block))
         using (var context = new NSExpression(NSExpressionType.EvaluatedObject))
             using (var fetch = NSFetchRequestExpression.FromFetch(exp, context, false))
                 Assert.That(exp.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
 }
 public void GetContext()
 {
     using (var exp = new NSExpression(NSExpressionType.Block))
         using (var context = new NSExpression(NSExpressionType.EvaluatedObject))
             using (var fetch = NSFetchRequestExpression.FromFetch(exp, context, false))
                 Assert.NotNull(fetch.Context);
 }
Esempio n. 5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            //MGLAccountManager.AccessToken = @"";

            var mapView = new MGLMapView(
                View.Bounds);

            this.View.AddSubview(mapView);
            mapView.WeakDelegate = this;

            mapView.SetCenterCoordinate(new CLLocationCoordinate2D(21.028511, 105.804817), 11, false);

            var temple = new MGLPointAnnotation
            {
                Title      = "Temple of literature",
                Subtitle   = "Van Mieu - Quoc Tu Giam",
                Coordinate = new CLLocationCoordinate2D(21.0276, 105.8355)
            };

            mapView.AddAnnotation(temple);

            var newLayer = new MGLSymbolStyleLayer(Guid.NewGuid().ToString(), new MGLSource("xxx"))
            {
                IconImageName = NSExpression.FromConstant(new NSString("temple")),
                IconOpacity   = NSExpression.FromConstant(NSNumber.FromDouble(0.7))
            };
        }
Esempio n. 6
0
 void TestProperties(NSExpression expression, List <string> availableProperties)
 {
     foreach (var pName in properties)
     {
         var type  = typeof(NSExpression);
         var pInfo = type.GetProperty(pName);
         if (!availableProperties.Contains(pName))
         {
             Assert.Throws <InvalidOperationException> (() => {
                 // we want to make sure that is an invalid operation exception and not
                 // a reflection one
                 try {
                     pInfo.GetValue(expression);
                 } catch (TargetInvocationException e) {
                     throw e.GetBaseException();
                 }
             }, $"Expressions of type '{expression.ExpressionType}' does not support the property '{pName}'");
         }
         else
         {
             Assert.DoesNotThrow(() => {
                 pInfo.GetValue(expression);
             }, $"Expressions of type '{expression.ExpressionType}' do support the property '{pName}'");
         }
     }
 }
Esempio n. 7
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.
            var mapView = new MGLMapView(
                View.Bounds,
                new NSUrl("mapbox://styles/naxamtest/cj5kin5x21li42soxdx3mb1yt")
                );

            this.View.AddSubview(mapView);
            mapView.WeakDelegate = this;

            mapView.SetCenterCoordinate(new CLLocationCoordinate2D(21.028511, 105.804817), 11, false);

            var temple = new MGLPointAnnotation()
            {
                Title      = "Temple of literature",
                Subtitle   = "Van Mieu - Quoc Tu Giam",
                Coordinate = new CLLocationCoordinate2D(21.0276, 105.8355)
            };

            mapView.AddAnnotation(temple);

            var newLayer = new MGLSymbolStyleLayer(Guid.NewGuid().ToString(), new MGLSource("xxx"))
            {
                IconImageName = NSExpression.FromConstant(new NSString("temple")),
                IconOpacity   = NSExpression.FromConstant(NSNumber.FromDouble(0.7))
            };

            Debug.WriteLine(newLayer.IconImageName.ToString());
        }
        public void AnyKeyPropertiesTest()
        {
            var availableProperties = new List <string> {
            };

            using (var expression = NSExpression.FromAnyKey()) {
                Assert.AreEqual(NSExpressionType.AnyKey, expression.ExpressionType);
                TestProperties(expression, availableProperties);
            }
        }
Esempio n. 9
0
        public void KeyPathPropertiesTest()
        {
            var availableProperties = new List <string> {
                "KeyPath", "Operand", "Arguments"
            };

            using (var expression = NSExpression.FromKeyPath("value")) {
                Assert.AreEqual(NSExpressionType.KeyPath, expression.ExpressionType);
                TestProperties(expression, availableProperties);
            }
        }
Esempio n. 10
0
        public void VariablePropertiesTest()
        {
            var availableProperties = new List <string> {
                "Variable"
            };

            using (var expression = NSExpression.FromVariable("Variable")) {
                Assert.AreEqual(NSExpressionType.Variable, expression.ExpressionType);
                TestProperties(expression, availableProperties);
            }
        }
Esempio n. 11
0
        public void BlockPropertiesTest()
        {
            var availableProperties = new List <string> {
                "Block", "Arguments"
            };

            using (var expression = NSExpression.FromFunction((o, e, c) => { return(new NSString("Foo")); }, new NSExpression [] { })) {
                Assert.AreEqual(NSExpressionType.Block, expression.ExpressionType);
                TestProperties(expression, availableProperties);
            }
        }
Esempio n. 12
0
        public void FunctionPropertiesTest()
        {
            var availableProperties = new List <string> {
                "Function", "Operand", "Arguments"
            };

            using (var expression = NSExpression.FromFormat("2*2")) {
                Assert.AreEqual(NSExpressionType.Function, expression.ExpressionType);
                TestProperties(expression, availableProperties);
            }
        }
Esempio n. 13
0
        public void ConstantPropertiesTest()
        {
            var availableProperties = new List <string> {
                "ConstantValue"
            };

            using (var expression = NSExpression.FromFormat("2")) {
                Assert.AreEqual(NSExpressionType.ConstantValue, expression.ExpressionType);
                TestProperties(expression, availableProperties);
            }
        }
        public void GetIsCountOnly()
        {
            using (var exp = new NSExpression(NSExpressionType.Block))
                using (var context = new NSExpression(NSExpressionType.EvaluatedObject))
                    using (var fetch = NSFetchRequestExpression.FromFetch(exp, context, false))
                        Assert.IsFalse(fetch.IsCountOnly, "IsCountOnly was not correctly set to false.");

            using (var exp = new NSExpression(NSExpressionType.Block))
                using (var context = new NSExpression(NSExpressionType.EvaluatedObject))
                    using (var fetch = NSFetchRequestExpression.FromFetch(exp, context, true))
                        Assert.IsTrue(fetch.IsCountOnly, "IsCountOnly was not correctly set to true.");
        }
Esempio n. 15
0
        public void AggregatePropertiesTest()
        {
            var availableProperties = new List <string> {
                "Collection"
            };

            using (var lower = NSExpression.FromConstant(new NSNumber(0)))
                using (var upper = NSExpression.FromConstant(new NSNumber(5)))
                    using (var expression = NSExpression.FromAggregate(new NSExpression [] { lower, upper })) {
                        Assert.AreEqual(NSExpressionType.NSAggregate, expression.ExpressionType);
                        TestProperties(expression, availableProperties);
                    }
        }
Esempio n. 16
0
        public void AnyKeyPropertiesTest()
        {
            TestRuntime.AssertXcodeVersion(5, 0);
            TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 10, 9, throwIfOtherPlatform: false);

            var availableProperties = new List <string> {
            };

            using (var expression = NSExpression.FromAnyKey()) {
                Assert.AreEqual(NSExpressionType.AnyKey, expression.ExpressionType);
                TestProperties(expression, availableProperties);
            }
        }
 public NSPredicateEditorRowTemplate(
     IEnumerable <string> leftExpressionsFromKeyPaths,
     IEnumerable <string> rightExpressionsFromConstants,
     IEnumerable <NSPredicateOperatorType> operators,
     NSComparisonPredicateModifier modifier = NSComparisonPredicateModifier.Direct,
     NSComparisonPredicateOptions options   = NSComparisonPredicateOptions.None)
     : this(
         leftExpressionsFromKeyPaths.Select(k => NSExpression.FromKeyPath(k)),
         rightExpressionsFromConstants.Select(k => NSExpression.FromConstant(new NSString(k))),
         operators,
         modifier,
         options)
 {
 }
 public NSPredicateEditorRowTemplate(
     IEnumerable <string> leftExpressionsFromKeyPaths,
     NSAttributeType attributeType,
     IEnumerable <NSPredicateOperatorType> operators,
     NSComparisonPredicateModifier modifier = NSComparisonPredicateModifier.Direct,
     NSComparisonPredicateOptions options   = NSComparisonPredicateOptions.None)
     : this(
         leftExpressionsFromKeyPaths.Select(k => NSExpression.FromKeyPath(k)),
         attributeType,
         operators,
         modifier,
         options)
 {
 }
Esempio n. 19
0
        public object FromConstant(object input)
        {
            NSObject value = null;

            switch (input)
            {
            case String stringValue:
                value = new NSString(stringValue);
                break;
            }

            using (var expression = NSExpression.FromConstant(value))
                using (var result = expression.EvaluateWith(null, null) as NSObject)
                    return(result?.ToString());
        }
        public void UpdateLight(Light light)
        {
            var native = mapStyle.Light;

            if (!string.IsNullOrWhiteSpace(light.Anchor))
            {
                native.Anchor = NSExpression.FromConstant(new NSString(light.Anchor));
            }

            if (light.Color != null)
            {
                native.Color = NSExpression.FromConstant(light.Color.Value.ToUIColor());
            }

            if (light.ColorTransition != null)
            {
                native.ColorTransition = light.ColorTransition.ToNative();
            }

            if (light.Intensity.HasValue)
            {
                native.Intensity = NSExpression.FromConstant(NSNumber.FromFloat(light.Intensity.Value));
            }

            if (light.IntensityTransition != null)
            {
                native.IntensityTransition = light.IntensityTransition.ToNative();
            }

            if (light.Position.HasValue)
            {
                var position = NSValue_MGLAdditions.ValueWithMGLSphericalPosition(null, new MGLSphericalPosition
                {
                    radial    = light.Position.Value.Radial,
                    azimuthal = light.Position.Value.Azimuthal,
                    polar     = light.Position.Value.Polar
                });
                native.Position = NSExpression.FromConstant(position);
            }

            if (light.PositionTransition != null)
            {
                native.PositionTransition = light.PositionTransition.ToNative();
            }

            mapStyle.Light = native;
        }
        public void ShowBuilding(BuildingInfo buildingInfo)
        {
            if (map == null || mapStyle == null)
            {
                return;
            }

            var source = mapStyle.SourceWithIdentifier("composite");

            if (source == null)
            {
                return;
            }

            var layer = new MGLFillExtrusionStyleLayer("mapbox-android-plugin-3d-buildings", source);

            layer.SourceLayerIdentifier = "building";

            // Filter out buildings that should not extrude.
            //layer.Predicate = NSPredicate.FromFormat("extrude == 'true'");

            // Set the fill extrusion height to the value for the building height attribute.
            layer.FillExtrusionHeight = Expression.Interpolate(
                Expression.Exponential(1),
                Expression.Zoom(),
                Expression.CreateStop(15, 0),
                Expression.CreateStop(16, Expression.Get("height"))
                ).ToNative();
            layer.FillExtrusionOpacity = NSExpression.FromConstant(NSNumber.FromFloat(buildingInfo.Opacity));
            layer.FillExtrusionColor   = NSExpression.FromConstant(buildingInfo.Color.ToUIColor());
            layer.Visible = buildingInfo.IsVisible;

            // Insert the fill extrusion layer below a POI label layer. If you aren’t sure what the layer is called, you can view the style in Mapbox Studio or iterate over the style’s layers property, printing out each layer’s identifier.
            if (!string.IsNullOrWhiteSpace(buildingInfo.AboveLayerId))
            {
                var symbolLayer = mapStyle.LayerWithIdentifier(buildingInfo.AboveLayerId);

                if (symbolLayer != null)
                {
                    mapStyle.InsertLayerBelow(layer, symbolLayer);

                    return;
                }
            }

            mapStyle.AddLayer(layer);
        }
Esempio n. 22
0
        public void MinusSetPropertiesTest()
        {
            var availableProperties = new List <string> {
                "LeftExpression", "RightExpression"
            };

            using (var llower = NSExpression.FromConstant(new NSNumber(0)))
                using (var lupper = NSExpression.FromConstant(new NSNumber(5)))
                    using (var lh = NSExpression.FromAggregate(new NSExpression [] { llower, lupper }))
                        using (var rlower = NSExpression.FromConstant(new NSNumber(10)))
                            using (var rupper = NSExpression.FromConstant(new NSNumber(50)))
                                using (var rh = NSExpression.FromAggregate(new NSExpression [] { rlower, rupper }))
                                    using (var expression = NSExpression.FromMinusSet(lh, rh)) {
                                        Assert.AreEqual(NSExpressionType.MinusSet, expression.ExpressionType);
                                        TestProperties(expression, availableProperties);
                                    }
        }
Esempio n. 23
0
        public static NSExpression FromRgba(NSExpression[] components)
        {
            var color = ColorFromRgb(components);

            if (color != null)
            {
                return(NSExpression.FromConstant(color));
            }


            var colorClass      = ObjCRuntime.Class.GetHandleIntrinsic(nameof(UIColor));
            var colorExpression = NSExpression.FromConstant(ObjCRuntime.Runtime.GetNSObject(colorClass));

            return(NSExpression.FromFunction(
                       colorExpression,
                       "colorWithRed:green:blue:alpha:",
                       components
                       ));
        }
Esempio n. 24
0
        public T GetValueFromExpression <T>(NSExpression expr) where T : NSObject
        {
            if (expr == null)
            {
                return(default(T));
            }
            switch (expr.ExpressionType)
            {
            case NSExpressionType.ConstantValue:
                return(expr.ConstantValue as T);

            case NSExpressionType.NSAggregate:
                if (expr.Collection is T)
                {
                    return(expr.Collection as T);
                }
                if (expr.Collection is NSArray array &&
                    array.Count != 0)
                {
                    var first = array.GetItem <T>(0);
                    if (first is NSExpression innerExpr)
                    {
                        return(GetValueFromExpression <T>(innerExpr));
                    }
                    return(first);
                }
                return(default(T));

            case NSExpressionType.Function:
                //TODO
                var function = expr.Function;              //"mgl_interpolate:withCurveType:parameters:stops:"
                if (expr.Arguments is NSExpression[] args) // $zoomLevel, exponential, 1.299999, {{ 13 = "0.5", 20 = 2;}}
                {
                    //TODO
                }
                return(default(T));

            default:
                return(default(T));
            }
        }
Esempio n. 25
0
		private void initializeRoutesLayer()
		{
			// Just initialize with empty so that it's guaranteed that there are sources initiated
			// when the routes collection is still null
			var routeSource = new MGLShapeSource(line_source_key, new NSObject[] { }, null);
			nStyle.AddSource(routeSource);

			var borderLinesLayer = new MGLLineStyleLayer(border_line_layer_key, routeSource);
			borderLinesLayer.LineColor = NSExpression.FromKeyPath(border_line_color_key);
			borderLinesLayer.LineWidth = NSExpression.FromKeyPath(border_line_width_key);
			borderLinesLayer.LineJoin = NSExpression.FromConstant(NSObject.FromObject("round"));
			borderLinesLayer.LineCap = NSExpression.FromConstant(NSObject.FromObject("round"));
			nStyle.AddLayer(borderLinesLayer);

			var linesLayer = new MGLLineStyleLayer(line_layer_key, routeSource);
			linesLayer.LineColor = NSExpression.FromKeyPath(line_color_key);
			linesLayer.LineWidth = NSExpression.FromKeyPath(line_width_key);
			linesLayer.LineJoin = NSExpression.FromConstant(NSObject.FromObject("round"));
			linesLayer.LineCap = NSExpression.FromConstant(NSObject.FromObject("round"));
			nStyle.AddLayer(linesLayer);
		}
Esempio n. 26
0
        public static NSExpression FromRgb(NSExpression[] components)
        {
            var color = ColorFromRgb(components);

            if (color != null)
            {
                return(NSExpression.FromConstant(color));
            }

            var colorClass      = ObjCRuntime.Class.GetHandleIntrinsic(nameof(UIColor));
            var colorExpression = NSExpression.FromConstant(ObjCRuntime.Runtime.GetNSObject(colorClass));
            var alphaExpression = NSExpression.FromConstant(NSNumber.FromDouble(1));
            var rgbaArguments   = new NSExpression[components.Length + 1];

            components.CopyTo(rgbaArguments, 0);
            Array.ConstrainedCopy(new[] { alphaExpression }, 0, rgbaArguments, components.Length, 1);

            return(NSExpression.FromFunction(
                       colorExpression,
                       "colorWithRed:green:blue:alpha:",
                       rgbaArguments
                       ));
        }
Esempio n. 27
0
 public void FromKeyPath()
 {
     using (var expression = NSExpression.FromKeyPath("value"))
         using (var result = expression.EvaluateWith(null, null) as NSString)
             Assert.IsNull(result);
 }
Esempio n. 28
0
 public void FromFormatWithNoArgsTest()
 {
     using (var expression = NSExpression.FromFormat("2*2"))
         using (var result = expression.EvaluateWith(null, null) as NSNumber)
             Assert.AreEqual(4.0, result.DoubleValue);
 }
Esempio n. 29
0
 public void FromFormatWithArgsTest()
 {
     using (var expression = NSExpression.FromFormat("%f*%f", new NSObject [] { new NSNumber(2.0), new NSNumber(2.0) }))
         using (var result = expression.EvaluateWith(null, null) as NSNumber)
             Assert.AreEqual(4.0, result.DoubleValue);
 }
Esempio n. 30
0
 public void FromFunctionTest()
 {
     using (var expression = NSExpression.FromFunction((o, e, c) => { return(new NSString("Foo")); }, new NSExpression [] { }))
         using (var result = expression.EvaluateWith(null, null) as NSString)
             Assert.AreEqual("Foo", result.ToString());
 }