コード例 #1
0
        public MGLAnnotationView ViewForAnnotation(MGLMapView mapView, NSObject annotation)
        {
            if (annotation is MGLPointAnnotation)
            {
                var anno            = (MGLPointAnnotation)annotation;
                var reuseIdentifier = $"{anno.Coordinate.Longitude}";

                // For better performance, always try to reuse existing annotations.
                var annotationView = mapView.DequeueReusableAnnotationViewWithIdentifier(reuseIdentifier);
                if (annotationView == null)
                {
                    annotationView = new CustomAnnotationView(reuseIdentifier);

                    annotationView.Frame = new CGRect(x: 0, y: 0, width: 40, height: 40);

                    // Set the annotation view’s background color to a value determined by its longitude.
                    var hue = anno.Coordinate.Longitude / 100;

                    annotationView.BackgroundColor = UIColor.FromHSB((nfloat)hue, (nfloat)0.5, (nfloat)1);
                }

                return(annotationView);
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        public MGLAnnotationView MapView_ViewForAnnotation(MGLMapView mapView, IMGLAnnotation annotation)
        {
            var fannotation = Element.Annotations.FirstOrDefault(x => x.NativeHandle == annotation.Handle);

            switch (fannotation)
            {
            case SymbolAnnotation symbol:
                if (symbol.IconImage?.Source != null)
                {
                    return(null);
                }
                break;
            }

            var annotationView = mapView.DequeueReusableAnnotationViewWithIdentifier("draggablePoint");

            if (annotationView != null)
            {
                return(annotationView);
            }
            var view = new DraggableAnnotationView(reuseIdentifier: "draggablePoint", size: 24);

            view.DragFinished += (sender, e) =>
            {
                var point = new SymbolAnnotation();
                point.NativeHandle = annotation.Handle;
                point.Coordinates  = annotation.Coordinate.ToLatLng();
                Element.DragFinishedCommand?.Execute(point);
            };

            return(view);
        }
コード例 #3
0
        public MGLAnnotationView MapView_ViewForAnnotation(MGLMapView mapView, IMGLAnnotation annotation)
        {
            var fannotation = Element.Annotations.FirstOrDefault(x => x.NativeHandle == annotation.Handle);

            switch (fannotation)
            {
                case SymbolAnnotation symbol:
                    if (symbol.IconImage?.Source != null)
                    {
                        return null;
                    }
                    break;
            }

            var annotationView = mapView.DequeueReusableAnnotationViewWithIdentifier("draggablePoint");
            if (annotationView != null) return annotationView;
            var view = new DraggableAnnotationView(reuseIdentifier: "draggablePoint", size: 24);
            view.DragFinished += (sender, e) =>
            {
                var point = new SymbolAnnotation();
                point.NativeHandle = annotation.Handle;
                point.Coordinates = annotation.Coordinate.ToLatLng();
                Element.DragFinishedCommand?.Execute(point);
            };

            view.AddGestureRecognizer(new UITapGestureRecognizer(tap =>
            {
                Element.DidTapOnMarkerCommand?.Execute(fannotation.Id);
            }));

            //mapView.SelectAnnotation(annotation, true, null);

            return view;
        }
コード例 #4
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());
        }
コード例 #5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            MGLAccountManager.AccessToken = "YOUR API KEY HERE";


            var mapView = new MGLMapView(
                View.Bounds,
                new NSUrl("mapbox://styles/mapbox/light-v9")
                )
            {
                WeakDelegate = this
            };

            var center = new CLLocationCoordinate2D(29.7604, -95.3698);

            // Starting point
            mapView.SetCenterCoordinate(center, zoomLevel: 8, direction: 0, animated: false);

            // Zoom levels
            mapView.MinimumZoomLevel = 8;
            mapView.MaximumZoomLevel = 15;

            View.AddSubview(mapView);
        }
