I'm using the Android Mapbox SDK to add a VectorSource to a MapboxMap and then I'm trying to add a LineLayer to the map also.
Currently using the version 5.1.3
This code is going to be in TypeScript because it's using the NativeScript framework which allows the consumption of native libraries and direct access to native android/iOS APIs.
// these constants are just simple ways to reference a class in the mapbox package
const PropertyFactory = com.mapbox.mapboxsdk.style.layers.PropertyFactory;
const Property = com.mapbox.mapboxsdk.style.layers.Property;
const LineLayer = com.mapbox.mapboxsdk.style.layers.LineLayer;
const VectorSource = com.mapbox.mapboxsdk.style.sources.VectorSource;
const lineCap = com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineCap;
const lineColor = com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineColor;
const lineJoin = com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineJoin;
const lineWidth = com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth;
const LatLngBounds = com.mapbox.mapboxsdk.geometry.LatLngBounds;
const FillLayer = com.mapbox.mapboxsdk.style.layers.FillLayer;
const SymbolLayer = com.mapbox.mapboxsdk.style.layers.SymbolLayer;
const CircleLayer = com.mapbox.mapboxsdk.style.layers.CircleLayer;
// set the map GLSource (vector) to the mapbox map
const vectorSource = new VectorSource(
layer.ID.toString(),
`http://themaptiles.cloudapp.net/data/${layer.GLSource}.json`
);
this._mapboxMap.addSource(vectorSource);
let newLayer;
if (layer.Type == "line") {
console.log(`*** creating new LineLayer ***`);
newLayer = new LineLayer("line-layer", layer.ID.toString());
// get the line color for this style
const lColor = style["line"]["line-color"];
const androidColor = new Color(lColor).android; // ends up valid and something like -1293839 for android to use
newLayer.setSourceLayer(layer.ID.toString());
// will throw here with `Failed resolving method setProperties on class com.mapbox.mapboxsdk.style.layers.Layer`
newLayer.setProperties(
PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND),
PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
PropertyFactory.lineColor(androidColor),
PropertyFactory.lineWidth(new java.lang.Float(2))
);
}
this._mapboxMap.addLayer(newLayer);
If I don't attempt to use setProperties method then the code executes fine but there is no visible line on the map after the layer is added.