h0shy / pytheas Goto Github PK
View Code? Open in Web Editor NEWGeoJSON Serializer and Deserializer for MapKit and GoogleMaps
License: MIT License
GeoJSON Serializer and Deserializer for MapKit and GoogleMaps
License: MIT License
With the objective in mind of having every elements of our model Equatable
, it could be nice to reduce the usage of Any
.
When parsing a shape we could replace [Any]
by a generic type implementing Equatable.
Hey there,
so if you want to support both Apple MapKit and GoogleMaps I would suggest to not include these in your library, what makes them more platform independent. Instead a consumer needs the following data structures (that you have to construct from the GeoJSON), so heβs able to easily build polygons or poly lines or points for the respective platforms:
Path
that defines a set of coordinates coordinates: [CLLocationCoordinate2D]
. coordinates
must never be nil or empty and contain at least 2 items since otherwise it is a Position
(see below).Polygon
that has the properties path: Path
which defines the outer hull, interiorPolygons: [Polygon]
which is again a Polygon and defines inner holes plus whatever metadata there might be attached (title, etc.). interiorPolygons
should never be nil but can be empty. path
must never be nil and must contain at least 3 coordinates since otherwise it is not possible to construct a polygon (the smallest polygon is a triangle) .PolyLine
that has the property path: Path
which defines the poly line plus whatever metadata there might be attached (title, etc.). path
must contain at least 2 coordinates since that is the minimum amount for a line.Position
that has the properties coordinate: CLLocationCoordinate2D
which defines the position plus whatever metadata there might be attached (title, etc.). coordinate
must never be nil and never has the value kCLLocationCoordinate2DInvalid
(check with the function CLLocationCoordinate2DIsValid() before adding to results).You only have to define these structures. Since GeoJson can also contain multi-polygons and poly-lines the result of the parsing function of your library should be another struct Geometry
that contains the properties polygons: [Polygon]
, lines: [PolyLine]
and positions: [Position]
. All the constraints above can nicely be covered by unit tests π
Thats it! With this I can construct both Google and Apple objects. Do you think that is realistic?
PS: As a plus it would be nice to provide the computed property encodedPath: String
for the struct Path
since google objects are initialized using this string. The good thing is that this is an open standard which does not require to include the whole google library. We also have the algorithm for that in the app so this extra is not required but would be a nice addition. Documentation of how to construct it can be found here.
This would integrate much better in current and future projects and helps the user to avoid boilerplate code.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.