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()); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. // Create a MapView and set the coordinates/zoom mapView = new MGLMapView(View.Bounds); mapView.SetCenterCoordinate(new CLLocationCoordinate2D(37.745395, -119.594421), false); mapView.SetZoomLevel(11, false); View.AddSubview(mapView); mapView.WeakDelegate = this; button = new UIButton(UIButtonType.RoundedRect); button.Frame = new CoreGraphics.CGRect(10, 10, 150, 40); button.SetTitle("Toggle Contours", UIControlState.Normal); button.Selected = true; button.TouchUpInside += Button_TouchUpInside; mapView.Add(button); }
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()); }
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());*/ }