H.Karatsanov
H.Karatsanov

Reputation: 319

Mapbox: Problem with Line rendering on a Snapshot

I've created a LineLayer and GeoJsonSource in this way:

List<Point> routeCoordinates = new ArrayList<>();
for(LatLng latLng: newLatLngs){
   routeCoordinates.add(Point.fromLngLat(latLng.getLongitude(),latLng.getLatitude()));
}

GeoJsonSource lineSource = new GeoJsonSource("route-line-layer-source",LineString.fromLngLats(routeCoordinates));

LineLayer lineLayer = new LineLayer("route-line-layer","route-line-layer-source")
                              .withProperties(PropertyFactory.lineColor(ColorUtils.colorToRgbaString(Color.BLUE)),
                                              PropertyFactory.lineDasharray(new Float[] {0.01f, 2f}),
                                              PropertyFactory.lineWidth(5f),
                                              PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
                                              PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND))
                              .withSourceLayer("route-line-layer-source");

After that I create a new Style.Builder, MapSnapshotterOptions and pass them to the MapSnapshotter object:

Style.Builder builder1 = new Style.Builder()
                           .fromUri(chosenStyleMode)
                           .withLayer(lineLayer);

MapSnapshotter.Options options = new MapSnapshotter.Options(mapFragment.getView().getMeasuredWidth(), mapFragment.getView().getMeasuredHeight())
                                        .withRegion(mMapboxMap.getProjection().getVisibleRegion().latLngBounds)
                                        .withCameraPosition(cu.getCameraPosition(mMapboxMap))
                                        .withStyleBuilder(builder1);

mapSnapshotter = new MapSnapshotter(RunningActivity.this, options);

The image gets rendered, but the line doesn't appear on the style.

Why it is so?

Upvotes: 0

Views: 247

Answers (1)

Matt O
Matt O

Reputation: 26

Had the same problem today, I fixed it by also including the GeoJsonSource in the style.

Style.Builder builder1 = new Style.Builder()
                           .fromUri(chosenStyleMode)
                           .withSource(lineSource)
                           .withLayer(lineLayer);

Upvotes: 1

Related Questions