Exemple #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);
		}
        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))
            };
        }
        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());
        }
Exemple #4
0
        private MGLVectorStyleLayer GetStyleLayer(StyleLayer styleLayer, NSString id)
        {
            if (string.IsNullOrEmpty(styleLayer.SourceId))
            {
                return(null);
            }
            var sourceId = styleLayer.SourceId.ToCustomId();

            var source = MapView.Style.SourceWithIdentifier(sourceId);

            if (source == null)
            {
                return(null);
            }
            if (styleLayer is CircleLayer circleLayer)
            {
                var newLayer = new MGLCircleStyleLayer(id, source)
                {
                    CircleColor   = MGLStyleValue.ValueWithRawValue(circleLayer.CircleColor.ToUIColor()),
                    CircleOpacity = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(circleLayer.CircleOpacity)),
                    CircleRadius  = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(circleLayer.CircleRadius))
                };
                if (circleLayer.StrokeColor is Color strokeColor)
                {
                    newLayer.CircleStrokeColor   = MGLStyleValue.ValueWithRawValue(strokeColor.ToUIColor());
                    newLayer.CircleStrokeOpacity = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(circleLayer.StrokeOpacity));
                    newLayer.CircleStrokeWidth   = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(circleLayer.StrokeWidth));
                }
                return(newLayer);
            }

            if (styleLayer is LineLayer lineLayer)
            {
                var newLayer = new MGLLineStyleLayer(id, source)
                {
                    LineWidth = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(lineLayer.LineWidth)),
                    LineColor = MGLStyleValue.ValueWithRawValue(lineLayer.LineColor.ToUIColor())
                };
                if (lineLayer.Dashes != null && lineLayer.Dashes.Length != 0)
                {
                    var arr = new NSMutableArray <NSNumber>();
                    foreach (double dash in lineLayer.Dashes)
                    {
                        arr.Add(NSNumber.FromDouble(dash));
                    }
                    newLayer.LineDashPattern = MGLStyleValue.ValueWithRawValue(arr);
                }
                //TODO lineCap
                return(newLayer);
            }

            if (styleLayer is FillLayer fl)
            {
                var newLayer = new MGLFillStyleLayer(id, source)
                {
                    FillColor   = MGLStyleValue.ValueWithRawValue(fl.FillColor.ToUIColor()),
                    FillOpacity = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(fl.FillOpacity))
                };
                return(newLayer);
            }

            if (styleLayer is SymbolLayer sl)
            {
                var newLayer = new MGLSymbolStyleLayer(id, source)
                {
                    IconImageName = MGLConstantStyleValue.ValueWithRawValue((NSString)sl.IconImageName),
                    IconOpacity   = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(sl.IconOpacity))
                };
                return(newLayer);
            }

            return(null);
        }