Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Example] Fix crash in Annotation test demo #17

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,57 +23,58 @@ import java.util.*
*/
class CircleActivity : AppCompatActivity() {
private val random = Random()
private lateinit var circleManager: CircleManager
private var circleManager: CircleManager? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_annotation)
mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS) {
val annotationPlugin = mapView.getAnnotationPlugin()
circleManager = annotationPlugin.getCircleManager()
circleManager.addClickListener(
OnCircleClickListener {
Toast.makeText(this@CircleActivity, "click", Toast.LENGTH_LONG).show()
false
}
)
circleManager = annotationPlugin.getCircleManager().apply {
addClickListener(
OnCircleClickListener {
Toast.makeText(this@CircleActivity, "click", Toast.LENGTH_LONG).show()
false
}
)

val circleOptions: CircleOptions = CircleOptions()
.withPoint(Point.fromLngLat(0.381457, 6.687337))
.withCircleColor(ColorUtils.colorToRgbaString(Color.YELLOW))
.withCircleRadius(12.0)
.withDraggable(true)
circleManager.create(circleOptions)
val circleOptions: CircleOptions = CircleOptions()
.withPoint(Point.fromLngLat(0.381457, 6.687337))
.withCircleColor(ColorUtils.colorToRgbaString(Color.YELLOW))
.withCircleRadius(12.0)
.withDraggable(true)
create(circleOptions)

// random add circles across the globe
val circleOptionsList: MutableList<CircleOptions> = ArrayList()
for (i in 0..20) {
val color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256))
circleOptionsList.add(
CircleOptions()
.withPoint(createRandomPoints())
.withCircleColor(ColorUtils.colorToRgbaString(color))
.withCircleRadius(8.0)
.withDraggable(true)
)
}
circleManager.create(circleOptionsList)
// random add circles across the globe
val circleOptionsList: MutableList<CircleOptions> = ArrayList()
for (i in 0..20) {
val color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256))
circleOptionsList.add(
CircleOptions()
.withPoint(createRandomPoints())
.withCircleColor(ColorUtils.colorToRgbaString(color))
.withCircleRadius(8.0)
.withDraggable(true)
)
}
create(circleOptionsList)

try {
circleManager.create(
FeatureCollection.fromJson(
Assets.loadStringFromAssets(
this,
"annotations.json"
try {
create(
FeatureCollection.fromJson(
Assets.loadStringFromAssets(
this@CircleActivity,
"annotations.json"
)
)
)
)
} catch (e: IOException) {
throw RuntimeException("Unable to parse annotations.json")
} catch (e: IOException) {
throw RuntimeException("Unable to parse annotations.json")
}
}
}

deleteAll.setOnClickListener { circleManager.deleteAll() }
deleteAll.setOnClickListener { circleManager?.deleteAll() }
}

private fun createRandomPoints(): Point {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,62 +24,63 @@ import java.util.*
*/
class FillActivity : AppCompatActivity() {
private val random = Random()
private lateinit var fillManager: FillManager
private var fillManager: FillManager? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_annotation)
mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS) {
val annotationPlugin = mapView.getAnnotationPlugin()
fillManager = annotationPlugin.getFillManager()
fillManager.addClickListener(
OnFillClickListener {
Toast.makeText(this@FillActivity, "click", Toast.LENGTH_LONG).show()
false
}
)
val points = listOf(
listOf(
Point.fromLngLat(-3.363937, -10.733102),
Point.fromLngLat(1.754703, -19.716317),
Point.fromLngLat(-15.747196, -21.085074),
Point.fromLngLat(-3.363937, -10.733102)
fillManager = annotationPlugin.getFillManager().apply {
addClickListener(
OnFillClickListener {
Toast.makeText(this@FillActivity, "click", Toast.LENGTH_LONG).show()
false
}
)
val points = listOf(
listOf(
Point.fromLngLat(-3.363937, -10.733102),
Point.fromLngLat(1.754703, -19.716317),
Point.fromLngLat(-15.747196, -21.085074),
Point.fromLngLat(-3.363937, -10.733102)
)
)
)

val fillOptions: FillOptions = FillOptions()
.withPoints(points)
.withData(JsonPrimitive("Foobar"))
.withFillColor(ColorUtils.colorToRgbaString(Color.RED))
fillManager.create(fillOptions)
val fillOptions: FillOptions = FillOptions()
.withPoints(points)
.withData(JsonPrimitive("Foobar"))
.withFillColor(ColorUtils.colorToRgbaString(Color.RED))
create(fillOptions)

// random add fills across the globe
val fillOptionsList: MutableList<FillOptions> = ArrayList()
for (i in 0..2) {
val color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256))
fillOptionsList.add(
FillOptions()
.withPoints(createRandomPoints())
.withFillColor(ColorUtils.colorToRgbaString(color))
)
}
fillManager.create(fillOptionsList)
// random add fills across the globe
val fillOptionsList: MutableList<FillOptions> = ArrayList()
for (i in 0..2) {
val color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256))
fillOptionsList.add(
FillOptions()
.withPoints(createRandomPoints())
.withFillColor(ColorUtils.colorToRgbaString(color))
)
}
create(fillOptionsList)

