Вот мой деятельность:
Код: Выделить всё
class MapBoxActivity : AppCompatActivity() {
private lateinit var mapboxMap: MapboxMap
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val mapView = MapView(this)
setContentView(mapView)
mapboxMap = mapView.mapboxMap
mapboxMap.setCamera(
CameraOptions.Builder()
.zoom(12.0)
.center(Point.fromLngLat(-87.622088, 41.878781))
.build()
)
val styleJson = loadStyleFromAssets("mapbox_style.json")
if (styleJson != null) {
mapboxMap.loadStyleJson(styleJson) { style ->
updateTileSource(style)
}
}
}
private fun updateTileSource(style: Style) {
val url = "http://ts.carsprogram.org/public.rwrc_view/{z}/{x}/{y}.pbf"
// Remove existing source if it exists
if (style.styleSourceExists(SOURCE_ID)) {
style.removeStyleSource(SOURCE_ID)
}
// Add new source with updated URL
style.addSource(
vectorSource(SOURCE_ID) {
tiles(listOf(url))
minzoom(6)
maxzoom(14)
}
)
// Add or update the layer
if (!style.styleLayerExists(LAYER_ID)) {
style.addLayerBelow(
lineLayer(LAYER_ID, SOURCE_ID) {
sourceLayer(SOURCE_LAYER_ID)
lineCap(LineCap.ROUND)
lineJoin(LineJoin.ROUND)
lineOpacity(0.6)
lineColor(Expression.rgb(53.0, 175.0, 109.0))
lineWidth(2.0)
},
BELOW_LAYER_ID
)
}
}
private fun loadStyleFromAssets(fileName: String): String? {
return try {
val inputStream = assets.open(fileName)
val size = inputStream.available()
val buffer = ByteArray(size)
inputStream.read(buffer)
inputStream.close()
String(buffer, Charsets.UTF_8)
} catch (e: Exception) {
e.printStackTrace()
null
}
}
private companion object {
const val SOURCE_ID = "mapillary"
const val LAYER_ID = SOURCE_ID
const val TAG = SOURCE_ID
const val SOURCE_LAYER_ID = "sequence"
const val BELOW_LAYER_ID = "road-label-simple"
}
}
Код: Выделить всё
{
"id": "public.rwrc_view",
"schema": "public",
"name": "rwrc_view",
"properties": [
{
"name": "objectid",
"type": "int8",
"description": ""
},
{
"name": "road_condition",
"type": "float8",
"description": ""
},
{
"name": "color",
"type": "text",
"description": ""
},
{
"name": "segment_id",
"type": "text",
"description": ""
},
{
"name": "segment_name",
"type": "text",
"description": ""
},
{
"name": "headline",
"type": "text",
"description": ""
},
{
"name": "status",
"type": "text",
"description": ""
},
{
"name": "route_name",
"type": "text",
"description": ""
},
{
"name": "primarymp",
"type": "text",
"description": ""
},
{
"name": "secondarymp",
"type": "text",
"description": ""
},
{
"name": "primarylat",
"type": "text",
"description": ""
},
{
"name": "primarylong",
"type": "text",
"description": ""
},
{
"name": "secondarylat",
"type": "text",
"description": ""
},
{
"name": "secondarylong",
"type": "text",
"description": ""
},
{
"name": "description",
"type": "text",
"description": ""
},
{
"name": "source",
"type": "text",
"description": ""
},
{
"name": "source_link",
"type": "text",
"description": ""
},
{
"name": "report_updated",
"type": "float8",
"description": ""
},
{
"name": "report_created",
"type": "float8",
"description": ""
},
{
"name": "report_id",
"type": "text",
"description": ""
},
{
"name": "creationdate",
"type": "int8",
"description": ""
},
{
"name": "creator",
"type": "text",
"description": ""
},
{
"name": "editdate",
"type": "int8",
"description": ""
},
{
"name": "editor",
"type": "text",
"description": ""
},
{
"name": "route_rank",
"type": "float8",
"description": ""
},
{
"name": "pk",
"type": "int4",
"description": ""
}
],
"geometrytype": "Geometry",
"center": [
-95.51685333251953,
42.49988555908203
],
"bounds": [
-104.055908203125,
35.99919891357422,
-86.97779846191406,
49.000572204589844
],
"minzoom": 2,
"maxzoom": 22,
"tileurl": "http://ts.carsprogram.org/public.rwrc_view/{z}/{x}/{y}.pbf"
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... ox-android