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