Reputation: 839
I have a very simple GeoJSON that covers the entire globe:
{
"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]
]
]
}
}
]
}
In order to display this polygon on my map, I simply do this:
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()
}
When I view the GeoJSON here, for example, it appears perfectly. However, when I try to render on a GMSMapView on iOS, it does not render at all.
How can I make the polygon be visible?
Upvotes: 2
Views: 492
Reputation: 3597
I have used a working approximation to achieve something like this. It, as far as I can tell, looks perfectly fine to the user, but keep in mind it is not perfect. There are two things that are problematic here.
Major vs. minor
The map is not actually clipping anything: it is drawing a direct line from 0 to 0. That is, it is not going all the way around the globe. In a way, you can say it is drawing the minor arc instead of the major arc.
Overlap
Using 180 will make the polygon overlap with itself, which makes it sort of glitchy. Additionally, you have the map extend about 5º above and below the map's boundaries, which seems to cause problems as well.
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
Upvotes: 2