diff --git a/android/src/main/java/com/luggmaps/LuggPolygonView.kt b/android/src/main/java/com/luggmaps/LuggPolygonView.kt index 91569a7..07064bc 100644 --- a/android/src/main/java/com/luggmaps/LuggPolygonView.kt +++ b/android/src/main/java/com/luggmaps/LuggPolygonView.kt @@ -16,6 +16,9 @@ class LuggPolygonView(context: Context) : ReactViewGroup(context) { var coordinates: List = emptyList() private set + var holes: List> = emptyList() + private set + var strokeColor: Int = Color.BLACK private set @@ -42,6 +45,10 @@ class LuggPolygonView(context: Context) : ReactViewGroup(context) { coordinates = coords } + fun setHoles(value: List>) { + holes = value + } + fun setStrokeColor(color: Int) { strokeColor = color } diff --git a/android/src/main/java/com/luggmaps/LuggPolygonViewManager.kt b/android/src/main/java/com/luggmaps/LuggPolygonViewManager.kt index ed66a8c..94c381d 100644 --- a/android/src/main/java/com/luggmaps/LuggPolygonViewManager.kt +++ b/android/src/main/java/com/luggmaps/LuggPolygonViewManager.kt @@ -47,6 +47,27 @@ class LuggPolygonViewManager : } } + @ReactProp(name = "holes") + override fun setHoles(view: LuggPolygonView, value: ReadableArray?) { + value?.let { array -> + val holesList = mutableListOf>() + for (i in 0 until array.size()) { + val holeArray = array.getArray(i) + val hole = mutableListOf() + if (holeArray != null) { + for (j in 0 until holeArray.size()) { + val coord = holeArray.getMap(j) + val lat = coord?.getDouble("latitude") ?: 0.0 + val lng = coord?.getDouble("longitude") ?: 0.0 + hole.add(LatLng(lat, lng)) + } + } + holesList.add(hole) + } + view.setHoles(holesList) + } + } + @ReactProp(name = "strokeColor", customType = "Color") override fun setStrokeColor(view: LuggPolygonView, value: Int?) { view.setStrokeColor(value ?: android.graphics.Color.BLACK) diff --git a/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt b/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt index 08dc587..9fc5486 100644 --- a/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt +++ b/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt @@ -540,6 +540,7 @@ class GoogleMapProvider(private val context: Context) : polygonView.polygon?.apply { points = polygonView.coordinates + holes = polygonView.holes fillColor = polygonView.fillColor strokeColor = polygonView.strokeColor strokeWidth = polygonView.strokeWidth.dpToPx() @@ -565,6 +566,10 @@ class GoogleMapProvider(private val context: Context) : .zIndex(polygonView.zIndex) .clickable(true) + for (hole in polygonView.holes) { + options.addHole(hole) + } + val polygon = map.addPolygon(options) polygonView.polygon = polygon polygonToViewMap[polygon] = polygonView diff --git a/docs/POLYGON.md b/docs/POLYGON.md index bd7d633..fd21a01 100644 --- a/docs/POLYGON.md +++ b/docs/POLYGON.md @@ -21,6 +21,27 @@ import { MapView, Polygon } from '@lugg/maps'; strokeWidth={2} onPress={() => console.log('Polygon pressed')} /> + + {/* Polygon with a hole */} + ``` @@ -29,6 +50,7 @@ import { MapView, Polygon } from '@lugg/maps'; | Prop | Type | Default | Description | |------|------|---------|-------------| | `coordinates` | `Coordinate[]` | **required** | Array of coordinates forming the polygon boundary | +| `holes` | `Coordinate[][]` | - | Array of coordinate arrays representing interior holes | | `fillColor` | `ColorValue` | - | Fill color of the polygon | | `strokeColor` | `ColorValue` | - | Stroke (outline) color | | `strokeWidth` | `number` | - | Stroke width in points | diff --git a/example/shared/src/Home.tsx b/example/shared/src/Home.tsx index a5b1ad3..67ba56d 100644 --- a/example/shared/src/Home.tsx +++ b/example/shared/src/Home.tsx @@ -134,7 +134,7 @@ function HomeContent() { [] ); - const addMarker = () => { + const addMarker = (coordinate = lastCoordinate.current) => { const type = randomFrom(MARKER_TYPES); const id = Date.now().toString(); @@ -143,7 +143,7 @@ function HomeContent() { { id, name: `marker-${id}`, - coordinate: lastCoordinate.current, + coordinate, type, anchor: { x: 0.5, y: type === 'icon' ? 1 : 0.5 }, text: randomLetter(), @@ -190,7 +190,10 @@ function HomeContent() { userLocationEnabled={locationPermission} onReady={handleMapReady} onPress={(e) => formatPressEvent(e, 'Press')} - onLongPress={(e) => formatPressEvent(e, 'Long press')} + onLongPress={(e) => { + formatPressEvent(e, 'Long press'); + addMarker(e.nativeEvent.coordinate); + }} onCameraMove={(e) => formatCameraEvent(e, false)} onCameraIdle={(e) => formatCameraEvent(e, true)} onMarkerPress={(e, m) => formatPressEvent(e, `Marker(${m.name})`)} @@ -222,7 +225,7 @@ function HomeContent() { > {statusText} -