Last active
February 13, 2023 08:18
-
-
Save kuwapa/a8d198ec2a027ca71a3ed5a991cc7bad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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