Skip to content

Commit

Permalink
apply changes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Elter71 committed Oct 30, 2024
1 parent 6d8e8f7 commit 96ee8b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import com.facebook.react.viewmanagers.RNMBXRasterSourceManagerInterface
import com.rnmapbox.rnmbx.events.constants.EventKeys
import com.rnmapbox.rnmbx.events.constants.eventMapOf
import javax.annotation.Nonnull
import com.facebook.react.bridge.ReadableArray
import com.rnmapbox.rnmbx.components.styles.RNMBXStyleImportManager
import com.rnmapbox.rnmbx.components.styles.RNMBXStyleImportManager.Companion
import com.facebook.react.bridge.ReadableType
import com.rnmapbox.rnmbx.utils.Logger

class RNMBXRasterSourceManager(reactApplicationContext: ReactApplicationContext) :
Expand Down Expand Up @@ -49,25 +47,21 @@ class RNMBXRasterSourceManager(reactApplicationContext: ReactApplicationContext)

@ReactProp(name = "sourceBounds")
override fun setSourceBounds(source: RNMBXRasterSource, value: Dynamic) {
if (value.type.name == "Array") {
val readableArray: ReadableArray = value.asArray()

if (readableArray.size() == 4) {
val bboxArray = Array(4) { i -> readableArray.getDouble(i) }

if(this.validateBbox(bboxArray)){
source.setSourceBounds(bboxArray)
} else {
Logger.e(RNMBXRasterSourceManager.REACT_CLASS, "source bounds contain invalid bbox")
}
if (value.type != ReadableType.Array || value.asArray().size() != 4) {
Logger.e(REACT_CLASS, "source bounds must be an array with left, bottom, top, and right values")
return
}
val bboxArray = Array(4) { i -> value.asArray().getDouble(i) }

return
}
if(!this.validateBbox(bboxArray)){
Logger.e(REACT_CLASS, "source bounds contain invalid bbox")
return
}
Logger.e(RNMBXRasterSourceManager.REACT_CLASS, "source bounds must be an array with left, bottom, top, and right values")

source.setSourceBounds(bboxArray)
}

fun validateBbox(bbox: Array<Double>): Boolean {
private fun validateBbox(bbox: Array<Double>): Boolean {
if (bbox.size != 4) return false

val (swLng, swLat, neLng, neLat) = bbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ abstract class RNMBXTileSource<T : Source?>(context: Context?) : RNMBXSource<T>(
if (attribution != null) {
builder.attribution(attribution)
}
if(bounds != null) {
val boundsArray = bounds!!.clone()
builder.bounds(Arrays.asList(*boundsArray))
bounds?.let {
builder.bounds(it.toList())
}
return builder.build()
}
Expand Down

0 comments on commit 96ee8b7

Please sign in to comment.