コード例 #6
0
        public virtual MGLAnnotationImage ImageForAnnotation(MGLMapView mapView, NSObject annotation)
        {
            // Try to reuse the existing ‘pisa’ annotation image, if it exists.
            var annotationImage = mapView.DequeueReusableAnnotationImageWithIdentifier("pisa");

            if (annotationImage == null)
            {
                // Leaning Tower of Pisa by Stefan Spieler from the Noun Project.
                var image = UIImage.FromBundle("pisavector");

                // The anchor point of an annotation is currently always the center. To
                // shift the anchor point to the bottom of the annotation, the image
                // asset includes transparent bottom padding equal to the original image
                // height.
                //
                // To make this padding non-interactive, we create another image object
                // with a custom alignment rect that excludes the padding.
                image = image.ImageWithAlignmentRectInsets(new UIEdgeInsets(top: 0, left: 0, bottom: image.Size.Height / 2, right: 0));

                // Initialize the ‘pisa’ annotation image with the UIImage we just loaded.
                annotationImage = MGLAnnotationImage.AnnotationImageWithImage(image: image, reuseIdentifier: "pisa");
            }

            return(annotationImage);
        }
コード例 #7
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            mapView = new MGLMapView(View.Bounds);

            // Set the map’s center coordinate and zoom level.
            mapView.SetCenterCoordinate(new CLLocationCoordinate2D(40.7326808, -73.9843407), 12, false);

            // Set the delegate property of our map view to `self` after instantiating it.
            mapView.WeakDelegate = this;

            View.AddSubview(mapView);

            // Declare the marker `hello` and set its coordinates, title, and subtitle.
            var hello = new MGLPointAnnotation();

            hello.Coordinate = new CLLocationCoordinate2D(40.7326808, -73.9843407);
            hello.Title      = "Hello world!";
            hello.Subtitle   = "Welcome to my marker";

            // Add marker `hello` to the map.
            mapView.AddAnnotation(hello);
        }
コード例 #8
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            mapView           = new MGLMapView(View.Bounds, MGLStyle.LightStyleURLWithVersion(9));
            mapView.TintColor = UIColor.DarkGray;

            // Set the map's bounds to Pisa, Italy.
            var bounds = new MGLCoordinateBounds()
            {
                sw = new CLLocationCoordinate2D(latitude: 43.7115, longitude: 10.3725),
                ne = new CLLocationCoordinate2D(latitude: 43.7318, longitude: 10.4222)
            };

            mapView.SetVisibleCoordinateBounds(bounds, animated: false);

            // Set the map view‘s delegate property.
            mapView.WeakDelegate = this;

            View.AddSubview(mapView);

            // Initialize and add the point annotation.
            var pisa = new MGLPointAnnotation();

            pisa.Coordinate = new CLLocationCoordinate2D(latitude: 43.72305, longitude: 10.396633);
            pisa.Title      = "Leaning Tower of Pisa";

            mapView.AddAnnotation(pisa);
        }
コード例 #9
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))
            };
        }
コード例 #10
0
 /**
  * Create a traffic plugin.
  *
  * @param mapView    the MapView to apply the traffic plugin to
  * @param mapboxMap  the MapboxMap to apply traffic plugin with
  * @param belowLayer the layer id where you'd like the traffic to display below
  */
 public TrafficPlugin(MGLMapView mapboxMap, MGLStyle style,
                      string belowLayer)
 {
     this.mapboxMap  = mapboxMap;
     this.style      = style;
     this.belowLayer = belowLayer;
 }
コード例 #11
0
        public virtual MGLAnnotationImage ImageForAnnotation(MGLMapView mapView, NSObject annotation)
        {
            if (annotation is MyCustomPointAnnotation)
            {
                var castAnnotation = (MyCustomPointAnnotation)annotation;
                if (!castAnnotation.WillUseImage)
                {
                    return(null);
                }

                // For better performance, always try to reuse existing annotations.
                var annotationImage = mapView.DequeueReusableAnnotationImageWithIdentifier("camera");

                // If there is no reusable annotation image available, initialize a new one.
                if (annotationImage == null)
                {
                    annotationImage = MGLAnnotationImage.AnnotationImageWithImage(UIImage.FromBundle("camera"), "camera");
                }

                return(annotationImage);
            }
            else
            {
                return(null);
            }
        }
