离线地图图块已停止显示

时间:2016-12-12 19:03:34

标签: ios swift3 mktileoverlay

我已经在15到18号的缩放下载了一个小镇的瓷砖。它们按预期显示但现在没有。 我在Yosemite上使用xcode 7和swift 2。我现在使用xcode 8.1和sierra上的swift 3。我很确定在升级之前问题已经开始,但是没有时间机器可以返回。我升级是因为我想在我的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

1 个答案:

答案 0 :(得分:1)

我发现了问题。但它不在我所包含的代码中。 我放了最小和最大变焦。当我改变值时,我互换了min和max

overlay.maximumZ = 15

overlay.minimumZ = 17

这些条件是相互矛盾的,所以叠加没有表现出来。 如果我写得超过最大值,我可能已经注意到了。