Mapbox:快照上的线渲染问题
Mapbox: Problem with Line rendering on a Snapshot
我用这种方式创建了 LineLayer
和 GeoJsonSource
:
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");
之后,我创建了一个新的 Style.Builder
、MapSnapshotterOptions
并将它们传递给 MapSnapshotter
对象:
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);
图像得到渲染,但线条没有出现在样式上。
为什么会这样?
今天遇到了同样的问题,我通过在样式中也包含 GeoJsonSource
来解决它。
Style.Builder builder1 = new Style.Builder()
.fromUri(chosenStyleMode)
.withSource(lineSource)
.withLayer(lineLayer);
我用这种方式创建了 LineLayer
和 GeoJsonSource
:
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");
之后,我创建了一个新的 Style.Builder
、MapSnapshotterOptions
并将它们传递给 MapSnapshotter
对象:
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);
图像得到渲染,但线条没有出现在样式上。
为什么会这样?
今天遇到了同样的问题,我通过在样式中也包含 GeoJsonSource
来解决它。
Style.Builder builder1 = new Style.Builder()
.fromUri(chosenStyleMode)
.withSource(lineSource)
.withLayer(lineLayer);