コード例 #12
0
        public MGLAnnotationImage MapView_ImageForAnnotation(MGLMapView mapView, IMGLAnnotation annotation)
        {
            var fannotation = Element.Annotations.FirstOrDefault(x => x.NativeHandle == annotation.Handle);

            switch (fannotation)
            {
                case SymbolAnnotation symbol:
                    switch (symbol.IconImage.Source)
                    {
                        case FileImageSource fileImageSource:
                            var cachedImage = mapView.DequeueReusableAnnotationImageWithIdentifier(fileImageSource.File);

                            if (cachedImage != null) return cachedImage;

                            var fileImageSourceHandler = new FileImageSourceHandler();
                            var image = fileImageSourceHandler.LoadImageAsync(fileImageSource).Result;

                            if (image == null) return null;

                            return MGLAnnotationImage.AnnotationImageWithImage(image, fileImageSource.File);
                    }
                    break;
            }

            return null;
        }
コード例 #13
0
 protected virtual bool AnnotationCanShowCallout(MGLMapView mapView, IMGLAnnotation annotation)
 {
     if (annotation is MGLShape && Element.CanShowCalloutChecker != null)
     {
         return Element.CanShowCalloutChecker.Invoke(((MGLShape)annotation).Id());
     }
     return true;
 }
コード例 #14
0
 private void CreateDashedLine(List <CLLocationCoordinate2D> points, MGLMapView mapView)
 {
     for (var i = 0; i < (points.Count - 1); i += 2)
     {
         var nextLine = new CLLocationCoordinate2D[2];
         nextLine[0] = points[i];
         nextLine[1] = points[i + 1];
         var polyline = MGLPolyline.PolylineWithCoordinates(ref nextLine[0], (nuint)nextLine.Length);
         mapView.AddAnnotation(polyline);
     }
 }
コード例 #15
0
 protected virtual void MapView_TapOnCalloutForAnnotation(MGLMapView mapView, NSObject annotation)
 {
     if (annotation is MGLShape shape)
     {
         Element.DidTapOnCalloutViewCommand?.Execute(shape.Id());
     }
     else
     {
         Element.DidTapOnCalloutViewCommand?.Execute(null);
     }
 }
コード例 #16
0
 public virtual UIColor StrokeColorForShapeAnnotation(MGLMapView mapView, MGLShape annotation)
 {
     if (annotation.Title == "Crema to Council Crest" && annotation is MGLPolyline)
     {
         // Mapbox cyan
         return(new UIColor(red: 59 / 255, green: 178 / 255, blue: 208 / 255, alpha: 1));
     }
     else
     {
         return(UIColor.Red);
     }
 }
コード例 #17
0
        public IMGLCalloutView MapView_CalloutViewForAnnotation(MGLMapView mapView, IMGLAnnotation annotation)
        {
            var id = annotation.Handle;
            if (mapView.Annotations != null)
            {
                var bindingContext = Element.Annotations.FirstOrDefault(a => a.NativeHandle == id);
                UIView calloutContent = Element.InfoWindowTemplate.DataTemplateToNativeView(bindingContext, Element);
                return new MGLCustomCalloutView(null, calloutContent);
            }

            return null;
        }
コード例 #18
0
        public static IMGLFeature[] VisibleFeaturesInRect(this MGLMapView map, CGRect point, params string[] layers)
        {
            if (layers.Length > 0)
            {
                using (var layerIds = new NSSet <NSString>(layers.Select(x => (NSString)x).ToArray()))
                {
                    return(map.VisibleFeaturesInRect(point, layerIds));
                }
            }

            return(map.VisibleFeaturesInRect(point));
        }
コード例 #19
0
        public MGLAnnotationImage MapView_ImageForAnnotation(MGLMapView mapView, IMGLAnnotation annotation)
        {
            var annotationImage = mapView.DequeueReusableAnnotationImageWithIdentifier("temple");

            if (annotationImage == null)
            {
                var image = UIImage.FromBundle("temple");
                image           = image.ImageWithAlignmentRectInsets(new UIEdgeInsets(0, 0, image.Size.Height / 2, 0));
                annotationImage = MGLAnnotationImage.AnnotationImageWithImage(image, "temple");
            }
            return(annotationImage);
        }
コード例 #20
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            // Local paths are also acceptable.
            var styleURL = new NSUrl("https://www.mapbox.com/ios-sdk/files/mapbox-raster-v8.json");

            mapView = new MGLMapView(View.Bounds, styleURL);

            View.AddSubview(mapView);
        }
コード例 #21
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            // Create a MapView
            mapView = new MGLMapView(View.Bounds);
            mapView.SetCenterCoordinate(new CLLocationCoordinate2D(45.520486, -122.673541), 11, false);
            mapView.WeakDelegate = this;

            View.AddSubview(mapView);

            DrawShape();
        }
