0

小さな町のタイルをズーム 15 から 18 でダウンロードしました。期待どおりに表示されていましたが、現在は表示されません。Yosemiteでswift 2でxcode 7を使用していました。私は現在、sierraでswift 3を使用してxcode 8.1を使用しています。アップグレードの前に問題が始まったと確信していますが、戻るタイムマシンはありません。IPad 2 でアプリをテストしたかったのでアップグレードしましたが、xcode が ipad の ios と互換性がないというメッセージが表示され、xcode 8.1 を Yosemite にロードできないというメッセージが表示されたため、sierra にアップグレードしました。コードは以下です。そして、その下のコンソール出力。エラーなし

//
//  MapViewController.swift
//  button scale
//
//  Created by Colin McGarry on 24/03/16.
//  Copyright © 2016 Colin McGarry. All rights reserved.
//

import UIKit
import MapKit
import CoreLocation


class MapViewController: UIViewController /*, MKMapViewDelegate*/{

  var guideData: GuideData?
  var dataM:[GuideData] = [GuideData]()
  var placeNumb = 0

  var modifyingMap = true

  @IBOutlet weak var mapView: MKMapView!

  override func viewDidLoad() {
        super.viewDidLoad()

      let IS_RETINA = (UIScreen.mainScreen().respondsToSelector(#selector(UIScreen.displayLinkWithTarget(_:selector:))) && (UIScreen.mainScreen().scale >= 2.0))
      // from shankar map
    if IS_RETINA {
      print("Is Retina")
    } else {
      print("not retina")
    }
      zoomToRegion()

      let annotations = getMapAnnotations()
      // Add mappoints to Map
      mapView.addAnnotations(annotations)

      // end shankar map



    //Get the URL template to the map tiles
    let baseURL = NSBundle.mainBundle().bundleURL.absoluteString

    let urlTemplate = baseURL!.stringByAppendingString("osmm/{z}/{x}/{y}.png/")
    //let urlTemplate = baseURL.stringByAppendingString("two/{z}/{x}/{y}@2x.png/")
    //let urlTemplate = "http://tile.openstreetmap.org/{z}/{x}/{y}.png"

    print(urlTemplate)


    let carte_indice = MKTileOverlay(URLTemplate:urlTemplate)

    carte_indice.geometryFlipped = false

    carte_indice.canReplaceMapContent = true

    //carte_indice.tileSize = CGSize(width: 512, height: 512)

    carte_indice.maximumZ = 16
    carte_indice.minimumZ = 18



    self.mapView.addOverlay(carte_indice)


     }

  /// from shankar map

  func zoomToRegion() {
    let location = CLLocationCoordinate2D(latitude: 49.275, longitude: -0.7028)
    let region =  MKCoordinateRegionMakeWithDistance(location, 500.0, 500.0)
    mapView.setRegion(region, animated: true)
  }

  //MARK:- Annotations

  func getMapAnnotations() -> [Stands] {
    var annotations:Array = [Stands]()

    //load plist file
    var stands: NSArray?
    if let path = NSBundle.mainBundle().pathForResource("stands", ofType: "plist") {
      stands = NSArray(contentsOfFile: path)
      }
    //iterate and create annotations
    if let items = stands {
      for item in items {
        let lat = item.valueForKey("lat") as! Double
        let long = item.valueForKey("long")as! Double
        let annotation = Stands(latitude: lat, longitude: long)
        let tit = item.valueForKey("title") as! String
        let numb = item.valueForKey("no") as! Int
        annotation.title = "\(numb) \(tit)"
        annotation.no = numb
        // new added
        // annotation.enabled = true
        // annotation.canShowCallOut = true
        // end added
        annotations.append(annotation)
      }
    }
    return annotations
  }




  // end From Shankar map

  func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
    // 1
    let identifier = "Stand"

    // 2
    if annotation.isKindOfClass(Stands.self) {
      // 3
      var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)

      if annotationView == nil {
        //4
        annotationView = MKPinAnnotationView(annotation:annotation, reuseIdentifier:identifier)
        annotationView!.canShowCallout = true

        // 5
        let btn = UIButton(type: .DetailDisclosure)
        annotationView!.rightCalloutAccessoryView = btn
      } else {
        // 6
        annotationView!.annotation = annotation
      }

      return annotationView
    }

    // 7
    return nil
  }

  func mapView( mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) {
    let standM = view.annotation as! Stands
    let placeName = standM.title
    let placeInfo = standM.title
    placeNumb = standM.no!
    /*
    let ac = UIAlertController(title: placeName, message: placeInfo, preferredStyle: .Alert)
    ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
    presentViewController(ac, animated: true, completion: nil) */

    performSegueWithIdentifier("MapToText", sender: self)


    }


  func mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
    // enforce maximum zoom level
    let place = mapView.visibleMapRect

    if(  place.origin.x < 133686298
      || place.origin.x > 133697376
      || place.origin.y < 91864219
      || place.origin.y > 91874305
      )
    {
      zoomToRegion()
    }

    print("alt \(mapView.camera.altitude)")
    let maxAlt = 3000.00
    if (mapView.camera.altitude >  maxAlt && self.modifyingMap)
    {
      self.modifyingMap = false
      // prevents strange infinite loop case

      self.mapView.zoomEnabled = false
/*      self.mapView.scrollEnabled = false
      self.mapView.userInteractionEnabled = false
      */


      print("place \(place)")

      self.mapView.camera.altitude = maxAlt
      self.modifyingMap = true
      print("alt>\(maxAlt)")
    } else {
      self.mapView.zoomEnabled = true
      print("place2 \(place)")
      print("x \(place.origin.x)")
      print(" alt less than \(maxAlt)")
      print(mapView.camera.altitude)
    }

  }

  func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer!
  {
    print("call overlay")
    if overlay is MKTileOverlay
    {

      print("is MKTileoverlay")


      let renderer = MKTileOverlayRenderer(overlay:overlay)

      renderer.alpha = 0.8

      return renderer
    }
    return nil
  }




override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
  if segue.identifier == "MapToText" {

    let webviewController:webViewController = segue.destinationViewController as! webViewController

    webviewController.index = placeNumb - 1

    // webviewController.standTitle = sender as! MKAnnotationView
    webviewController.inde = placeNumb - 1
    print("prepSeg \(webviewController.inde)")
  }




}

}

コンソール出力

/Users/colinmcgarry/Library/Developer/CoreSimulator/Devices/4F5E35FC-45F9-4A16-8A0A-1AFD51616CCA/data/Containers/Bundle/Application/046B53E5-D3CD-4E7A-926D-7D77E069AAA0/button scale.app/stands.plist
Optional("/Users/colinmcgarry/Library/Developer/CoreSimulator/Devices/4F5E35FC-45F9-4A16-8A0A-1AFD51616CCA/data/Containers/Bundle/Application/046B53E5-D3CD-4E7A-926D-7D77E069AAA0/button scale.app/2page.html")
Is Retina
alt 1100.94691259802
place2 MKMapRect(origin: __C.MKMapPoint(x: 133691120.58898854, y: 91870217.34526816), size: __C.MKMapSize(width: 5123.4971518665552, height: 6063.3100336045027))
x 133691120.588989
 alt less than 3000.0
1100.94691259802
file:///Users/colinmcgarry/Library/Developer/CoreSimulator/Devices/4F5E35FC-45F9-4A16-8A0A-1AFD51616CCA/data/Containers/Bundle/Application/046B53E5-D3CD-4E7A-926D-7D77E069AAA0/button%20scale.app/osmm/{z}/{x}/{y}.png/
call overlay
is MKTileoverlay
4

1 に答える 1