MapZoomViewController.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright 2016 Google Inc. All rights reserved.
  3. *
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
  6. * file except in compliance with the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software distributed under
  11. * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  12. * ANY KIND, either express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #import "GoogleMapsDemos/Samples/MapZoomViewController.h"
  16. #import <GoogleMaps/GoogleMaps.h>
  17. @implementation MapZoomViewController {
  18. GMSMapView *_mapView;
  19. UITextView *_zoomRangeView;
  20. NSUInteger _nextMode;
  21. }
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
  25. longitude:151.2086
  26. zoom:6];
  27. _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  28. _mapView.settings.scrollGestures = NO;
  29. self.view = _mapView;
  30. // Add a display for the current zoom range restriction.
  31. _zoomRangeView = [[UITextView alloc] init];
  32. _zoomRangeView.frame =
  33. CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 0);
  34. _zoomRangeView.text = @"";
  35. _zoomRangeView.textAlignment = NSTextAlignmentCenter;
  36. _zoomRangeView.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.8f];
  37. _zoomRangeView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  38. _zoomRangeView.editable = NO;
  39. [self.view addSubview:_zoomRangeView];
  40. [_zoomRangeView sizeToFit];
  41. [self didTapNext];
  42. // Add a button toggling through modes.
  43. self.navigationItem.rightBarButtonItem =
  44. [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay
  45. target:self
  46. action:@selector(didTapNext)];
  47. }
  48. - (void)didTapNext {
  49. NSString *label = @"";
  50. float minZoom = kGMSMinZoomLevel;
  51. float maxZoom = kGMSMaxZoomLevel;
  52. switch (_nextMode) {
  53. case 0:
  54. label = @"Default";
  55. break;
  56. case 1:
  57. minZoom = 18;
  58. label = @"Zoomed in";
  59. break;
  60. case 2:
  61. maxZoom = 8;
  62. label = @"Zoomed out";
  63. break;
  64. case 3:
  65. minZoom = 10;
  66. maxZoom = 11.5;
  67. label = @"Small range";
  68. break;
  69. }
  70. _nextMode = (_nextMode + 1) % 4;
  71. [_mapView setMinZoom:minZoom maxZoom:maxZoom];
  72. _zoomRangeView.text =
  73. [NSString stringWithFormat:@"%@ (%.2f - %.2f)", label, _mapView.minZoom, _mapView.maxZoom];
  74. }
  75. @end