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 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. 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); }
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); }
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); }
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); }
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(0, 66), false); mapView.SetZoomLevel(2, false); mapView.StyleURL = MGLStyle.DarkStyleURLWithVersion(9); // Set the delegate property of our map view to `self` after instantiating it mapView.WeakDelegate = this; View.AddSubview(mapView); // Specify coordinates for our annotations. List <CLLocationCoordinate2D> coordinates = new List <CLLocationCoordinate2D>(); coordinates.Add(new CLLocationCoordinate2D(0, 33)); coordinates.Add(new CLLocationCoordinate2D(0, 66)); coordinates.Add(new CLLocationCoordinate2D(0, 99)); List <MGLPointAnnotation> pointAnnotations = new List <MGLPointAnnotation>(); // Fill an array with point annotations and add it to the map. foreach (var coord in coordinates) { MGLPointAnnotation point = new MGLPointAnnotation(); point.Coordinate = coord; point.Title = $"Lat: {coord.Latitude}, Long: {coord.Longitude}"; pointAnnotations.Add(point); } mapView.AddAnnotations(pointAnnotations.ToArray()); }
MGLShape ShapeFromAnnotation(FormsMB.Annotation annotation) { MGLShape shape = null; if (annotation is PointAnnotation) { shape = new MGLPointAnnotation() { Coordinate = new CLLocationCoordinate2D(((PointAnnotation)annotation).Coordinate.Lat, ((PointAnnotation)annotation).Coordinate.Long), }; } else if (annotation is PolylineAnnotation) { var polyline = annotation as PolylineAnnotation; shape = PolyLineWithCoordinates(polyline.Coordinates.ToArray()); var notifiyCollection = polyline.Coordinates as INotifyCollectionChanged; if (notifiyCollection != null) { notifiyCollection.CollectionChanged += (sender, e) => { //TODO Move to a separated method if (e.Action == NotifyCollectionChangedAction.Add) { foreach (Position pos in e.NewItems) { var coord = TypeConverter.FromPositionToCoordinate(pos); (shape as MGLPolyline).AppendCoordinates(ref coord, 1); } } else if (e.Action == NotifyCollectionChangedAction.Remove) { (shape as MGLPolyline).RemoveCoordinatesInRange(new NSRange(e.OldStartingIndex, e.OldItems.Count)); } }; } } else if (annotation is MultiPolylineAnnotation) { var polyline = annotation as MultiPolylineAnnotation; if (polyline.Coordinates == null || polyline.Coordinates.Length == 0) { return(null); } var lines = new MGLPolyline [polyline.Coordinates.Length]; for (var i = 0; i < polyline.Coordinates.Length; i++) { if (polyline.Coordinates [i].Length == 0) { continue; } lines [i] = PolyLineWithCoordinates(polyline.Coordinates[i]); } shape = MGLMultiPolyline.MultiPolylineWithPolylines(lines); } if (shape != null) { if (annotation.Title != null) { shape.Title = annotation.Title; } if (annotation.SubTitle != null) { shape.Subtitle = annotation.SubTitle; } if (!string.IsNullOrEmpty(annotation.Id)) { shape.SetId(annotation.Id); } } return(shape); }
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());*/ }
MGLShape ShapeFromAnnotation(Annotation annotation) { MGLShape shape = null; if (annotation is SymbolAnnotation symbol) { shape = new MGLPointAnnotation { Coordinate = symbol.Coordinates.ToCLCoordinate(), }; } else if (annotation is LineAnnotation line) { shape = PolyLineWithCoordinates(line.Coordinates.ToArray()); //if (polyline.Coordinates is INotifyCollectionChanged notifiyCollection) //{ // notifiyCollection.CollectionChanged += (sender, e) => // { // //TODO Move to a separated method // if (e.Action == NotifyCollectionChangedAction.Add) // { // foreach (FormsMB.Point pos in e.NewItems) // { // var coord = TypeConverter.FromPositionToCoordinate(pos); // (shape as MGLPolyline).AppendCoordinates(ref coord, 1); // } // } // else if (e.Action == NotifyCollectionChangedAction.Remove) // { // (shape as MGLPolyline).RemoveCoordinatesInRange(new NSRange(e.OldStartingIndex, e.OldItems.Count)); // } // }; //} } else if (annotation is FillAnnotation polyline) { //if (polyline.Coordinates == null || polyline.Coordinates.Length == 0) //{ // return null; //} //var lines = new MGLPolyline[polyline.Coordinates.Length]; //for (var i = 0; i < polyline.Coordinates.Length; i++) //{ // if (polyline.Coordinates[i].Length == 0) // { // continue; // } // lines[i] = PolyLineWithCoordinates(polyline.Coordinates[i]); //} //shape = MGLMultiPolyline.MultiPolylineWithPolylines(lines); } if (shape != null) { if (annotation.Title != null) { shape.Title = annotation.Title; } if (annotation.SubTitle != null) { shape.Subtitle = annotation.SubTitle; } if (!string.IsNullOrEmpty(annotation.Id)) { shape.SetId(annotation.Id); } annotation.NativeHandle = shape.Handle; } return shape; }