@@ -203,6 +203,24 @@ class MapController(
203203 zoom = zoom,
204204 )
205205
206+ /* *
207+ * Creates a Projection instance for coordinate conversions.
208+ *
209+ * The projection captures the current map state (center, zoom, view size, pan offset)
210+ * and provides methods for converting between screen and geographic coordinates.
211+ *
212+ * @return A Projection instance for the current map state
213+ */
214+ fun createProjection (): Projection =
215+ Projection (
216+ center = center,
217+ zoom = zoom,
218+ viewWidth = viewWidth,
219+ viewHeight = viewHeight,
220+ panOffsetX = panOffsetX,
221+ panOffsetY = panOffsetY,
222+ )
223+
206224 /* *
207225 * Converts screen coordinates to geographic coordinates.
208226 *
@@ -217,15 +235,15 @@ class MapController(
217235 screenY : Float ,
218236 ): LatLng {
219237 // Get center pixel coordinates at current zoom
220- val (centerPixelX, centerPixelY) = Projection .latLngToPixel(center, zoom.toInt())
238+ val (centerPixelX, centerPixelY) = ProjectionUtils .latLngToPixel(center, zoom.toInt())
221239
222240 // Convert screen coordinates to pixel coordinates
223241 // Account for view center offset and pan offset
224242 val pixelX = (centerPixelX + (screenX - viewWidth / 2 + panOffsetX).toDouble()).toInt()
225243 val pixelY = (centerPixelY + (screenY - viewHeight / 2 + panOffsetY).toDouble()).toInt()
226244
227245 // Convert pixel coordinates to LatLng
228- return Projection .pixelToLatLng(pixelX, pixelY, zoom.toInt())
246+ return ProjectionUtils .pixelToLatLng(pixelX, pixelY, zoom.toInt())
229247 }
230248
231249 /* *
@@ -432,11 +450,11 @@ class MapController(
432450 if (panOffsetX == 0f && panOffsetY == 0f ) return
433451
434452 // Convert accumulated pan offset to new center
435- val (centerPixelX, centerPixelY) = Projection .latLngToPixel(center, zoom.toInt())
453+ val (centerPixelX, centerPixelY) = ProjectionUtils .latLngToPixel(center, zoom.toInt())
436454 val newCenterPixelX = (centerPixelX + panOffsetX).toInt()
437455 val newCenterPixelY = (centerPixelY + panOffsetY).toInt()
438456
439- center = Projection .pixelToLatLng(newCenterPixelX, newCenterPixelY, zoom.toInt())
457+ center = ProjectionUtils .pixelToLatLng(newCenterPixelX, newCenterPixelY, zoom.toInt())
440458
441459 // Reset pan offset
442460 panOffsetX = 0f
@@ -466,10 +484,10 @@ class MapController(
466484 panOffsetY,
467485 )
468486
469- val (centerPixelX, centerPixelY) = Projection .latLngToPixel(center, zoom.toInt())
487+ val (centerPixelX, centerPixelY) = ProjectionUtils .latLngToPixel(center, zoom.toInt())
470488
471489 for (tile in visibleTiles) {
472- val (tilePixelX, tilePixelY) = Projection .tileToPixel(tile)
490+ val (tilePixelX, tilePixelY) = ProjectionUtils .tileToPixel(tile)
473491
474492 val screenX = (tilePixelX - centerPixelX + viewWidth / 2 - panOffsetX).toFloat()
475493 val screenY = (tilePixelY - centerPixelY + viewHeight / 2 - panOffsetY).toFloat()
@@ -549,7 +567,7 @@ class MapController(
549567 var isFirst = true
550568
551569 for (point in polyline.points) {
552- val (pixelX, pixelY) = Projection .latLngToPixel(point, zoom.toInt())
570+ val (pixelX, pixelY) = ProjectionUtils .latLngToPixel(point, zoom.toInt())
553571 val screenX = (pixelX - centerPixelX + viewWidth / 2 - panOffsetX).toFloat()
554572 val screenY = (pixelY - centerPixelY + viewHeight / 2 - panOffsetY).toFloat()
555573
@@ -593,7 +611,7 @@ class MapController(
593611 // Draw main polygon outline
594612 var isFirst = true
595613 for (point in polygon.points) {
596- val (pixelX, pixelY) = Projection .latLngToPixel(point, zoom.toInt())
614+ val (pixelX, pixelY) = ProjectionUtils .latLngToPixel(point, zoom.toInt())
597615 val screenX = (pixelX - centerPixelX + viewWidth / 2 - panOffsetX).toFloat()
598616 val screenY = (pixelY - centerPixelY + viewHeight / 2 - panOffsetY).toFloat()
599617
@@ -611,7 +629,7 @@ class MapController(
611629 if (hole.size < 3 ) continue
612630 isFirst = true
613631 for (point in hole) {
614- val (pixelX, pixelY) = Projection .latLngToPixel(point, zoom.toInt())
632+ val (pixelX, pixelY) = ProjectionUtils .latLngToPixel(point, zoom.toInt())
615633 val screenX = (pixelX - centerPixelX + viewWidth / 2 - panOffsetX).toFloat()
616634 val screenY = (pixelY - centerPixelY + viewHeight / 2 - panOffsetY).toFloat()
617635
@@ -641,7 +659,7 @@ class MapController(
641659 if (! marker.visible) continue
642660
643661 // Convert marker position to pixel coordinates
644- val (markerPixelX, markerPixelY) = Projection .latLngToPixel(marker.position, zoom.toInt())
662+ val (markerPixelX, markerPixelY) = ProjectionUtils .latLngToPixel(marker.position, zoom.toInt())
645663
646664 // Calculate screen position
647665 val screenX = (markerPixelX - centerPixelX + viewWidth / 2 - panOffsetX).toFloat()
@@ -818,11 +836,11 @@ class MapController(
818836 x : Float ,
819837 y : Float ,
820838 ): Marker ? {
821- val (centerPixelX, centerPixelY) = Projection .latLngToPixel(center, zoom.toInt())
839+ val (centerPixelX, centerPixelY) = ProjectionUtils .latLngToPixel(center, zoom.toInt())
822840
823841 // Check markers in reverse order (top to bottom) for correct z-ordering
824842 for (marker in markers.reversed()) {
825- val (markerPixelX, markerPixelY) = Projection .latLngToPixel(marker.position, zoom.toInt())
843+ val (markerPixelX, markerPixelY) = ProjectionUtils .latLngToPixel(marker.position, zoom.toInt())
826844
827845 val screenX = (markerPixelX - centerPixelX + viewWidth / 2 - panOffsetX).toFloat()
828846 val screenY = (markerPixelY - centerPixelY + viewHeight / 2 - panOffsetY).toFloat()
0 commit comments