Advertisement
Guest User

Untitled

a guest
Apr 21st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.88 KB | None | 0 0
  1. //
  2. // MapKit.m
  3. //
  4. //
  5. // Created by Victor Zimmer on 09/11/15.
  6. //
  7. //
  8.  
  9. #import "MapKit.h"
  10. #import <MapKit/MapKit.h>
  11. #import <CoreLocation/CoreLocation.h>
  12. #import "MKComplexMapPin.h"
  13.  
  14. //@interface ViewController : UIViewController <MKMapViewDelegate>
  15.  
  16.  
  17.  
  18. @implementation MapKit
  19.  
  20. CLLocationManager* locationManager;
  21. UIWebView* webView;
  22.  
  23. //NSMutableDictionary* pinColors;
  24.  
  25. - (id)init
  26. {
  27.  
  28. }
  29.  
  30.  
  31.  
  32. - (void)test:(CDVInvokedUrlCommand*)command
  33. {
  34.  
  35. NSString* callbackId = [command callbackId];
  36. NSString* name = [[command arguments] objectAtIndex:0];
  37. NSString* msg = [NSString stringWithFormat: @"MapKit, %@", name];
  38.  
  39. CDVPluginResult* result = [CDVPluginResult
  40. resultWithStatus:CDVCommandStatus_OK
  41. messageAsString:msg];
  42.  
  43.  
  44.  
  45. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  46. }
  47.  
  48. - (void)checkLocationAuthStatus:(CDVInvokedUrlCommand*)command
  49. {
  50. NSString* callbackId = [command callbackId];
  51.  
  52. CLAuthorizationStatus* authStatus = [CLLocationManager authorizationStatus];
  53.  
  54. NSString* resultString;
  55.  
  56. if (authStatus == kCLAuthorizationStatusAuthorized) {
  57. resultString = @"LOCATION_AUTH_AUTHORIZED";
  58. }
  59. else if (authStatus == kCLAuthorizationStatusAuthorizedAlways) {
  60. resultString = @"LOCATION_AUTH_AUTHORIZED_ALWAYS";
  61. }
  62. else if (authStatus == kCLAuthorizationStatusAuthorizedWhenInUse) {
  63. resultString = @"LOCATION_AUTH_AUTHORIZED_WHEN_IN_USE";
  64. }
  65. else if (authStatus == kCLAuthorizationStatusNotDetermined) {
  66. resultString = @"LOCATION_AUTH_NOT_DETERMINED";
  67. }
  68. else if (authStatus == kCLAuthorizationStatusRestricted) {
  69. resultString = @"LOCATION_AUTH_RESTRICTED";
  70. }
  71. else if (authStatus == kCLAuthorizationStatusDenied) {
  72. resultString = @"LOCATION_AUTH_DENIED";
  73. }
  74.  
  75.  
  76. CDVPluginResult* result = [CDVPluginResult
  77. resultWithStatus:CDVCommandStatus_OK
  78. messageAsString:resultString];
  79.  
  80.  
  81.  
  82. //[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  83. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  84. }
  85.  
  86. - (void)requestLocationWhenInUsePermission:(CDVInvokedUrlCommand*)command
  87. {
  88. NSString* callbackId = [command callbackId];
  89.  
  90. locationManager = [[CLLocationManager alloc] init];
  91. locationManager.delegate = self;
  92. [locationManager requestWhenInUseAuthorization];
  93. [locationManager startUpdatingLocation];
  94.  
  95.  
  96.  
  97.  
  98. CDVPluginResult* result = [CDVPluginResult
  99. resultWithStatus:CDVCommandStatus_OK
  100. messageAsString:@"OK"];
  101.  
  102. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  103. }
  104.  
  105.  
  106. - (void)requestLocationAlwaysPermission:(CDVInvokedUrlCommand*)command
  107. {
  108. NSString* callbackId = [command callbackId];
  109.  
  110. locationManager = [[CLLocationManager alloc] init];
  111. locationManager.delegate = self;
  112. [locationManager requestAlwaysAuthorization];
  113. [locationManager startUpdatingLocation];
  114.  
  115.  
  116.  
  117.  
  118. CDVPluginResult* result = [CDVPluginResult
  119. resultWithStatus:CDVCommandStatus_OK
  120. messageAsString:@"OK"];
  121.  
  122. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  123.  
  124. }
  125.  
  126.  
  127. - (void)createMapView:(CDVInvokedUrlCommand*)command
  128. {
  129. NSString* callbackId = [command callbackId];
  130. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  131. CGFloat height = [[[command arguments] objectAtIndex:1]floatValue];
  132. CGFloat width = [[[command arguments] objectAtIndex:2]floatValue];
  133. CGFloat xPos = [[[command arguments] objectAtIndex:3]floatValue];
  134. CGFloat yPos = [[[command arguments] objectAtIndex:4]floatValue];
  135.  
  136. webView = self.webView;
  137.  
  138. MKMapView* mapView = [[MKMapView alloc]initWithFrame:CGRectMake(xPos, yPos, width, height)];
  139. mapView.tag = mapId;
  140. mapView.delegate = self;
  141. [webView addSubview:mapView];
  142.  
  143.  
  144.  
  145.  
  146. CDVPluginResult* result = [CDVPluginResult
  147. resultWithStatus:CDVCommandStatus_OK
  148. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  149.  
  150. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  151. }
  152.  
  153.  
  154. - (void)showMapView:(CDVInvokedUrlCommand*)command
  155. {
  156. NSString* callbackId = [command callbackId];
  157. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  158. MKMapView* mapView = [webView viewWithTag:mapId];
  159.  
  160. mapView.hidden = NO;
  161.  
  162.  
  163. CDVPluginResult* result = [CDVPluginResult
  164. resultWithStatus:CDVCommandStatus_OK
  165. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  166.  
  167. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  168.  
  169. }
  170.  
  171.  
  172. - (void)hideMapView:(CDVInvokedUrlCommand*)command
  173. {
  174. NSString* callbackId = [command callbackId];
  175. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  176. MKMapView* mapView = [webView viewWithTag:mapId];
  177.  
  178. mapView.hidden = YES;
  179.  
  180.  
  181. CDVPluginResult* result = [CDVPluginResult
  182. resultWithStatus:CDVCommandStatus_OK
  183. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  184.  
  185. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  186.  
  187. }
  188.  
  189.  
  190. - (void)removeMapView:(CDVInvokedUrlCommand*)command
  191. {
  192. NSString* callbackId = [command callbackId];
  193. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  194. MKMapView* mapView = [webView viewWithTag:mapId];
  195. [mapView removeFromSuperview];
  196.  
  197.  
  198. CDVPluginResult* result = [CDVPluginResult
  199. resultWithStatus:CDVCommandStatus_OK
  200. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  201.  
  202. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  203.  
  204. }
  205.  
  206. - (void)changeMapHeight:(CDVInvokedUrlCommand*)command
  207. {
  208. NSString* callbackId = [command callbackId];
  209. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  210. CGFloat height = [[[command arguments] objectAtIndex:1]floatValue];
  211. MKMapView* mapView = [self.webView viewWithTag:mapId];
  212.  
  213. [mapView setFrame:CGRectMake(mapView.frame.origin.x, mapView.frame.origin.y, mapView.frame.size.width, height)];
  214.  
  215.  
  216. CDVPluginResult* result = [CDVPluginResult
  217. resultWithStatus:CDVCommandStatus_OK
  218. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  219.  
  220. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  221.  
  222.  
  223. }
  224.  
  225. - (void)changeMapWidth:(CDVInvokedUrlCommand*)command
  226. {
  227. NSString* callbackId = [command callbackId];
  228. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  229. CGFloat width = [[[command arguments] objectAtIndex:1]floatValue];
  230. MKMapView* mapView = [self.webView viewWithTag:mapId];
  231.  
  232. [mapView setFrame:CGRectMake(mapView.frame.origin.x, mapView.frame.origin.y, width, mapView.frame.size.height)];
  233.  
  234.  
  235. CDVPluginResult* result = [CDVPluginResult
  236. resultWithStatus:CDVCommandStatus_OK
  237. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  238.  
  239. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  240.  
  241.  
  242. }
  243.  
  244. - (void)changeMapBounds:(CDVInvokedUrlCommand*)command
  245. {
  246. NSString* callbackId = [command callbackId];
  247. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  248. CGFloat height = [[[command arguments] objectAtIndex:1]floatValue];
  249. CGFloat width = [[[command arguments] objectAtIndex:2]floatValue];
  250. MKMapView* mapView = [self.webView viewWithTag:mapId];
  251.  
  252. [mapView setFrame:CGRectMake(mapView.frame.origin.x, mapView.frame.origin.y, width, height)];
  253.  
  254.  
  255. CDVPluginResult* result = [CDVPluginResult
  256. resultWithStatus:CDVCommandStatus_OK
  257. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  258.  
  259. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  260.  
  261.  
  262. }
  263.  
  264. - (void)changeMapXPos:(CDVInvokedUrlCommand*)command
  265. {
  266. NSString* callbackId = [command callbackId];
  267. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  268. CGFloat XPos = [[[command arguments] objectAtIndex:1]floatValue];
  269. MKMapView* mapView = [self.webView viewWithTag:mapId];
  270.  
  271. [mapView setFrame:CGRectMake(XPos, mapView.frame.origin.y, mapView.frame.size.width, mapView.frame.size.height)];
  272.  
  273.  
  274. CDVPluginResult* result = [CDVPluginResult
  275. resultWithStatus:CDVCommandStatus_OK
  276. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  277.  
  278. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  279.  
  280.  
  281. }
  282.  
  283. - (void)changeMapYPos:(CDVInvokedUrlCommand*)command
  284. {
  285. NSString* callbackId = [command callbackId];
  286. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  287. CGFloat YPos = [[[command arguments] objectAtIndex:1]floatValue];
  288. MKMapView* mapView = [self.webView viewWithTag:mapId];
  289.  
  290. [mapView setFrame:CGRectMake(mapView.frame.origin.x, YPos, mapView.frame.size.width, mapView.frame.size.height)];
  291.  
  292.  
  293. CDVPluginResult* result = [CDVPluginResult
  294. resultWithStatus:CDVCommandStatus_OK
  295. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  296.  
  297. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  298.  
  299.  
  300. }
  301.  
  302. - (void)changeMapPosition:(CDVInvokedUrlCommand*)command
  303. {
  304. NSString* callbackId = [command callbackId];
  305. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  306. CGFloat XPos = [[[command arguments] objectAtIndex:1]floatValue];
  307. CGFloat YPos = [[[command arguments] objectAtIndex:2]floatValue];
  308. MKMapView* mapView = [self.webView viewWithTag:mapId];
  309.  
  310. [mapView setFrame:CGRectMake(XPos, YPos, mapView.frame.size.width, mapView.frame.size.height)];
  311.  
  312.  
  313. CDVPluginResult* result = [CDVPluginResult
  314. resultWithStatus:CDVCommandStatus_OK
  315. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  316.  
  317. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  318.  
  319.  
  320. }
  321.  
  322.  
  323.  
  324. - (void)isShowingUserLocation:(CDVInvokedUrlCommand*)command
  325. {
  326. NSString* callbackId = [command callbackId];
  327. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  328. MKMapView* mapView = [webView viewWithTag:mapId];
  329.  
  330. NSString* stringRes;
  331.  
  332. if (mapView.userLocationVisible) {
  333. stringRes = @"true";
  334. }
  335. else
  336. {
  337. stringRes = @"false";
  338. }
  339.  
  340. CDVPluginResult* result = [CDVPluginResult
  341. resultWithStatus:CDVCommandStatus_OK
  342. messageAsString:stringRes];
  343.  
  344. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  345.  
  346. }
  347.  
  348.  
  349. - (void)showMapScale:(CDVInvokedUrlCommand*)command
  350. {
  351. NSString* callbackId = [command callbackId];
  352. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  353. MKMapView* mapView = [self.webView viewWithTag:mapId];
  354.  
  355.  
  356.  
  357. NSLog(@"%@", mapView);
  358.  
  359. mapView.showsScale = YES;
  360.  
  361.  
  362. CDVPluginResult* result = [CDVPluginResult
  363. resultWithStatus:CDVCommandStatus_OK
  364. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  365.  
  366. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  367.  
  368. }
  369.  
  370. - (void)hideMapScale:(CDVInvokedUrlCommand*)command
  371. {
  372. NSString* callbackId = [command callbackId];
  373. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  374. MKMapView* mapView = [self.webView viewWithTag:mapId];
  375.  
  376. mapView.showsScale = NO;
  377.  
  378.  
  379. CDVPluginResult* result = [CDVPluginResult
  380. resultWithStatus:CDVCommandStatus_OK
  381. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  382.  
  383. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  384.  
  385. }
  386.  
  387. - (void)showMapUserLocation:(CDVInvokedUrlCommand*)command
  388. {
  389. NSString* callbackId = [command callbackId];
  390. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  391. MKMapView* mapView = [self.webView viewWithTag:mapId];
  392.  
  393. mapView.showsUserLocation = YES;
  394.  
  395.  
  396. CDVPluginResult* result = [CDVPluginResult
  397. resultWithStatus:CDVCommandStatus_OK
  398. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  399.  
  400. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  401.  
  402. }
  403.  
  404. - (void)hideMapUserLocation:(CDVInvokedUrlCommand*)command
  405. {
  406. NSString* callbackId = [command callbackId];
  407. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  408. MKMapView* mapView = [self.webView viewWithTag:mapId];
  409.  
  410. mapView.showsUserLocation = NO;
  411.  
  412.  
  413. CDVPluginResult* result = [CDVPluginResult
  414. resultWithStatus:CDVCommandStatus_OK
  415. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  416.  
  417. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  418.  
  419. }
  420.  
  421. - (void)showMapCompass:(CDVInvokedUrlCommand*)command
  422. {
  423. NSString* callbackId = [command callbackId];
  424. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  425. MKMapView* mapView = [self.webView viewWithTag:mapId];
  426.  
  427. mapView.showsCompass = YES;
  428.  
  429.  
  430. CDVPluginResult* result = [CDVPluginResult
  431. resultWithStatus:CDVCommandStatus_OK
  432. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  433.  
  434. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  435.  
  436. }
  437.  
  438. - (void)hideMapCompass:(CDVInvokedUrlCommand*)command
  439. {
  440. NSString* callbackId = [command callbackId];
  441. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  442. MKMapView* mapView = [self.webView viewWithTag:mapId];
  443.  
  444. mapView.showsCompass = NO;
  445.  
  446.  
  447. CDVPluginResult* result = [CDVPluginResult
  448. resultWithStatus:CDVCommandStatus_OK
  449. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  450.  
  451. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  452.  
  453. }
  454.  
  455. - (void)showMapPointsOfInterest:(CDVInvokedUrlCommand*)command
  456. {
  457. NSString* callbackId = [command callbackId];
  458. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  459. MKMapView* mapView = [self.webView viewWithTag:mapId];
  460.  
  461. mapView.showsPointsOfInterest = YES;
  462.  
  463.  
  464. CDVPluginResult* result = [CDVPluginResult
  465. resultWithStatus:CDVCommandStatus_OK
  466. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  467.  
  468. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  469.  
  470. }
  471.  
  472. - (void)hideMapPointsOfInterest:(CDVInvokedUrlCommand*)command
  473. {
  474. NSString* callbackId = [command callbackId];
  475. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  476. MKMapView* mapView = [self.webView viewWithTag:mapId];
  477.  
  478. mapView.showsPointsOfInterest = NO;
  479.  
  480.  
  481. CDVPluginResult* result = [CDVPluginResult
  482. resultWithStatus:CDVCommandStatus_OK
  483. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  484.  
  485. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  486.  
  487. }
  488.  
  489. - (void)showMapBuildings:(CDVInvokedUrlCommand*)command
  490. {
  491. NSString* callbackId = [command callbackId];
  492. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  493. MKMapView* mapView = [self.webView viewWithTag:mapId];
  494.  
  495. mapView.showsBuildings = YES;
  496.  
  497.  
  498. CDVPluginResult* result = [CDVPluginResult
  499. resultWithStatus:CDVCommandStatus_OK
  500. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  501.  
  502. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  503.  
  504. }
  505.  
  506. - (void)hideMapBuildings:(CDVInvokedUrlCommand*)command
  507. {
  508. NSString* callbackId = [command callbackId];
  509. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  510. MKMapView* mapView = [self.webView viewWithTag:mapId];
  511.  
  512. mapView.showsBuildings = NO;
  513.  
  514.  
  515. CDVPluginResult* result = [CDVPluginResult
  516. resultWithStatus:CDVCommandStatus_OK
  517. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  518.  
  519. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  520.  
  521. }
  522.  
  523. - (void)showMapTraffic:(CDVInvokedUrlCommand*)command
  524. {
  525. NSString* callbackId = [command callbackId];
  526. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  527. MKMapView* mapView = [self.webView viewWithTag:mapId];
  528.  
  529. mapView.showsTraffic = YES;
  530.  
  531.  
  532. CDVPluginResult* result = [CDVPluginResult
  533. resultWithStatus:CDVCommandStatus_OK
  534. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  535.  
  536. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  537.  
  538. }
  539.  
  540. - (void)hideMapTraffic:(CDVInvokedUrlCommand*)command
  541. {
  542. NSString* callbackId = [command callbackId];
  543. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  544. MKMapView* mapView = [self.webView viewWithTag:mapId];
  545.  
  546. mapView.showsTraffic = NO;
  547.  
  548.  
  549. CDVPluginResult* result = [CDVPluginResult
  550. resultWithStatus:CDVCommandStatus_OK
  551. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  552.  
  553. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  554.  
  555. }
  556.  
  557. - (void)setMapOpacity:(CDVInvokedUrlCommand*)command
  558. {
  559. NSString* callbackId = [command callbackId];
  560. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  561. CGFloat newAlpha = [[[command arguments] objectAtIndex:1] floatValue];
  562. MKMapView* mapView = [self.webView viewWithTag:mapId];
  563.  
  564. [mapView setAlpha: newAlpha];
  565.  
  566.  
  567. CDVPluginResult* result = [CDVPluginResult
  568. resultWithStatus:CDVCommandStatus_OK
  569. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  570.  
  571. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  572.  
  573. }
  574.  
  575. - (void)setMapCenter:(CDVInvokedUrlCommand*)command
  576. {
  577. NSString* callbackId = [command callbackId];
  578. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  579. CGFloat centerLat = [[[command arguments] objectAtIndex:1] floatValue];
  580. CGFloat centerLon = [[[command arguments] objectAtIndex:2] floatValue];
  581. BOOL animated = [[[command arguments] objectAtIndex:3] boolValue];
  582. MKMapView* mapView = [self.webView viewWithTag:mapId];
  583.  
  584. CLLocationCoordinate2D newCenter = CLLocationCoordinate2DMake(centerLat, centerLon);
  585. [mapView setCenterCoordinate:newCenter animated:animated];
  586.  
  587.  
  588. CDVPluginResult* result = [CDVPluginResult
  589. resultWithStatus:CDVCommandStatus_OK
  590. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  591.  
  592. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  593.  
  594. }
  595.  
  596. - (void)enableMapRotate:(CDVInvokedUrlCommand*)command
  597. {
  598. NSString* callbackId = [command callbackId];
  599. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  600. MKMapView* mapView = [self.webView viewWithTag:mapId];
  601.  
  602. [mapView setRotateEnabled:YES];
  603.  
  604.  
  605. CDVPluginResult* result = [CDVPluginResult
  606. resultWithStatus:CDVCommandStatus_OK
  607. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  608.  
  609. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  610.  
  611. }
  612. - (void)disableMapRotate:(CDVInvokedUrlCommand*)command
  613. {
  614. NSString* callbackId = [command callbackId];
  615. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  616. MKMapView* mapView = [self.webView viewWithTag:mapId];
  617.  
  618. [mapView setRotateEnabled:NO];
  619.  
  620.  
  621. CDVPluginResult* result = [CDVPluginResult
  622. resultWithStatus:CDVCommandStatus_OK
  623. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  624.  
  625. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  626.  
  627. }
  628.  
  629. - (void)enableMapScroll:(CDVInvokedUrlCommand*)command
  630. {
  631. NSString* callbackId = [command callbackId];
  632. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  633. MKMapView* mapView = [self.webView viewWithTag:mapId];
  634.  
  635. [mapView setScrollEnabled:YES];
  636.  
  637.  
  638. CDVPluginResult* result = [CDVPluginResult
  639. resultWithStatus:CDVCommandStatus_OK
  640. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  641.  
  642. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  643.  
  644. }
  645. - (void)disableMapScroll:(CDVInvokedUrlCommand*)command
  646. {
  647. NSString* callbackId = [command callbackId];
  648. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  649. MKMapView* mapView = [self.webView viewWithTag:mapId];
  650.  
  651. [mapView setScrollEnabled:NO];
  652.  
  653.  
  654. CDVPluginResult* result = [CDVPluginResult
  655. resultWithStatus:CDVCommandStatus_OK
  656. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  657.  
  658. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  659.  
  660. }
  661.  
  662. - (void)enableMapUserInteraction:(CDVInvokedUrlCommand*)command
  663. {
  664. NSString* callbackId = [command callbackId];
  665. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  666. MKMapView* mapView = [self.webView viewWithTag:mapId];
  667.  
  668. [mapView setUserInteractionEnabled:YES];
  669.  
  670.  
  671. CDVPluginResult* result = [CDVPluginResult
  672. resultWithStatus:CDVCommandStatus_OK
  673. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  674.  
  675. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  676.  
  677. }
  678. - (void)disableMapUserInteraction:(CDVInvokedUrlCommand*)command
  679. {
  680. NSString* callbackId = [command callbackId];
  681. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  682. MKMapView* mapView = [self.webView viewWithTag:mapId];
  683.  
  684. [mapView setUserInteractionEnabled:NO];
  685.  
  686.  
  687. CDVPluginResult* result = [CDVPluginResult
  688. resultWithStatus:CDVCommandStatus_OK
  689. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  690.  
  691. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  692.  
  693. }
  694.  
  695. - (void)setMapRegion:(CDVInvokedUrlCommand*)command
  696. {
  697. NSString* callbackId = [command callbackId];
  698. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  699. CGFloat centerLat = [[[command arguments] objectAtIndex:1] floatValue];
  700. CGFloat centerLon = [[[command arguments] objectAtIndex:2] floatValue];
  701. CGFloat spanLat = [[[command arguments] objectAtIndex:3] floatValue];
  702. CGFloat spanLon = [[[command arguments] objectAtIndex:4] floatValue];
  703. BOOL animated = [[[command arguments] objectAtIndex:5] boolValue];
  704. MKMapView* mapView = [self.webView viewWithTag:mapId];
  705.  
  706. CLLocationCoordinate2D newCenter = CLLocationCoordinate2DMake(centerLat, centerLon);
  707. MKCoordinateSpan newSpan = MKCoordinateSpanMake(spanLat, spanLon);
  708.  
  709. MKCoordinateRegion newRegion = MKCoordinateRegionMake(newCenter, newSpan);
  710. [mapView setRegion:newRegion animated:animated];
  711.  
  712.  
  713. CDVPluginResult* result = [CDVPluginResult
  714. resultWithStatus:CDVCommandStatus_OK
  715. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  716.  
  717. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  718.  
  719. }
  720.  
  721. - (void)getMapCenter:(CDVInvokedUrlCommand*)command
  722. {
  723. NSString* callbackId = [command callbackId];
  724. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  725.  
  726. MKMapView* mapView = [self.webView viewWithTag:mapId];
  727.  
  728. CLLocationCoordinate2D center = mapView.centerCoordinate;
  729. CGPoint centerPoint = CGPointMake(center.longitude, center.latitude);
  730.  
  731. NSString *jsEval = [NSString stringWithFormat:@"MKInterface.__objc__.getCenterCallback(%f, %@)", mapId, [[NSStringFromCGPoint(centerPoint) stringByReplacingOccurrencesOfString:@"{" withString:@"["]stringByReplacingOccurrencesOfString:@"}" withString:@"]" ]];
  732.  
  733.  
  734. [webView stringByEvaluatingJavaScriptFromString: jsEval];
  735.  
  736. CDVPluginResult* result = [CDVPluginResult
  737. resultWithStatus:CDVCommandStatus_OK
  738. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  739.  
  740. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  741. }
  742.  
  743.  
  744.  
  745. - (void)addSimpleMapPin:(CDVInvokedUrlCommand*)command
  746. {
  747. NSString* callbackId = [command callbackId];
  748. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  749. CGFloat lat = [[[command arguments] objectAtIndex:1]floatValue];
  750. CGFloat lon = [[[command arguments] objectAtIndex:2]floatValue];
  751. NSString* title = [[command arguments] objectAtIndex:3];
  752. NSString* description = [[command arguments] objectAtIndex:4];
  753. MKMapView* mapView = [self.webView viewWithTag:mapId];
  754.  
  755. MKPointAnnotation* pin = [[MKPointAnnotation alloc]init];
  756. pin.coordinate = CLLocationCoordinate2DMake(lat, lon);
  757. pin.title = title;
  758. pin.subtitle = description;
  759.  
  760.  
  761. [mapView addAnnotation:pin];
  762.  
  763. CDVPluginResult* result = [CDVPluginResult
  764. resultWithStatus:CDVCommandStatus_OK
  765. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  766.  
  767. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  768.  
  769. }
  770.  
  771. - (void)addSimpleMapPins:(CDVInvokedUrlCommand*)command
  772. {
  773. NSString* callbackId = [command callbackId];
  774. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  775. MKMapView* mapView = [self.webView viewWithTag:mapId];
  776.  
  777. NSArray* pins = [[command arguments] objectAtIndex:1];
  778. NSMutableArray* Pins = [[NSMutableArray alloc] init];
  779.  
  780. for (int i = 0; i < pins.count; i++)
  781. {
  782. NSArray* pinInfo = [pins objectAtIndex:i];
  783.  
  784. CGFloat lat = [[pinInfo objectAtIndex:0]floatValue];
  785. CGFloat lon = [[pinInfo objectAtIndex:1]floatValue];
  786. NSString* title = [pinInfo objectAtIndex:2];
  787. NSString* description = [pinInfo objectAtIndex:3];
  788.  
  789. MKPointAnnotation* pin = [[MKPointAnnotation alloc]init];
  790. pin.coordinate = CLLocationCoordinate2DMake(lat, lon);
  791. pin.title = title;
  792. pin.subtitle = description;
  793.  
  794. [Pins addObject:pin];
  795. }
  796.  
  797. [mapView addAnnotations:Pins];
  798.  
  799. CDVPluginResult* result = [CDVPluginResult
  800. resultWithStatus:CDVCommandStatus_OK
  801. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  802.  
  803. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  804.  
  805. }
  806.  
  807. - (void)removeMapPin:(CDVInvokedUrlCommand*)command
  808. {
  809. NSString* callbackId = [command callbackId];
  810. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  811. NSString* pinTitle = [[command arguments] objectAtIndex:1];
  812. MKMapView* mapView = [self.webView viewWithTag:mapId];
  813.  
  814. NSArray* pins = [mapView annotations];
  815.  
  816. for (int i = 0; i < pins.count; i++)
  817. {
  818. MKPointAnnotation* pin = [pins objectAtIndex:i];
  819. if (pin.title == pinTitle)
  820. {
  821. [mapView removeAnnotation:pin];
  822. }
  823. }
  824.  
  825.  
  826. CDVPluginResult* result = [CDVPluginResult
  827. resultWithStatus:CDVCommandStatus_OK
  828. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  829.  
  830. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  831.  
  832. }
  833.  
  834. - (void)removeAllMapPins:(CDVInvokedUrlCommand*)command
  835. {
  836. NSString* callbackId = [command callbackId];
  837. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  838. MKMapView* mapView = [self.webView viewWithTag:mapId];
  839.  
  840. [mapView removeAnnotations:mapView.annotations];
  841.  
  842.  
  843. CDVPluginResult* result = [CDVPluginResult
  844. resultWithStatus:CDVCommandStatus_OK
  845. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  846.  
  847. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  848.  
  849. }
  850.  
  851. - (void)addComplexMapPin:(CDVInvokedUrlCommand*)command
  852. {
  853. NSString* callbackId = [command callbackId];
  854. CGFloat mapId = [[[command arguments] objectAtIndex:0] floatValue];
  855. CGFloat lat = [[[command arguments] objectAtIndex:1]floatValue];
  856. CGFloat lon = [[[command arguments] objectAtIndex:2]floatValue];
  857. NSString* title = [[command arguments] objectAtIndex:3];
  858. NSString* description = [[command arguments] objectAtIndex:4];
  859. CGFloat pinColor = [[[command arguments] objectAtIndex:5] floatValue];
  860. NSString* pinImage = [[command arguments] objectAtIndex:6];
  861. CGFloat pinImageOffsetX = [[[command arguments] objectAtIndex:7] floatValue];
  862. CGFloat pinImageOffsetY = [[[command arguments] objectAtIndex:8] floatValue];
  863. CGFloat draggable = [[[command arguments] objectAtIndex:9] floatValue];
  864. CGFloat canShowCallout = [[[command arguments] objectAtIndex:10] floatValue];
  865. CGFloat showInfoButton = [[[command arguments] objectAtIndex:11] floatValue];
  866. // CGFloat inaccuracyRadius = [[[command arguments] objectAtIndex:6]floatValue];
  867. MKMapView* mapView = [self.webView viewWithTag:mapId];
  868.  
  869.  
  870.  
  871. MKComplexMapPin* pinAnnotation = [[MKComplexMapPin alloc] init];
  872. pinAnnotation.coordinate = CLLocationCoordinate2DMake(lat, lon);
  873. pinAnnotation.title = title;
  874. pinAnnotation.subtitle = description;
  875. pinAnnotation.mapId = mapId;
  876.  
  877.  
  878.  
  879. if (pinColor == 1)
  880. {
  881. pinAnnotation.pinColor = MKPinAnnotationColorRed;
  882. }
  883. else if (pinColor == 2)
  884. {
  885. pinAnnotation.pinColor = MKPinAnnotationColorGreen;
  886. }
  887. else if (pinColor == 3)
  888. {
  889. pinAnnotation.pinColor = MKPinAnnotationColorPurple;
  890. }
  891. else
  892. {
  893. pinAnnotation.pinColor = MKPinAnnotationColorRed;
  894. }
  895.  
  896. if ([pinImage length] != 0) {
  897. pinAnnotation.customImage = YES;
  898. pinAnnotation.pinImage = pinImage;
  899. pinAnnotation.pinImageOffsetX = pinImageOffsetX;
  900. pinAnnotation.pinImageOffsetY = pinImageOffsetY;
  901. }
  902.  
  903. if ([pinImage length] != 0) {
  904. pinAnnotation.customImage = YES;
  905. pinAnnotation.pinImage = pinImage;
  906. pinAnnotation.pinImageOffsetX = pinImageOffsetX;
  907. pinAnnotation.pinImageOffsetY = pinImageOffsetY;
  908. }
  909.  
  910. if (draggable > 0)
  911. {
  912. pinAnnotation.draggable = YES;
  913. }
  914. else
  915. {
  916. pinAnnotation.draggable = NO;
  917. }
  918.  
  919. if (canShowCallout > 0)
  920. {
  921. pinAnnotation.canShowCallout = YES;
  922. }
  923. else
  924. {
  925. pinAnnotation.canShowCallout = NO;
  926. }
  927.  
  928. if (showInfoButton > 0)
  929. {
  930. pinAnnotation.showInfoButton = YES;
  931. }
  932. else
  933. {
  934. pinAnnotation.showInfoButton = NO;
  935. }
  936.  
  937. // pinAnnotation.canShowCallout = canShowCallout;
  938.  
  939. [mapView addAnnotation:pinAnnotation];
  940.  
  941. CDVPluginResult* result = [CDVPluginResult
  942. resultWithStatus:CDVCommandStatus_OK
  943. messageAsString:[NSString stringWithFormat:@"%f", mapId]];
  944.  
  945. [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
  946.  
  947. }
  948.  
  949. -(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
  950. id <MKAnnotation> annotation = [view annotation];
  951. if ([annotation isKindOfClass:[MKComplexMapPin class]])
  952. {
  953. MKComplexMapPin *pin = (MKComplexMapPin *)annotation;
  954. NSLog(@"Clicked Complex Pin Infobutton");
  955. // NSLog(pin.mapId);
  956. NSLog(pin.title);
  957. NSMutableString* jsParam = [[NSMutableString alloc] init];
  958. [jsParam appendString:@"\""];
  959. [jsParam appendString:[NSString stringWithFormat:@"%f", pin.mapId]];
  960. [jsParam appendString:@"\""];
  961. [jsParam appendString:@","];
  962. [jsParam appendString:@"\""];
  963. [jsParam appendString:pin.title];
  964. [jsParam appendString:@"\""];
  965. NSLog(jsParam);
  966.  
  967. NSString* jsString = [NSString stringWithFormat:@"MKInterface.__objc__.pinInfoClickCallback(%@);", jsParam];
  968. [(UIWebView*)self.webView stringByEvaluatingJavaScriptFromString:jsString];
  969. }
  970.  
  971. }
  972.  
  973. -(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState {
  974. id <MKAnnotation> annotation = [view annotation];
  975. if ([annotation isKindOfClass:[MKComplexMapPin class]] && newState == MKAnnotationViewDragStateEnding)
  976. {
  977. MKComplexMapPin *pin = (MKComplexMapPin *)annotation;
  978. NSLog(@"Moved Complex Pin Infobutton");
  979. NSLog(@"%f", pin.mapId);
  980. NSLog(pin.title);
  981. NSMutableString* jsParam = [[NSMutableString alloc] init];
  982. [jsParam appendString:@"\""];
  983. [jsParam appendString:[NSString stringWithFormat:@"%f", pin.mapId]];
  984. [jsParam appendString:@"\""];
  985. [jsParam appendString:@","];
  986. [jsParam appendString:@"\""];
  987. [jsParam appendString:pin.title];
  988. [jsParam appendString:@"\""];
  989. [jsParam appendString:@","];
  990. [jsParam appendString:[NSString stringWithFormat:@"%f", pin.coordinate.latitude]];
  991. [jsParam appendString:@","];
  992. [jsParam appendString:[NSString stringWithFormat:@"%f", pin.coordinate.longitude]];
  993. NSLog(jsParam);
  994.  
  995. NSString* jsString = [NSString stringWithFormat:@"MKInterface.__objc__.pinDragCallback(%@);", jsParam];
  996. [(UIWebView*)self.webView stringByEvaluatingJavaScriptFromString:jsString];
  997. }
  998.  
  999. }
  1000.  
  1001. - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(nonnull MKAnnotationView *)view
  1002. {
  1003. id <MKAnnotation> annotation = [view annotation];
  1004. if ([annotation isKindOfClass:[MKComplexMapPin class]])
  1005. {
  1006. MKComplexMapPin *pin = (MKComplexMapPin *)annotation;
  1007. NSLog(@"Clicked Complex Pin");
  1008. NSLog(@"%f", pin.mapId);
  1009. NSLog(pin.title);
  1010. NSMutableString* jsParam = [[NSMutableString alloc] init];
  1011. [jsParam appendString:@"\""];
  1012. [jsParam appendString:[NSString stringWithFormat:@"%f", pin.mapId]];
  1013. [jsParam appendString:@"\""];
  1014. [jsParam appendString:@","];
  1015. [jsParam appendString:@"\""];
  1016. [jsParam appendString:pin.title];
  1017. [jsParam appendString:@"\""];
  1018. NSLog(jsParam);
  1019.  
  1020. NSString* jsString = [NSString stringWithFormat:@"MKInterface.__objc__.pinClickCallback(%@);", jsParam];
  1021. [(UIWebView*)self.webView stringByEvaluatingJavaScriptFromString:jsString];
  1022. }
  1023. }
  1024.  
  1025. - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
  1026. {
  1027. if ([annotation isKindOfClass:[MKUserLocation class]])
  1028. return nil;
  1029.  
  1030. static NSString *reuseSimplePinId = @"SimplePin";
  1031. static NSString *reuseComplexPinId = @"ComplexPin";
  1032. static NSString *reuseCustomImageComplexPinId = @"CustomImageComplexPin";
  1033. MKAnnotationView *pav = nil;
  1034. if ([annotation isKindOfClass:[MKComplexMapPin class]])
  1035. {
  1036. MKComplexMapPin *pin = (MKComplexMapPin *)annotation;
  1037. if (pin.customImage)
  1038. {
  1039. pav = [mapView dequeueReusableAnnotationViewWithIdentifier:reuseCustomImageComplexPinId];
  1040. if (pav == nil)
  1041. {
  1042. pav = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseCustomImageComplexPinId];
  1043. }
  1044. else
  1045. {
  1046. pav.annotation = annotation;
  1047. }
  1048.  
  1049. NSURL *url = [NSURL URLWithString:pin.pinImage];
  1050. NSData *imageData = [NSData dataWithContentsOfURL:url];
  1051. pav.image = [UIImage imageWithData:imageData];
  1052. pav.centerOffset = CGPointMake(pin.pinImageOffsetX, pin.pinImageOffsetY);
  1053. }
  1054. else
  1055. {
  1056. pav = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseComplexPinId];
  1057. if (pav == nil)
  1058. {
  1059. pav = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseComplexPinId];
  1060. }
  1061. else
  1062. {
  1063. pav.annotation = annotation;
  1064. }
  1065.  
  1066.  
  1067. ((MKPinAnnotationView *)pav).pinColor = pin.pinColor;
  1068. }
  1069.  
  1070. pav.draggable = pin.draggable;
  1071. pav.canShowCallout = pin.canShowCallout;
  1072.  
  1073. if (pin.showInfoButton)
  1074. {
  1075. UIButton* info = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
  1076. pav.rightCalloutAccessoryView = info;
  1077. }
  1078.  
  1079. }
  1080. else if ([annotation isKindOfClass:[MKPointAnnotation class]])
  1081. {
  1082. pav = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseSimplePinId];
  1083. if (pav == nil)
  1084. {
  1085. pav = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseSimplePinId];
  1086. }
  1087. else
  1088. {
  1089. pav.annotation = annotation;
  1090. }
  1091. pav.canShowCallout = YES;
  1092. }
  1093.  
  1094. return pav;
  1095. }
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement