Skip to content

Commit

Permalink
fix(android): fix queryRenderedFeaturesInRect in case rect is not con…
Browse files Browse the repository at this point in the history
…ventional format
  • Loading branch information
mfazekas committed Sep 3, 2023
1 parent 336582e commit 3ee9dcf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -964,9 +964,9 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
}
}

fun queryRenderedFeaturesInRect(rect: RectF, filter: Expression?, layerIDs: List<String>?, response: CommandResponse) {
fun queryRenderedFeaturesInRect(rect: RectF?, filter: Expression?, layerIDs: List<String>?, response: CommandResponse) {
val size = mMap!!.getMapOptions().size
val screenBox = if (rect.isEmpty()) ScreenBox(ScreenCoordinate(0.0, 0.0), ScreenCoordinate(size?.width!!.toDouble(), size?.height!!.toDouble())) else ScreenBox(
val screenBox = if (rect == null) ScreenBox(ScreenCoordinate(0.0, 0.0), ScreenCoordinate(size?.width!!.toDouble(), size?.height!!.toDouble())) else ScreenBox(
ScreenCoordinate(rect.right.toDouble(), rect.bottom.toDouble() ),
ScreenCoordinate(rect.left.toDouble(), rect.top.toDouble()),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.mapbox.rctmgl.utils.ConvertUtils
import com.mapbox.rctmgl.utils.ExpressionParser
import com.mapbox.rctmgl.utils.Logger
import com.mapbox.rctmgl.utils.extensions.toCoordinate
import com.mapbox.rctmgl.utils.extensions.toRectF
import com.mapbox.rctmgl.utils.extensions.toScreenCoordinate
import java.lang.Exception
import java.util.HashMap
Expand Down Expand Up @@ -325,7 +326,7 @@ open class RCTMGLMapViewManager(context: ReactApplicationContext) :
"queryRenderedFeaturesInRect" -> {
val layerIds = ConvertUtils.toStringList(args!!.getArray(3))
mapView.queryRenderedFeaturesInRect(
ConvertUtils.toRectF(args.getArray(1)),
if ((args.getArray(1)?.size() ?: 0) == 0) null else args.getArray(1).toRectF(),
ExpressionParser.from(args!!.getArray(2)),
if (layerIds.size == 0) null else layerIds,
response
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.mapbox.rctmgl.utils.extensions

import android.graphics.RectF
import com.facebook.react.bridge.ReadableArray
import com.mapbox.geojson.Point
import com.mapbox.maps.ScreenCoordinate
import com.mapbox.rctmgl.utils.Logger
import java.lang.Float.min
import java.lang.Float.max

fun ReadableArray.toCoordinate() : Point {
if (this.size() != 2) {
Expand All @@ -21,3 +24,15 @@ fun ReadableArray.toScreenCoordinate() : ScreenCoordinate {
}
return ScreenCoordinate(getDouble(0), getDouble(1))
}

fun ReadableArray.toRectF() : RectF? {
if (size() != 4) {
return null;
}
return RectF(
min(getDouble(3).toFloat(), getDouble(1).toFloat()),
min(getDouble(0).toFloat(), getDouble(2).toFloat()),
max(getDouble(3).toFloat(), getDouble(1).toFloat()),
max(getDouble(0).toFloat(), getDouble(2).toFloat())
)
}

0 comments on commit 3ee9dcf

Please sign in to comment.