mapbox-gl-rs
mapbox-gl-rs copied to clipboard
Style as string or struct
Hello. I am using this crate in a project of my own, and had to make the changes encapsulated here for my own purposes. Just wanted to bundle them into a PR to see if they wouldn't be of interest to you.
Why
The specification for the object passed to the Map
constructor in the JS library is documented here (this is the MapOptions
struct in this crate). In the JS spec, the style
property can be an Object
conforming to the Mapbox Style spec or a string
that references a document with such a spec. Currently, this crate only accepts the string form of this property. This PR adds the ability for a style spec Object
to be passed as well.
What
The core of this PR is the addition of a StyleOrRef
enum that expresses the optional Object
or string
in JS. It also adds the minimal features of a valid Style
object (the required properties of the above-linked spec). It also makes some small modifications to existing method definitions to support the new type. Last, it adds a simple example to demonstrate how to use the new enum type.
NB
- As mentioned above, this PR only adds support for the minimal, required properties of a
Style
object -- it does not pretend to fully support these objects! If this PR is accepted, it should be followed up with another PR to add all of that support. - There are other places in the object passed to a
Map
constructor that allow for a similar option between a simple type or more elaborate object. This PR is only interested in thestyle
property; if it is of interest to add similar functionality elsewhere, I think this PR may serve as a good pattern to adopt.