コード例 #22
0
        public void MapViewDidFinishLoadingMap(MGLMapView mapView)
        {
            var coordinates = new CLLocationCoordinate2D[] {
                new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude + 0.03, longitude: mapView.CenterCoordinate.Longitude - 0.02),
                new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude + 0.02, longitude: mapView.CenterCoordinate.Longitude - 0.03),
                new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude, longitude: mapView.CenterCoordinate.Longitude - 0.02),
                new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude - 0.01, longitude: mapView.CenterCoordinate.Longitude),
                new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude - 0.04, longitude: mapView.CenterCoordinate.Longitude + 0.01),
                new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude - 0.04, longitude: mapView.CenterCoordinate.Longitude + 0.04)
            };
            var polyline = MGLPolyline.PolylineWithCoordinates(ref coordinates[0], (nuint)coordinates.Length);

            mapView.AddAnnotation(polyline);
        }
コード例 #23
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            // Create a MapView
            mapView           = new MGLMapView(View.Bounds);
            mapView.StyleURL  = MGLStyle.LightStyleURLWithVersion(9);
            mapView.TintColor = UIColor.DarkGray;
            mapView.SetZoomLevel(1, false);
            mapView.WeakDelegate = this;

            View.AddSubview(mapView);

            // Polyline
            // Create a coordinates array with all of the coordinates for our polyline.
            List <CLLocationCoordinate2D> coordinates = new List <CLLocationCoordinate2D>()
            {
                new CLLocationCoordinate2D(35, -25),
                new CLLocationCoordinate2D(20, -30),
                new CLLocationCoordinate2D(0, -25),
                new CLLocationCoordinate2D(-15, 0),
                new CLLocationCoordinate2D(-45, 10),
                new CLLocationCoordinate2D(-45, 40)
            };

            var coords = coordinates.ToArray();

            //TODO Use CustomPolyline
            MGLPolyline polyline = CustomPolyline.PolylineWithCoordinates(ref coords[0], (uint)coords.Count());

            // Set the custom `color` property, later used in the `mapView:strokeColorForShapeAnnotation:` delegate method.
            //((CustomPolyline)polyline).Color = UIColor.DarkGray;

            // Add the polyline to the map. Note that this method name is singular.
            mapView.AddAnnotation(polyline);


            // Point Annotations
            // Add a custom point annotation for every coordinate (vertex) in the polyline.
            List <CustomPointAnnotation> pointAnnotations = new List <CustomPointAnnotation>();

            foreach (var coordinate in coordinates)
            {
                CustomPointAnnotation point = new CustomPointAnnotation(coordinate, "Custom Point Annotation " + pointAnnotations.Count + 1, "");
                pointAnnotations.Add(point);
            }
            mapView.AddAnnotations(pointAnnotations.ToArray());
        }
コード例 #24
0
 public virtual UIColor StrokeColorForShapeAnnotation(MGLMapView mapView, MGLShape annotation)
 {
     if (annotation is CustomPolyline)
     {
         if (((CustomPolyline)annotation).Color == null)
         {
             return(UIColor.Orange);
         }
         else
         {
             return(((CustomPolyline)annotation).Color);
         }
     }
     return(UIColor.Orange);
 }
コード例 #25
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            // Fill in the next line with your style URL from Mapbox Studio.
            var styleURL = new NSUrl("https://www.mapbox.com/ios-sdk/files/mapbox-raster-v8.json");

            mapView = new MGLMapView(View.Bounds, styleURL);

            // Set the map’s center coordinate and zoom level.
            mapView.SetCenterCoordinate(new CLLocationCoordinate2D(45.52954, -122.72317), 14, false);

            View.AddSubview(mapView);
        }
コード例 #26
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            // A hybrid style with unobtrusive labels is also available via satelliteStreetsStyleURL(withVersion:).
            mapView = new MGLMapView(View.Bounds, MGLStyle.SatelliteStyleURLWithVersion(9));

            // Tint the i button.
            mapView.AttributionButton.TintColor = UIColor.White;

            // Set the map’s center coordinate and zoom level.
            mapView.SetCenterCoordinate(new CLLocationCoordinate2D(45.5188, -122.6748), 13, false);

            View.AddSubview(mapView);
        }
