0

我已经下载了缩放 15 到 18 的小镇的瓷砖。它们按预期显示,但现在没有。我在 Yosemite 上使用 xcode 7 和 swift 2。我现在在 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

1

我发现了问题。但它不在我包含的代码中。我放了最小和最大缩放。当我更改值时,我交换了最小值和最大值

叠加.maximumZ = 15

覆盖.minimumZ = 17

这些条件相互矛盾,因此没有显示叠加。如果我把 min 写在 max 之上,我之前可能已经注意到了。

于 2017-01-24T16:45:18.110 回答