Skip to content

Instantly share code, notes, and snippets.

@kuwapa
Last active February 13, 2023 08:18
Show Gist options
  • Save kuwapa/a8d198ec2a027ca71a3ed5a991cc7bad to your computer and use it in GitHub Desktop.
Save kuwapa/a8d198ec2a027ca71a3ed5a991cc7bad to your computer and use it in GitHub Desktop.
//Fetching the local styles JSON file from the assets
val styleJsonInputStream = assets.open("bright.json")
//Creating a new file to which to copy the json content to
val dir = File(filesDir.absolutePath)
val styleFile = File(dir, "bright.json")
//Copying the original JSON content to new file
copyStreamToFile(styleJsonInputStream, styleFile)
//Getting reference to mbtiles file in assets
val mbtilesFile = getFileFromAssets(this, "india_coimbatore.mbtiles")
val bounds = getLatLngBounds(mbtilesFile)
//Replacing placeholder with uri of the mbtiles file
val newFileStr = styleFile.inputStream().readToString()
.replace("___FILE_URI___", "mbtiles:///${mbtilesFile.absolutePath}")
//Writing new content to file
val gpxWriter = FileWriter(styleFile)
val out = BufferedWriter(gpxWriter)
out.write(newFileStr)
out.close()
//Setting the map style using the new edited JSON file
map.setStyle(Style.Builder().fromUri(Uri.fromFile(styleFile).toString()))
//Setting camera view over the mbtiles area
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment