Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Runtime styling API #837

Closed
incanus opened this issue Feb 10, 2015 · 16 comments
Closed

Runtime styling API #837

incanus opened this issue Feb 10, 2015 · 16 comments
Assignees
Labels
GL JS parity For feature parity with Mapbox GL JS

Comments

@incanus
Copy link
Contributor

incanus commented Feb 10, 2015

[Updated 20 April 2016 by @jfirebaugh]

The Mapbox GL Style Specification forms the domain model for Mapbox maps. It defines objects such as:

  • styles
  • sources
  • layers
  • paint and layout properties

These domain objects are central to rendering and manipulating the map, and they should be exposed by both the core mapbox-gl-native API and by the Android and iOS bindings.

This functionality exists in mapbox-gl-js already, via APIs such as addSource, addLayer, and setPaintProperty. Together, we call this set of APIs the runtime styling API (not to be confused with the Mapbox Styles API, a web API).

To get a sense of what is possible with read and write access to the style and its contents, take a look the mapbox-gl-js examples: the large majority of them use one or more runtime styling APIs.

Furthermore, the rich functionality provided by mapbox-gl-js plugins like mapbox-gl-directions, mapbox-gl-geocoder, and mapbox-gl-draw are enabled by the runtime styling API.

What we have now

mapbox-gl-native and the mobile SDKs currently have an "Annotations API" which provides some forms of runtime styling, namely adding and removing markers, lines, and polygons, with a limited degree of control over their visual appearance.

Rough compatibility with other mapping SDKs, and familiarity to users porting from them, were higher design priorities for the Annotations API than exposing the full gamut of GL style capabilities. This allowed us to satisfy a number of common and important use cases quickly, but it is limiting in a number of respects, and has led to a impedance mismatch between what users expect to be able to accomplish with the Annotations API versus what can be tractably and efficiently implemented.

The primary problem in this regard is that the Annotations API does not provide any means to group annotations into subsets that share common data sources or rendering properties. This is exactly the problem that style sources and layers were designed to solve, and instead of continuing to try to warp the Annotations API to fit sources and layers, or vice versa, we should expose sources and layers as first class API entities.

Specific runtime styling API related feature requests

Timeline

We've been working on internal prerequisites for a runtime styling API for some time now. Most importantly, we:

  • Converted the internal representation of layers to a class hierarchy matching the style specification
  • Moved ownership of the style and associated data from an auxiliary thread to the main thread, so that it is possible to manipulate it without complex cross-thread communication

Current development on the runtime styling API is focused on adding support to the core C++ API for adding and manipulating layers, including rendering properties. The approach is to use code generators whose input is the style specification itself.

Another major task that remains is to convert the internal representation of sources to a class hierarchy matching the style specification. This is a significant internal refactoring that will be necessary to support runtime creation and manipulation of sources.

The runtime styling API is a high priority, but as always, competes with other high priority items for resources. We currently aim to ship a runtime styling API in some form in late Q2 to early Q3.

@incanus incanus added the GL JS parity For feature parity with Mapbox GL JS label Feb 10, 2015
@kkaefer
Copy link
Member

kkaefer commented Feb 17, 2015

also see #883 #881

@1ec5
Copy link
Contributor

1ec5 commented Jun 26, 2015

This would benefit greatly from the approach outlined in mapbox/mapbox-gl-js#1341.

@ljbade
Copy link
Contributor

ljbade commented Oct 28, 2015

Putting note from @jfirebaugh that this style API will replace the annotations API style property functions.

I assume we will provide some sort of function that returns the style API object for a given annotation (or make it function on the annotation object itself). And existing style functions will be forwarded to the new API and deprecated.

@jfirebaugh
Copy link
Contributor

@ljbade No, not exactly. What will happen to the existing annotations API hasn't been decided.

I assume we will provide some sort of function that returns the style API object for a given annotation

I don't think we'll do this.

And existing style functions will be forwarded to the new API and deprecated.

We may rewrite the implementation of the existing iOS and Android annotation API in terms of the Style API. But that's probably the extent of the connection between the two APIs.

@ljbade
Copy link
Contributor

ljbade commented Oct 28, 2015

@jfirebaugh How will one style an individual annotation? Generate a unique layer per annotation?

@jfirebaugh
Copy link
Contributor

The Style API will not have a concept of "annotations". It will have the concepts of sources, layers, paint properties, and layout properties. And when the style spec supports data-driven styling, so will the Style API.

@jlansing
Copy link

Would love a status update on this as well. Being able to texture polylines, polygons and circles would be big for us.

@jfirebaugh
Copy link
Contributor

I've updated the issue description with a much expanded description of what a runtime styling API encompasses and what our plans for it are.

@jfirebaugh
Copy link
Contributor

jfirebaugh commented Jun 16, 2016

The key parts of the runtime styling API -- mutable sources and layers -- are now implemented in mbgl core. The remaining core work involves testing these more fully and adding a few miscellaneous APIs such as source data mutation for GeoJSON sources, and layer filter accessors.

Part of my testing strategy involves expanding the style-spec driven code generation such that it generates portions of the node bindings for the runtime styling API. This is proving to work well, and I anticipate that code generation will play a key role for the iOS and Android SDKs as well. @mapbox/mobile -- whenever you have bandwidth to start work on this, let me know and I can give you a walkthrough of how I see this working.

@jfirebaugh
Copy link
Contributor

jfirebaugh commented Jun 22, 2016

testing these more fully

Done -- see https://github.com/mapbox/mapbox-gl-test-suite/tree/master/render-tests/runtime-styling

source data mutation for GeoJSON sources

This is pending the integration of the new geometry.hpp-based geojson-vt-cpp.

layer filter accessors

Done in 3459b83

Next up: adding and testing node bindings for addSource and addLayer.

@jfirebaugh
Copy link
Contributor

adding and testing node bindings for addSource and addLayer.

Done in #5462.

@1ec5
Copy link
Contributor

1ec5 commented Jul 12, 2016

@yhahn
Copy link
Member

yhahn commented Jul 13, 2016

\o/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
GL JS parity For feature parity with Mapbox GL JS
Projects
None yet
Development

No branches or pull requests

10 participants