首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xcode 6中的Mapkit在放大时只显示日期线以西的覆盖(使用Swift)

Xcode 6中的Mapkit在放大时只显示日期线以西的覆盖(使用Swift)
EN

Stack Overflow用户
提问于 2014-10-13 15:55:33
回答 1查看 615关注 0票数 3

我大概花了6个小时对这个问题进行了研究和尝试,并陷入了困境--帮助!

我在世界各地创建了一组简单的纵向多线线,当日期线(反子午线)在180度E/W可见时,我会发现奇怪的行为。如果完全放大,所有的复线正确显示,但一旦我开始放大,反子午线以东的线开始消失。如果我放大,线会重新出现。或者,如果我平移到地图上,所以蚂蚁线/日期线就在视图的左边边缘,那么所有的线也会重新出现(不管缩放级别如何)!我在下面展示4张截图:

  • (未显示)跨度约为。108度及以上(所有多角线可见)
  • 跨度为101度(我在日期线以东的折线开始消失)

  • 跨距92度(更多线消失)

  • 跨度为81度(日期线以东的所有多边形都消失了)

  • 跨度为82,日期线刚好在左边边沿(所有的折线都会重新出现) //忽略这张屏幕截图中的线条看起来更薄--我一直在玩线的厚度。

我的密码在下面。对每个区域更新都调用绞车网格()函数。这在iOS 8+ iPhone 6模拟器和实际设备(运行iOS 7.1的iPhone 4)中都是相同的。

代码语言:javascript
复制
func drawgrid() {
    var b: [CLLocationCoordinate2D] = []    
    for var x = -179.99; x <= 179.99; x = x + 1.0 { // I tried -180.0 to 180.0 as well -> no effect     
        let c1 = CLLocationCoordinate2D(latitude: 90.0, longitude: x) // Tried 80.0 as well
        let c2 = CLLocationCoordinate2D(latitude: -90.0, longitude: x) // Tried -80.0 as well
        b = [c1, c2]
        var polyline = MKPolyline(coordinates: &b, count: b.count)
        mapView.addOverlay(polyline)
    }
}

func mapView(mapView: MKMapView!,regionDidChangeAnimated animated: Bool) {
    mapView.removeOverlays(mapView.overlays) // Already tried commenting this out (it's for a different purpose elsewhere in the app)
    drawgrid()
    MyLabel.text = "Span = \(mapView.region.span.longitudeDelta) deg"
    MyLabel2.text = "Center = \(mapView.region.center.longitude) \(mapView.region.center.latitude)"
}

func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {
    if overlay is MKPolyline{
        var polylineRenderer = MKPolylineRenderer(overlay: overlay)
        polylineRenderer.strokeColor = UIColor.redColor()
        polylineRenderer.lineWidth = 0.1 // tried thicker value of 1.0 too
        return polylineRenderer
    }
    return nil
}

任何和所有的帮助都非常感谢!我是个新手(几周前刚开始编码),所以如果你能用Swift而不是Objective提供指导的话,我就不会把头撞到桌子上了。谢谢!

编辑11/22/2014:仍然存在这个问题,它似乎不仅影响覆盖,而且影响注释。只要国际日期行在视图中,我所有的注释都会消失,不管它们在地图上的位置。仍然找不到办法绕过这件事,它闻起来真像一只虫子.

EN

回答 1

Stack Overflow用户

发布于 2014-10-14 01:33:14

添加以下println()。

代码语言:javascript
复制
    func mapView(mapView: MKMapView!,regionDidChangeAnimated animated: Bool) {
    println("region did change*****************************") // Added
    mapView.removeOverlays(mapView.overlays) // Already tried commenting this out (it's for a different purpose elsewhere in the app)
    drawgrid()
    MyLabel.text = "Span = \(mapView.region.span.longitudeDelta) deg"
    MyLabel2.text = "Center = \(mapView.region.center.longitude) \(mapView.region.center.latitude)"
}

代码语言:javascript
复制
    func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {





    if overlay is MKPolyline{
        var polylineRenderer = MKPolylineRenderer(overlay: overlay)
        polylineRenderer.strokeColor = UIColor.redColor()
        polylineRenderer.lineWidth = 1 // tried thicker value of 1.0 too
        println("Lonitude " + "\(overlay.coordinate.longitude)") //Added
        return polylineRenderer
    }
    return nil
}

然后运行您的应用程序并查看控制台框,您将看到您的值显示为正常,直到您到达问题区域,然后负经度在某个点被切断。

查找renderForOverlay函数的引用。ref/occ/instm/MKMapView/addOverlays:它说,正在包围的多边形与地图的视图部分相交,它将被呈现(我认为是那些不会被渲染的)。我相信这可能是你的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26344094

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档