try {
fillManager.create(
FeatureCollection.fromJson(
Assets.loadStringFromAssets(
this,
"annotations.json"
try {
create(
FeatureCollection.fromJson(
Assets.loadStringFromAssets(
this@FillActivity,
"annotations.json"
)
)
)
)
} catch (e: IOException) {
throw RuntimeException("Unable to parse annotations.json")
} catch (e: IOException) {
throw RuntimeException("Unable to parse annotations.json")
}
}
}

deleteAll.setOnClickListener { fillManager.deleteAll() }
deleteAll.setOnClickListener { fillManager?.deleteAll() }
}

private fun createRandomPoints(): List<List<Point>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,66 +23,67 @@ import java.util.*
*/
class LineActivity : AppCompatActivity() {
private val random = Random()
private lateinit var lineManager: LineManager
private var lineManager: LineManager? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_annotation)
mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS) {
val annotationPlugin = mapView.getAnnotationPlugin()
lineManager = annotationPlugin.getLineManager()
lineManager.addClickListener(
OnLineClickListener {
Toast.makeText(
this@LineActivity,
"click",
Toast.LENGTH_LONG
).show()
false
}
)
lineManager = annotationPlugin.getLineManager().apply {
addClickListener(
OnLineClickListener {
Toast.makeText(
this@LineActivity,
"click",
Toast.LENGTH_LONG
).show()
false
}
)

val points = listOf(
Point.fromLngLat(-4.375974, -2.178992),
Point.fromLngLat(-7.639772, -4.107888),
Point.fromLngLat(-11.439207, 2.798737),
)
val points = listOf(
Point.fromLngLat(-4.375974, -2.178992),
Point.fromLngLat(-7.639772, -4.107888),
Point.fromLngLat(-11.439207, 2.798737),
)

val lineOptions: LineOptions = LineOptions()
.withPoints(points)
.withLineColor(ColorUtils.colorToRgbaString(Color.RED))
.withLineWidth(5.0)
lineManager.create(lineOptions)
val lineOptions: LineOptions = LineOptions()
.withPoints(points)
.withLineColor(ColorUtils.colorToRgbaString(Color.RED))
.withLineWidth(5.0)
create(lineOptions)

// random add lines across the globe
val lists: MutableList<List<Point>> = ArrayList<List<Point>>()
for (i in 0..99) {
lists.add(createRandomPoints())
}
val lineOptionsList = lists.map {
val color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256))
LineOptions()
.withPoints(it)
.withLineColor(ColorUtils.colorToRgbaString(color))
}
// random add lines across the globe
val lists: MutableList<List<Point>> = ArrayList<List<Point>>()
for (i in 0..99) {
lists.add(createRandomPoints())
}
val lineOptionsList = lists.map {
val color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256))
LineOptions()
.withPoints(it)
.withLineColor(ColorUtils.colorToRgbaString(color))
}

lineManager.create(lineOptionsList)
create(lineOptionsList)

try {
lineManager.create(
FeatureCollection.fromJson(
Assets.loadStringFromAssets(
this,
"annotations.json"
try {
create(
FeatureCollection.fromJson(
Assets.loadStringFromAssets(
this@LineActivity,
"annotations.json"
)
)
)
)
} catch (e: IOException) {
throw RuntimeException("Unable to parse annotations.json")
} catch (e: IOException) {
throw RuntimeException("Unable to parse annotations.json")
}
}
}

deleteAll.setOnClickListener { lineManager.deleteAll() }
deleteAll.setOnClickListener { lineManager?.deleteAll() }
}

private fun createRandomPoints(): List<Point> {
Expand Down
Loading