Guest User

Untitled

a guest
May 27th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. //
  2. // MapView.m
  3. // Campus Tour
  4. //
  5. // Created by trey t on 11/16/08.
  6. // Copyright 2008 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #import "MapView.h"
  10. #import "TiledDelegate.h"
  11. #import <QuartzCore/CoreAnimation.h>
  12.  
  13. @implementation MapView
  14.  
  15. @synthesize pdf, scale, popUpIndex, sfMuni, map;
  16.  
  17. +(Class)layerClass
  18. {
  19. return [CATiledLayer class];
  20. }
  21.  
  22. -(id)initWithFrame:(CGRect)r
  23. {
  24. self = [super initWithFrame:r];
  25. if(self != nil)
  26. {
  27. CATiledLayer *l = (CATiledLayer*)self.layer;
  28. l.levelsOfDetail = 15;
  29. l.levelsOfDetailBias = 12;
  30. }
  31. return self;
  32. }
  33.  
  34. - (id)init
  35. {
  36. return [self initWithFrame:CGRectZero];
  37. }
  38.  
  39. -(void)zoomIn{
  40. // NSLog(@"zoom");
  41. // zoom = scale;
  42. // self.layer.transform = CATransform3DMakeScale(zoom, zoom, 1.0f);
  43. }
  44.  
  45. -(void)drawRect:(CGRect)r
  46. {
  47. }
  48.  
  49. - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
  50. CGContextSaveGState(ctx);
  51. CGContextTranslateCTM( ctx, 0,layer.bounds.size.height);
  52. CGContextScaleCTM(ctx, 1.0, -1.0);
  53.  
  54. CGContextSaveGState(ctx);
  55. CGRect pageRect = CGPDFPageGetBoxRect(map, kCGPDFCropBox);
  56. NSString *path = [[NSBundle mainBundle] pathForResource:@"NTMap2" ofType:@"pdf"];
  57. NSURL *docURL = [NSURL fileURLWithPath:path];
  58. sfMuni = CGPDFDocumentCreateWithURL((CFURLRef)docURL);
  59. if(NULL == map) {
  60. map = CGPDFDocumentGetPage(self.sfMuni, 1);
  61. }
  62. self.layer.bounds = CGRectMake(0.0f, 0.0f, CGRectGetWidth(pageRect),CGRectGetHeight(pageRect));
  63.  
  64. CGFloat x = CGRectGetWidth(self.layer.bounds) * self.layer.anchorPoint.x;
  65. CGFloat y = CGRectGetHeight(self.layer.bounds) * self.layer.anchorPoint.y;
  66. //868x816
  67. tiledLayer.position = CGPointMake(x * zoom, y * zoom);
  68. tiledLayer.transform = CATransform3DMakeScale(zoom, zoom, 1.0f);
  69. CGContextDrawPDFPage(ctx, map);
  70. CGContextRestoreGState(ctx);
  71. }
  72.  
  73.  
  74. -(void)dealloc {
  75. CGPDFDocumentRelease(pdf);
  76. [super dealloc];
  77. }
  78.  
  79. @end
Add Comment
Please, Sign In to add comment