I am currently utilizing the Android Mapbox SDK to integrate a VectorSource into a MapboxMap and then I am trying to incorporate a LineLayer onto the map as well.
My version is 5.1.3
This code will be written in TypeScript due to its compatibility with the NativeScript framework, which enables the utilization of native libraries and direct access to native android/iOS APIs.
// These variables serve as easy references to classes 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 vector source (GLSource) for 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());
// Obtain the line color for this style
const lColor = style["line"]["line-color"];
const androidColor = new Color(lColor).android; // Ends up valid and similar to -1293839 for android use
newLayer.setSourceLayer(layer.ID.toString());
// This will encounter an error 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 avoid using the setProperties
method, the code runs without issues but no visible line appears on the map after adding the layer.