完整世界 GeoJson 未出现在 Google 地球 iOS API 中

Full world GeoJson not appearing in Google Earth iOS API

我有一个覆盖整个地球的非常简单的 GeoJSON:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
         "coordinates": [
           [
             [-180.0, -90.0],
             [180.0, -90.0], 
             [180.0, 90.0], 
             [-180.0, 90.0], 
             [-180.0, -90.0]
           ]
         ]
      }
    }
  ]
}

为了在我的地图上显示这个多边形,我只是这样做:

if let url = Bundle.main.url(forResource: "sc_europe", withExtension: "geojson") {
    parser = GMUGeoJSONParser(url: url)
    parser.parse()
    renderer = GMUGeometryRenderer(map: map, geometries: parser.features)
    renderer.render()
} 

例如,当我查看 GeoJSON here 时,它看起来很完美。但是,当我尝试在 iOS 上的 GMSMapView 上呈现时,它根本不呈现。

如何使多边形可见?

我使用了一个有效的近似值来实现这样的效果。据我所知,它对用户来说看起来非常好,但请记住它并不完美。这里有两个问题。

问题

  1. 主要与次要
    地图实际上并没有裁剪任何东西:它正在绘制一条从 0 到 0 的直线。也就是说,它并没有绕地球一圈。在某种程度上,你可以说它绘制的是次弧而不是主弧。

  2. 重叠
    使用 180 会使多边形与自身重叠,这使得它有点故障。此外,地图在地图边界上方和下方延伸了大约 ,这似乎也会导致问题。

修复

CLLocationCoordinate2D(latitude: -85.0511, longitude: -180),      // latitude a little below the true maximum
CLLocationCoordinate2D(latitude: -85.0511, longitude: 0),         // Force major arc 
CLLocationCoordinate2D(latitude: -85.0511, longitude: 179.9999),  // no overlap
CLLocationCoordinate2D(latitude: 85.0511, longitude: 179.9999),   // no overlap
CLLocationCoordinate2D(latitude: 85.0511, longitude: 0),          // Force major arc
CLLocationCoordinate2D(latitude: 85.0511, longitude: -180)        // close the polygon