You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
It's been suggested to generate the Java bindings from the style specification. We can use the same approach as taken for the node bindings, using ejs templates or go for a more Java central approach by using a gradle plugin that transforms json into java classes, like jsonschema2pojo. Depending on integration in the main build or the Android sub-build (gradle).
Because the types (and manipulation of the types) need to go through jni, it's best to make the api flat (no 1-n relations). All manipulation/querying goes through the MapboxMap object. For some of the types we can use subclasses or type IntDef's if the types have little specialisation.
Possible api
Layer Types (generated):
BackgroundLayer
CircleLayer
FillLayer
LineLayer
RasterLayer
SymbolLayer
Related types:
LayoutProperty - Each layer supports a set of layout properties
PaintProperty - Each layer supports a set of paint properties
Ok, so we have a decision to make as to the level of typing we want in this api. The core api is beautifully typed, which is great to work with. For the android side of things there are some considerations though:
A completely typed api adds quite a bit of api surface
Passing rich types over JNI is not what we want, performance wise. So it would be translated to simpler types before crossing the boundary, where it would again be converted to core types.
The other end of the spectrum is a non-typed api (or very basic at least). Passing mostly Strings and values around. This is how the QT api is shaping up, and it's nice and small (see for example setLayoutProperty()). As the type checking is done on the core side anyways, there is not much lost here, except for code completion / compile time checking of correct property types.
A nice compromise might be, to offer some factory methods to construct properties (as we still want to avoid Enums). This would aid in compiler assistance of type checking per property. This can easily be generated. For example:
// This file is generated. Do not edit.
package com.mapbox.mapboxsdk.style.properties;
public class LayoutPropertyFactory {
public static LayoutProperty<Float> lineMiterLimit(Float value) {
return new LayoutProperty<>("line-miter-limit", value);
}
public static LayoutProperty<Float> lineRoundLimit(Float value) {
return new LayoutProperty<>("line-round-limit", value);
}
...
public static LayoutProperty<Boolean> textOptional(Boolean value) {
return new LayoutProperty<>("text-optional", value);
}
public static final class LayoutProperty<T> {
public final String name;
public final T value;
private LayoutProperty(String name, T value) {
this.name = name;
this.value = value;
}
}
}
Passing rich types over JNI is not what we want, performance wise.
Right. Do we foresee that the style API is something that devs would call so often that we'd notice the performance impact?
The other end of the spectrum is a non-typed api (or very basic at least). Passing mostly Strings and values around. This is how the QT api is shaping up
I personally like this approach, not only for consistency with Qt and because, as you say, checks are gonna happen anyway at the core level, but also because 1) it's easier to implement (and explain) and 2) it leaves the door open to a higher level API built on top of this one (e.g. factory methods) in the future should customers require it.
The other end of the spectrum is a non-typed api (or very basic at least). Passing mostly Strings and values around. This is how the QT api is shaping up
Another plus of this approach is as the spec changes, you get new properties, types, etc for free.
I don't think we can say performance is an advantage either way unless we implement both strong and weakly typed APIs and benchmark them. Whatever JNI overhead there may be could easily be negated by the need to manually typecheck arguments.
I think we're likely to eliminate an external distinction between paint and layout properties sometime in the future. To the runtime style API, the main implication of the distinction is that you can set a paint property for a specific paint class. But since the Android SDK is not exposing paint classes otherwise, it shouldn't provide this option for paint properties. So I see little reason to distinguish paint and layout properties in the runtime styling API.
I strongly encourage you to implement layer and source types, and not have the entire API live on Map. I.e., assuming a weakly typed API, map.getLayer(layerId) and layer.setProperty(property). (This is likely what gl-js will switch to.)
Reacted by Brad Leege, Minh Nguyễn and Thiago Marcos P. Santos
@jfirebaugh Thanks for the comments. I'll work that in.
About the JNI part; we've been limiting the amount of callbacks into the runtime lately (see #5103). But since we don't expose that part of the api, we can go either way depending on any performance issues.
Second issue still remains. To be more specific, the crash happens when adding a Layer in the onMapReady callback. I've added a test case here to reproduce the issue (thanks @cammace)
@ivovandongen Assuming the bug mentioned in #6014 is real (in which case we'll need to ticket it separately), otherwise this feature is fully built out, right? Can we close this ticket?
Activity
bleege commentedon Jul 7, 2016
/cc @mapbox/mobile
ivovandongen commentedon Jul 8, 2016
Ok, so we have a decision to make as to the level of typing we want in this api. The core api is beautifully typed, which is great to work with. For the android side of things there are some considerations though:
The other end of the spectrum is a non-typed api (or very basic at least). Passing mostly Strings and values around. This is how the QT api is shaping up, and it's nice and small (see for example setLayoutProperty()). As the type checking is done on the core side anyways, there is not much lost here, except for code completion / compile time checking of correct property types.
A nice compromise might be, to offer some factory methods to construct properties (as we still want to avoid Enums). This would aid in compiler assistance of type checking per property. This can easily be generated. For example:
cc @tobrun @zugaldia @bleege
zugaldia commentedon Jul 8, 2016
Right. Do we foresee that the style API is something that devs would call so often that we'd notice the performance impact?
I personally like this approach, not only for consistency with Qt and because, as you say, checks are gonna happen anyway at the core level, but also because 1) it's easier to implement (and explain) and 2) it leaves the door open to a higher level API built on top of this one (e.g. factory methods) in the future should customers require it.
tmpsantos commentedon Jul 8, 2016
Another plus of this approach is as the spec changes, you get new properties, types, etc for free.
[android] #5610 - Example api for layout properties (not complete)
ivovandongen commentedon Jul 8, 2016
I've added an example of the api we could use if we type the properties (Only layout properties done for this example). See the commit for details.
So, the main entry point for the user would look like:
public void setLayoutProperty(String layerId, LayoutProperty<?> property)Where the LayoutProperty can be retrieved from LayoutPropertyFactory. Both are generated with ejs templates.
Advantages:
Disadvantages:
ivovandongen commentedon Jul 8, 2016
Could animating properties from Android animators be a valid use case? If so, then yes.
@zugaldia
jfirebaugh commentedon Jul 8, 2016
Quick comments:
Map. I.e., assuming a weakly typed API,map.getLayer(layerId)andlayer.setProperty(property). (This is likely what gl-js will switch to.)ivovandongen commentedon Jul 8, 2016
@jfirebaugh Thanks for the comments. I'll work that in.
About the JNI part; we've been limiting the amount of callbacks into the runtime lately (see #5103). But since we don't expose that part of the api, we can go either way depending on any performance issues.
bleege commentedon Jul 11, 2016
For continuity, the iOS / mac OS Styling API is simultaneously being worked on in #5626.
[android] #5610 - Adjusted public api after discussion
[android] #5610 - added jni binding for NativeMapView#getLayer
[android] #5610 - Added initial test Activity
116 remaining items
ivovandongen commentedon Aug 2, 2016
First issue was resolved by rebasing master.
Second issue still remains. To be more specific, the crash happens when adding a Layer in the onMapReady callback. I've added a test case here to reproduce the issue (thanks @cammace)
ivovandongen commentedon Aug 2, 2016
Merged into master
incanus commentedon Aug 15, 2016
@ivovandongen Assuming the bug mentioned in #6014 is real (in which case we'll need to ticket it separately), otherwise this feature is fully built out, right? Can we close this ticket?
ivovandongen commentedon Aug 16, 2016
Thought it was closed already. #5852 was the last missing piece.
1ec5 commentedon Sep 28, 2016
For posterity, the PRs that implemented the initial buildout were #5734 and #5830.