Skip to content
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 @@ -227,7 +227,7 @@ object W3WMapDefaults {
fun defaultGridLinesConfig(
isGridEnabled: Boolean = true,
zoomSwitchLevel: Float = DEFAULT_MAP_ZOOM_SWITCH_LEVEL,
gridLineWidth: Dp = 2.dp,
gridLineWidth: Dp = 1.5.dp,
gridScale: Float = 6f
): GridLinesConfig {
return GridLinesConfig(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.what3words.components.compose.maps.extensions

import com.google.maps.android.collections.PolylineManager
import com.what3words.androidwrapper.What3WordsAndroidWrapper
import com.what3words.core.types.geometry.W3WCoordinates
import com.what3words.core.types.geometry.W3WLine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.what3words.components.compose.maps.models
import android.os.Parcel
import android.os.Parcelable
import androidx.compose.runtime.Immutable
import com.what3words.components.compose.maps.W3WMapManager
import com.what3words.core.types.domain.W3WAddress
import com.what3words.core.types.domain.W3WCountry
import com.what3words.core.types.geometry.W3WCoordinates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import com.google.android.gms.maps.model.BitmapDescriptor
import com.google.android.gms.maps.model.BitmapDescriptorFactory
import com.google.android.gms.maps.model.LatLng
Expand All @@ -35,6 +36,7 @@ import com.what3words.components.compose.maps.utils.getMarkerBitmap
import com.what3words.components.compose.maps.utils.getPinBitmap
import com.what3words.core.types.domain.W3WAddress
import com.what3words.core.types.geometry.W3WCoordinates
import com.what3words.design.library.ui.extensions.toFloatPx
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
Expand Down Expand Up @@ -68,7 +70,8 @@ fun W3WGoogleMapDrawer(
W3WGoogleMapDrawGridLines(
verticalLines = state.gridLines.verticalLines,
horizontalLines = state.gridLines.horizontalLines,
gridLineColor = mapColor.gridLineColor
gridLineColor = mapColor.gridLineColor,
gridLineWidth = mapConfig.gridLineConfig.gridLineWidth
)
}

Expand Down Expand Up @@ -153,7 +156,8 @@ fun W3WGoogleMapDrawer(
zoomLevel = cameraState.getZoomLevel(),
zoomSwitchLevel = mapConfig.gridLineConfig.zoomSwitchLevel,
selectedAddress = state.selectedAddress,
markersInSelectedAddress = markersInSelectedAddress
markersInSelectedAddress = markersInSelectedAddress,
gridLineWidth = mapConfig.gridLineConfig.gridLineWidth
)
}
}
Expand All @@ -175,7 +179,8 @@ fun W3WGoogleMapDrawer(
fun W3WGoogleMapDrawGridLines(
verticalLines: List<W3WCoordinates>,
horizontalLines: List<W3WCoordinates>,
gridLineColor: Color
gridLineColor: Color,
gridLineWidth: Dp
) {
val horizontalPolylines = remember(horizontalLines) {
horizontalLines.map { LatLng(it.lat, it.lng) }
Expand All @@ -188,15 +193,15 @@ fun W3WGoogleMapDrawGridLines(
Polyline(
points = horizontalPolylines,
color = gridLineColor,
width = 1f,
width = gridLineWidth.toFloatPx(),
clickable = false,
zIndex = 1f
)

Polyline(
points = verticalPolylines,
color = gridLineColor,
width = 1f,
width = gridLineWidth.toFloatPx(),
clickable = false,
zIndex = 1f
)
Expand All @@ -214,6 +219,7 @@ fun W3WGoogleMapDrawGridLines(
* @param zoomSwitchLevel Zoom level at which to switch between detail modes
* @param selectedAddress The currently selected what3words address
* @param markersInSelectedAddress List of markers that exist in the selected address's square
* @param gridLineWidth The base width for grid lines. Used to calculate the outline width when zoomed in.
*/
@Composable
@GoogleMapComposable
Expand All @@ -222,24 +228,24 @@ fun W3WGoogleMapDrawSelectedAddress(
zoomLevel: Float,
zoomSwitchLevel: Float,
selectedAddress: W3WAddress,
markersInSelectedAddress: ImmutableList<W3WMarker>
markersInSelectedAddress: ImmutableList<W3WMarker>,
gridLineWidth: Dp,
) {

val density = LocalDensity.current.density

val drawZoomIn = remember(zoomLevel) {
derivedStateOf {
zoomLevel > zoomSwitchLevel && zoomLevel >= MIN_SUPPORT_GRID_ZOOM_LEVEL_GOOGLE
}
}

val gridLineWidth = remember(zoomLevel) {
derivedStateOf {
getSelectedGridWidth(zoomLevel, density)
if (drawZoomIn.value) {
val gridLineWidthInPixels = gridLineWidth.toFloatPx()

val gridLineWidth = remember(zoomLevel) {
derivedStateOf {
getSelectedGridWidth(zoomLevel, gridLineWidthInPixels)
}
}
}

if (drawZoomIn.value) {
DrawZoomInSelectedAddress(
selectedMarkerColor = markerColors.selectedColor,
gridLineWidth = gridLineWidth.value,
Expand Down Expand Up @@ -534,17 +540,18 @@ fun rememberUpdatedMarkerState(newPosition: LatLng) =


/**
* Calculates the appropriate width for the selected grid based on the zoom level.
* Calculates the appropriate width for the selected grid outline based on the zoom level.
*
* This function adjusts the grid line width according to the current zoom level
* to ensure proper visibility at different scales.
* to ensure the selected square outline is clearly visible at different scales.
* The outline becomes thicker at higher zoom levels.
*
* @param zoomLevel The current map zoom level
* @param density The display density factor
* @return The calculated width for the selected grid lines
* @param zoomLevel The current map zoom level.
* @param gridLineWidth The base width of the grid line in pixels.
* @return The calculated width for the selected grid outline in pixels.
*/
private fun getSelectedGridWidth(zoomLevel: Float, density: Float): Float {
return density * if (zoomLevel < 19) {
private fun getSelectedGridWidth(zoomLevel: Float, gridLineWidth: Float): Float {
return gridLineWidth * if (zoomLevel < 19) {
1f
} else {
1.5f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import com.google.gson.JsonPrimitive
import com.mapbox.geojson.Feature
import com.mapbox.geojson.FeatureCollection
Expand Down Expand Up @@ -91,6 +92,7 @@ fun W3WMapBoxDrawer(
verticalLines = state.gridLines.verticalLines,
horizontalLines = state.gridLines.horizontalLines,
gridLineColor = mapColor.gridLineColor,
gridLineWidth = mapConfig.gridLineConfig.gridLineWidth
)
}

Expand Down Expand Up @@ -174,7 +176,8 @@ fun W3WMapBoxDrawer(
zoomLevel = cameraState.getZoomLevel(),
zoomSwitchLevel = mapConfig.gridLineConfig.zoomSwitchLevel,
selectedAddress = state.selectedAddress,
markersInSelectedSquare = markersInSelectedSquare
markersInSelectedSquare = markersInSelectedSquare,
gridLineWidth = mapConfig.gridLineConfig.gridLineWidth
)
}
}
Expand All @@ -195,7 +198,8 @@ fun W3WMapBoxDrawer(
fun W3WMapBoxDrawGridLines(
verticalLines: List<W3WCoordinates>,
horizontalLines: List<W3WCoordinates>,
gridLineColor: Color
gridLineColor: Color,
gridLineWidth: Dp,
) {
val verticalSourceState = remember(horizontalLines) {
GeoJsonSourceState(
Expand Down Expand Up @@ -237,7 +241,7 @@ fun W3WMapBoxDrawGridLines(
LineLayerState().apply {
lineOcclusionOpacity = DoubleValue(0.0)
lineEmissiveStrength = DoubleValue(1.0)
lineWidth = DoubleValue(1.0)
lineWidth = DoubleValue(gridLineWidth.value.toDouble())
lineColor = ColorValue(gridLineColor)
}
}
Expand Down Expand Up @@ -276,6 +280,7 @@ fun W3WMapBoxDrawSelectedAddress(
zoomSwitchLevel: Float,
selectedAddress: W3WAddress,
markersInSelectedSquare: ImmutableList<W3WMarker>,
gridLineWidth: Dp,
) {
val drawZoomIn = remember(zoomLevel) {
derivedStateOf {
Expand All @@ -286,7 +291,7 @@ fun W3WMapBoxDrawSelectedAddress(
if (drawZoomIn.value) {
val gridLineWidth = remember(zoomLevel) {
derivedStateOf {
getSelectedGridWidth(zoomLevel)
getSelectedGridWidth(zoomLevel, gridLineWidth.value)
}
}

Expand Down Expand Up @@ -606,10 +611,10 @@ private fun DrawZoomInSelectedAddress(
* @param zoomLevel The current map zoom level
* @return The calculated width for the selected grid lines
*/
private fun getSelectedGridWidth(zoomLevel: Float): Double {
return if (zoomLevel < 20) {
2.0
private fun getSelectedGridWidth(zoomLevel: Float, gridLineWidth: Float): Double {
return gridLineWidth * if (zoomLevel < 20) {
1.5
} else {
2.5
2.0
}
}
Loading