Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create GEOSwiftCoreGraphics Add-On Library #129

Open
siltrifork opened this issue Dec 6, 2018 · 9 comments
Open

Create GEOSwiftCoreGraphics Add-On Library #129

siltrifork opened this issue Dec 6, 2018 · 9 comments

Comments

@siltrifork
Copy link

siltrifork commented Dec 6, 2018

Hi,

I would like to draw my Polygons directly on an UIView. I don't have the need for an underlying map since the geojson file I'm parsing is basically represeting paths for drawing a polygon for every single country in the world. So the end result would be a world map drawn with polygons.

The reason why I don't want an underlying map:

  1. The rendering time of the map is too slow
  2. I don't have a need for any labels, roads or other map information
  3. I can't zoom out and show the entire world with MapKit.

I use below methods to parse the geojson file and get geometries from it:

func overlayEntireMap(completion: @escaping () -> Void) {
        background {
            if let geoJSONURL = Bundle.main.url(forResource: "countries", withExtension: "geojson") {
                if let features = try! Features.fromGeoJSON(geoJSONURL) {
                    self.features = features
                    self.drawPolygonsFromFeatures(features)
                }
                completion()
            }
        }
    }

func drawPolygonsFromFeatures(_ features: Features) {
        for feature in features {
            if let geometries = feature.geometries {
                for geometry in geometries {
                    
                }
            }
        }
    }

So I hope you have a solution for this :)

@macdrevx
Copy link
Member

macdrevx commented Dec 6, 2018

Check out Polygon's draw function in https://github.com/GEOSwift/GEOSwift/blob/master/GEOSwift/QuickLook.swift#L111 for an example. Given a MKMapRect, it renders the shape into a graphics context. While you probably won't want to use this function itself, you should be able to adapt the code to your use case.

@siltrifork
Copy link
Author

Thank you for your reply. However I'm not really sure how I go from having a Geometry object to having a Polygon object? Could you maybe show a code-example?

I can see that I can reach the "debugQuickLookObject" by writing geometry.debugQuickLookObject(), but the Polygon object I get from this object is a MKPolygon.

So some assistance would be greatly appreciated :)

@vfn
Copy link
Member

vfn commented Dec 11, 2018 via email

@siltrifork
Copy link
Author

I already asked on Stack Overflow (https://stackoverflow.com/questions/53613266/swift-convert-mkpolygon-to-uibeizerpath-and-draw-path-on-uiview). The questions is with a bit different approach than asked here, but I thought it would be more likely to get an answer from you guys than the Stack Overflow community.

Anyway I will try and see if I can make magic happen.

@alexcurylo
Copy link

@siltrifork I have the exact same use case, want to render a complete world map directly from GeoJSON -- did you manage to find some easy way to do so?

@macdrevx
Copy link
Member

I’ll mark this as a feature request. Perhaps we can add something to make this easier in the future.

Sent with GitHawk

@siltrifork
Copy link
Author

siltrifork commented Apr 5, 2019

@siltrifork I have the exact same use case, want to render a complete world map directly from GeoJSON -- did you manage to find some easy way to do so?

@alexcurylo - No unfortunately not. I still use MapKit, but I ended up with a solution where I render every tile on the map with an overlay so the entire map becomes blank. Then I draw the polygons with mapkit and kind of get the result I wanted.

So I'm happy that this has become a feature request, so we can work smarter in the future 👍

@alexcurylo
Copy link

It actually turned out not too hard to parse GeoJSON into reasonable looking UIBezierPaths, at least with my particular file; take a look at WorldMap.swift here if you like, I imagine it'd be more performant than MapKit rendering...

@macdrevx
Copy link
Member

macdrevx commented Sep 2, 2019

I'd love to see this functionality provided in an add-on library in the GEOSwift family. Maybe something like GEOSwiftCoreGraphics?

@macdrevx macdrevx changed the title Draw polygons on UIView Create GEOSwiftCoreGraphics Add-On Library Mar 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants