You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
private fun buildStyleWithRoutes(): Style.Builder {
val builder = Style.Builder().fromUri(mapStyle.uri)
routes.forEach { route ->
val sourceId = route.id
val layerId = layerIdFor(route.id)
val geoJson = Feature.fromGeometry(
LineString.fromLngLats(route.points.map { pt ->
Point.fromLngLat(pt.lon, pt.lat)
})
)
builder.withSource(
GeoJsonSource(sourceId, geoJson, GeoJsonOptions())
)
val colorHex = String.format("#%06X", route.color and 0xFFFFFF)
builder.withLayer(
LineLayer(layerId, sourceId).withProperties(
lineColor(colorHex),
lineWidth(route.widthPx),
lineCap(Property.LINE_CAP_ROUND),
lineJoin(Property.LINE_JOIN_ROUND),
visibility(if (route.visible) Property.VISIBLE else Property.NONE)
)
)
}
return builder
}
and then, I use it like this: mapSnapshotter = MapSnapshotter( applicationContext, MapSnapshotter.Options(imgWidth, imgHeight) .withLogo(false) .withStyleBuilder(styleBuilder) )
for IOS though, I cant seem to implement with the same logic.
heres the style builder: fun buildStyleWithRoutes() : MLNStyle{ val style = MLNStyle() var polyline : MLNPolyline for (route in routes) { if (!route.visible) continue // Convert route coordinates to CLLocationCoordinate2D array val coordList: List<CValue<CLLocationCoordinate2D>> = route.points.map { point -> memScoped { cValue<CLLocationCoordinate2D> { latitude = point.lat longitude = point.lon } } } memScoped { val coordinatesPointer = allocArray<CLLocationCoordinate2D>(coordList.size) coordList.forEachIndexed { index, coordinate -> coordinatesPointer[index].latitude = coordinate.useContents { latitude } coordinatesPointer[index].longitude = coordinate.useContents { longitude } } polyline = MLNPolyline.polylineWithCoordinates( coordinatesPointer, count = coordList.size.toULong() ) } val sourceId = "route-source-${route.id}" val shapeSource = MLNShapeSource(identifier = sourceId, shape = polyline, options = null) style.addSource(shapeSource) val layerId = "route-layer-${route.id}" val lineLayer = MLNLineStyleLayer(identifier = layerId, source = shapeSource) lineLayer.lineColor = NSExpression.expressionForConstantValue(route.color.toUIColor()) lineLayer.lineWidth = NSExpression.expressionForConstantValue(NSNumber(double = route.widthPx.toDouble())) lineLayer.lineCap = NSExpression.expressionForConstantValue("round") // round line endpoints style.addLayer(lineLayer) } return style }
but I dont know how and where to use it on my ios implementation in my kmp app, cant find it in documentation either.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
currently, my code goes like this:
`
and then, I use it like this:
mapSnapshotter = MapSnapshotter( applicationContext, MapSnapshotter.Options(imgWidth, imgHeight) .withLogo(false) .withStyleBuilder(styleBuilder) )
for IOS though, I cant seem to implement with the same logic.
heres the style builder:
fun buildStyleWithRoutes() : MLNStyle{ val style = MLNStyle() var polyline : MLNPolyline for (route in routes) { if (!route.visible) continue // Convert route coordinates to CLLocationCoordinate2D array val coordList: List<CValue<CLLocationCoordinate2D>> = route.points.map { point -> memScoped { cValue<CLLocationCoordinate2D> { latitude = point.lat longitude = point.lon } } } memScoped { val coordinatesPointer = allocArray<CLLocationCoordinate2D>(coordList.size) coordList.forEachIndexed { index, coordinate -> coordinatesPointer[index].latitude = coordinate.useContents { latitude } coordinatesPointer[index].longitude = coordinate.useContents { longitude } } polyline = MLNPolyline.polylineWithCoordinates( coordinatesPointer, count = coordList.size.toULong() ) } val sourceId = "route-source-${route.id}" val shapeSource = MLNShapeSource(identifier = sourceId, shape = polyline, options = null) style.addSource(shapeSource) val layerId = "route-layer-${route.id}" val lineLayer = MLNLineStyleLayer(identifier = layerId, source = shapeSource) lineLayer.lineColor = NSExpression.expressionForConstantValue(route.color.toUIColor()) lineLayer.lineWidth = NSExpression.expressionForConstantValue(NSNumber(double = route.widthPx.toDouble())) lineLayer.lineCap = NSExpression.expressionForConstantValue("round") // round line endpoints style.addLayer(lineLayer) } return style }
but I dont know how and where to use it on my ios implementation in my kmp app, cant find it in documentation either.
Beta Was this translation helpful? Give feedback.
All reactions