-
Describe the bug To Reproduce Expected behavior |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Please share more details about what platform you are using and how to reproduce the problem. |
Beta Was this translation helpful? Give feedback.
-
here is my code, and it just dark and hints Error setting property: line-color expected a literal expression protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Using MapView requires calling MapLibre.getInstance() before inflating or creating the view.
MapLibre.getInstance(this);
// EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
mapView = findViewById(R.id.mapView);
mapView.getMapAsync(map -> {
map.setStyle("https://api.maptiler.com/maps/basic-v2-dark/style.json?key=***********", new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
addLineToMap(style);
}
});
});
}
private void addLineToMap(Style style){
List<Point> lineCoordinates = new ArrayList<>();
lineCoordinates.add(Point.fromLngLat(0, 120));
lineCoordinates.add(Point.fromLngLat(0, -120));
LineString lineString = LineString.fromLngLats(lineCoordinates);
GeoJsonSource geoJsonSource = new GeoJsonSource("line-source",
FeatureCollection.fromFeature(Feature.fromGeometry(lineString)));
style.addSource(geoJsonSource);
LineLayer lineLayer = new LineLayer("line-layer", "line-source");
Expression expression = Expression.interpolate(linear(), Expression.lineProgress(), stop(0, color(Color.BLUE)), stop(1, color(Color.RED)));
lineLayer.setProperties(
lineColor(expression),
lineWidth(5f)
);
style.addLayer(lineLayer);
} |
Beta Was this translation helpful? Give feedback.
-
Try using something like this: LineLayer("gradient", LINE_SOURCE)
.withProperties(
PropertyFactory.lineGradient(
Expression.interpolate(
Expression.linear(),
Expression.lineProgress(),
Expression.stop(0f, Expression.rgb(0, 0, 255)),
Expression.stop(0.5f, Expression.rgb(0, 255, 0)),
Expression.stop(1f, Expression.rgb(255, 0, 0))
)
),
PropertyFactory.lineColor(Color.RED),
PropertyFactory.lineWidth(10.0f),
PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND)
) |
Beta Was this translation helpful? Give feedback.
-
I see, thank you!, I know where is the mistake is, thank you very much |
Beta Was this translation helpful? Give feedback.
Try using something like this: