-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Annotation] Automatically add layer and source while changing style. (…
…#29) * [Annotation] Automatically add layer and source while changing style. * Apply the cache properties while changing style * Fix test cases
- Loading branch information
Kevin Li
authored
Jan 26, 2021
1 parent
9691efd
commit be1bbbe
Showing
18 changed files
with
347 additions
and
304 deletions.
There are no files selected for viewing
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
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
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
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
114 changes: 114 additions & 0 deletions
114
app/src/main/java/com/mapbox/maps/testapp/examples/annotation/Utils.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.mapbox.maps.testapp.examples.annotation | ||
|
||
import android.content.Context | ||
import com.mapbox.core.utils.TextUtils | ||
import com.mapbox.geojson.Point | ||
import com.mapbox.maps.Style | ||
import java.io.BufferedReader | ||
import java.io.IOException | ||
import java.io.InputStreamReader | ||
import java.io.Reader | ||
import java.nio.charset.Charset | ||
import java.util.* | ||
|
||
/** | ||
* Useful utilities used throughout the testapp. | ||
*/ | ||
object Utils { | ||
|
||
private val STYLES = | ||
arrayOf(Style.MAPBOX_STREETS, Style.OUTDOORS, Style.LIGHT, Style.DARK, Style.SATELLITE_STREETS) | ||
|
||
private var index: Int = 0 | ||
|
||
/** | ||
* Utility to cycle through map styles. Useful to test if runtime styling source and layers transfer over to new | ||
* style. | ||
* | ||
* @return a string ID representing the map style | ||
*/ | ||
val nextStyle: String | ||
get() { | ||
index++ | ||
if (index == STYLES.size) { | ||
index = 0 | ||
} | ||
return STYLES[index] | ||
} | ||
|
||
/** | ||
* Utility for getting a list of random points. | ||
* | ||
* @return a a list of random points | ||
*/ | ||
fun createRandomPoints(): List<Point> { | ||
val random = Random() | ||
val points: MutableList<Point> = ArrayList<Point>() | ||
for (i in 0 until random.nextInt(10)) { | ||
points.add( | ||
Point.fromLngLat( | ||
random.nextDouble() * -360.0 + 180.0, | ||
random.nextDouble() * -180.0 + 90.0 | ||
) | ||
) | ||
} | ||
return points | ||
} | ||
|
||
/** | ||
* Utility for getting a list of lists of random points | ||
* | ||
* @return a list of lists of random points | ||
*/ | ||
fun createRandomPointsList(): List<List<Point>> { | ||
val random = Random() | ||
val points = mutableListOf<Point>() | ||
val firstLast = Point.fromLngLat( | ||
random.nextDouble() * -360.0 + 180.0, | ||
random.nextDouble() * -180.0 + 90.0 | ||
) | ||
points.add(firstLast) | ||
for (i in 0 until random.nextInt(10)) { | ||
points.add( | ||
Point.fromLngLat( | ||
random.nextDouble() * -360.0 + 180.0, | ||
random.nextDouble() * -180.0 + 90.0 | ||
) | ||
) | ||
} | ||
points.add(firstLast) | ||
return listOf(points) | ||
} | ||
|
||
/** | ||
* Utility for getting a random point | ||
* | ||
* @return a random point | ||
*/ | ||
fun createRandomPoint(): Point { | ||
val random = Random() | ||
return Point.fromLngLat( | ||
random.nextDouble() * -360.0 + 180.0, | ||
random.nextDouble() * -180.0 + 90.0 | ||
) | ||
} | ||
|
||
@Throws(IOException::class) | ||
fun loadStringFromAssets(context: Context, fileName: String): String { | ||
if (TextUtils.isEmpty(fileName)) { | ||
throw NullPointerException("No GeoJSON File Name passed in.") | ||
} | ||
val `is` = context.assets.open(fileName) | ||
val rd = BufferedReader(InputStreamReader(`is`, Charset.forName("UTF-8"))) | ||
return readAll(rd) | ||
} | ||
|
||
@Throws(IOException::class) | ||
private fun readAll(rd: Reader): String { | ||
val sb = StringBuilder() | ||
rd.forEachLine { | ||
sb.append(it) | ||
} | ||
return sb.toString() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.