コード例 #27
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            // Third party vector tile sources can be added.
            // In this case we're using custom style JSON (https://www.mapbox.com/mapbox-gl-style-spec/) to add a third party tile source: <https://vector.mapzen.com/osm/all/{z}/{x}/{y}.mvt>
            var customStyleURL = NSBundle.MainBundle.PathForResource("third_party_vector_style", "json");

            mapView           = new MGLMapView(View.Bounds, new NSUrl(customStyleURL));
            mapView.TintColor = UIColor.White;

            mapView.SetCenterCoordinate(new CLLocationCoordinate2D(51.50713, -0.10957), 13, false);

            View.AddSubview(mapView);
        }
コード例 #28
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            // Create a MapView
            mapView = new MGLMapView(View.Bounds, MGLStyle.OutdoorsStyleURLWithVersion(9));

            // Tint the i button and the user location annotation.
            mapView.TintColor = UIColor.DarkGray;

            // Set the map’s center coordinate and zoom level.
            mapView.SetCenterCoordinate(new CLLocationCoordinate2D(51.50713, -0.10957), 13, false);

            View.AddSubview(mapView);
        }
コード例 #29
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            map = new MGLMapView(View.Bounds);
            map.AutoresizingMask = new UIViewAutoresizing();
            map.WeakDelegate     = this;
            View.AddSubview(map);

            map.ShowsUserLocation = true;
            map.SetUserTrackingMode(MGLUserTrackingMode.Follow, true);


            UILongPressGestureRecognizer longPress = new UILongPressGestureRecognizer(DidLongPressOnMap);

            map.AddGestureRecognizer(longPress);

            MBWaypoint[] ways = new MBWaypoint[2];
            ways[0] = new MBWaypoint(new CLLocationCoordinate2D(45.622073, -73.824223), -1, "origin");
            ways[1] = new MBWaypoint(new CLLocationCoordinate2D(45.626764, -73.825742), -1, "destination");
            MBNavigationRouteOptions options = new MBNavigationRouteOptions(ways, MBDirectionsProfileIdentifier.Automobile);


            MBDirections.SharedDirections.CalculateDirectionsWithOptions(options, (way, routes, error) =>
            {
                if (routes.Length == 0 || routes == null)
                {
                    string errorMessage = "No routes found";
                    if (error != null)
                    {
                        errorMessage = error.LocalizedDescription;
                    }
                    var alert = UIAlertController.Create("Error", errorMessage, UIAlertControllerStyle.Alert);
                    alert.AddAction(UIAlertAction.Create("Dismiss", UIAlertActionStyle.Cancel, null));
                    PresentViewController(alert, true, null);
                }
                else
                {
                    MBRoute route = routes[0];
                    MBNavigationService navigationService = new MBNavigationService(route, MBDirections.SharedDirections, null, null, MBNavigationSimulationOptions.Always, null);
                    //MBNavigationOptions navigationOptions = new MBNavigationOptions(null, navigationService, null, null, null);
                    MBNavigationViewController navigationViewController = new MBNavigationViewController(route, null);

                    PresentViewController(navigationViewController, true, null);
                }
            });
        }
コード例 #30
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            mapView = new MGLMapView()
            {
                UserTrackingMode = MGLUserTrackingMode.Follow,
                WeakDelegate     = this
            };
            View.AddSubview(mapView);

            var bottomToolbar = new UIToolbar()
            {
                Tag = 101
            };

            View.AddSubview(bottomToolbar);
            var items = new List <UIBarButtonItem>();

            var bottomMessageLbl = new UILabel()
            {
                Text  = "Long press to\nselect destination",
                Lines = 2
            };

            bottomMessageLbl.SizeToFit();
            var messageItem = new UIBarButtonItem()
            {
                CustomView = bottomMessageLbl
            };

            items.Add(messageItem);
            items.Add(new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace));
            routingItem = new UIBarButtonItem("Show navigation", UIBarButtonItemStyle.Plain, DidTapOnRoutingBtn)
            {
                Enabled = false
            };
            items.Add(routingItem);

            bottomToolbar.SetItems(items.ToArray(), false);

            var longPress = new UILongPressGestureRecognizer(DidLongPressOnMap);

            mapView.AddGestureRecognizer(longPress);
        }