Skip to content

Failed to set line-gradient property for lineLayer layer. Error: color ramp must be an expression or valid color #2122

Closed

Description

@ZhangKun-long

Map SDK:10.14.0
Using GEOJSON to add a line segment, the line-gradient parameter is incorrect. I am using the Java language. I coded it according to the format given in the tutorial, but the result of adding the line segment has been unsuccessful, i would like to ask how I set the correct line-gradient parameter in the Java environment. Thank you.

This is my code:
Expression[] expressions = new Expression[listPolyLine.size() * 2 + 2];
expressions[0] = Expression.linear();
expressions[1] = Expression.lineProgress();

for (int i = 0; i < listPolyLine.size(); i++) {
expressions[index] = Expression.literal(temp);
expressions[index] = Expression.color(listPolyLine.get(i).getcolor());
}
//add Source
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("type", "geojson");
jsonObject.put("data", featureCollection.toJson());
jsonObject.put("lineMetrics", true);
} catch (JsonIOException e) {
MXLog.d(TAG, "[PloyLine]" + e.getMessage());
}
Expected<String, Value> outSource = Value.fromJson(jsonObject.toString());
Expected<String, None> success = mMap.getStyle().addStyleSource(sourceId, Objects.requireNonNull(outSource.getValue()));
MXLog.d(TAG, "[initClusterLayers]source create: " + (success.isError() ? success.getError() : "success"));
//add Line
JSONObject lineLayer = new JSONObject();
try {
lineLayer.put("id", layerId);
lineLayer.put("type", "line");
lineLayer.put("source", sourceId);
lineLayer.put("line-cap", "round");
lineLayer.put("line-join", "round");
lineLayer.put("line-width", polylineOption.fWidth);
lineLayer.put("line-gradient", Expression.interpolate(expressions));
/**
**Current format: "{"id":"" + layerId + "","type":"line","source":""+ sourceId + "","line-cap":"round","line-**join":"round","line-width":6,"line-gradient":"[interpolate,[linear],[line-progress],0.0, #ff0000, 1.0, #ff0000]"}";
**/
`} catch (JSONException e) {
e.printStackTrace();
}
Expected<String, Value> outLayer = Value.fromJson(str);
Expected<String, None> successLayer = mMap.getStyle().addStyleLayer(Objects.requireNonNull(outLayer.getValue()), new LayerPosition(null, "mapbox-android-pointAnnotation-layer-1", null));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions