예제 #1
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))
            };
        }
예제 #2
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());
        }
예제 #3
0
        void DrawShape()
        {
            List <CLLocationCoordinate2D> coordinates = new List <CLLocationCoordinate2D>()
            {
                new CLLocationCoordinate2D(45.522585, -122.685699),
                new CLLocationCoordinate2D(45.534611, -122.708873),
                new CLLocationCoordinate2D(45.530883, -122.678833),
                new CLLocationCoordinate2D(45.547115, -122.667503),
                new CLLocationCoordinate2D(45.530643, -122.660121),
                new CLLocationCoordinate2D(45.533529, -122.636260),
                new CLLocationCoordinate2D(45.521743, -122.659091),
                new CLLocationCoordinate2D(45.510677, -122.648792),
                new CLLocationCoordinate2D(45.515008, -122.664070),
                new CLLocationCoordinate2D(45.502496, -122.669048),
                new CLLocationCoordinate2D(45.515369, -122.678489),
                new CLLocationCoordinate2D(45.506346, -122.702007),
                new CLLocationCoordinate2D(45.522585, -122.685699)
            };

            var coords = coordinates.ToArray();

            MGLPolygon shape = MGLPolygon.PolygonWithCoordinates(ref coords[0], (uint)coords.Count());

            mapView.AddAnnotation(shape);
        }
예제 #4
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);
        }
예제 #5
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);
        }
        void DrawPolyline()
        {
            var     jsonPath = NSBundle.MainBundle.PathForResource("example", "geojson");
            NSData  data     = NSFileManager.DefaultManager.Contents(jsonPath);
            NSError err;
            MGLShapeCollectionFeature shapeCollectionFeature = (MGLShapeCollectionFeature)MGLShape.ShapeWithData(data, (uint)NSStringEncoding.UTF8, out err);
            MGLPolylineFeature        polyline = (MGLPolylineFeature)shapeCollectionFeature.Shapes.First();

            mapView.AddAnnotation(polyline);
        }
예제 #7
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);
     }
 }
예제 #8
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);
        }
        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());
        }
예제 #10
0
        private void DidLongPressOnMap(UILongPressGestureRecognizer sender)
        {
            if (sender.State != UIGestureRecognizerState.Began)
            {
                return;
            }

            var point = sender.LocationInView(mapView);

            destinationCoordinate = mapView.ConvertPoint(point, mapView);
            if (mapView.Annotations != null)
            {
                mapView.RemoveAnnotations(mapView.Annotations);
            }
            mapView.AddAnnotation(new MGLPointAnnotation()
            {
                Coordinate = (CoreLocation.CLLocationCoordinate2D)destinationCoordinate
            });
            routingItem.Enabled = userCoordinate != null && destinationCoordinate != null;
        }
        private void DidLongPressOnMap(UILongPressGestureRecognizer sender)
        {
            if (sender.State != UIGestureRecognizerState.Began)
            {
                return;
            }

            CGPoint point = sender.LocationInView(map);
            CLLocationCoordinate2D coordinate2D = map.ConvertPoint(point, map);

            if (map.Annotations != null)
            {
                map.RemoveAnnotations(map.Annotations);
            }
            MGLPointAnnotation pointAnnotation = new MGLPointAnnotation();

            pointAnnotation.Coordinate = coordinate2D;
            pointAnnotation.Title      = "Start Navigation";
            map.AddAnnotation(pointAnnotation);
        }
예제 #12
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);
        }
