예제 #1
0
        internal NSDictionary?ToDictionary()
        {
            int n = 0;

            if (DirectionsMode.HasValue)
            {
                n++;
            }
#if !WATCH
            if (MapType.HasValue)
            {
                n++;
            }
#endif
            if (MapCenter.HasValue)
            {
                n++;
            }
            if (MapSpan.HasValue)
            {
                n++;
            }
#if !WATCH
            if (ShowTraffic.HasValue)
            {
                n++;
            }
            if (Camera != null)
            {
                n++;
            }
#endif
            if (n == 0)
            {
                return(null);
            }

            var keys   = new NSObject [n];
            var values = new NSObject [n];
            int i      = 0;
            if (DirectionsMode.HasValue)
            {
                keys [i] = MKMapItem.MKLaunchOptionsDirectionsModeKey;
                NSString v = MKMapItem.MKLaunchOptionsDirectionsModeDriving;
                switch (DirectionsMode.Value)
                {
                case MKDirectionsMode.Driving:
                    v = MKMapItem.MKLaunchOptionsDirectionsModeDriving;
                    break;

                case MKDirectionsMode.Transit:
                    v = MKMapItem.MKLaunchOptionsDirectionsModeTransit;
                    break;

                case MKDirectionsMode.Walking:
                    v = MKMapItem.MKLaunchOptionsDirectionsModeWalking;
                    break;

#if !TV
                case MKDirectionsMode.Default:
                    v = MKMapItem.MKLaunchOptionsDirectionsModeDefault;
                    break;
#endif
                }
                values [i++] = v;
            }

#if !WATCH // MapType: __WATCHOS_PROHIBITED
            if (MapType.HasValue)
            {
                keys [i]     = MKMapItem.MKLaunchOptionsMapTypeKey;
                values [i++] = new NSNumber((int)MapType.Value);
            }
#endif
            if (MapCenter.HasValue)
            {
                keys [i]     = MKMapItem.MKLaunchOptionsMapCenterKey;
                values [i++] = NSValue.FromMKCoordinate(MapCenter.Value);
            }
            if (MapSpan.HasValue)
            {
                keys [i]     = MKMapItem.MKLaunchOptionsMapSpanKey;
                values [i++] = NSValue.FromMKCoordinateSpan(MapSpan.Value);
            }
#if !WATCH // ShowsTraffic: __WATCHOS_PROHIBITED
            if (ShowTraffic.HasValue)
            {
                keys [i]     = MKMapItem.MKLaunchOptionsShowsTrafficKey;
                values [i++] = new NSNumber(ShowTraffic.Value);
            }
#endif
#if !WATCH // MKLaunchOptionsCameraKey is allowed in WatchOS, but there's no MKMapCamera type.
            if (Camera != null)
            {
                keys [i]     = MKMapItem.MKLaunchOptionsCameraKey;
                values [i++] = Camera;
            }
#endif
            return(NSDictionary.FromObjectsAndKeys(values, keys));
        }