예제 #13
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            /*Dictionary<string, CLLocationCoordinate2D> boundsDict = FindBounds(lat1, lng1, lat2, lng2);*/

            var lat1          = 21.353550;
            var lng1          = -157.842061;
            var lat2          = 35.832595;
            var lng2          = 139.535024;
            var pickupPoint   = new CLLocationCoordinate2D(lat1, lng1);
            var deliveryPoint = new CLLocationCoordinate2D(lat2, lng2);

            var initialBounds = new MGLCoordinateBounds()
            {
                sw = pickupPoint,
                ne = deliveryPoint
            };

            var mapView = new MGLMapView(frame: View.Bounds)
            {
                //This can be cleaned up at the end

/*                ZoomLevel = 6,
 *              CenterCoordinate = new CLLocationCoordinate2D(28.903782, -36.516551),
 *              VisibleCoordinateBounds = initialBounds,
 *              Direction = 0*/
            };

            bool crossesMeridianOrDateline;

            if ((lng1 > 0.0 && lng2 < 0.0) || (lng1 < 0.0 && lng2 > 0.0))
            {
                crossesMeridianOrDateline = true;
            }
            else
            {
                crossesMeridianOrDateline = false;
            }

            var xDiffPrimeMeridianZero = FindXDiffPrimeMeridianZero(lng1, lng2);
            var xDiffDatelineZero      = FindXDiffDatelineZero(lng1, lng2);

            List <double> xList;
            List <double> lngList;

            if ((Math.Abs(xDiffDatelineZero) > Math.Abs(xDiffPrimeMeridianZero)) && crossesMeridianOrDateline == true)
            {
                var latCenter = (lat1 + lat2) / 2.0;

                // Find center coordinate here
                var    x1      = FindXPrimeMeridianZero(lng1);
                var    xCenter = x1 + (xDiffPrimeMeridianZero / 2.0);
                double lngCenter;

                if (x1 > 180.0)
                {
                    lngCenter = xCenter - 360.0;
                }
                else
                {
                    lngCenter = xCenter;
                }

                mapView.SetCenterCoordinate(new CLLocationCoordinate2D(latCenter, lngCenter), false);
                mapView.SetZoomLevel(1.5, false);

                xList   = CreateXList(xDiffPrimeMeridianZero, x1);
                lngList = ConvertToLngsPrimeMeridianZero(xList);
            }
            else
            {
                // find max/min lat/lng here
                // use those to determine the initialBounds

                var latDict = FindLowHigh(lat1, lat2);
                var latHigh = latDict["high"];
                var latLow  = latDict["low"];
                var lngDict = FindLowHigh(lng1, lng2);
                var lngHigh = lngDict["high"];
                var lngLow  = lngDict["low"];

                var latBuffer = (latHigh - latLow) / 10.0;
                var lngBuffer = (lngHigh - lngLow) / 10.0;

                var swLat = latLow - latBuffer;
                var swLng = lngLow - lngBuffer;
                var neLat = latHigh + latBuffer;
                var neLng = lngHigh + lngBuffer;

                var bounds = new MGLCoordinateBounds()
                {
                    sw = new CLLocationCoordinate2D(swLat, swLng),
                    ne = new CLLocationCoordinate2D(neLat, neLng)
                };

                mapView.SetVisibleCoordinateBounds(bounds, new UIEdgeInsets(top: 0.0f, left: 0.0f, bottom: 0.0f, right: 0.0f), false);

                xList   = CreateXList(xDiffDatelineZero, FindXDatelineZero(lng1));
                lngList = ConvertToLngsDatelineZero(xList);
            }

            var yList = CreateYList(lat1, lat2);

            var latList = ConvertToLats(yList);
            var coords  = ConvertToCoords(latList, lngList);


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

/*            mapView.SetCenterCoordinate(new CLLocationCoordinate2D(50.392381, -98.94189), 6, false);*/

            var pickupPointAnnotation = new MGLPointAnnotation()
            {
                Title      = "Echo Chicago",
                Subtitle   = "#1 3PL",
                Coordinate = pickupPoint
            };

            var deliveryPointAnnotation = new MGLPointAnnotation()
            {
                Title      = "St. Louis",
                Subtitle   = "Delivery Spot",
                Coordinate = deliveryPoint
            };

            mapView.AddAnnotation(pickupPointAnnotation);
            mapView.AddAnnotation(deliveryPointAnnotation);

            CreateDashedLine(coords, mapView);

            /*			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());*/
        }